
    +h[                        d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZdZdZ ej*                  d      Z ej*                  d      Z G d de      Z G d de      Zd Zd Zd Zd Zd Zd Z d Z!d Z" G d d ejF                  jH                        Z% G d! d"ejF                  jH                        Z& ejN                  d#      d$        Z( G d% d&e      Z) G d' d(e      Z* G d) d*e      Z+ G d+ d,e      Z, G d- d.e+      Z- G d/ d0e.      Z/ G d1 d2 ej`                  e/            Z1 G d3 d4e1e      Z2 G d5 d6e	      Z3 G d7 d8ejh                  e+      Z5 G d9 d:e6      Z7 G d; d<e      Z8 G d= d>e      Z9 G d? d@e      Z: G dA dBe:      Z; G dC dDejx                  e:      Z= G dE dFej|                        Z?dJdGZ@dH ZAefdIZBy)Kz4Foundational utilities common to many sql modules.

    N   )roles)visitors)HasCacheKey)HasCopyInternals)MemoizedHasCacheKey)ClauseVisitor)ExtendedInternalTraversal)InternalTraversal   )exc)util)HasMemoized)hybridmethodPARSE_AUTOCOMMITNO_ARGc                   ,    e Zd ZdZdZd Zd Zd Zd Zy)	Immutablez@mark a ClauseElement as 'immutable' when expressions are cloned.Tc                     t        d      Nz(Immutable objects do not support copyingNotImplementedErrorselfoptionaldictkwargss      F/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/sql/base.pyunique_paramszImmutable.unique_params,       !"LMM    c                     t        d      r   r   r   s      r   paramszImmutable.params/   r   r    c                     | S N r   kws     r   _clonezImmutable._clone2   s    r    c                      y r$   r%   r&   s     r   _copy_internalszImmutable._copy_internals5   s    r    N)	__name__
__module____qualname____doc___is_immutabler   r"   r(   r*   r%   r    r   r   r   '   s     JMNNr    r   c                   *    e Zd ZdZdZd Zed        Zy)SingletonConstantz.Represent SQL constants like NULL, TRUE, FALSETc                     | j                   S r$   )
_singleton)clsargr'   s      r   __new__zSingletonConstant.__new__>   s    ~~r    c                 ~    t         j                  |       }|j                          t        |g      |_        || _        y r$   )objectr6   __init__	frozenset	proxy_setr3   )r4   objs     r   _create_singletonz#SingletonConstant._create_singletonA   s0    nnS! "3%(r    N)r+   r,   r-   r.   _is_singleton_constantr6   classmethodr=   r%   r    r   r1   r1   9   s$    8!  r    r1   c                  z    t         j                  j                  | D cg c]  }|j                   c}      S c c}w r$   )	itertoolschainfrom_iterable_from_objects)elementselements     r   rD   rD   Q   s0    ??((.677		7 7   8c                 z    t         j                  j                  | D cg c]  }|j                   c}      S c c}w )zXexpand tables into individual columns in the
    given list of column expressions.

    )rA   rB   rC   _select_iterable)rE   cs     r   _select_iterablesrK   W   s2    
 ??((%-.		. .rG   c                 P    t         j                  d        } ||       }| |_        |S )znon-caching _generative() decorator.

    This is basically the legacy decorator that copies the object and
    runs a method on the new copy.

    c                 P    |j                         } | |g|i |}|J d       |S )zMark a method as generative.z,generative methods must have no return value)	_generate)fnr   argsr'   xs        r   _generativez _generative.<locals>._generativei   s9     ~~t!d!b!yHHHyr    )r   	decoratornon_generative)rO   rR   	decorateds      r   rR   rR   a   s3     
^^  BI!Ir    c            	          |j                  di       |j                  di       }| D cg c]*  }|t        j                  |      |j                  |d       f, c}t        j
                  fd       }|S c c}w )Nmsgsdefaultsc           	          |d   }|dd  }D ]R  \  }}} ||      |us	j                  |d| j                  d|j                  d      }t        j                  |        | |g|i |S )Nr   r   zMethod z$() has already been invoked on this z
 construct)getr+   	__class__r   InvalidRequestError)
rO   rP   r'   r   namegetterdefault_msggettersrW   s
           r   checkz!_exclusive_against.<locals>.check   s     AwABx&- 	3"D&(d|8+hh{{DNN4
 --c22	3 $$$$$r    )popoperator
attrgetterrZ   r   rS   )namesr'   rX   r]   rb   ra   rW   s        @@r   _exclusive_againstrg   w   s~    66&"Dvvj"%H  
x""4((,,tT*BCG
 
^^% % L+s   /A8c                 &     | j                   di |S Nr%   )r(   )rF   r'   s     r   r(   r(      s    7>>Br    c                 `    t        j                  | D cg c]  }|j                   c} S c c}w )z\expand the given set of ClauseElements to be the set of all 'cloned'
    predecessors.

    )rA   rB   _cloned_set)rE   rQ   s     r   _expand_clonedrl      s%    
 ??H=qQ]]=>>=s   +c                     t        t        |             j                  t        |            t        fd| D              S )zreturn the intersection of sets a and b, counting
    any overlap between 'cloned' predecessors.

    The returned set is in terms of the entities present within 'a'.

    c              3   Z   K   | ]"  }j                  |j                        s| $ y wr$   intersectionrk   .0elemall_overlaps     r   	<genexpr>z'_cloned_intersection.<locals>.<genexpr>   s)      k66t7G7GH    ++setrl   rp   abrt   s     @r   _cloned_intersectionr|      s>     nQ'(55nQ6GHK   r    c                     t        t        |             j                  t        |            t        fd| D              S )Nc              3   Z   K   | ]"  }j                  |j                        r| $ y wr$   ro   rq   s     r   ru   z%_cloned_difference.<locals>.<genexpr>   s)      +":":4;K;K"Lrv   rw   ry   s     @r   _cloned_differencer      s<    nQ'(55nQ6GHK   r    c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
_DialectArgViewzaA dictionary view of dialect-level arguments in the form
    <dialectname>_<argument_name>.

    c                     || _         y r$   )r<   )r   r<   s     r   r9   z_DialectArgView.__init__   s	    r    c                     	 |j                  dd      \  }}||fS # t        $ r*}t        j                  t	        |      |       Y d }~y d }~ww xY w)N_r   replace_context)split
