403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.148.217.26
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/__pycache__/ddl.cpython-37.pyc
B

��4]}��@s�dZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZGdd
�d
e�Z
Gdd�dee
�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de
�ZGdd�de�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�ZGd&d'�d'e�ZGd(d)�d)e�ZGd*d+�d+e�ZGd,d-�d-e�ZGd.d/�d/e�ZGd0d1�d1e�ZGd2d3�d3e�Z Gd4d5�d5e�Z!Gd6d7�d7e!�Z"Gd8d9�d9e!�Z#d?d;d<�Z$d@d=d>�Z%d:S)Azq
Provides the hierarchy of DDL-defining schema items as well as routines
to invoke them for a create/drop call.

�)�_bind_or_error)�_generative)�
Executable)�
SchemaVisitor)�
ClauseElement�)�event)�exc)�util)�topologicalc@seZdZdd�ZdS)�_DDLCompilescKs|j||f|�S)zNReturn a compiler appropriate for this ClauseElement, given a
        Dialect.)Zddl_compiler)�self�dialect�kw�r�E/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/ddl.py�	_compilersz_DDLCompiles._compilerN)�__name__�
__module__�__qualname__rrrrrrsrc@s�eZdZdZej�ddi�ZdZdZdZ	dZ
dd�Zddd�Ze
�d	d
�dd��Zed
d��Zed dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zeee�Zdd�ZdS)!�
DDLElementa�Base class for DDL expression constructs.

    This class is the base for the general purpose :class:`.DDL` class,
    as well as the various create/drop clause constructs such as
    :class:`.CreateTable`, :class:`.DropTable`, :class:`.AddConstraint`,
    etc.

    :class:`.DDLElement` integrates closely with SQLAlchemy events,
    introduced in :ref:`event_toplevel`.  An instance of one is
    itself an event receiving callable::

        event.listen(
            users,
            'after_create',
            AddConstraint(constraint).execute_if(dialect='postgresql')
        )

    .. seealso::

        :class:`.DDL`

        :class:`.DDLEvents`

        :ref:`event_toplevel`

        :ref:`schema_ddl_sequences`

    Z
autocommitTNcCs|�|||�S)N)Z_execute_ddl)r
�
connectionZmultiparams�paramsrrr�_execute_on_connectionGsz!DDLElement._execute_on_connectioncCs>|dkrt|�}|�||�r,|�|�|��S|jj�d�dS)a Execute this DDL immediately.

        Executes the DDL statement in isolation using the supplied
        :class:`.Connectable` or
        :class:`.Connectable` assigned to the ``.bind``
        property, if not supplied. If the DDL has a conditional ``on``
        criteria, it will be invoked with None as the event.

        :param bind:
          Optional, an ``Engine`` or ``Connection``. If not supplied, a valid
          :class:`.Connectable` must be present in the
          ``.bind`` property.

        :param target:
          Optional, defaults to None.  The target SchemaItem for the
          execute call.  Will be passed to the ``on`` callable if any,
          and may also provide string expansion data for the
          statement. See ``execute_at`` for more information.

        Nz(DDL execution skipped, criteria not met.)r�_should_execute�execute�against�engine�logger�info)r
�bind�targetrrrrJs
zDDLElement.executez0.7z�The :meth:`.DDLElement.execute_at` method is deprecated and will be removed in a future release.  Please use the :class:`.DDLEvents` listener interface in conjunction with the :meth:`.DDLElement.execute_if` method.cs,��fdd�}t�|d��dd�|�dS)aQLink execution of this DDL to the DDL lifecycle of a SchemaItem.

        Links this ``DDLElement`` to a ``Table`` or ``MetaData`` instance,
        executing it when that schema item is created or dropped. The DDL
        statement will be executed using the same Connection and transactional
        context as the Table create/drop itself. The ``.bind`` property of
        this statement is ignored.

        :param event:
          One of the events defined in the schema item's ``.ddl_events``;
          e.g. 'before-create', 'after-create', 'before-drop' or 'after-drop'

        :param target:
          The Table or MetaData instance for which this DDLElement will
          be associated with.

        A DDLElement instance can be linked to any number of schema items.

        ``execute_at`` builds on the ``append_ddl_listener`` interface of
        :class:`.MetaData` and :class:`.Table` objects.

        Caveat: Creating or dropping a Table in isolation will also trigger
        any DDL set to ``execute_at`` that Table's MetaData.  This may change
        in a future release.

        cs&�j�||f|�r"|���|��SdS)N)�_should_execute_deprecatedrr)r!rr)�
