Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
‹EYc@s¸dZddlmZmZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZd	d
lm
Z
ejd„ƒZdefd
„ƒYZdS(sãProvides an abstraction for obtaining database schema information.

Usage Notes:

Here are some general conventions when accessing the low level inspector
methods such as get_table_names, get_columns, etc.

1. Inspector methods return lists of dicts in most cases for the following
   reasons:

   * They're both standard types that can be serialized.
   * Using a dict instead of a tuple allows easy expansion of attributes.
   * Using a list for the outer structure maintains order and is easy to work
     with (e.g. list comprehension [d['name'] for d in cols]).

2. Records that contain a name, such as the column name in a column record
   use the key 'name'. So for most return values, each record will have a
   'name' attribute..
i(texctsql(tschema(tutil(t
TypeEngine(t
deprecated(ttopological(t
inspectioni(tConnectablecOsª|jddƒ}|dkr1|||||ŽS|jtd„|Dƒƒtd„|jƒDƒƒf}|j|ƒ}|dkr¦|||||Ž}|||<n|S(Nt
info_cachecss'|]}t|tjƒr|VqdS(N(t
isinstanceRtstring_types(t.0ta((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>-scssA|]7\}}t|tjtjtfƒr||fVqdS(N(R
RRt	int_typestfloat(Rtktv((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>.s	(tgettNonet__name__ttupletitems(tfntselftcontargstkwR	tkeytret((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pytcache&s
t	InspectorcBs@eZdZd„Zed„ƒZejeƒd„ƒZ	e
d„ƒZd„Zddd„Zdd„Zd„Zd	„Zdd
„Zdd„Zdd„Zdd
„Zeddƒdd„ƒZdd„Zdd„Zdd„Zdd„Zdd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"RS(smPerforms database schema inspection.

    The Inspector acts as a proxy to the reflection methods of the
    :class:`~sqlalchemy.engine.interfaces.Dialect`, providing a
    consistent interface as well as caching support for previously
    fetched metadata.

    A :class:`.Inspector` object is usually created via the
    :func:`.inspect` function::

        from sqlalchemy import inspect, create_engine
        engine = create_engine('...')
        insp = inspect(engine)

    The inspection method above is equivalent to using the
    :meth:`.Inspector.from_engine` method, i.e.::

        engine = create_engine('...')
        insp = Inspector.from_engine(engine)

    Where above, the :class:`~sqlalchemy.engine.interfaces.Dialect` may opt
    to return an :class:`.Inspector` subclass that provides additional
    methods specific to the dialect's target database.

    cCsn||_t|dƒr'|j|_n	||_|j|krR|jƒjƒn|jj|_i|_dS(sjInitialize a new :class:`.Inspector`.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        For a dialect-specific instance of :class:`.Inspector`, see
        :meth:`.Inspector.from_engine`

        tengineN(tbindthasattrR tconnecttclosetdialectR	(RR!((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyt__init__Vs
		cCs,t|jdƒr"|jj|ƒSt|ƒS(s‘Construct a new dialect-specific Inspector object from the given
        engine or connection.

        :param bind: a :class:`~sqlalchemy.engine.Connectable`,
          which is typically an instance of
          :class:`~sqlalchemy.engine.Engine` or
          :class:`~sqlalchemy.engine.Connection`.

        This method differs from direct a direct constructor call of
        :class:`.Inspector` in that the
        :class:`~sqlalchemy.engine.interfaces.Dialect` is given a chance to
        provide a dialect-specific :class:`.Inspector` instance, which may
        provide additional methods.

        See the example at :class:`.Inspector`.

        t	inspector(R"R%R'R(tclsR!((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pytfrom_enginerscCs
tj|ƒS(N(RR)(R!((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyt_insp‰scCs
|jjS(sÏReturn the default schema name presented by the dialect
        for the current engine's database user.

        E.g. this is typically ``public`` for Postgresql and ``dbo``
        for SQL Server.

        (R%tdefault_schema_name(R((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR+s	cCs2t|jdƒr.|jj|jd|jƒSgS(s!Return all schema names.
        tget_schema_namesR	(R"R%R,R!R	(R((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR,˜s
cCsÑt|jdƒr6|jj|j|d|jƒ}n|jj|ƒ}|dkrÍg}xU|D]M}xD|j||ƒD]0}||dkrz|j|d|fƒqzqzWqaWt	t
j||ƒƒ}n|S(sãReturn all table names in referred to within a particular schema.

        The names are expected to be real tables only, not views.
        Views are instead returned using the :meth:`.Inspector.get_view_names`
        method.


        :param schema: Schema name. If ``schema`` is left at ``None``, the
         database's default schema is
         used, else the named schema is searched.  If the database does not
         support named schemas, behavior is undefined if ``schema`` is not
         passed as ``None``.  For special quoting, use :class:`.quoted_name`.

        :param order_by: Optional, may be the string "foreign_key" to sort
         the result on foreign key dependencies.  Does not automatically
         resolve cycles, and will raise :class:`.CircularDependencyError`
         if cycles exist.

         .. deprecated:: 1.0.0 - see
            :meth:`.Inspector.get_sorted_table_and_fkc_names` for a version
            of this which resolves foreign key cycles between tables
            automatically.

         .. versionchanged:: 0.8 the "foreign_key" sorting sorts tables
            in order of dependee to dependent; that is, in creation
            order, rather than in drop order.  This is to maintain
            consistency with similar features such as
            :attr:`.MetaData.sorted_tables` and :func:`.util.sort_tables`.

        .. seealso::

            :meth:`.Inspector.get_sorted_table_and_fkc_names`

            :attr:`.MetaData.sorted_tables`

        tget_table_namesR	tforeign_keytreferred_table(R"R%R-R!R	R ttable_namestget_foreign_keystappendtlistRtsort(RRtorder_byttnamesttuplesttnametfkey((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR-¡s&	
"csµt|jdƒr6|jj|j|d|jƒ}n|jj|ƒ}tƒ}tƒ}i}x‚|D]z}|j||ƒ}tg|D]}|d^q‰ƒ||<x8|D]0}	||	dkr­|j	|	d|fƒq­q­WqgWyt
tj||ƒƒ}
Wntt
jk
rw}xC|jD]8‰|jˆƒ|j‡fd†|ˆdDƒƒq Wt
tj||ƒƒ}
nXg|
D]}|||j|ƒf^qdt
|ƒfgS(sxReturn dependency-sorted table and foreign key constraint names in
        referred to within a particular schema.

        This will yield 2-tuples of
        ``(tablename, [(tname, fkname), (tname, fkname), ...])``
        consisting of table names in CREATE order grouped with the foreign key
        constraint names that are not detected as belonging to a cycle.
        The final element
        will be ``(None, [(tname, fkname), (tname, fkname), ..])``
        which will consist of remaining
        foreign key constraint names that would require a separate CREATE
        step after-the-fact, based on dependencies between tables.

        .. versionadded:: 1.0.-

        .. seealso::

            :meth:`.Inspector.get_table_names`

            :func:`.sort_tables_and_constraints` - similar method which works
             with an already-given :class:`.MetaData`.

        R-R	tnameR/c3s|]}ˆd|fVqdS(iN((Rtfkc(tedge(sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>siN(R"R%R-R!R	R R0tsetR1taddR3RR4RtCircularDependencyErrortedgestremovetupdatet
differenceR(RRR6R7tremaining_fkcstfknames_for_tableR8tfkeystfkR9tcandidate_sortterr((R<sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pytget_sorted_table_and_fkc_namesÕs4			
$
"
&cCs|jj|jd|jƒS(sÊreturn a list of temporary table names for the current bind.

        This method is unsupported by most dialects; currently
        only SQLite implements it.

        .. versionadded:: 1.0.0

        R	(R%tget_temp_table_namesR!R	(R((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRKs		cCs|jj|jd|jƒS(sÉreturn a list of temporary view names for the current bind.

        This method is unsupported by most dialects; currently
        only SQLite implements it.

        .. versionadded:: 1.0.0

        R	(R%tget_temp_view_namesR!R	(R((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRLs		cKs;t|jdƒr7|jj|j||d|j|SiS(sÑReturn a dictionary of options specified when the table of the
        given name was created.

        This currently includes some options that apply to MySQL tables.

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        tget_table_optionsR	(R"R%RMR!R	(Rt
table_nameRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRM's
	
cCs|jj|j|d|jƒS(s±Return all view names in `schema`.

        :param schema: Optional, retrieve names from a non-default schema.
         For special quoting, use :class:`.quoted_name`.

        R	(R%tget_view_namesR!R	(RR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRO;scCs"|jj|j||d|jƒS(s±Return definition for `view_name`.

        :param schema: Optional, retrieve names from a non-default schema.
         For special quoting, use :class:`.quoted_name`.

        R	(R%tget_view_definitionR!R	(Rt	view_nameR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRPFs	cKse|jj|j||d|j|}x7|D]/}|d}t|tƒs.|ƒ|d<q.q.W|S(sìReturn information about columns in `table_name`.

        Given a string `table_name` and an optional string `schema`, return
        column information as a list of dicts with these keys:

        name
          the column's name

        type
          :class:`~sqlalchemy.types.TypeEngine`

        nullable
          boolean

        default
          the column's default value

        attrs
          dict containing optional column attributes

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        R	ttype(R%tget_columnsR!R	R
R(RRNRRtcol_defstcol_deftcoltype((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRSQs	

s0.7sKCall to deprecated method get_primary_keys.  Use get_pk_constraint instead.cKs)|jj|j||d|j|dS(sÈReturn information about primary keys in `table_name`.

        Given a string `table_name`, and an optional string `schema`, return
        primary key information as a list of column names.
        R	tconstrained_columns(R%tget_pk_constraintR!R	(RRNRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pytget_primary_keysys	cKs%|jj|j||d|j|S(s˜Return information about primary key constraint on `table_name`.

        Given a string `table_name`, and an optional string `schema`, return
        primary key information as a dictionary with these keys:

        constrained_columns
          a list of column names that make up the primary key

        name
          optional name of the primary key constraint.

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        R	(R%RXR!R	(RRNRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRX†scKs%|jj|j||d|j|S(s—Return information about foreign_keys in `table_name`.

        Given a string `table_name`, and an optional string `schema`, return
        foreign key information as a list of dicts with these keys:

        constrained_columns
          a list of column names that make up the foreign key

        referred_schema
          the name of the referred schema

        referred_table
          the name of the referred table

        referred_columns
          a list of column names in the referred table that correspond to
          constrained_columns

        name
          optional name of the foreign key constraint.

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        R	(R%R1R!R	(RRNRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR1žscKs%|jj|j||d|j|S(sReturn information about indexes in `table_name`.

        Given a string `table_name` and an optional string `schema`, return
        index information as a list of dicts with these keys:

        name
          the index's name

        column_names
          list of column names in order

        unique
          boolean

        dialect_options
          dict of dialect-specific index options.  May not be present
          for all dialects.

          .. versionadded:: 1.0.0

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        R	(R%tget_indexesR!R	(RRNRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRZÁscKs%|jj|j||d|j|S(sReturn information about unique constraints in `table_name`.

        Given a string `table_name` and an optional string `schema`, return
        unique constraint information as a list of dicts with these keys:

        name
          the unique constraint's name

        column_names
          list of column names in order

        :param table_name: string name of the table.  For special quoting,
         use :class:`.quoted_name`.

        :param schema: string schema name; if omitted, uses the default schema
         of the database connection.  For special quoting,
         use :class:`.quoted_name`.

        .. versionadded:: 0.8.4

        R	(R%tget_unique_constraintsR!R	(RRNRR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR[ãs	csŸ|jj}ˆj}ˆj}t‡fd†|jDƒƒ}|j||ˆj}|rkˆj|ƒnt	j
r¿t|tƒr˜|j
|jƒ}nt|tƒr¿|j
|jƒ}q¿nt}	i}
x?|j||ˆjD]%}t}	|jˆ||||
ƒqäW|	s(tjˆjƒ‚n|j||ˆ|
|ƒ|j||ˆ|
||ƒ|j||ˆ|
|||ƒ|j||ˆ|
|||ƒdS(sGiven a Table object, load its internal constructs based on
        introspection.

        This is the underlying method used by most dialects to produce
        table reflection.  Direct usage is like::

            from sqlalchemy import create_engine, MetaData, Table
            from sqlalchemy.engine import reflection

            engine = create_engine('...')
            meta = MetaData()
            user_table = Table('user', meta)
            insp = Inspector.from_engine(engine)
            insp.reflecttable(user_table, None)

        :param table: a :class:`~sqlalchemy.schema.Table` instance.
        :param include_columns: a list of string column names to include
          in the reflection process.  If ``None``, all columns are reflected.

        c3s6|],}|ˆjkr|ˆjj|ƒfVqdS(N(tdialect_kwargsR(RR(ttable(sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>sN(R!R%RR:tdicttreflection_optionsRMR\t_validate_dialect_kwargsRtpy2kR
tstrtdecodetencodingtFalseRStTruet_reflect_columnRtNoSuchTableErrort_reflect_pkt_reflect_fkt_reflect_indexest_reflect_unique_constraints(RR]tinclude_columnstexclude_columnsR%RRNR_ttbl_optstfound_tabletcols_by_orig_nametcol_d((R]sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pytreflecttableýsH					

c
s<ˆd}|jj||ˆƒˆd}|r<||ksN|rR||krRdSˆd}t‡fd†dddddgDƒƒ}	g}
ˆjd	ƒdk	rÎ|
jtjtj	ˆd	ƒd
t
ƒƒndˆkrí|jˆ|
ƒntj|||
|	Ž||<}|j
|jkr+t
|_n|j|ƒdS(NR:RRc3s+|]!}|ˆkr|ˆ|fVqdS(N((RR(Rr(sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>^stnullablet
autoincrementtquotetinfoRtdefaultt
_reflectedtsequence(tdispatchtcolumn_reflectR^RRR2t	sa_schemat
DefaultClauseRttextRft_reflect_col_sequencetColumnRtprimary_keyt
append_column(RR]RrRmRnRqt	orig_nameR:RVtcol_kwtcolargstcol((RrsQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRgLs*


  cCs{d|krw|d}tj|dddƒ}d|krK|d|_nd|krg|d|_n|j|ƒndS(NRzR:itstartt	increment(R}tSequenceRˆR‰R2(RRrR†tseqRz((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR€xs
c	Csƒ|j|||j}|rg|dD](}||kr)||kr)||^q)}|jdƒ|j_|jj|ƒndS(NRWR:(RXR\RR‚R:t_reload(	RRNRR]RqRntpk_constpktpk_cols((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRiƒs(cCs»|j|||j}xœ|D]”}|d}	g|dD]%}
|
|krY||
jn|
^q:}|r†t|ƒj|ƒr†qn|d}|d}
|d}g}|dk	rtj|
|jdt	d|d|j
|x‹|D]%}|jd	j||
|gƒƒqèWn[tj|
|jdt	d|j
dtj
|x*|D]"}|jd	j|
|gƒƒqIWd
|krˆ|d
}ni}|jtj|||	dt	|ƒqWdS(NR:RWtreferred_schemaR/treferred_columnstautoloadRt
autoload_witht.toptionstlink_to_name(R1R\RR=tintersectionRR}tTabletmetadataRfR!R2tjointBLANK_SCHEMAtappend_constrainttForeignKeyConstraint(RRNRR]RqRnR_RFtfkey_dtconnametcRWRR/R‘trefspectcolumnR•((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRj–sD

3	



	
 
	c	Csq|j||ƒ}xX|D]P}	|	d}
|	d}|	d}|	jddƒ}
|	jdiƒ}|	jdƒ}|r²t|ƒj|ƒr²tjd|
d	j|ƒfƒqn|r¾qng}xp|D]h}y'||krê||n
|j|}Wn+tk
r%tjd
|
||fƒqËX|j	|ƒqËWt
j|
|tt
|jƒƒd|fgƒŽqWdS(NR:tcolumn_namestuniqueRRtindextdialect_optionstduplicates_constraints5Omitting %s key for (%s), key covers omitted columns.s, s5%s key '%s' was not located in columns for table '%s'(RZRR=tissubsetRtwarnRšR tKeyErrorR2R}tIndexR^R3R(RRNRR]RqRmRnR_tindexestindex_dR:tcolumnsR¤tflavorR¦t
duplicatestidx_colsR tidx_col((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRkÅs8




'
cCs=y|j||ƒ}Wntk
r*dSXx|D]}	|	d}
|	d}|	jdƒ}|r—t|ƒj|ƒr—tjddj|ƒƒq2n|r£q2ng}
xm|D]e}y'||krÏ||n
|j|}Wn(t	k
rtjd||fƒq°X|
j
|ƒq°W|jtj
d|
|
Œƒq2WdS(NR:R£tduplicates_indexsDOmitting unique constraint key for (%s), key covers omitted columns.s, sDunique constraint key '%s' was not located in columns for table '%s'(R[tNotImplementedErrorRR=R¨RR©RšR RªR2RœR}tUniqueConstraint(RRNRR]RqRmRnR_tconstraintstconst_dRŸR®R°tconstrained_colsR tconstrained_col((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyRlïs6




'
N((#Rt
__module__t__doc__R&tclassmethodR)Rt	_inspectsRR*tpropertyR+R,RR-RJRKRLRMRORPRSRRYRXR1RZR[RsRgR€RiRjRkRl(((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyR;s6			4:		(#"O	,			/	*N(R»tRRRR}Rtsql.type_apiRRRRtbaseRt	decoratorRtobjectR(((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/engine/reflection.pyt<module>s