ValueErrorr   raise_KeyError)r   keydialect	value_keyerrs        r   _keyz_DialectArgView._key   sP    	&!$3!2GY I%%  	<KKs;;	<s    	A A		Ac                     | j                  |      \  }}	 | j                  j                  |   }||   S # t        j                  $ r*}t        j                  t        |      |       Y d }~y d }~ww xY wNr   )r   r<   dialect_optionsr   NoSuchModuleErrorr   r   r   )r   r   r   r   optr   s         r   __getitem__z_DialectArgView.__getitem__   sf    !YYs^	"((**73C y>! $$ 	<KKs;;	<s   4 A1 A,,A1c                     	 | j                  |      \  }}|| j                  j                  |   |<   y # t        $ r4}t	        j
                  t        j                  d      |       Y d }~y d }~ww xY w)Nz0Keys must be of the form <dialectname>_<argname>r   )r   r<   r   r   r   r   r   ArgumentError)r   r   valuer   r   r   s         r   __setitem__z_DialectArgView.__setitem__   so    
	A!%3GY <ADHH$$W-i8  	KK!!F !$	 	s   3 	A0*A++A0c                 `    | j                  |      \  }}| j                  j                  |   |= y r$   )r   r<   r   )r   r   r   r   s       r   __delitem__z_DialectArgView.__delitem__   s+    !YYs^HH$$W-i8r    c                 j    t        d | j                  j                  j                         D              S )Nc              3   F   K   | ]  }t        |j                          y wr$   )len_non_defaults)rr   rP   s     r   ru   z*_DialectArgView.__len__.<locals>.<genexpr>   s#      
 ""#
s   !)sumr<   r   valuesr   s    r   __len__z_DialectArgView.__len__   s/     
00779
 
 	
r    c                 B      fd j                   j                  D        S )Nc              3   |   K   | ]3  }j                   j                  |   j                  D ]  }|d |  5 yw)r   N)r<   r   r   )rr   dialect_name
value_namer   s      r   ru   z+_DialectArgView.__iter__.<locals>.<genexpr>   sJ      
"hh66m
  $Z0
0
s   9<)r<   r   r   s   `r   __iter__z_DialectArgView.__iter__   s    
 $ 8 8
 	
r    N)r+   r,   r-   r.   r9   r   r   r   r   r   r   r%   r    r   r   r      s+    
&"A9

r    r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	_DialectArgDictzA dictionary view of dialect-level arguments for a specific
    dialect.

    Maintains a separate collection of user-specified arguments
    and dialect-specified default arguments.

    c                      i | _         i | _        y r$   r   	_defaultsr   s    r   r9   z_DialectArgDict.__init__   s    r    c                 p    t        t        | j                        j                  | j                              S r$   )r   rx   r   unionr   r   s    r   r   z_DialectArgDict.__len__   s'    3t))*00@AAr    c                 p    t        t        | j                        j                  | j                              S r$   )iterrx   r   r   r   r   s    r   r   z_DialectArgDict.__iter__   s'    C**+11$..ABBr    c                 Z    || j                   v r| j                   |   S | j                  |   S r$   r   r   r   s     r   r   z_DialectArgDict.__getitem__  s0    $$$$%%c**>>#&&r    c                 "    || j                   |<   y r$   r   r   r   r   s      r   r   z_DialectArgDict.__setitem__	  s    "'3r    c                     | j                   |= y r$   r   r   s     r   r   z_DialectArgDict.__delitem__  s    s#r    N)
r+   r,   r-   r.   r9   r   r   r   r   r   r%   r    r   r   r      s'    BC'($r    r   zsqlalchemy.dialectsc                     t         j                  j                  j                  j	                  |       }|j
                  y t        |j
                        S r$   )r   	preloadeddialectsregistryloadconstruct_argumentsdict)r   dialect_clss     r   _kw_reg_for_dialectr     sB    ..))2277EK&&.//00r    c                       e Zd ZdZdej
                  fgZed        Ze	j                  d        Zed        Z e	j                  e      Zd Ze	j                  d        Zd Zy	)