event_namer
rr�
call_event�sz)DDLElement.execute_at.<locals>.call_event��-�_N)r�listen�replace)r
r#r!r$r)r#r
r�
execute_aths#zDDLElement.execute_atcCs
||_dS)z9Return a copy of this DDL against a specific schema item.N)r!)r
r!rrrr�szDDLElement.againstcCs||_||_||_dS)a�Return a callable that will execute this
        DDLElement conditionally.

        Used to provide a wrapper for event listening::

            event.listen(
                        metadata,
                        'before_create',
                        DDL("my_ddl").execute_if(dialect='postgresql')
                    )

        :param dialect: May be a string, tuple or a callable
          predicate.  If a string, it will be compared to the name of the
          executing database dialect::

            DDL('something').execute_if(dialect='postgresql')

          If a tuple, specifies multiple dialect names::

            DDL('something').execute_if(dialect=('postgresql', 'mysql'))

        :param callable\_: A callable, which will be invoked with
          four positional arguments as well as optional keyword
          arguments:

            :ddl:
              This DDL element.

            :target:
              The :class:`.Table` or :class:`.MetaData` object which is the
              target of this event. May be None if the DDL is executed
              explicitly.

            :bind:
              The :class:`.Connection` being used for DDL execution

            :tables:
              Optional keyword argument - a list of Table objects which are to
              be created/ dropped within a MetaData.create_all() or drop_all()
              method call.

            :state:
              Optional keyword argument - will be the ``state`` argument
              passed to this function.

            :checkfirst:
             Keyword argument, will be True if the 'checkfirst' flag was
             set during the call to ``create()``, ``create_all()``,
             ``drop()``, ``drop_all()``.

          If the callable returns a true value, the DDL statement will be
          executed.

        :param state: any value which will be passed to the callable\_
          as the ``state`` keyword argument.

        .. seealso::

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        N)r�	callable_�state)r
rr+r,rrr�
execute_if�sAzDDLElement.execute_ifcKs�|jdk	r |jd||f|�s dSt|jtj�rB|j|jjkrfdSn$t|jtt	t
f�rf|jj|jkrfdS|jdk	r�|j|||fd|ji|��s�dSdS)NFr,T)
�onr"�
isinstancerr
�string_typesr�name�tuple�list�setr+r,)r
r!r rrrrr�szDDLElement._should_executecKsb|jdkrdSt|jtj�r*|j|jjkSt|jtttf�rJ|jj|jkS|j||||f|�SdS)NT)	r.r/r
r0rr1r2r3r4)r
rr!r rrrrr"�s
z%DDLElement._should_execute_deprecatedcKs$|j||f|�r |�|�|��SdS)z"Execute the DDL as a ddl_listener.N)rrr)r
r!r rrrr�__call__�szDDLElement.__call__cCs@|dk	r<t|tjtttf�s<t�|�s<t�dt	|�j
��dS)NzjExpected the name of a database dialect, a tuple of names, or a callable for 'on' criteria, got type '%s'.)r/r
r0r2r3r4�callabler	�
ArgumentError�typer)r
r.rrr�
_check_ddl_ons
zDDLElement._check_ddl_oncCs|jr|jSdS)N)�_bind)r
rrrr szDDLElement.bindcCs
||_dS)N)r:)r
r rrr�	_set_bindszDDLElement._set_bindcCs|j�|j�}|j��|_|S)N)�	__class__�__new__�__dict__�copy)r
�srrr�	_generateszDDLElement._generate)NN)NNN)rrr�__doc__rZ_execution_options�unionr!r.rr+rrr
Z
deprecatedr*rrr-rr"r5r9r r;�propertyrArrrrr s.

)D

