• File: reflection.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyc
  • Date Modified: 08/05/2019 10:14 AM
  • File size: 29.12 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

4]c@sdZddlmZddlmZddlmZddlmZddlmZddlmZdd	lm	Z
dd
lmZddlm
Z
ddlmZejd
ZdefdYZdS(sProvides 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(tConnectablei(texc(t
inspection(tsql(tutil(t	operators(tschema(t
TypeEngine(t
deprecated(ttopologicalcOs|jdd}|dkr1|||||S|jtd|Dtd|jDf}|j|}|dkr|||||}|||<n|S(Nt
info_cachecss'|]}t|tjr|VqdS(N(t
isinstanceRtstring_types(t.0ta((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>/scssA|]7\}}t|tjtjtfr||fVqdS(N(RRRt	int_typestfloat(R
tktv((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>1s	(tgettNonet__name__ttupletitems(tfntselftcontargstkwR
tkeytret((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytcache(s
t	InspectorcBseZdZdZedZejedZ	e
dZdZe
jdd'd(d(d	Zd(d
ZdZdZd(d
Zd(dZd(dZd(dZeddd(dZd(dZd(dZd(dZd(dZd(dZd(dZd)e d(dZ!dZ"dZ#dZ$dZ%de&j'fd e&j(fd!e&j)fd"e&j*fgZ+d#Z,d$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|dr'|j|_n	||_|j|krR|jjn|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"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt__init__Xs
		cCs,t|jdr"|jj|St|S(sConstruct 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"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytfrom_enginetscCs
tj|S(N(R R*(R"((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt_inspscCs
|jjS(sReturn 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((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR,s	cCs2t|jdr.|jj|jd|jSgS(s!Return all schema names.
        tget_schema_namesR
(R#R&R-R"R
(R((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR-s	torder_bys1.0sThe :paramref:`get_table_names.order_by` parameter is deprecated and will be removed in a future release.  Please refer to :meth:`.Inspector.get_sorted_table_and_fkc_names` for a more comprehensive solution to resolving foreign key cycles between tables.cCst|jdr6|jj|j|d|j}n|jj|}|dkrg}xU|D]M}xD|j||D]0}||dkrz|j|d|fqzqzWqaWt	t
j||}n|S(sReturn 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.

        .. 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_keystappendtlistR	tsort(RRR.ttnamesttuplesttnametfkey((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR/s%	
"cst|jdr6|jj|j|d|j}n|jj|}t}t}i}x|D]z}|j||}tg|D]}|d^q||<x8|D]0}	||	dkr|j	|	d|fqqWqgWyt
tj||}
Wntt
jk
rw}xC|jD]8|j|jfd|dDq 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
tnameR1c3s|]}d|fVqdS(iN((R
tfkc(tedge(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>siN(R#R&R/R"R
R!R2tsetR3taddR5R	R6RtCircularDependencyErrortedgestremovetupdatet
differenceR(RRR7R8tremaining_fkcstfknames_for_tableR9tfkeystfkR:tcandidate_sortterr((R=sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytget_sorted_table_and_fkc_namess0			
'
"
#&cCs|jj|jd|jS(sreturn 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((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRLs		cCs|jj|jd|jS(sreturn 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((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRMs		cKs;t|jdr7|jj|j||d|j|SiS(sReturn 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&RNR"R
(Rt
table_nameRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRN*s	cCs|jj|j|d|jS(sReturn 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((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRP>s	cCs"|jj|j||d|jS(sReturn 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((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRQJs	cKse|jj|j||d|j|}x7|D]/}|d}t|ts.||d<q.q.W|S(sReturn 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`` - the type of this column; an instance of
          :class:`~sqlalchemy.types.TypeEngine`

        * ``nullable`` - boolean flag if the column is NULL or NOT NULL

        * ``default`` - the column's server default value - this is returned
          as a string SQL expression.

        * ``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`.

        :return: list of dictionaries, each representing the definition of
         a database column.

        R
ttype(R&tget_columnsR"R
RR(RRORRtcol_defstcol_deftcoltype((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRTVs	

s0.7sThe :meth:`.Inspector.get_primary_keys` method is deprecated and will be removed in a future release.  Please refer to the :meth:`.Inspector.get_pk_constraint` method.cKs)|jj|j||d|j|dS(sReturn 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
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytget_primary_keys~s
	cKs%|jj|j||d|j|S(sReturn 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&RYR"R
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRYs	cKs%|jj|j||d|j|S(sReturn 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&R3R"R
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR3s	cKs%|jj|j||d|j|S(sReturn 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

        column_sorting
          optional dict mapping column names to tuple of sort keywords,
          which may include ``asc``, ``desc``, ``nullsfirst``, ``nullslast``.

          .. versionadded:: 1.3.5

        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
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR[s$	cKs%|jj|j||d|j|S(soReturn 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`.

        R
(R&tget_unique_constraintsR"R
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR\s	cKs%|jj|j||d|j|S(sReturn information about the table comment for ``table_name``.

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

        text
            text of the comment.

        Raises ``NotImplementedError`` for a dialect that does not support
        comments.

        .. versionadded:: 1.2

        R
(R&tget_table_commentR"R
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR]s	cKs%|jj|j||d|j|S(sReturn information about check constraints in `table_name`.

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

        name
          the check constraint's name

        sqltext
          the check constraint's SQL expression

        :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:: 1.1.0

        R
(R&tget_check_constraintsR"R
(RRORR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR^s	c	s|dk	r,|krdS|jn|jj}|jj}j}tfd|jD}	|j||j	}
|
rj
|
ntjrt
|tr|j|j}nt
|tr|j|j}qnt}i}x?|j||j	D]%}
t}|j|
|||qW|s]tjjn|j|||||j|||||||	|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.reflection import Inspector

            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.

        Nc3s6|],}|jkr|jj|fVqdS(N(tdialect_kwargsR(R
R(ttable(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>hs(RR?R"R&tschema_for_objectR;tdicttreflection_optionsRNR_t_validate_dialect_kwargsRtpy2kRtstrtdecodetencodingtFalseRTtTruet_reflect_columnRtNoSuchTableErrort_reflect_pkt_reflect_fkt_reflect_indexest_reflect_unique_constraintst_reflect_check_constraintst_reflect_table_comment(RR`tinclude_columnstexclude_columnstresolve_fkst
_extend_onR&RRORcttbl_optstfound_tabletcols_by_orig_nametcol_d((R`sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pytreflecttable:s			c
sd}|jj||d}|r<||ksN|rR||krRdSd}tfddddddd	gD}	d
kr|	jd
ng}
jddk	rCd}t|tjj	rt
j|dt}n7t|t
j
s3t
jtjddt}n|
j|nd
krb|j|
nt
j|||
|	||<}|j|jkrt|_n|j|dS(NR;RSc3s+|]!}|kr||fVqdS(N((R
R(Rz(sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pys	<genexpr>stnullablet
autoincrementtquotetinfoRtcommenttdialect_optionstdefaultt
_reflectedtsequence(tdispatchtcolumn_reflectRbRCRRRRtelementst
TextClauset	sa_schemat
DefaultClauseRjtFetchedValuettextR4t_reflect_col_sequencetColumnRtprimary_keyt
append_column(
RR`RzRsRtRyt	orig_nameR;RWtcol_kwtcolargsRtcol((RzsO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRksB



cCs{d|krw|d}tj|ddd}d|krK|d|_nd|krg|d|_n|j|ndS(NRR;itstartt	increment(RtSequenceRRR4(RRzRtseqR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRs
c	Cs|j|||j}|rg|dD](}||kr)||kr)||^q)}|jd|j_|jj|ndS(NRXR;(RYR_RRR;t_reload(	RRORR`RyRttpk_constpktpk_cols((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRms(c	
Cs|j|||j}	x|	D]}
|
d}g|
dD]%}||krY||jn|^q:}
|rt|
j|rqn|
d}|
d}|
d}g}|dk	r#|rtj||jdt	d|d|j
d	||nx|D]%}|jd
j|||gqWnj|r`tj||jdt	d|j
dtj
d	||nx*|D]"}|jd
j||gqgWd|
kr|
d}ni}|jtj|
||dt	|qWdS(
NR;RXtreferred_schemaR1treferred_columnstautoloadRt
autoload_withRvt.toptionstlink_to_name(R3R_RR>tintersectionRRtTabletmetadataRjR"R4tjointBLANK_SCHEMAtappend_constrainttForeignKeyConstraint(RRORR`RyRtRuRvRcRGtfkey_dtconnametcRXRR1RtrefspectcolumnR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRns^

3	


		

 			

 
tasctdesct
nullsfirstt	nullslastc
Cs|j||}x|D]}	|	d}
|	d}|	jdi}|	d}
|	jdd}|	jdi}|	jd}|rt|j|rtjd	|d
j|fqn|rqng}x|D]}y'||kr||n
|j|}Wn.tk
r:tjd|||fqnX|j|d
}x2|j	D]'\}}||krW||}qWqWW|j
|qWtj|
d||t
t|jd|
fgqWdS(NR;tcolumn_namestcolumn_sortingtuniqueRStindexRtduplicates_constraints5Omitting %s key for (%s), key covers omitted columns.s, s5%s key '%s' was not located in columns for table '%s't_table((R[RR>tissubsetRtwarnRRtKeyErrort_index_sort_exprsR4RtIndexRbR5R(RRORR`RyRsRtRctindexestindex_dR;tcolumnsRRtflavorRt
duplicatestidx_colsRtidx_colt	c_sortingRtop((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRogsF





cCs=y|j||}Wntk
r*dSXx|D]}	|	d}
|	d}|	jd}|rt|j|rtjddj|q2n|rq2ng}
xm|D]e}y'||kr||n
|j|}Wn(t	k
rtjd||fqX|
j
|qW|jtj
d|
|
q2WdS(NR;Rtduplicates_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>RRRRRRR4RRtUniqueConstraint(RRORR`RyRsRtRctconstraintstconst_dRRRtconstrained_colsRtconstrained_col((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRps6





c
CsVy|j||}Wntk
r*dSXx$|D]}	|jtj|	q2WdS(N(R^RRRtCheckConstraint(
RRORR`RyRsRtRcRR((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRqs


cCsDy|j||}Wntk
r*dSX|jdd|_dS(NR(R]RRRR(RRORR`Rctcomment_dict((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyRrs

(s1.0sThe :paramref:`get_table_names.order_by` parameter is deprecated and will be removed in a future release.  Please refer to :meth:`.Inspector.get_sorted_table_and_fkc_names` for a more comprehensive solution to resolving foreign key cycles between tables.N((0Rt
__module__t__doc__R'tclassmethodR*Rt	_inspectsRR+tpropertyR,R-Rtdeprecated_paramsRR/RKRLRMRNRPRQRTRRZRYR3R[R\R]R^RjR{RkRRmRnRtasc_optdesc_opt
nullsfirst_optnullslast_opRRoRpRqRr(((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyR =sT		
	*8	
	
(#(	9			I	:	3	N(RtbaseRtRRRRRRRtsql.type_apiRRR	t	decoratorRtobjectR (((sO/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/engine/reflection.pyt<module>s