DialectKWArgsa9  Establish the ability for a class to have dialect-specific arguments
    with defaults and constructor validation.

    The :class:`.DialectKWArgs` interacts with the
    :attr:`.DefaultDialect.construct_arguments` present on a dialect.

    .. seealso::

        :attr:`.DefaultDialect.construct_arguments`

    r   c                     t         j                  |   }|t        j                  d|z        | |vri || <   |||    |<   y)a  Add a new kind of dialect-specific keyword argument for this class.

        E.g.::

            Index.argument_for("mydialect", "length", None)

            some_index = Index('a', 'b', mydialect_length=5)

        The :meth:`.DialectKWArgs.argument_for` method is a per-argument
        way adding extra arguments to the
        :attr:`.DefaultDialect.construct_arguments` dictionary. This
        dictionary provides a list of argument names accepted by various
        schema-level constructs on behalf of a dialect.

        New dialects should typically specify this dictionary all at once as a
        data member of the dialect class.  The use case for ad-hoc addition of
        argument names is typically for end-user code that is also using
        a custom compilation scheme which consumes the additional arguments.

        :param dialect_name: name of a dialect.  The dialect must be
         locatable, else a :class:`.NoSuchModuleError` is raised.   The
         dialect must also include an existing
         :attr:`.DefaultDialect.construct_arguments` collection, indicating
         that it participates in the keyword-argument validation and default
         system, else :class:`.ArgumentError` is raised.  If the dialect does
         not include this collection, then any keyword argument can be
         specified on behalf of this dialect already.  All dialects packaged
         within SQLAlchemy include this collection, however for third party
         dialects, support may vary.

        :param argument_name: name of the parameter.

        :param default: default value of the parameter.

        .. versionadded:: 0.9.4

        NzRDialect '%s' does have keyword-argument validation and defaults enabled configured)r   _kw_registryr   r   )r4   r   argument_namedefaultconstruct_arg_dictionarys        r   argument_forzDialectKWArgs.argument_for)  sc    P $1#=#=l#K #+##=?KL  ..,.$S)7> %m4r    c                     t        |       S )a9  A collection of keyword arguments specified as dialect-specific
        options to this construct.

        The arguments are present here in their original ``<dialect>_<kwarg>``
        format.  Only arguments that were actually passed are included;
        unlike the :attr:`.DialectKWArgs.dialect_options` collection, which
        contains all options known by this dialect including defaults.

        The collection is also writable; keys are accepted of the
        form ``<dialect>_<kwarg>`` where the value will be assembled
        into the list of options.

        .. versionadded:: 0.9.2

        .. versionchanged:: 0.9.4 The :attr:`.DialectKWArgs.dialect_kwargs`
           collection is now writable.

        .. seealso::

            :attr:`.DialectKWArgs.dialect_options` - nested dictionary form

        )r   r   s    r   dialect_kwargszDialectKWArgs.dialect_kwargs[  s    0 t$$r    c                     | j                   S )z4A synonym for :attr:`.DialectKWArgs.dialect_kwargs`.)r   r   s    r   r   zDialectKWArgs.kwargsu  s     """r    c                    t         j                  |   }t               }||j                  j	                  dd i       |S t        | j                  j                        D ]%  }||v s|j                  j	                  ||          ' |S )N*)r   r   r   r   updatereversedr[   __mro__)r   r   r   dr4   s        r   _kw_reg_for_dialect_clsz%DialectKWArgs._kw_reg_for_dialect_cls|  s    #0#=#=l#K #+KKT{+
    6 67 F22KK&&'?'DEF r    c                 f    t        j                  t        j                  | j                              S )a  A collection of keyword arguments specified as dialect-specific
        options to this construct.

        This is a two-level nested registry, keyed to ``<dialect_name>``
        and ``<argument_name>``.  For example, the ``postgresql_where``
        argument would be locatable as::

            arg = my_object.dialect_options['postgresql']['where']

        .. versionadded:: 0.9.2

        .. seealso::

            :attr:`.DialectKWArgs.dialect_kwargs` - flat dictionary form

        )r   PopulateDictportable_instancemethodr   r   s    r   r   zDialectKWArgs.dialect_options  s+    &   (()E)EF
 	
r    c           	         |sy |D ]  }t        j                  d|      }|st        d|z        |j                  dd      \  }}	 | j                  |   }d|vr,||vr(t        j                  d|d|d| j                        ||   ||<    y # t
        j                  $ rg t        j                  d	|d
|       t               x| j                  |<   }|j                  j                  dd i       ||   |j                  |<   Y w xY w)Nz^(.+?)_(.+)$zGAdditional arguments should be named <dialectname>_<argument>, got '%s'r   r   r   z	Argument z is not accepted by dialect z on behalf of zCan't validate argument z,; can't locate any SQLAlchemy dialect named )rematch	TypeErrorgroupr   r   r   r[   r   r   warnr   r   r   r   )r   r   kmr   arg_namer   r   s           r   _validate_dialect_kwargsz&DialectKWArgs._validate_dialect_kwargs  s3     	CA+A?ABC  &'WWQ]"L(C+/+?+?+M( 77 (@@++ lDNN<  :@,X6?	C (( 6		 ,(
 :I9JJ$$\2Q""C;/,21I)6s   BA6D	D	N)r+   r,   r-   r.   r   dp_dialect_options"_dialect_kwargs_traverse_internalsr?   r   r   memoized_propertyr   propertyr   r   r   r   r   r   r   r%   r    r   r   r     s    
 
-@@A*& /? /?b 
% %2 # # %4$$%89L
 

 
,%Cr    r   c                   ^    e Zd ZdZdZi Zed        Zd Zed        Z	ed        Z
ed        Zy)	CompileStatea  Produces additional object state necessary for a statement to be
    compiled.

    the :class:`.CompileState` class is at the base of classes that assemble
    state for a particular statement object that is then used by the
    compiler.   This process is essentially an extension of the process that
    the SQLCompiler.visit_XYZ() method takes, however there is an emphasis
    on converting raw user intent into more organized structures rather than
    producing string output.   The top-level :class:`.CompileState` for the
    statement being executed is also accessible when the execution context
    works with invoking the statement and collecting results.

    The production of :class:`.CompileState` is specific to the compiler,  such
    as within the :meth:`.SQLCompiler.visit_insert`,
    :meth:`.SQLCompiler.visit_select` etc. methods.  These methods are also
    responsible for associating the :class:`.CompileState` with the
    :class:`.SQLCompiler` itself, if the statement is the "toplevel" statement,
    i.e. the outermost SQL statement that's actually being executed.
    There can be other :class:`.CompileState` objects that are not the
    toplevel, such as when a SELECT subquery or CTE-nested
    INSERT/UPDATE/DELETE is generated.

    .. versionadded:: 1.4

    	statementc                 X   |j                   rb|j                   j                  dd      }| j                  j                  ||j                  fd       }|7| j                  d|j                  f   }n| j                  d|j                  f   }|| u r
 | ||fi |S  |j                  ||fi |S Ncompile_state_pluginr   )_propagate_attrsrZ   plugins_effective_plugin_targetcreate_for_statement)r4   r   compilerr'   plugin_nameklasss         r   r   z!CompileState.create_for_statement  s     %%#4488&	K KKOOi@@A4E }	 B BC
 KKI>>?E C<y(1b11-5--iHRHHr    c                     || _         y r$   r   )r   r   r   r'   s       r   r9   zCompileState.__init__   s	    "r    c                     |j                   j                  dd       }|r+||j                  f}|| j                  v r| j                  |   S 	 | j                  d|j                  f   S # t        $ r Y y w xY wr   )r   rZ   r   r   r   )r4   r   r   r   s       r   get_plugin_classzCompileState.get_plugin_class  s~    0044"D
 	 B BCCckk!{{3''	;;	9+M+MNOO 		s   A& &	A21A2c                 X    	 | j                   ||j                  f   S # t        $ r Y y w xY wr$   )r   r   r   )r4   r   r   s      r   _get_plugin_class_for_pluginz)CompileState._get_plugin_class_for_plugin  s:    	;;i@@A   		s    	))c                       fd}|S )Nc                 *    | j                   f<   | S r$   )r   )cls_to_decorater4   r   
visit_names    r   decoratez)CompileState.plugin_for.<locals>.decorate"  s    5DCKKj12""r    r%   )r4   r   r   r   s   ``` r   
plugin_forzCompileState.plugin_for   s    	# r    N)r+   r,   r-   r.   	__slots__r   r?   r   r9   r   r   r   r%   r    r   r   r     sh    4 IGI I2#  &    r    r   c                       e Zd ZdZd Zy)
GenerativezUProvide a method-chaining pattern in conjunction with the
    @_generative decorator.c                 6   | j                   }| j                  }|j                  |      }|rH| j                  j	                         j                         D ci c]  \  }}||vs|| c}}|_        |S | j                  j	                         |_        |S c c}}w r$   )_memoized_keysr[   r6   __dict__copyitems)r   skipr4   sr   vs         r   rN   zGenerative._generate-  s    ""nnKK "&!3!3!5!;!;!=A$1AJ
  ++-AJs   B$BNr+   r,   r-   r.   rN   r%   r    r   r   r   )  s    r    r   c                       e Zd ZdZd Zy)InPlaceGenerativezkProvide a method-chaining pattern in conjunction with the
    @_generative decorator that mutates in place.c                 d    | j                   }|D ]  }| j                  j                  |d          | S r$   )r  r  rc   )r   r  r   s      r   rN   zInPlaceGenerative._generate?  s5    "" 	'AMMa&	'r    Nr  r%   r    r   r
  r
  ;  s    5r    r
  c                   N    e Zd ZdZdZ ej                         Zej                  Z
y)HasCompileStatez=A class that has a :class:`.CompileState` associated with it.N)r+   r,   r-   r.   _compile_state_pluginr   immutabledict_attributesr   r   _compile_state_factoryr%   r    r   r  r  F  s'    G $$$$&K)>>r    r  c                       e Zd ZdZd Zd Zy)_MetaOptionsz metaclass for the Options class.c                 t    t        t        d |D                    | _        t        j	                  | |||       y )Nc              3   J   K   | ]  }|j                  d       s|dvr|  yw)__)_cache_key_traversalN)
startswith)rr   r   s     r   ru   z(_MetaOptions.__init__.<locals>.<genexpr>U  s-      ||D)66 s   !#)tuplesorted_cache_attrstyper9   )r4   	classnamebasesdict_s       r   r9   z_MetaOptions.__init__S  s8       
 	c9eU3r    c                      |        }t        |      j                  | j                        r3t        d| dt        |      j                  | j                              |j                  j                  |       |S Nz<dictionary contains attributes not covered by Options class z: )rx   
differencer  r   r  r   r   othero1s      r   __add__z_MetaOptions.__add__^  si    Vu:  !2!23 U..t/@/@AC  	5!	r    N)r+   r,   r-   r.   r9   r&  r%   r    r   r  r  P  s    *	4r    r  c                       e Zd ZdZd Zd Zd Zd Zed        Z	e
d        Ze
d        Z ej                         Zej                   d	        Zed
        Zed        Zy)Optionsz,A cacheable option dictionary with defaults.c                 :    | j                   j                  |       y r$   )r  r   r&   s     r   r9   zOptions.__init__o  s    R r    c                 ~   | j                   j                  | j                         }|j                  j                  | j                         t	        |      j                  | j                        r3t        d| dt	        |      j                  | j                              |j                  j                  |       |S r!  )r[   r6   r  r   rx   r"  r  r   r#  s      r   r&  zOptions.__add__r  s    ^^##DNN3
4==)u:  !2!23 U..t/@/@AC  	5!	r    c                     t        j                  | j                  |j                        D ]   \  }}t        | |      t        ||      k7  s  y yNFT)r   zip_longestr  getattr)r   r$  rz   r{   s       r   __eq__zOptions.__eq__  sN     $$T%6%68J8JK 	DAqtQ75!#44	 r    c                       j                   j                  ddj                   fd j                  D              dS )N(, c              3   b   K   | ]&  }|j                   v r|d j                   |    ( yw)=Nr  )rr   r   r   s     r   ru   z#Options.__repr__.<locals>.<genexpr>  s3      % dmmA./s   ,/))r[   r+   joinr  r   s   `r   __repr__zOptions.__repr__  s;     NN##II ** 
 	
r    c                     t        | |      S r$   )
issubclass)r4   r   s     r   
isinstancezOptions.isinstance  s    #u%%r    c                 *    | |t        | |      |z   iz   S r$   )r.  )r   r]   r   s      r   add_to_elementzOptions.add_to_element  s    tWT4058999r    c                     | j                   S r$   r5  r   s    r   _state_dictzOptions._state_dict  s    }}r    c                     | j                   S r$   )_state_dict_const)r4   s    r   r?  zOptions._state_dict  s    $$$r    c           
      <   |j                         }| |j                  urz|j                  rnt        |j                        j	                  | j                        r@t        d|d| dt        |j                        j	                  | j                              | |z   S )Nzother element z is not empty, is not of type z+, and contains attributes not covered here )r?  r[   r  rx   r"  r   )r4   r$  r   s      r   
safe_mergezOptions.safe_merge  s     u&""E&&'2233C3CD **+66s7G7GH  Qwr    c                 2   |j                  t        |      j                  |            }|j                  ||       }|rWi }|D ]!  }d|z   }	||v r	||   ||	<   ||v s||   ||	<   # ||z   }
t	        j
                         j                  |||
i      }|
|fS ||fS )a{  process Options argument in terms of execution options.


        e.g.::

            (
                load_options,
                execution_options,
            ) = QueryContext.default_load_options.from_execution_options(
                "_sa_orm_load_options",
                {
                    "populate_existing",
                    "autoflush",
                    "yield_per"
                },
                execution_options,
                statement._execution_options,
            )

        get back the Options and refresh "_sa_orm_load_options" in the
        exec options dict w/ the Options as well

        r   )rp   rx   r   rZ   r   r  
merge_with)r4   r   attrsexec_optionsstatement_exec_optionscheck_argnamesexisting_optionsresultargnamelocalnew_optionss              r   from_execution_optionszOptions.from_execution_options  s    < ++##$:;
 (++C5F) Dgl*$0$9F5M 66$:7$CF5MD +V3K--/::sK0L ,, $\11r    N)r+   r,   r-   r.   r9   r&  r/  r8  r?   r;  r   r=  r?  r   r  rA  
classlevelrC  rO  r%   r    r   r(  r(  l  s    6!

 & & : :   +**,% %  0 32 32r    r(  c                   P    e Zd Zed        Zej
                  d        Zed        Zy)CacheableOptionsc                 0    t        j                  | ||      S r$   )r   _gen_cache_key)r   anon_map
bindparamss      r   rT  zCacheableOptions._gen_cache_key  s    ))$*EEr    c                 
    | dfS ri   r%   )r4   rU  rV  s      r   rT  zCacheableOptions._gen_cache_key  s    Ryr    c                 ,    t        j                  |       S r$   )r   _generate_cache_key_for_objectr   s    r   _generate_cache_keyz$CacheableOptions._generate_cache_key  s    99$??r    N)r+   r,   r-   r   rT  rP  rZ  r%   r    r   rR  rR    sF    F F   @ @r    rR  c                   2    e Zd Zej                  ZdZdZd Zy)ExecutableOptionexecutable_optionFc                     | j                   j                  | j                         }t        | j                        |_        |S )z/Create a shallow copy of this ExecutableOption.)r[   r6   r   r  )r   r'   rJ   s      r   r(   zExecutableOption._clone  s/    NN""4>>2$--(
r    N)	r+   r,   r-   r   
EMPTY_DICT_annotations__visit_name___is_has_cache_keyr(   r%   r    r   r\  r\    s    ??L(Nr    r\  c                      e Zd ZdZdZ ej                         ZdZdZ	dZ
dej                  fdej                  fdej                  fgZdZdZdZdZdZdZed	        Zed
        Zed        Zed        Zed        Zed        Zd Z ej@                  dd      d        Z! ej@                  dd      d        Z"e ej@                  ddd      d               Z#y)
ExecutablezMark a :class:`_expression.ClauseElement` as supporting execution.

    :class:`.Executable` is a superclass for all "statement" types
    of objects, including :func:`select`, :func:`delete`, :func:`update`,
    :func:`insert`, :func:`text`.

    TNr%   _with_options_with_context_optionsr   Fc                     | j                   S r$   )ra  r   s    r   r   z#Executable._effective_plugin_target1  s    """r    c                 N    | xj                   t        d |D              z  c_         y)aK  Apply options to this statement.

        In the general sense, options are any kind of Python object
        that can be interpreted by the SQL compiler for the statement.
        These options can be consumed by specific dialects or specific kinds
        of compilers.

        The most commonly known kind of option are the ORM level options
        that apply "eager load" and other loading behaviors to an ORM
        query.   However, options can theoretically be used for many other
        purposes.

        For background on specific kinds of options for specific kinds of
        statements, refer to the documentation for those option objects.

        .. versionchanged:: 1.4 - added :meth:`.Generative.options` to
           Core statement objects towards the goal of allowing unified
           Core / ORM querying capabilities.

        .. seealso::

            :ref:`deferred_options` - refers to options specific to the usage
            of ORM queries

            :ref:`relationship_loader_options` - refers to options specific
            to the usage of ORM queries

        c              3   d   K   | ](  }t         j                  t        j                  |       * y wr$   )	coercionsexpectr   ExecutableOptionRole)rr   r   s     r   ru   z%Executable.options.<locals>.<genexpr>S  s+      $
 U77=$