rc@s2eZdZdZdZejdd�d
dd��Zdd	�ZdS)�DDLa1A literal DDL statement.

    Specifies literal SQL DDL to be executed by the database.  DDL objects
    function as DDL event listeners, and can be subscribed to those events
    listed in :class:`.DDLEvents`, using either :class:`.Table` or
    :class:`.MetaData` objects as targets.   Basic templating support allows
    a single DDL instance to handle repetitive tasks for multiple tables.

    Examples::

      from sqlalchemy import event, DDL

      tbl = Table('users', metadata, Column('uid', Integer))
      event.listen(tbl, 'before_create', DDL('DROP TRIGGER users_trigger'))

      spow = DDL('ALTER TABLE %(table)s SET secretpowers TRUE')
      event.listen(tbl, 'after_create', spow.execute_if(dialect='somedb'))

      drop_spow = DDL('ALTER TABLE users SET secretpowers FALSE')
      connection.execute(drop_spow)

    When operating on Table events, the following ``statement``
    string substitutions are available::

      %(table)s  - the Table name, with any required quoting applied
      %(schema)s - the schema name, with any required quoting applied
      %(fullname)s - the Table name including schema, quoted if needed

    The DDL's "context", if any, will be combined with the standard
    substitutions noted above.  Keys present in the context will override
    the standard substitutions.

    Zddl)z0.7z�The :paramref:`.DDL.on` parameter is deprecated and will be removed in a future release.  Please refer to :meth:`.DDLElement.execute_if`.)r.NcCsDt|tj�st�d|��||_|p&i|_|�|�||_||_	dS)a)Create a DDL statement.

        :param statement:
          A string or unicode string to be executed.  Statements will be
          processed with Python's string formatting operator.  See the
          ``context`` argument and the ``execute_at`` method.

          A literal '%' in a statement must be escaped as '%%'.

          SQL bind parameters are not available in DDL statements.

        :param on:

          Optional filtering criteria.  May be a string, tuple or a callable
          predicate.  If a string, it will be compared to the name of the
          executing database dialect::

            DDL('something', on='postgresql')

          If a tuple, specifies multiple dialect names::

            DDL('something', on=('postgresql', 'mysql'))

          If a callable, it will be invoked with four positional arguments
          as well as optional keyword arguments:

            :ddl:
              This DDL element.

            :event:
              The name of the event that has triggered this DDL, such as
              'after-create' Will be None if the DDL is executed explicitly.

            :target:
              The ``Table`` or ``MetaData`` object which is the target of
              this event. May be None if the DDL is executed explicitly.

            :connection:
              The ``Connection`` being used for DDL execution

            :tables:
              Optional keyword argument - a list of Table objects which are to
              be created/ dropped within a MetaData.create_all() or drop_all()
              method call.


          If the callable returns a true value, the DDL statement will be
          executed.

        :param context:
          Optional dictionary, defaults to None.  These values will be
          available for use in string substitutions on the DDL statement.

        :param bind:
          Optional. A :class:`.Connectable`, used by
          default when ``execute()`` is invoked without a bind argument.


        .. seealso::

            :class:`.DDLEvents`

            :ref:`event_toplevel`

        z4Expected a string or unicode SQL statement, got '%r'N)
r/r
r0r	r7�	statement�contextr9r.r:)r
rFr.rGr rrr�__init__@sK

zDDL.__init__c	s8dt��jt��d�t�j�g�fdd�dD��fS)Nz<%s@%s; %s>z, cs(g|] }t�|�rd|t�|�f�qS)z%s=%r)�getattr)�.0�key)r
rr�
<listcomp>�sz DDL.__repr__.<locals>.<listcomp>)r.rG)r8r�id�join�reprrF)r
r)r
r�__repr__�s

zDDL.__repr__)NNN)	rrrrB�__visit_name__r
Zdeprecated_paramsrHrPrrrrrEs!PrEc@s"eZdZdZddd�Zdd�ZdS)�_CreateDropBasez�Base class for DDL constructs that represent CREATE and DROP or
    equivalents.

    The common theme of _CreateDropBase is a single
    ``element`` attribute which refers to the element
    to be created or dropped.

    NcCs ||_|�|�||_||_dS)N)�elementr9r.r )r