s   .0N)re  r  r   optionss     r   rn  zExecutable.options5  s)    < 	e $
$
 
 	
r    c                     || _         y)z|Assign the compile options to a new value.

        :param compile_options: appropriate CacheableOptions structure

        N_compile_options)r   compile_optionss     r   _set_compile_optionszExecutable._set_compile_optionsX  s     !0r    c                 .    | xj                   |z  c_         y)z*update the _compile_options with new keys.Nrp  rm  s     r   _update_compile_optionsz"Executable._update_compile_optionsb  s     	(r    c                 4    | xj                   ||ffz  c_         y)aM  Add a context option to this statement.

        These are callable functions that will
        be given the CompileState object upon compilation.

        A second argument cache_args is required, which will be combined with
        the ``__code__`` identity of the function itself in order to produce a
        cache key.

        N)rf  )r   	callable_
cache_argss      r   _add_context_optionzExecutable._add_context_optionh  s     	""	:'>&@@"r    c                     d|v rt        j                  d      d|v rt        j                  d      | j                  j                  |      | _        y)a  Set non-SQL options for the statement which take effect during
        execution.

        Execution options can be set on a per-statement or
        per :class:`_engine.Connection` basis.   Additionally, the
        :class:`_engine.Engine` and ORM :class:`~.orm.query.Query`
        objects provide
        access to execution options which they in turn configure upon
        connections.

        The :meth:`execution_options` method is generative.  A new
        instance of this statement is returned that contains the options::

            statement = select(table.c.x, table.c.y)
            statement = statement.execution_options(autocommit=True)

        Note that only a subset of possible execution options can be applied
        to a statement - these include "autocommit" and "stream_results",
        but not "isolation_level" or "compiled_cache".
        See :meth:`_engine.Connection.execution_options` for a full list of
        possible options.

        .. seealso::

            :meth:`_engine.Connection.execution_options`

            :meth:`_query.Query.execution_options`

            :meth:`.Executable.get_execution_options`

        isolation_levelz'isolation_level' execution option may only be specified on Connection.execution_options(), or per-engine using the isolation_level argument to create_engine().compiled_cachezm'compiled_cache' execution option may only be specified on Connection.execution_options(), not per statement.N)r   r   _execution_optionsr   r&   s     r   execution_optionszExecutable.execution_optionsv  sc    B "##/  r!##H  #'"9"9"?"?"Cr    c                     | j                   S )zGet the non-SQL options which will take effect during execution.

        .. versionadded:: 1.3

        .. seealso::

            :meth:`.Executable.execution_options`
        )r}  r   s    r   get_execution_optionsz Executable.get_execution_options  s     &&&r    z:meth:`.Executable.execute`zAll statement execution in SQLAlchemy 2.0 is performed by the :meth:`_engine.Connection.execute` method of :class:`_engine.Connection`, or in the ORM by the :meth:`.Session.execute` method of :class:`.Session`.)alternativec                     | j                   }|?t        | dd      xs | j                  j                  }d|z  }t	        j
                  |      |j                  | ||t        j                               S )z.Compile and execute this :class:`.Executable`.NdescriptionzThis %s is not directly bound to a Connection or Engine. Use the .execute() method of a Connection or Engine to execute this construct.)	bindr.  r[   r+   r   UnboundExecutionError_execute_clauseelementr   r  )r   multiparamsr"   elabelr`   s         r   executezExecutable.execute  s|     II9mT2Mdnn6M6M -/45 
 ++C00''+vt'9'9';
 	