rSr.r rrrrH�s
z_CreateDropBase.__init__cCsdS)z�Allow disable of _create_rule using a callable.

        Pass to _create_rule using
        util.portable_instancemethod(self._create_rule_disable)
        to retain serializability.

        Fr)r
�compilerrrr�_create_rule_disable�sz$_CreateDropBase._create_rule_disable)NN)rrrrBrHrUrrrrrR�s
rRcs&eZdZdZdZd�fdd�	Z�ZS)�CreateSchemazcRepresent a CREATE SCHEMA statement.

    The argument here is the string name of the schema.

    Z
create_schemaNcs||_tt|�j|f|�dS)z.Create a new :class:`.CreateSchema` construct.N)�quote�superrVrH)r
r1rWr)r<rrrH�szCreateSchema.__init__)N)rrrrBrQrH�
__classcell__rr)r<rrV�srVcs&eZdZdZdZd�fdd�	Z�ZS)�
DropSchemazaRepresent a DROP SCHEMA statement.

    The argument here is the string name of the schema.

    Zdrop_schemaNFcs$||_||_tt|�j|f|�dS)z,Create a new :class:`.DropSchema` construct.N)rW�cascaderXrZrH)r
r1rWr[r)r<rrrH�szDropSchema.__init__)NF)rrrrBrQrHrYrr)r<rrZ�srZcs&eZdZdZdZd�fdd�	Z�ZS)�CreateTablez#Represent a CREATE TABLE statement.Zcreate_tableNcs2tt|�j|||d�dd�|jD�|_||_dS)aLCreate a :class:`.CreateTable` construct.

        :param element: a :class:`.Table` that's the subject
         of the CREATE
        :param on: See the description for 'on' in :class:`.DDL`.
        :param bind: See the description for 'bind' in :class:`.DDL`.
        :param include_foreign_key_constraints: optional sequence of
         :class:`.ForeignKeyConstraint` objects that will be included
         inline within the CREATE construct; if omitted, all foreign key
         constraints that do not specify use_alter=True are included.

         .. versionadded:: 1.0.0

        )r.r cSsg|]}t|��qSr)�CreateColumn)rJ�columnrrrrL�sz(CreateTable.__init__.<locals>.<listcomp>N)rXr\rH�columns�include_foreign_key_constraints)r
rSr.r r`)r<rrrH�szCreateTable.__init__)NNN)rrrrBrQrHrYrr)r<rr\�sr\c@seZdZdZdZdS)�	_DropViewz�Semi-public 'DROP VIEW' construct.

    Used by the test suite for dialect-agnostic drops of views.
    This object will eventually be part of a public "view" API.

    Z	drop_viewN)rrrrBrQrrrrra�srac@seZdZdZdZdd�ZdS)r]a\Represent a :class:`.Column` as rendered in a CREATE TABLE statement,
    via the :class:`.CreateTable` construct.

    This is provided to support custom column DDL within the generation
    of CREATE TABLE statements, by using the
    compiler extension documented in :ref:`sqlalchemy.ext.compiler_toplevel`
    to extend :class:`.CreateColumn`.

    Typical integration is to examine the incoming :class:`.Column`
    object, and to redirect compilation if a particular flag or condition
    is found::

        from sqlalchemy import schema
        from sqlalchemy.ext.compiler import compiles

        @compiles(schema.CreateColumn)
        def compile(element, compiler, **kw):
            column = element.element

            if "special" not in column.info:
                return compiler.visit_create_column(element, **kw)

            text = "%s SPECIAL DIRECTIVE %s" % (
                    column.name,
                    compiler.type_compiler.process(column.type)
                )
            default = compiler.get_column_default_string(column)
            if default is not None:
                text += " DEFAULT " + default

            if not column.nullable:
                text += " NOT NULL"

            if column.constraints:
                text += " ".join(
                            compiler.process(const)
                            for const in column.constraints)
            return text

    The above construct can be applied to a :class:`.Table` as follows::

        from sqlalchemy import Table, Metadata, Column, Integer, String
        from sqlalchemy import schema

        metadata = MetaData()

        table = Table('mytable', MetaData(),
                Column('x', Integer, info={"special":True}, primary_key=True),
                Column('y', String(50)),
                Column('z', String(20), info={"special":True})
            )

        metadata.create_all(conn)

    Above, the directives we've added to the :attr:`.Column.info` collection
    will be detected by our custom compilation scheme::

        CREATE TABLE mytable (
                x SPECIAL DIRECTIVE INTEGER NOT NULL,
                y VARCHAR(50),
                z SPECIAL DIRECTIVE VARCHAR(20),
            PRIMARY KEY (x)
        )

    The :class:`.CreateColumn` construct can also be used to skip certain
    columns when producing a ``CREATE TABLE``.  This is accomplished by
    creating a compilation rule that conditionally returns ``None``.
    This is essentially how to produce the same effect as using the
    ``system=True`` argument on :class:`.Column`, which marks a column
    as an implicitly-present "system" column.

    For example, suppose we wish to produce a :class:`.Table` which skips
    rendering of the PostgreSQL ``xmin`` column against the PostgreSQL
    backend, but on other backends does render it, in anticipation of a
    triggered rule.  A conditional compilation rule could skip this name only
    on PostgreSQL::

        from sqlalchemy.schema import CreateColumn

        @compiles(CreateColumn, "postgresql")
        def skip_xmin(element, compiler, **kw):
            if element.element.name == 'xmin':
                return None
            else:
                return compiler.visit_create_column(element, **kw)


        my_table = Table('mytable', metadata,
                    Column('id', Integer, primary_key=True),
                    Column('xmin', Integer)
                )

    Above, a :class:`.CreateTable` construct will generate a ``CREATE TABLE``
    which only includes the ``id`` column in the string; the ``xmin`` column
    will be omitted, but only against the PostgreSQL backend.

    Z
create_columncCs
||_dS)N)rS)r
rSrrrrHnszCreateColumn.__init__N)rrrrBrQrHrrrrr]	sar]c@seZdZdZdZdS)�	DropTablez!Represent a DROP TABLE statement.Z
drop_tableN)rrrrBrQrrrrrbrsrbc@seZdZdZdZdS)�CreateSequencez&Represent a CREATE SEQUENCE statement.Zcreate_sequenceN)rrrrBrQrrrrrcxsrcc@seZdZdZdZdS)�DropSequencez$Represent a DROP SEQUENCE statement.Z
drop_sequenceN)rrrrBrQrrrrrd~srdc@seZdZdZdZdS)�CreateIndexz#Represent a CREATE INDEX statement.Zcreate_indexN)rrrrBrQrrrrre�srec@seZdZdZdZdS)�	DropIndexz!Represent a DROP INDEX statement.Z
drop_indexN)rrrrBrQrrrrrf�srfcs$eZdZdZdZ�fdd�Z�ZS)�
AddConstraintz2Represent an ALTER TABLE ADD CONSTRAINT statement.Zadd_constraintcs*tt|�j|f|�|�t�|j�|_dS)N)rXrgrHr
�portable_instancemethodrU�_create_rule)r
rS�argsr)r<rrrH�szAddConstraint.__init__)rrrrBrQrHrYrr)r<rrg�srgcs&eZdZdZdZd�fdd�	Z�ZS)�DropConstraintz3Represent an ALTER TABLE DROP CONSTRAINT statement.Zdrop_constraintFcs,||_tt|�j|f|�t�|j�|_dS)N)r[rXrkrHr
rhrUri)r
rSr[r)r<rrrH�szDropConstraint.__init__)F)rrrrBrQrHrYrr)r<rrk�srkc@seZdZdZdZdS)�SetTableCommentz*Represent a COMMENT ON TABLE IS statement.Zset_table_commentN)rrrrBrQrrrrrl�srlc@seZdZdZdZdS)�DropTableCommentzfRepresent a COMMENT ON TABLE '' statement.

    Note this varies a lot across database backends.

    Zdrop_table_commentN)rrrrBrQrrrrrm�srmc@seZdZdZdZdS)�SetColumnCommentz+Represent a COMMENT ON COLUMN IS statement.Zset_column_commentN)rrrrBrQrrrrrn�srnc@seZdZdZdZdS)�DropColumnCommentz0Represent a COMMENT ON COLUMN IS NULL statement.Zdrop_column_commentN)rrrrBrQrrrrro�sroc@seZdZdd�ZdS)�DDLBasecCs
||_dS)N)r)r
rrrrrH�szDDLBase.__init__N)rrrrHrrrrrp�srpcsZeZdZd�fdd�	Zdd�Zdd�Zd	d
�Zddd�Zd
d�Zddd�Z	dd�Z
�ZS)�SchemaGeneratorFNcs8tt|�j|f|�||_||_|j|_||_i|_dS)N)	rXrqrH�
checkfirst�tables�identifier_preparer�preparerr�memo)r
rrrrrs�kwargs)r<rrrH�szSchemaGenerator.__init__cCsJ|j�|j�|j�|�}|r*|j�|�|jpH|jj|j|j|d�S)N)�schema)r�validate_identifierr1r�schema_for_objectrr�	has_table)r
�table�effective_schemarrr�_can_create_table�sz!SchemaGenerator._can_create_tablecCsF|j�|�}|jjoD|jjs&|joD|jpD|jj|j|j|d�S)N)rx)	rrzr�supports_sequences�sequences_optional�optionalrr�has_sequencer1)r
�sequencer}rrr�_can_create_sequence�sz$SchemaGenerator._can_create_sequencec
s��jdk	r�j}nt|j���}t�fdd�|D��}�fdd�|j��D�}dd�|D�}|jj|�j|�j�d�x|D]}�j	|dd�q|WxD|D]<\}}|dk	r��j	|d|dd�q�x|D]}	��	|	�q�Wq�W|jj
|�j|�j�d�dS)	Ncsg|]}��|�r|�qSr)r~)rJ�t)r
rrrL�sz2SchemaGenerator.visit_metadata.<locals>.<listcomp>cs$g|]}|jdkr��|�r|�qS)N)r^r�)rJr@)r
rrrL�scSsg|]\}}|dk	r|�qS)Nr)rJr��fksrrrrL�s)rsrr�_ddl_runnerT)�	create_ok)r�r`�_is_metadata_operation)rsr3�values�sort_tables_and_constraints�
_sequences�dispatch�
before_createrrr�traverse_single�after_create)
r
�metadatars�
collection�seq_coll�event_collection�seqr|�fkcs�fkcr)r
r�visit_metadata�s>