r    z:meth:`.Executable.scalar`zScalar execution in SQLAlchemy 2.0 is performed by the :meth:`_engine.Connection.scalar` method of :class:`_engine.Connection`, or in the ORM by the :meth:`.Session.scalar` method of :class:`.Session`.c                 B     | j                   |i |j                         S )znCompile and execute this :class:`.Executable`, returning the
        result's scalar representation.

        )r  scalar)r   r  r"   s      r   r  zExecutable.scalar  s#     t||[3F3::<<r    z:attr:`.Executable.bind`z5Bound metadata is being removed as of SQLAlchemy 2.0.)r  enable_warningsc                     | j                   | j                   S t        |       D ]  }|| u r|j                  }||c S  y)aK  Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
        to
        which this :class:`.Executable` is bound, or None if none found.

        This is a traversal which checks locally, then
        checks among the "from" clauses of associated objects
        until a bound engine or connection is found.

        N)_bindrD   r  )r   fengines      r   r  zExecutable.bind  sO      ::!::t$ 	ADyVVF!	 r    )$r+   r,   r-   r.   supports_executionr   r  r}  r  re  rf  r   dp_executable_optionsr
   dp_with_context_optionsdp_propagate_attrs_executable_traverse_internals	is_select	is_update	is_insertis_text	is_deleteis_dmlr   r   rR   rn  rs  ru  ry  r~  r  deprecated_20r  r  r  r%   r    r   rd  rd    s    +++-EM 
+AAB#%==	
 
6IIJ&" IIIGIF# #  
  
D 0 0 ) )
 A A ,D ,D\	' T%

" T$== T"K
 r    rd  c                       e Zd ZdZd Zy)prefix_anon_mapaf  A map that creates new keys for missing key access.

    Considers keys of the form "<ident> <name>" to produce
    new symbols "<name>_<index>", where "index" is an incrementing integer
    corresponding to <name>.

    Inlines the approach taken by :class:`sqlalchemy.util.PopulateDict` which
    is otherwise usually used for this type of operation.

    c                     |j                  dd      \  }}| j                  |d      }|dz   | |<   |dz   t        |      z   }|| |<   |S )N r   r   )r   rZ   str)r   r   identderivedanonymous_counterr   s         r   __missing__zprefix_anon_map.__missing__  sX    99S!, HHWa0)A-W#$5 66S	r    N)r+   r,   r-   r.   r  r%   r    r   r  r    s    	r    r  c                       e Zd ZdZd Zd Zy)SchemaEventTargetzBase class for elements that are the targets of :class:`.DDLEvents`
    events.

    This includes :class:`.SchemaItem` as well as :class:`.SchemaType`.

    c                      y)z0Associate with this SchemaEvent's parent object.Nr%   r   parentr'   s      r   _set_parentzSchemaEventTarget._set_parent  s    r    c                     | j                   j                  | |        | j                  |fi | | j                   j                  | |       y r$   )dispatchbefore_parent_attachr  after_parent_attachr  s      r   _set_parent_with_dispatchz+SchemaEventTarget._set_parent_with_dispatch  s?    **48&2&))$7r    N)r+   r,   r-   r.   r  r  r%   r    r   r  r  
  s    ?8r    r  c                       e Zd ZdZddiZy)SchemaVisitorz/Define the visiting for ``SchemaItem`` objects.schema_visitorTN)r+   r,   r-   r.   __traverse_options__r%   r    r   r  r    s    9,d3r    r  c                       e Zd ZdZdZd!dZd Zed        Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd!dZd Zd Zd Zd Zd Zd Zd ZdZd Zd!dZd Zd Z d Z!d Z"d"d Z#y)#ColumnCollectiona  Collection of :class:`_expression.ColumnElement` instances,
    typically for
    :class:`_sql.FromClause` objects.

    The :class:`_sql.ColumnCollection` object is most commonly available
    as the :attr:`_schema.Table.c` or :attr:`_schema.Table.columns` collection
    on the :class:`_schema.Table` object, introduced at
    :ref:`metadata_tables_and_columns`.

    The :class:`_expression.ColumnCollection` has both mapping- and sequence-
    like behaviors. A :class:`_expression.ColumnCollection` usually stores
    :class:`_schema.Column` objects, which are then accessible both via mapping
    style access as well as attribute access style.

    To access :class:`_schema.Column` objects using ordinary attribute-style
    access, specify the name like any other object attribute, such as below
    a column named ``employee_name`` is accessed::

        >>> employee_table.c.employee_name

    To access columns that have names with special characters or spaces,
    index-style access is used, such as below which illustrates a column named
    ``employee ' payment`` is accessed::

        >>> employee_table.c["employee ' payment"]

    As the :class:`_sql.ColumnCollection` object provides a Python dictionary
    interface, common dictionary method names like
    :meth:`_sql.ColumnCollection.keys`, :meth:`_sql.ColumnCollection.values`,
    and :meth:`_sql.ColumnCollection.items` are available, which means that
    database columns that are keyed under these names also need to use indexed
    access::

        >>> employee_table.c["values"]


    The name for which a :class:`_schema.Column` would be present is normally
    that of the :paramref:`_schema.Column.key` parameter.  In some contexts,
    such as a :class:`_sql.Select` object that uses a label style set
    using the :meth:`_sql.Select.set_label_style` method, a column of a certain
    key may instead be represented under a particular label name such
    as ``tablename_columnname``::

        >>> from sqlalchemy import select, column, table
        >>> from sqlalchemy import LABEL_STYLE_TABLENAME_PLUS_COL
        >>> t = table("t", column("c"))
        >>> stmt = select(t).set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL)
        >>> subq = stmt.subquery()
        >>> subq.c.t_c
        <sqlalchemy.sql.elements.ColumnClause at 0x7f59dcf04fa0; t_c>

    :class:`.ColumnCollection` also indexes the columns in order and allows
    them to be accessible by their integer position::

        >>> cc[0]
        Column('x', Integer(), table=None)
        >>> cc[1]
        Column('y', Integer(), table=None)

    .. versionadded:: 1.4 :class:`_expression.ColumnCollection`
       allows integer-based
       index access to the collection.

    Iterating the collection yields the column expressions in order::

        >>> list(cc)
        [Column('x', Integer(), table=None),
         Column('y', Integer(), table=None)]

    The base :class:`_expression.ColumnCollection` object can store
    duplicates, which can
    mean either two columns with the same key, in which case the column
    returned by key  access is **arbitrary**::

        >>> x1, x2 = Column('x', Integer), Column('x', Integer)
        >>> cc = ColumnCollection(columns=[(x1.name, x1), (x2.name, x2)])
        >>> list(cc)
        [Column('x', Integer(), table=None),
         Column('x', Integer(), table=None)]
        >>> cc['x'] is x1
        False
        >>> cc['x'] is x2
        True

    Or it can also mean the same column multiple times.   These cases are
    supported as :class:`_expression.ColumnCollection`
    is used to represent the columns in
    a SELECT statement which may include duplicates.

    A special subclass :class:`.DedupeColumnCollection` exists which instead
    maintains SQLAlchemy's older behavior of not allowing duplicates; this
    collection is used for schema level objects like :class:`_schema.Table`
    and
    :class:`.PrimaryKeyConstraint` where this deduping is helpful.  The
    :class:`.DedupeColumnCollection` class also has additional mutation methods
    as the schema constructs have more use cases that require removal and
    replacement of columns.

    .. versionchanged:: 1.4 :class:`_expression.ColumnCollection`
       now stores duplicate
       column keys as well as the same column in multiple positions.  The
       :class:`.DedupeColumnCollection` class is added to maintain the
       former behavior in those cases where deduplication as well as
       additional replace/remove operations are needed.


    )_collection_index_colsetNc                     t         j                  | dt                      t         j                  | di        t         j                  | dg        |r| j                  |       y y )Nr  r  r  )r8   __setattr__rx   _initial_populate)r   columnss     r   r9   zColumnCollection.__init__  sP    4CE242.43""7+ r    c                 &    | j                  |       y r$   _populate_separate_keysr   iter_s     r   r  z"ColumnCollection._initial_populate  s    $$U+r    c                 L    | j                   D cg c]  \  }}|	 c}}S c c}}w r$   r  r   r   cols      r   _all_columnszColumnCollection._all_columns  s     $($4$45C555    c                 L    | j                   D cg c]  \  }}|	 c}}S c c}}w )zQReturn a sequence of string key names for all columns in this
        collection.r  r  s      r   keyszColumnCollection.keys  s"     #'"2"23hq#333r  c                 L    | j                   D cg c]  \  }}|	 c}}S c c}}w )zReturn a sequence of :class:`_sql.ColumnClause` or
        :class:`_schema.Column` objects for all columns in this
        collection.r  r  s      r   r   zColumnCollection.values  s"     %)$4$45C555r  c                 ,    t        | j                        S )zReturn a sequence of (key, column) tuples for all columns in this
        collection each consisting of a string key name and a
        :class:`_sql.ColumnClause` or
        :class:`_schema.Column` object.
        )listr  r   s    r   r  zColumnCollection.items  s     D$$%%r    c                 ,    t        | j                        S r$   )boolr  r   s    r   __bool__zColumnCollection.__bool__  s    D$$%%r    c                 ,    t        | j                        S r$   )r   r  r   s    r   r   zColumnCollection.__len__  s    4##$$r    c                 ^    t        | j                  D cg c]  \  }}|	 c}}      S c c}}w r$   )r   r  r  s      r   r   zColumnCollection.__iter__  s%    t'7'78VQS8998s   )
c                     	 | j                   |   S # t        $ rF}t        |t        j                        r!t        j
                  t        |      |       n Y d }~y d }~ww xY wr   )r  r   r;  r   	int_typesr   
IndexErrorr   r   r   s      r   r   zColumnCollection.__getitem__  sO    	;;s## 	#t~~.JsOSA B	s    	A <AA c                     	 | j                   |   S # t        $ r*}t        j                  t	        |      |       Y d }~y d }~ww xY wr   )r  r   r   r   AttributeErrorr  s      r   __getattr__zColumnCollection.__getattr__  s?    	B;;s## 	BKKs+SAA	Bs    	A ?Ac                     || j                   vr0t        |t        j                        st	        j
                  d      yy)Nz'__contains__ requires a string argumentFT)r  r;  r   string_typesr   r   r   s     r   __contains__zColumnCollection.__contains__  s<    dkk!c4#4#45''=  r    c                 L    t        j                  | |      D ]  \  }}||us y y)zdCompare this :class:`_expression.ColumnCollection` to another
        based on the names of the keysFT)r   r-  )r   r$  lrs       r   comparezColumnCollection.compare  s3     $$T51 	DAqz	 r    c                 $    | j                  |      S r$   )r  r   r$  s     r   r/  zColumnCollection.__eq__  s    ||E""r    c                 @    || j                   v r| j                   |   S |S )zGet a :class:`_sql.ColumnClause` or :class:`_schema.Column` object
        based on a string key name from this
        :class:`_expression.ColumnCollection`.)r  )r   r   r   s      r   rZ   zColumnCollection.get  s$    
 $++;;s##Nr    c                 f    | j                   j                  ddj                  d | D              dS )Nr1  r2  c              3   2   K   | ]  }t        |        y wr$   )r  )rr   rJ   s     r   ru   z+ColumnCollection.__str__.<locals>.<genexpr>  s     +c!f+s   r6  )r[   r+   r7  r   s    r   __str__zColumnCollection.__str__  s+    NN##II+d++
 	
r    c                     t               r$   r   r   s      r   r   zColumnCollection.__setitem__      !##r    c                     t               r$   r   r   s     r   r   zColumnCollection.__delitem__  r  r    c                     t               r$   r   )r   r   r<   s      r   r  zColumnCollection.__setattr__  r  r    c                     t               )zQDictionary clear() is not implemented for
        :class:`_sql.ColumnCollection`.r   r   s    r   clearzColumnCollection.clear       "##r    c                     t               )zRDictionary remove() is not implemented for
        :class:`_sql.ColumnCollection`.r   )r   columns     r   removezColumnCollection.remove   r  r    c                     t               )zRDictionary update() is not implemented for
        :class:`_sql.ColumnCollection`.r   r  s     r   r   zColumnCollection.update  r  r    c                    t        |      }|| j                  dd | j                  j                  d | j                  D               | j                  j                  d t        | j                        D               | j                  j                  t        | j                        D ci c]  \  }}||
 c}}       yc c}}w )*populate from an iterator of (key, column)Nc              3   &   K   | ]	  \  }}|  y wr$   r%   rr   r   rJ   s      r   ru   z;ColumnCollection._populate_separate_keys.<locals>.<genexpr>  s     ;$!QA;   c              3   0   K   | ]  \  }\  }}||f  y wr$   r%   rr   idxr   rJ   s       r   ru   z;ColumnCollection._populate_separate_keys.<locals>.<genexpr>  !      