zSchemaGenerator.visit_metadatacCs|s|�|�sdS|jj||j|j||d�x$|jD]}|jdk	r4|�|j�q4W|jj	s^d}|j�
t||d��t|d�r�x|j
D]}|�|�q�W|jjr�|jjs�|jdk	r�|j�
t|��x(|jD]}|jdk	r�|j�
t|��q�W|jj||j|j||d�dS)N)rrr�r�)r`�indexes)r~r�r�rrrr_�defaultr�r�supports_alterrr\�hasattrr�Zsupports_commentsZinline_comments�commentrlrnr�)r
r|r�r`r�r^�indexrrr�visit_tables@




zSchemaGenerator.visit_tablecCs |jjsdS|j�t|��dS)N)rr�rrrg)r
�
constraintrrr�visit_foreign_key_constraintSsz,SchemaGenerator.visit_foreign_key_constraintcCs&|s|�|�sdS|j�t|��dS)N)r�rrrc)r
r�r�rrr�visit_sequenceXszSchemaGenerator.visit_sequencecCs|j�t|��dS)N)rrre)r
r�rrr�visit_index]szSchemaGenerator.visit_index)FN)FNF)F)rrrrHr~r�r�r�r�r�r�rYrr)r<rrq�s		
3
3
rqcsZeZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zdd
d�Zdd�Z	ddd�Z
�ZS)�
SchemaDropperFNcs8tt|�j|f|�||_||_|j|_||_i|_dS)N)	rXr�rHrrrsrtrurrv)r
rrrrrsrw)r<rrrHbszSchemaDropper.__init__cs��jdk	r�j}nt|j���}y2�fdd�|D�}ttt|�fdd�d���}Wn�tjk
r�}z|�jjs�t	�
dd�tdd�|j
D����d	d�|D�}n<t	�tj|jd
|j
|jdd�tdd�|j
D���d
��Wdd}~XYnX�fdd�|j��D�}dd�|D�}|jj|�j|�j�d�xH|D]@\}}	|dk	�rZ�j|ddd�nx|	D]}
��|
��q`W�q6Wx|D]}�j|dd��q�W|jj|�j|�j�d�dS)Ncsg|]}��|�r|�qSr)�_can_drop_table)rJr�)r
rrrLssz0SchemaDropper.visit_metadata.<locals>.<listcomp>cs�jjr|jdkrdSdS)NF)rr�r1)r�)r
rr�<lambda>xsz.SchemaDropper.visit_metadata.<locals>.<lambda>)�	filter_fna4Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s, and backend does not support ALTER.  To restore at least a partial sort, apply use_alter=True to ForeignKey and ForeignKeyConstraint objects involved in the cycle to mark these as known cycles that will be ignored.z, cSsg|]
}|j�qSr)�fullname)rJr�rrrrL�scSsg|]}|df�qS)rr)rJr�rrrrL�s�z�Can't sort tables for DROP; an unresolvable foreign key dependency exists between tables: %s.  Please ensure that the ForeignKey and ForeignKeyConstraint objects involved in the cycle have names so that they can be dropped using DROP CONSTRAINT.cSsg|]
}|j�qSr)r�)rJr�rrrrL�s)�msgcs$g|]}|jdkr��|�r|�qS)N)r^�_can_drop_sequence)rJr@)r
rrrL�scSsg|]\}}|dk	r|�qS)Nr)rJr�r�rrrrL�s)rsrrr�T)�drop_okr�)r�)rsr3r��reversedr�r	�CircularDependencyErrorrr�r
�warnrN�sortedZcyclesZraise_from_causerj�edgesr�r��before_droprrrr��
after_drop)r
r�rsZunsorted_tablesr�Zerr2r�r�r|r�r�r�r)r
rr�ls^
0



zSchemaDropper.visit_metadatacCsH|j�|j�|j�|�}|r*|j�|�|jpF|jj|j|j|d�S)N)rx)rryr1rrzrrr{)r
r|r}rrrr��szSchemaDropper._can_drop_tablecCsD|j�|�}|jjoB|jjs&|joB|jpB|jj|j|j|d�S)N)rx)	rrzrrr�r�rrr�r1)r
r�r}rrrr��sz SchemaDropper._can_drop_sequencecCs|j�t|��dS)N)rrrf)r
r�rrrr��szSchemaDropper.visit_indexcCs�|s|�|�sdS|jj||j|j||d�|j�t|��x$|jD]}|jdk	rD|�	|j�qDW|jj
||j|j||d�dS)N)rrr�r�)r�r�r�rrrrrbr_r�r�r�)r
r|r�r�r^rrrr��s$
zSchemaDropper.visit_tablecCs |jjsdS|j�t|��dS)N)rr�rrrk)r
r�rrrr��sz*SchemaDropper.visit_foreign_key_constraintcCs&|s|�|�sdS|j�t|��dS)N)r�rrrd)r
r�r�rrrr�szSchemaDropper.visit_sequence)FN)FF)F)rrrrHr�r�r�r�r�r�r�rYrr)r<rr�as	Z	
r�Ncs2�dk	r�fdd�}nd}dd�t|||d�D�S)a]sort a collection of :class:`.Table` objects based on dependency.

    This is a dependency-ordered sort which will emit :class:`.Table`
    objects such that they will follow their dependent :class:`.Table` objects.
    Tables are dependent on another based on the presence of
    :class:`.ForeignKeyConstraint` objects as well as explicit dependencies
    added by :meth:`.Table.add_is_dependent_on`.

    .. warning::

        The :func:`.sort_tables` function cannot by itself accommodate
        automatic resolution of dependency cycles between tables, which
        are usually caused by mutually dependent foreign key constraints.
        To resolve these cycles, either the
        :paramref:`.ForeignKeyConstraint.use_alter` parameter may be applied
        to those constraints, or use the
        :func:`.sql.sort_tables_and_constraints` function which will break
        out foreign key constraints involved in cycles separately.

    :param tables: a sequence of :class:`.Table` objects.

    :param skip_fn: optional callable which will be passed a
     :class:`.ForeignKey` object; if it returns True, this
     constraint will not be considered as a dependency.  Note this is
     **different** from the same parameter in
     :func:`.sort_tables_and_constraints`, which is
     instead passed the owning :class:`.ForeignKeyConstraint` object.

    :param extra_dependencies: a sequence of 2-tuples of tables which will
     also be considered as dependent on each other.

    .. seealso::

        :func:`.sort_tables_and_constraints`

        :meth:`.MetaData.sorted_tables` - uses this function to sort


    Ncs$x|jD]}�|�rdSqWdSdS)NT)�elements)r�Zfk)�skip_fnrr�_skip_fn4szsort_tables.<locals>._skip_fncSsg|]\}}|dk	r|�qS)Nr)rJr�r�rrrrL?szsort_tables.<locals>.<listcomp>)r��extra_dependencies)r�)rsr�r�r�r)r�r�sort_tables	s)r�c
s�t�}t�}|dk	r|�|�t��x�|D]��x`�jD]V}|jdkrP��|�q6�rp�|�}|dkrp��|�q6|j}|�k	r6|�|�f�q6W|��fdd��jD��q*Wyttj	|�
|�|dd��}Wn�tjk
�rx}	z�xj|	j
D]`}
|
|kr�|
d��fdd��jD�}��|�x,|D]$}|j}|�k	�r"|�|�f��q"Wq�Wttj	|�
|�|dd��}Wdd}	~	XYnX�fd	d�|D�dt��fgS)
a�sort a collection of :class:`.Table`  / :class:`.ForeignKeyConstraint`
    objects.

    This is a dependency-ordered sort which will emit tuples of
    ``(Table, [ForeignKeyConstraint, ...])`` such that each
    :class:`.Table` follows its dependent :class:`.Table` objects.
    Remaining :class:`.ForeignKeyConstraint` objects that are separate due to
    dependency rules not satisfied by the sort are emitted afterwards
    as ``(None, [ForeignKeyConstraint ...])``.

    Tables are dependent on another based on the presence of
    :class:`.ForeignKeyConstraint` objects, explicit dependencies
    added by :meth:`.Table.add_is_dependent_on`, as well as dependencies
    stated here using the :paramref:`~.sort_tables_and_constraints.skip_fn`
    and/or :paramref:`~.sort_tables_and_constraints.extra_dependencies`
    parameters.

    :param tables: a sequence of :class:`.Table` objects.

    :param filter_fn: optional callable which will be passed a
     :class:`.ForeignKeyConstraint` object, and returns a value based on
     whether this constraint should definitely be included or excluded as
     an inline constraint, or neither.   If it returns False, the constraint
     will definitely be included as a dependency that cannot be subject
     to ALTER; if True, it will **only** be included as an ALTER result at
     the end.   Returning None means the constraint is included in the
     table-based result unless it is detected as part of a dependency cycle.

    :param extra_dependencies: a sequence of 2-tuples of tables which will
     also be considered as dependent on each other.

    .. versionadded:: 1.0.0

    .. seealso::

        :func:`.sort_tables`


    NTc3s|]}|�fVqdS)Nr)rJ�parent)r|rr�	<genexpr>�sz.sort_tables_and_constraints.<locals>.<genexpr>)Zdeterministic_orderrcs$g|]}�dks�|�dk	r|�qS)NFr)rJr�)r�rrrL�sz/sort_tables_and_constraints.<locals>.<listcomp>csg|]}||j���f�qSr)�foreign_key_constraints�
difference)rJr|)�remaining_fkcsrrrL�s)r4�updater�Z	use_alter�addZreferred_tableZ_extra_dependenciesr3r�sortrCr	r�r��discard)rsr�r�Zfixed_dependenciesZmutable_dependenciesr��filteredZdependent_onZcandidate_sort�errZedgeZ
can_remover)r�r�r|rr�GsZ+










r�)NN)NN)&rB�baserrrrr�rr%rr	r
rrrrErRrVrZr\rar]rbrcrdrerfrgrkrlrmrnrorprqr�r�r�rrrr�<module>sL|
i

)
?

Youez - 2016 - github.com/yon3zu
LinuXploit