$fq!S!H
   )r  r  r  r   r  	enumerater   )r   r  colsr   r  s        r   r  z(ColumnCollection._populate_separate_keys  s    E{";$*:*:;; 
(1$2B2B(C
 	
 	$:J:J1KLvq#AsFLMLs   )B?
c                    ||j                   }t        | j                        }| j                  j                  ||f       | j                  j                  |       || j                  |<   || j                  vr|| j                  |<   yy)a  Add a column to this :class:`_sql.ColumnCollection`.

        .. note::

            This method is **not normally used by user-facing code**, as the
            :class:`_sql.ColumnCollection` is usually part of an existing
            object such as a :class:`_schema.Table`. To add a
            :class:`_schema.Column` to an existing :class:`_schema.Table`
            object, use the :meth:`_schema.Table.append_column` method.

        N)r   r   r  appendr  addr  )r   r  r   r  s       r   r  zColumnCollection.add  sx     ;**C  !f. Adkk!%DKK "r    c                 4    | j                   | j                  dS )Nr  r  r  r   s    r   __getstate__zColumnCollection.__getstate__,  s    #//4;;GGr    c           
          t         j                  | d|d          t         j                  | d|d          t         j                  | d| j                  D ch c]  \  }}|	 c}}       y c c}}w )Nr  r  r  )r8   r  r  )r   stater   r  s       r   __setstate__zColumnCollection.__setstate__/  s\    45?;4m0DE)0@0@AfacA	
As   A*c                     || j                   vr0t        |t        j                        rt	        j
                  d      yy)z3Checks if a column object exists in this collectionzZcontains_column cannot be used with string arguments. Use ``col_name in table.c`` instead.FT)r  r;  r   r  r   r   r   r  s     r   contains_columnz ColumnCollection.contains_column6  s>    dll"#t001'';  r    c                     t        |       S )zJReturn an "immutable" form of this
        :class:`_sql.ColumnCollection`.)ImmutableColumnCollectionr   s    r   as_immutablezColumnCollection.as_immutableB  s     )..r    c                 L   d }|| j                   v r|S d\  }}|j                  }| j                  D cg c]  \  }}|	 }	}}|	D ]K  }t        t	        |j                              }
|j                  |
      }|s6|r
 ||
|      sB|||}}It        |      t        |      kD  r||}}e||k(  skt        j                  t        j                  |j                         D cg c]/  }|j                  |      r|j                  j                  dd      1 c}      }t        j                  t        j                  |j                         D cg c]/  }|j                  |      r|j                  j                  dd      1 c}      }||k  sH||}}N |S c c}}w c c}w c c}w )a  Given a :class:`_expression.ColumnElement`, return the exported
        :class:`_expression.ColumnElement` object from this
        :class:`_expression.ColumnCollection`
        which corresponds to that original :class:`_expression.ColumnElement`
        via a common
        ancestor column.

        :param column: the target :class:`_expression.ColumnElement`
                      to be matched.

        :param require_embedded: only return corresponding columns for
         the given :class:`_expression.ColumnElement`, if the given
         :class:`_expression.ColumnElement`
         is actually present within a sub-element
         of this :class:`_expression.Selectable`.
         Normally the column will match if
         it merely shares a common ancestor with one of the exported
         columns of this :class:`_expression.Selectable`.

        .. seealso::

            :meth:`_expression.Selectable.corresponding_column`
            - invokes this method
            against the collection returned by
            :attr:`_expression.Selectable.exported_columns`.

        .. versionchanged:: 1.4 the implementation for ``corresponding_column``
           was moved onto the :class:`_expression.ColumnCollection` itself.

        c                 |    |j                  |       D ](  }t        t        |g            j                  |       r( y yr,  )r"  rx   rl   rp   )expanded_proxy_set
target_setts      r   embeddedz7ColumnCollection.corresponding_column.<locals>.embeddedh  sD    **+=> !>1#./<<& !	!
 r    )NNweightr   )r  r;   r  rx   rl   rp   r   r   reducerd   r  _uncached_proxy_listshares_lineager`  rZ   )r   r  require_embeddedr  r  	intersectr  r   rJ   r  r  isccol_distance
c_distances                  r   corresponding_columnz%ColumnCollection.corresponding_columnH  s   @	 T\\!M#Y%%
 $ 0 01fq!11 0	.A!$^AKK%@!A''(:;A$.
;; &'CVc)n, &'C)^ $(;;  '*&>&>&@ "!008 OO//!<$L "&  '(&<&<&> "!008 OO//!<"J "L0)*AYa0	.b 
e 2Ds   F 4F4F!r$   )F)$r+   r,   r-   r.   r   r9   r  r   r  r  r   r  r  r   r   r   r  r  r  r/  rZ   r  r   r   r  r  r  r   __hash__r  r  r  r  r
  r  r  r%   r    r   r  r  !  s    jX 3I,, 6 64
6&&%:B#
$$$$
$
$
 HN&,H

/_r    r  c                   0    e Zd ZdZddZd Zd Zd Zd Zy)	DedupeColumnCollectionau  A :class:`_expression.ColumnCollection`
    that maintains deduplicating behavior.

    This is useful by schema level objects such as :class:`_schema.Table` and
    :class:`.PrimaryKeyConstraint`.    The collection includes more
    sophisticated mutator methods as well to suit schema objects which
    require mutable column collections.

    .. versionadded:: 1.4

    Nc                    |$|j                   |k7  rt        j                  d      |j                   }|t        j                  d      || j                  v rF| j                  |   }||u ry | j	                  |       t
        j                  j                  |d       y t        | j                        }| j                  j                  ||f       | j                  j                  |       || j                  |<   || j                  |<   y )NKDedupeColumnCollection requires columns be under the same key as their .keyz-Can't add unnamed column to column collectionr;   )r   r   r   r  replacer   r   resetr   r  r   r  r  )r   r  r   existingr  s        r   r  zDedupeColumnCollection.add  s    ?vzzS0##-  jj;##?  $++{{3'H6!LL 
 ""((=D$$%A##S&M2LLV$#DKKN%DKKr    c                    t        |      }g }|D ]  \  }}|j                  |k7  rt        j                  d      |j                  | j
                  v r+|j                  |j                  k7  r|j                  |       m|j                  | j
                  v r|j                  |       || j
                  |<   | j                  j                  ||f        | j                  j                  d | j                  D               | j
                  j                  d t        | j                        D               |D ]  }| j                  |        y)r  r#  c              3   &   K   | ]	  \  }}|  y wr$   r%   r  s      r   ru   zADedupeColumnCollection._populate_separate_keys.<locals>.<genexpr>  s     =&1aA=r  c              3   0   K   | ]  \  }\  }}||f  y wr$   r%   r  s       r   ru   zADedupeColumnCollection._populate_separate_keys.<locals>.<genexpr>  r  r  N)r  r   r   r   r]   r  r   r  r  r   r  r$  )r   r  r  replace_colr   r  s         r   r  z.DedupeColumnCollection._populate_separate_keys  s   E{ 	2FAsww!|''1  xx4;;&377chh+>""3'DKK'""3'!$A  ''C1	2 	=D,<,<== 
(1$2B2B(C
 	
  	CLL	r    c                 4    | j                  d |D               y )Nc              3   8   K   | ]  }|j                   |f  y wr$   )r   )rr   r  s     r   ru   z0DedupeColumnCollection.extend.<locals>.<genexpr>  s     $Ecggs^$Es   r  r  s     r   extendzDedupeColumnCollection.extend  s    $$$Eu$EEr    c           	         || j                   vrt        d|z        | j                  |j                  = | j                   j	                  |       | j
                  D cg c]  \  }}||us||f c}}| j
                  d d  | j                  j                  t        | j
                        D ci c]  \  }\  }}|| c}}}       | j                  t        | j
                        = y c c}}w c c}}}w )Nz8Can't remove column %r; column is not in this collection)	r  r   r  r   r  r  r   r  r   )r   r  r   rJ   r  r  s         r   r  zDedupeColumnCollection.remove  s    %J  KK

#F#!%!1!1
1Qf_QF
 	+4T5E5E+FGG-#x3S#XG	
 KKD,,-.
 Hs   C*+C*0C0c           	      
   t               }|j                  | j                  v r\|j                  |j                  k7  rC| j                  |j                     }|j                  |j                  k(  r|j	                  |       |j                  | j                  v r(|j	                  | j                  |j                            g }d}| j
                  D ]?  \  }}||v r#|rd}|j                  |j                  |f       -|j                  ||f       A |r| j                  j                  |       |s|j                  |j                  |f       | j                  j	                  |       || j
                  dd | j                  j                          | j                  j                  t        | j
                        D ci c]  \  }\  }}|| c}}}       | j                  j                  | j
                         yc c}}}w )a  add the given column to this collection, removing unaliased
        versions of this column  as well as existing columns with the
        same key.

        e.g.::

            t = Table('sometable', metadata, Column('col1', Integer))
            t.columns.replace(Column('col1', Integer, key='columnone'))

        will remove the original 'col1' from the collection, and add
        the new column under the name 'columnname'.

        Used by schema.Column to override columns during table reflection.

        FTN)rx   r]   r  r   r  r  r   r  difference_updater  r   r  )	r   r  
remove_colr$  new_colsreplacedr   r  r  s	            r   r$  zDedupeColumnCollection.replace  s   " U
;;$++%&***CKK,EzzUYY&u%::$NN4;;vzz23&& 	*FAsj #HOOVZZ$89C)	* LL**:6OOVZZ01 &+4T5E5E+FGG-#x3S#XG	
 	4++, Hs   ?G>r$   )	r+   r,   r-   r.   r  r  r-  r  r$  r%   r    r   r!  r!    s"    
 &D2F/"2-r    r!  c                   V    e Zd ZdZd Zd Zd Zej                  j                  xZ
xZZy)r  _parentc                     t         j                  | d|       t         j                  | d|j                         t         j                  | d|j                         t         j                  | d|j                         y )Nr6  r  r  r  )r8   r  r  r  r  )r   
collections     r   r9   z"ImmutableColumnCollection.__init__>  s\    4J74J,>,>?4:+<+<=4
0F0FGr    c                     d| j                   iS Nr6  r5  r   s    r   r  z&ImmutableColumnCollection.__getstate__D  s    4<<((r    c                 0    |d   }| j                  |       y r:  )r9   )r   r  r  s      r   r  z&ImmutableColumnCollection.__setstate__G  s    y!fr    N)r+   r,   r-   r   r9   r  r  r   ImmutableContainer
_immutabler  r-  r  r%   r    r   r  r  ;  s4    IH) !33>>>C>&6r    r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)	ColumnSetc                 
    || v S r$   r%   r	  s     r   r
  zColumnSet.contains_columnO  s    d{r    c                 4    |D ]  }| j                  |        y r$   )r  )r   r  r  s      r   r-  zColumnSet.extendR  s     	CHHSM	r    c                 0    t        |       t        |      z   S r$   )r  r  s     r   r&  zColumnSet.__add__V  s    DzDK''r    c                     g }|D ]/  }| D ](  }|j                  |      s|j                  ||k(         * 1 t        j                  | S r$   )r  r   rE   and_)r   r$  r  rJ   rM  s        r   r/  zColumnSet.__eq__Y  sT     	)A )##E*HHQ%Z()	) }}a  r    c                 8    t        t        d | D                    S )Nc              3       K   | ]  }|  y wr$   r%   )rr   rQ   s     r   ru   z%ColumnSet.__hash__.<locals>.<genexpr>b  s     *!*s   )hashr  r   s    r   r  zColumnSet.__hash__a  s    E*T**++r    N)r+   r,   r-   r
  r-  r&  r/  r  r%   r    r   r?  r?  N  s    (!,r    r?  c           	          t        j                  d       | j                  }|sY| j                  j                  }t        | dt        | dd             }|r|d|}nd|z  }|d|z  }t        j                  |      |S )Nz|The ``bind`` argument for schema methods that invoke SQL against an engine or connection will be required in SQLAlchemy 2.0.fullnamer]   z object z	%s objectzm%s is not bound to an Engine or Connection.  Execution can not proceed without a database to execute against.)r   warn_deprecated_20r  r[   r+   r.  r   r  )
schemaitemr`   r  r]   r  items         r   _bind_or_errorrM  e  s    	N ??D##,,
GJ$E
 %)51D%D;!" 
 '',,Kr    c                     	 | j                   S # t        $ r8 t        j                  |       D ]  }t	        |d      s|j                   c cY S   w xY w)zReturn the nearest .entity_namespace for the given entity.

    If not immediately available, does an iterate to find a sub-element
    that has one, if any.

    entity_namespace)rO  r  r   iteratehasattr)entityrs   s     r   _entity_namespacerS    sX    &&& $$V, 	Dt/0,,,	 s    -AAAc           
          	 t        |       }|t        urt        |||      S t        ||      S # t        $ r;}t	        j
                  t        j                  d| d|d      |       Y d}~yd}~ww xY w)zReturn an entry from an entity_namespace.


    Raises :class:`_exc.InvalidRequestError` rather than attribute error
    on not found.

    zEntity namespace for "z" has no property ""r   N)rS  r   r.  r  r   r   r   r\   )rR  r   r   nsr   s        r   _entity_namespace_keyrW    ss    
v&& 2sG,,2s## 
##3   	
 	

s   . . 	A21A--A2r$   )Cr.   rA   rd   r    r   r   
traversalsr   r   r   r	   r
   r   r   r   r   r   rj  rE   type_apisymbolr   r   r8   r   r1   rD   rK   rR   rg   r(   rl   r|   r   collections_abcMutableMappingr   r   preload_moduler   r   r   r   r
  r  r  r  with_metaclassr(  rR  r\  StatementRolerd  r   r  r  r  r  r!  r<  r  ordered_column_setr?  rM  rS  rW  r%   r    r   <module>rb     s  
   	   # ( + # / '     	4;;12 	X	 $	 0,: ?
9
d**99 9
x$d**99 $@ *+1 ,1lCF lC^_6 _D $ ?j ?4 8G2!d!!,/ G2T@w @' `$$j `Fd *8 8"4M 4Fv FRN-- N-b? 7 79I ?&,'' ,.4" 06 
r    