
    ؄_#r                     >   d Z ddlm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  e            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e          Z G d de          Z G d de          Z G d dee          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% d&e          Z  G d' d(e          Z!eZ"eZ#eZ$ e ej%                  Z& e d)           Z'd=d*Z( G d+ d,e          Z)d- Z*d=d.Z+d/ Z,d0 Z-d1 Z.d=d2Z/d3 Z0 G d4 d5e          Z1 e1d6          Z2d7 Z3 G d8 d9e          Z4 G d: d;e4          Z5d< Z6dS )>zCollection classes and helpers.    )absolute_importN   )binary_types)collections_abc)itertools_filterfalse)py2k)string_types)	threadingc                       e Zd ZdZd ZdS )AbstractKeyedTuple c                 *    t          | j                  S )zReturn a list of string key names for this :class:`.KeyedTuple`.

        .. seealso::

            :attr:`.KeyedTuple._fields`

        )list_fieldsselfs    a/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/util/_collections.pykeyszAbstractKeyedTuple.keys   s     DL!!!    N)__name__
__module____qualname__	__slots__r   r   r   r   r   r      s(        I	" 	" 	" 	" 	"r   r   c                   <    e Zd ZdZddZed             Zd Zd ZdS )
KeyedTuplea  ``tuple`` subclass that adds labeled names.

    E.g.::

        >>> k = KeyedTuple([1, 2, 3], labels=["one", "two", "three"])
        >>> k.one
        1
        >>> k.two
        2

    Result rows returned by :class:`_query.Query` that contain multiple
    ORM entities and/or column expressions make use of this
    class to return rows.

    The :class:`.KeyedTuple` exhibits similar behavior to the
    ``collections.namedtuple()`` construct provided in the Python
    standard library, however is architected very differently.
    Unlike ``collections.namedtuple()``, :class:`.KeyedTuple` is
    does not rely on creation of custom subtypes in order to represent
    a new series of keys, instead each :class:`.KeyedTuple` instance
    receives its list of keys in place.   The subtype approach
    of ``collections.namedtuple()`` introduces significant complexity
    and performance overhead, which is not necessary for the
    :class:`_query.Query` object's use case.

    .. seealso::

        :ref:`ormtutorial_querying`

    Nc                     t                               | |          }|r)|j                            t	          ||                     ng }||j        d<   |S )N_labels)tuple__new____dict__updatezip)clsvalslabelsts       r   r   zKeyedTuple.__new__J   sV    MM#t$$ 	Jc&$//0000F &
9r   c                 >    t          d | j        D                       S )zReturn a tuple of string key names for this :class:`.KeyedTuple`.

        This method provides compatibility with ``collections.namedtuple()``.

        .. seealso::

            :meth:`.KeyedTuple.keys`

        c                     g | ]}||S Nr   ).0ls     r   
<listcomp>z&KeyedTuple._fields.<locals>.<listcomp>^   s    ???Aar   )r   r   r   s    r   r   zKeyedTuple._fieldsS   s#     ?????@@@r   c                 &    t          d|z            )NzCan't set attribute: %s)AttributeErrorr   keyvalues      r   __setattr__zKeyedTuple.__setattr__`   s    6<===r   c                 D      fd                                  D             S )zReturn the contents of this :class:`.KeyedTuple` as a dictionary.

        This method provides compatibility with ``collections.namedtuple()``,
        with the exception that the dictionary returned is **not** ordered.

        c                 ,    i | ]}|j         |         S r   )r    r*   r0   r   s     r   
<dictcomp>z&KeyedTuple._asdict.<locals>.<dictcomp>j   s"    ???CT]3'???r   )r   r   s   `r   _asdictzKeyedTuple._asdictc   s(     @???499;;????r   r)   )	r   r   r   __doc__r   propertyr   r2   r7   r   r   r   r   r   *   ss         >    
A 
A X
A> > >@ @ @ @ @r   r   c                   $    e Zd ZdZd Zd Zd ZdS )_LWr   c                 8    t                               | |          S r)   )r   r   )r#   r$   s     r   r   z_LW.__new__p   s    }}S$'''r   c                 <    t           t          |           | j        ffS r)   )r   r   _real_fieldsr   s    r   
__reduce__z_LW.__reduce__s   s     DJJ(9:::r   c                 v    t          t          | j        |                     }|                    dd           |S )zAReturn the contents of this :class:`.KeyedTuple` as a dictionary.N)dictr"   r>   popr   ds     r   r7   z_LW._asdicty   s7     T&--..	dDr   N)r   r   r   r   r   r?   r7   r   r   r   r;   r;   m   sF        I( ( (; ; ;    r   r;   c                        e Zd Zd ZexZxZZdS )ImmutableContainerc                 :    t          d| j        j        z            )Nz%s object is immutable)	TypeError	__class__r   r   argkws      r   
_immutablezImmutableContainer._immutable   s    04>3JJKKKr   N)r   r   r   rM   __delitem____setitem__r2   r   r   r   rF   rF      s1        L L L /98K8+r   rF   c                   J    e Zd Zej        xZxZxZxZZ	d Z
d Zd Zd Zd ZdS )immutabledictc                 ^    t                               |           }t          j        |g|R   |S r)   )rA   r   __init__)r#   argsnews      r   r   zimmutabledict.__new__   s0    ll3c!D!!!!
r   c                     d S r)   r   )r   rT   s     r   rS   zimmutabledict.__init__   s    r   c                 0    t           t          |           ffS r)   )rQ   rA   r   s    r   r?   zimmutabledict.__reduce__   s    tDzzm++r   c                     |s| S | s&t          |t                    r|S t          |          S t          |           }t                              ||           |S r)   )
isinstancerQ   rA   r!   )r   rD   d2s      r   unionzimmutabledict.union   sb     
	K 	!]++ ($Q'''t$$BKKAIr   c                 <    dt                               |           z  S )Nzimmutabledict(%s))rA   __repr__r   s    r   r]   zimmutabledict.__repr__   s    "T]]4%8%888r   N)r   r   r   rF   rM   clearrB   popitem
setdefaultr!   r   rS   r?   r[   r]   r   r   r   rQ   rQ      s{        2D2OOEOCO'OJ  
  , , ,  9 9 9 9 9r   rQ   c                        e Zd ZdZdZd Zd Zd Z f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 xZS )
Propertiesz8Provide a __getattr__/__setattr__ interface over a dict._datac                 >    t                               | d|           d S Nrd   objectr2   )r   datas     r   rS   zProperties.__init__   s     4$/////r   c                 *    t          | j                  S r)   )lenrd   r   s    r   __len__zProperties.__len__   s    4:r   c                 h    t          t          | j                                                            S r)   )iterr   rd   valuesr   s    r   __iter__zProperties.__iter__   s&    D**,,--...r   c                     t          t          t          |                     d | j                                        D             z   S )Nc                 ,    g | ]}t          |          S r   )str)r*   ks     r   r,   z&Properties.__dir__.<locals>.<listcomp>   s+     /
 /
 /
CFF/
 /
 /
r   )dirsuperrb   rd   r   )r   rI   s    r   __dir__zProperties.__dir__   sJ    5T**++ /
 /
 JOO--/
 /
 /
 
 	
r   c                 @    t          |           t          |          z   S r)   r   r   others     r   __add__zProperties.__add__   s    DzzDKK''r   c                     || j         |<   d S r)   rc   r   r0   objs      r   rO   zProperties.__setitem__       
3r   c                     | j         |         S r)   rc   r   r0   s     r   __getitem__zProperties.__getitem__       z#r   c                     | j         |= d S r)   rc   r   s     r   rN   zProperties.__delitem__   s    JsOOOr   c                     || j         |<   d S r)   rc   r~   s      r   r2   zProperties.__setattr__   r   r   c                     d| j         iS rf   rc   r   s    r   __getstate__zProperties.__getstate__   s    $$r   c                 J    t                               | d|d                    d S rf   rg   )r   states     r   __setstate__zProperties.__setstate__   s$    4%.99999r   c                 X    	 | j         |         S # t          $ r t          |          w xY wr)   )rd   KeyErrorr.   r   s     r   __getattr__zProperties.__getattr__   s<    	&:c?" 	& 	& 	& %%%	&s    )c                     || j         v S r)   rc   r   s     r   __contains__zProperties.__contains__       dj  r   c                 *    t          | j                  S )z8Return an immutable proxy for this :class:`.Properties`.)ImmutablePropertiesrd   r   s    r   as_immutablezProperties.as_immutable   s     #4:...r   c                 :    | j                             |           d S r)   )rd   r!   r   r1   s     r   r!   zProperties.update   s    
%     r   Nc                     || v r| |         S |S r)   r   )r   r0   defaults      r   getzProperties.get   s    $;;9Nr   c                 *    t          | j                  S r)   )r   rd   r   s    r   r   zProperties.keys       DJr   c                 N    t          | j                                                  S r)   )r   rd   ro   r   s    r   ro   zProperties.values   s    DJ%%''(((r   c                 N    t          | j                                                  S r)   )r   rd   itemsr   s    r   r   zProperties.items   s    DJ$$&&'''r   c                     || j         v S r)   rc   r   s     r   has_keyzProperties.has_key   r   r   c                 8    | j                                          d S r)   )rd   r^   r   s    r   r^   zProperties.clear   s    
r   r)   )r   r   r   r8   r   rS   rl   rp   rw   r|   rO   r   rN   r2   r   r   r   r   r   r!   r   r   ro   r   r   r^   __classcell__)rI   s   @r   rb   rb      st       BBI0 0 0  / / /
 
 
 
 

( ( (        % % %: : :& & &! ! !/ / /
! ! !        ) ) )( ( (! ! !      r   rb   c                       e Zd ZdZdZd ZdS )OrderedPropertieszUProvide a __getattr__/__setattr__ interface with an OrderedDict
    as backing store.r   c                 T    t                               | t                                 d S r)   )rb   rS   OrderedDictr   s    r   rS   zOrderedProperties.__init__   s"    D+--00000r   N)r   r   r   r8   r   rS   r   r   r   r   r      s4          I1 1 1 1 1r   r   c                       e Zd ZdZdZdS )r   zDProvide immutable dict/object attribute to an underlying dictionary.r   N)r   r   r   r8   r   r   r   r   r   r     s        NNIIIr   r   c                       e Zd ZdZdZd ZddZd Zd Zd Z	d	 Z
dd
Zd Zd Zd Zd Zd Zer	d Zd Zd Zd Zd Zd Zd ZdS )r   zCA dict that returns keys/values/items in the order they were added._listc                 :    t           |                                 ffS r)   )r   r   r   s    r   r?   zOrderedDict.__reduce__  s    TZZ\\O++r   Nc                 Z    g | _         ||r | j        di | d S d S  | j        |fi | d S )Nr   )r   r!   )r   _OrderedDict____sequencekwargss      r   rS   zOrderedDict.__init__  sa    
 &%%f%%%%%& & DK///////r   c                 H    g | _         t                              |            d S r)   )r   rA   r^   r   s    r   r^   zOrderedDict.clear  s!    


4r   c                 *    |                                  S r)   )__copy__r   s    r   copyzOrderedDict.copy  s    }}r   c                      t          |           S r)   )r   r   s    r   r   zOrderedDict.__copy__  s    4   r   c                 *     | j         j        |i | d S r)   )r   sortrJ   s      r   r   zOrderedDict.sort!  s!    
######r   c                     |Qt          |d          r4|                                D ]}|                     |||                    n|D ]
\  }}|| |<   |r|                     |           d S d S )Nr   )hasattrr   rO   r!   )r   r   r   r0   r1   s        r   r!   zOrderedDict.update$  s    #|V,, &',,.. = =C$$S,s*;<<<<= #/ & &JC %DII 	 KK	  	 r   c                 d    || vr|                      ||           |S |                     |          S r)   )rO   r   r/   s      r   r`   zOrderedDict.setdefault/  s:    d??S%(((L##C(((r   c                 *    t          | j                  S r)   rn   r   r   s    r   rp   zOrderedDict.__iter__6  r   r   c                      t          |           S r)   ry   r   s    r   r   zOrderedDict.keys9  s    Dzzr   c                 *      fd j         D             S )Nc                      g | ]
}|         S r   r   r5   s     r   r,   z&OrderedDict.values.<locals>.<listcomp>=  s    000cS	000r   r   r   s   `r   ro   zOrderedDict.values<  s    0000TZ0000r   c                 *      fd j         D             S )Nc                 $    g | ]}||         fS r   r   r5   s     r   r,   z%OrderedDict.items.<locals>.<listcomp>@  s"    777Sd3i 777r   r   r   s   `r   r   zOrderedDict.items?  s    7777DJ7777r   c                 D    t          |                                           S r)   )rn   ro   r   s    r   
itervalueszOrderedDict.itervaluesD  s    &&&r   c                      t          |           S r)   )rn   r   s    r   iterkeyszOrderedDict.iterkeysG  s    ::r   c                 D    t          |                                           S r)   )rn   r   r   s    r   	iteritemszOrderedDict.iteritemsJ  s    

%%%r   c                     || vr4	 | j                             |           n# t          $ r |g| _         Y nw xY wt                              | ||           d S r)   )r   appendr.   rA   rO   r~   s      r   rO   zOrderedDict.__setitem__M  ss    d??#
!!#&&&&! # # # "U


# 	sC(((((s   ! 66c                 p    t                               | |           | j                            |           d S r)   )rA   rN   r   remover   s     r   rN   zOrderedDict.__delitem__W  s4    s###
#r   c                 l    || v }t          j        | |g|R  }|r| j                            |           |S r)   )rA   rB   r   r   )r   r0   r   presentr1   s        r   rB   zOrderedDict.pop[  sG    +s-W--- 	#Jc"""r   c                 z    t                               |           }| j                            |d                    |S Nr   )rA   r_   r   r   r   items     r   r_   zOrderedDict.popitemb  s2    ||D!!
$q'"""r   r)   )r   r   r   r8   r   r?   rS   r^   r   r   r   r!   r`   rp   r   ro   r   r   r   r   r   rO   rN   rB   r_   r   r   r   r   r     sP       MMI, , ,0 0 0 0    ! ! !$ $ $	  	  	  	 ) ) )       1 1 18 8 8  	&	' 	' 	'	 	 		& 	& 	&) ) )        r   r   c                       e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd ZeZd ZeZd ZeZd ZeZd ZeZd ZeZd ZeZd ZeZd ZeZdS )
OrderedSetNc                     t                               |            g | _        |6t          |          | _        t                               | | j                   d S g | _        d S r)   )setrS   r   unique_listr!   rC   s     r   rS   zOrderedSet.__init__i  sT    T
=$QDJJJtTZ(((((DJJJr   c                 x    || vr| j                             |           t                              | |           d S r)   r   r   r   addr   elements     r   r   zOrderedSet.addr  s=    $Jg&&&gr   c                 p    t                               | |           | j                            |           d S r)   )r   r   r   r   s     r   r   zOrderedSet.removew  s2    

4!!!
'"""""r   c                 z    || vr| j                             ||           t                              | |           d S r)   )r   insertr   r   )r   posr   s      r   r   zOrderedSet.insert{  s?    $Jc7+++gr   c                 |    || v r7| j                             |           t                              | |           d S d S r)   )r   r   r   r   s     r   discardzOrderedSet.discard  sB    d??Jg&&&JJtW%%%%% ?r   c                 H    t                               |            g | _        d S r)   )r   r^   r   r   s    r   r^   zOrderedSet.clear  s    		$


r   c                     | j         |         S r)   r   r   s     r   r   zOrderedSet.__getitem__  r   r   c                 *    t          | j                  S r)   r   r   s    r   rp   zOrderedSet.__iter__  r   r   c                 ,    |                      |          S r)   )r[   rz   s     r   r|   zOrderedSet.__add__  s    zz%   r   c                 0    | j         j        d| j        dS N())rI   r   r   r   s    r   r]   zOrderedSet.__repr__  s    >222DJJJ??r   c                     |D ];}|| vr5| j                             |           t                              | |           <| S r)   r   )r   iterablees      r   r!   zOrderedSet.update  sJ     	! 	!A}}
!!!$$$a   r   c                 Z    |                      |           }|                    |           |S r)   )rI   r!   r   r{   results      r   r[   zOrderedSet.union  s*    %%er   c                 d    t                    |                     fd| D                       S )Nc              3   $   K   | ]
}|v |V  d S r)   r   r*   ar{   s     r   	<genexpr>z*OrderedSet.intersection.<locals>.<genexpr>  s'      <<Aea<<r   r   rI   rz   s    `r   intersectionzOrderedSet.intersection  s5    E

~~<<<<<<<<<<r   c                      t                                         fd D                       }|                     fdD                        |S )Nc              3   $   K   | ]
}|v|V  d S r)   r   r   s     r   r   z2OrderedSet.symmetric_difference.<locals>.<genexpr>  s'      BBa1E>>>>>>BBr   c              3   $   K   | ]
}|v|V  d S r)   r   r*   r   r   s     r   r   z2OrderedSet.symmetric_difference.<locals>.<genexpr>  s'      88A!4--a----88r   )r   rI   r!   r   s   `` r   symmetric_differencezOrderedSet.symmetric_difference  sa    E

BBBB4BBBBB8888888888r   c                 d    t                    |                     fd| D                       S )Nc              3   $   K   | ]
}|v|V  d S r)   r   r   s     r   r   z(OrderedSet.difference.<locals>.<genexpr>  s'      @@A%a@@r   r   rz   s    `r   
differencezOrderedSet.difference  s5    E

~~@@@@@@@@@@r   c                     t                    t                               |            fd| j        D             | _        | S )Nc                     g | ]}|v |	S r   r   r   s     r   r,   z2OrderedSet.intersection_update.<locals>.<listcomp>  s    :::AqEzzazzzr   )r   intersection_updater   rz   s    `r   r   zOrderedSet.intersection_update  sF    E

e,,,:::::::
r   c                      t                                |            fd j        D              _         xj         fd|j        D             z  c_         S )Nc                     g | ]}|v |	S r   r   r   s     r   r,   z:OrderedSet.symmetric_difference_update.<locals>.<listcomp>      999AqDyyayyyr   c                     g | ]}|v |	S r   r   r   s     r   r,   z:OrderedSet.symmetric_difference_update.<locals>.<listcomp>  s    ;;;Qdqr   )r   symmetric_difference_updater   rz   s   ` r   r  z&OrderedSet.symmetric_difference_update  sb    ''e4449999999


;;;;%+;;;;

r   c                 n     t                                |            fd j        D              _         S )Nc                     g | ]}|v |	S r   r   r   s     r   r,   z0OrderedSet.difference_update.<locals>.<listcomp>  r  r   )r   difference_updater   rz   s   ` r   r  zOrderedSet.difference_update  s;    dE***9999999
r   r)   )r   r   r   rS   r   r   r   r   r^   r   rp   r|   r]   __str__r!   __ior__r[   __or__r   __and__r   __xor__r   __sub__r   __iand__r  __ixor__r  __isub__r   r   r   r   r   h  sf            
# # #  
& & &
         ! ! !@ @ @ G   G  
 F= = = G   #GA A A G   #H   +H  
 !HHHr   r   c                       e 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 Z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 Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$e$Z%d$ Z&d% Z'd& Z(d' Z)dS ))IdentitySetzA set that considers only object id() for uniqueness.

    This strategy has edge cases for builtin types- it's possible to have
    two 'foo' strings in one of these sets, for example.  Use sparingly.

    Nc                 ^    t                      | _        |r|                     |           d S d S r)   )rA   _membersr!   r   r   s     r   rS   zIdentitySet.__init__  s7     	"KK!!!!!	" 	"r   c                 4    || j         t          |          <   d S r)   r  idr   s     r   r   zIdentitySet.add  s    #(bii   r   c                 .    t          |          | j        v S r)   )r  r  r   s     r   r   zIdentitySet.__contains__  s    %yyDM))r   c                 0    | j         t          |          = d S r)   r  r   s     r   r   zIdentitySet.remove  s    M"U))$$$r   c                 T    	 |                      |           d S # t          $ r Y d S w xY wr)   )r   r   r   s     r   r   zIdentitySet.discard  sA    	KK 	 	 	DD	s    
''c                     	 | j                                         }|d         S # t          $ r t          d          w xY w)Nr   zpop from an empty set)r  r_   r   )r   pairs     r   rB   zIdentitySet.pop  sM    	4=((**D7N 	4 	4 	42333	4s    # =c                 8    | j                                          d S r)   )r  r^   r   s    r   r^   zIdentitySet.clear  s    r   c                      t          d          )Nzcannot compare sets using cmp()rH   rz   s     r   __cmp__zIdentitySet.__cmp__  s    9:::r   c                 P    t          |t                    r| j        |j        k    S dS )NFrY   r  r  rz   s     r   __eq__zIdentitySet.__eq__  s(    e[)) 	=EN225r   c                 P    t          |t                    r| j        |j        k    S dS NTr#  rz   s     r   __ne__zIdentitySet.__ne__  s(    e[)) 	=EN224r   c                     |                      |          }t          |           t          |          k    rdS t          |j        j        t          | j                                                            D ]} dS dS NFTrI   rk   r   r  r   rn   r   r   r   r{   ms       r   issubsetzIdentitySet.issubset  sv    x((t99s5zz!!5&N'dm.@.@.B.B)C)C
 
 	 	A 55tr   c                 d    t          |t                    st          S |                     |          S r)   )rY   r  NotImplementedr-  rz   s     r   __le__zIdentitySet.__le__  s,    %-- 	"!!}}U###r   c                     t          |t                    st          S t          |           t          |          k     o|                     |          S r)   )rY   r  r/  rk   r-  rz   s     r   __lt__zIdentitySet.__lt__  sB    %-- 	"!!4yy3u::%>$--*>*>>r   c                     |                      |          }t          |           t          |          k     rdS t          | j        j        t          |j                                                            D ]} dS dS r)  r*  r+  s       r   
issupersetzIdentitySet.issuperset  sv    x((t99s5zz!!5&M&U^-@-@-B-B(C(C
 
 	 	A 55tr   c                 d    t          |t                    st          S |                     |          S r)   )rY   r  r/  r4  rz   s     r   __ge__zIdentitySet.__ge__)  ,    %-- 	"!!u%%%r   c                     t          |t                    st          S t          |           t          |          k    o|                     |          S r)   )rY   r  r/  rk   r4  rz   s     r   __gt__zIdentitySet.__gt__.  sB    %-- 	"!!4yy3u::%@$//%*@*@@r   c                     |                                  }| j        }|j                            |           |j                            d |D                        |S )Nc              3   8   K   | ]}t          |          |fV  d S r)   r  r*   r   s     r   r   z$IdentitySet.union.<locals>.<genexpr>7  s,      BB#3~BBBBBBr   )rI   r  r!   )r   r   r   memberss       r   r[   zIdentitySet.union3  sX    !!-w'''BBBBBBBBr   c                 d    t          |t                    st          S |                     |          S r)   )rY   r  r/  r[   rz   s     r   r
  zIdentitySet.__or__:  s,    %-- 	"!!zz%   r   c                 N    | j                             d |D                        d S )Nc              3   8   K   | ]}t          |          |fV  d S r)   r<  r=  s     r   r   z%IdentitySet.update.<locals>.<genexpr>@  s,      @@bggs^@@@@@@r   )r  r!   r  s     r   r!   zIdentitySet.update?  s-    @@x@@@@@@@@r   c                 h    t          |t                    st          S |                     |           | S r)   )rY   r  r/  r!   rz   s     r   r	  zIdentitySet.__ior__B  s1    %-- 	"!!Er   c                     |                                  }| j        }d |D             |j                            fd|                                D                        |S )Nc                 ,    h | ]}t          |          S r   r<  r=  s     r   	<setcomp>z)IdentitySet.difference.<locals>.<setcomp>K      ---SC---r   c              3   .   K   | ]\  }}|v	||fV  d S r)   r   r*   rt   vr{   s      r   r   z)IdentitySet.difference.<locals>.<genexpr>M  /      BB11E>>aV>>>>BBr   rI   r  r!   r   r   r   r   r>  r{   s       @r   r   zIdentitySet.differenceH  sl    !!---H---BBBBBBB	
 	
 	
 r   c                 d    t          |t                    st          S |                     |          S r)   )rY   r  r/  r   rz   s     r   r  zIdentitySet.__sub__Q  r7  r   c                 D    |                      |          j        | _        d S r)   )r   r  r  s     r   r  zIdentitySet.difference_updateV  s    11:r   c                 h    t          |t                    st          S |                     |           | S r)   )rY   r  r/  r  rz   s     r   r  zIdentitySet.__isub__Y  s3    %-- 	"!!u%%%r   c                     |                                  }| j        }d |D             |j                            fd|                                D                        |S )Nc                 ,    h | ]}t          |          S r   r<  r=  s     r   rE  z+IdentitySet.intersection.<locals>.<setcomp>b  rF  r   c              3   .   K   | ]\  }}|v 	||fV  d S r)   r   rH  s      r   r   z+IdentitySet.intersection.<locals>.<genexpr>c  s8       
 
q!!u**QF****
 
r   rK  rL  s       @r   r   zIdentitySet.intersection_  s{    !!---H--- 
 
 
 
&}}
 
 
 	
 	
 	
 r   c                 d    t          |t                    st          S |                     |          S r)   )rY   r  r/  r   rz   s     r   r  zIdentitySet.__and__h  s.    %-- 	"!!  '''r   c                 D    |                      |          j        | _        d S r)   )r   r  r  s     r   r   zIdentitySet.intersection_updatem  s    ))(33<r   c                 h    t          |t                    st          S |                     |           | S r)   )rY   r  r/  r   rz   s     r   r  zIdentitySet.__iand__p  s3    %-- 	"!!  '''r   c                 8   |                                  }| j        d |D             |j                            fd                                D                        |j                            fd                                D                        |S )Nc                 .    i | ]}t          |          |S r   r<  r=  s     r   r6   z4IdentitySet.symmetric_difference.<locals>.<dictcomp>y  s     222#C#222r   c              3   .   K   | ]\  }}|v	||fV  d S r)   r   rH  s      r   r   z3IdentitySet.symmetric_difference.<locals>.<genexpr>{  rJ  r   c              3   .   K   | ]\  }}|v	||fV  d S r)   r   )r*   rt   rI  r>  s      r   r   z3IdentitySet.symmetric_difference.<locals>.<genexpr>~  s5      BB1'1A1AaV1A1A1A1ABBr   rK  rL  s      @@r   r   z IdentitySet.symmetric_differencev  s    !!-22222BBBBBBB	
 	
 	
 	BBBBBBB	
 	
 	
 r   c                 d    t          |t                    st          S |                     |          S r)   rY   r  r/  r   rz   s     r   r  zIdentitySet.__xor__  s.    %-- 	"!!((///r   c                 D    |                      |          j        | _        d S r)   )r   r  r  s     r   r  z'IdentitySet.symmetric_difference_update  s    11(;;Dr   c                 h    t          |t                    st          S |                     |           | S r)   r[  rz   s     r   r  zIdentitySet.__ixor__  s3    %-- 	"!!!!%(((r   c                 z     t          |           t          | j                                                            S r)   )typern   r  ro   r   s    r   r   zIdentitySet.copy  s.    tDzz$t}335566777r   c                 *    t          | j                  S r)   )rk   r  r   s    r   rl   zIdentitySet.__len__      4=!!!r   c                 N    t          | j                                                  S r)   )rn   r  ro   r   s    r   rp   zIdentitySet.__iter__  s    DM((**+++r   c                      t          d          )Nzset objects are unhashabler   r   s    r   __hash__zIdentitySet.__hash__  s    4555r   c                 ~    t          |           j        dt          | j                                                  dS r   )r_  r   r   r  ro   r   s    r   r]   zIdentitySet.__repr__  s8    ::...T]5I5I5K5K0L0L0L0LMMr   r)   )*r   r   r   r8   rS   r   r   r   r   rB   r^   r!  r$  r'  r-  r0  r2  r4  r6  r9  r[   r
  r!   r	  r   r  r  r  r   r  r   r  r   r  r  r  r   r   rl   rp   rd  r]   r   r   r   r  r    sc        " " " "
) ) )* * *% % %  4 4 4  ; ; ;    	 	 	$ $ $
? ? ?

 
 
& & &
A A A
  ! ! !
A A A    & & &
; ; ;    ( ( (
= = =  
 
 
0 0 0
E E E  8 8 8 H" " ", , ,6 6 6N N N N Nr   r  c                   .    e Zd ZddZd Zd Zd Zd ZdS )	WeakSequencer   c                 j    t          j        |           fd| _        fd|D             | _        d S )Nc                 V     |            }||j                             |            d S d S r)   )_storager   )r   selfrefr   s      r   _removez&WeakSequence.__init__.<locals>._remove  s7    799D$$T*****  r   c                 :    g | ]}t          j        |          S r   )weakrefref)r*   r   rl  s     r   r,   z)WeakSequence.__init__.<locals>.<listcomp>  s2     
 
 
.5GK))
 
 
r   )rn  ro  rl  rj  )r   _WeakSequence__elementsrl  s     @r   rS   zWeakSequence.__init__  s]     #*+d"3"3 	+ 	+ 	+ 	+
 
 
 
 
9C
 
 
r   c                 j    | j                             t          j        || j                             d S r)   )rj  r   rn  ro  rl  r   s     r   r   zWeakSequence.append  s,    W[t|<<=====r   c                 *    t          | j                  S r)   )rk   rj  r   s    r   rl   zWeakSequence.__len__  ra  r   c                 8    d d | j         D             D             S )Nc              3      K   | ]}||V  	d S r)   r   r=  s     r   r   z(WeakSequence.__iter__.<locals>.<genexpr>  s+       
 
sC
 
r   c              3   *   K   | ]} |            V  d S r)   r   )r*   ro  s     r   r   z(WeakSequence.__iter__.<locals>.<genexpr>  s(      ;;cCCEE;;;;;;r   )rj  r   s    r   rp   zWeakSequence.__iter__  s3    
 
;;T];;;
 
 
 	
r   c                 r    	 | j         |         } |            S # t          $ r t          d|z            w xY w)NzIndex %s out of range)rj  r   
IndexError)r   indexr   s      r   r   zWeakSequence.__getitem__  sQ    	-&C 355L  	> 	> 	>4u<===	>s    6N)r   )r   r   r   rS   r   rl   rp   r   r   r   r   rg  rg    sd        
 
 
 
> > >" " "
 
 

    r   rg  c                       e Zd ZddZdS )OrderedIdentitySetNc                     t                               |            t                      | _        |r|D ]}|                     |           d S d S r)   )r  rS   r   r  r   )r   r   os      r   rS   zOrderedIdentitySet.__init__  s]    T"""# 	  	 	 r   r)   )r   r   r   rS   r   r   r   rz  rz    s(             r   rz  c                       e Zd ZdZd Zd ZdS )PopulateDictzA dict which populates missing values via a creation function.

    Note the creation function takes a key, unlike
    collections.defaultdict.

    c                     || _         d S r)   creator)r   r  s     r   rS   zPopulateDict.__init__  s    r   c                 :    |                      |          x| |<   }|S r)   r  r   r0   vals      r   __missing__zPopulateDict.__missing__  s!    ,,s+++S	C
r   Nr   r   r   r8   rS   r  r   r   r   r~  r~    s<               r   r~  c                       e Zd ZdZd Zd ZdS )WeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create
    a reference cycle.

    c                 ^    |j         | _        |j        }t          j        |          | _        d S r)   )__func__r  __self__rn  ro  weakself)r   creator_methodr  s      r   rS   zWeakPopulateDict.__init__  s)    %.!*H--r   c                 `    |                      |                                 |          x| |<   }|S r)   )r  r  r  s      r   r  zWeakPopulateDict.__missing__  s+    ,,t}}<<<S	C
r   Nr  r   r   r   r  r    s<         
. . .
    r   r  c                 D    t          t          j        |                     S r)   )r9   operator
itemgetter)idxs    r   <lambda>r    s    ,S1122 r   c                 t    t                      j        sfd| D             S fd| D             S )Nc                 2    g | ]}|v |          |S r   r   )r*   xseenseen_adds     r   r,   zunique_list.<locals>.<listcomp>  s*    DDDa!4------r   c                 V    g | ]%} |          v  |                    #|&S r   r   )r*   r  hashfuncr  r  s     r   r,   zunique_list.<locals>.<listcomp>  sM     
 
 
x{{$&&xx/D/D& &&&r   )r   r   )seqr  r  r  s    `@@r   r   r     so    55DxH 
DDDDD3DDDD
 
 
 
 
 

 
 
 	
r   c                   &    e Zd ZdZddZd Zd ZdS )UniqueAppenderzAppends items to a collection ensuring uniqueness.

    Additional appends() of the same object are ignored.  Membership is
    determined by identity (``is a``) not equality (``==``).
    Nc                     || _         i | _        |rt          ||          | _        d S t	          |d          r|j        | _        d S t	          |d          r|j        | _        d S d S )Nr   r   )ri   _uniquegetattr_data_appenderr   r   r   )r   ri   vias      r   rS   zUniqueAppender.__init__  s~    	 	+")$"4"4DT8$$ 	+"&+DT5!! 	+"&(D	+ 	+r   c                 x    t          |          }|| j        vr!|                     |           d| j        |<   d S d S r&  )r  r  r  )r   r   id_s      r   r   zUniqueAppender.append  sH    hhdl""%%% $DL #"r   c                 *    t          | j                  S r)   )rn   ri   r   s    r   rp   zUniqueAppender.__iter__!  s    DIr   r)   )r   r   r   r8   rS   r   rp   r   r   r   r  r  
  sP         + + + +% % %    r   r  c                     t          |           dk    r5t          | d         t          j                  rt	          | d                   S | S )Nr   r   )rk   rY   typesGeneratorTyper   )rK   s    r   coerce_generator_argr  %  s;    
3xx1}}CFE,?@@}CF||
r   c                     | |S t          | t          j                  rt          | t          t          z             r| gS t          | t
                    r| S t          |           S r)   )rY   r   Iterabler	   r   r   )r  r   s     r   to_listr  ,  sg    ya122 j	<,&7 7  s
	At		 Awwr   c                 Z    t          |                     d |D                                 S )zreturn True if any items of set\_ are present in iterable.

    Goes through special effort to ensure __hash__ is not called
    on items in iterable that don't support it.

    c                      g | ]}|j         	|S r   )rd  r*   is     r   r,   z$has_intersection.<locals>.<listcomp>A  s    "E"E"E!*"E1"E"E"Er   )boolr   )set_r   s     r   has_intersectionr  9  s/     !!"E"Eh"E"E"EFFGGGr   c                     | t                      S t          | t                     st          t          |                     S | S r)   )r   rY   r  r  s    r   to_setr  D  s9    yuua 71::r   c                     | t                      S t          | t                     st          t          |                     S | S r)   )
column_setrY   r  r  s    r   to_column_setr  M  s<    y||a$$ '!**%%%r   c                 v    |                                  } |r|                     |            | j        di | | S )z5Copy the given dict and update with the given values.r   )r   r!   )rD   _newrL   s      r   update_copyr  V  s@     	
A 	AHNNrNNNHr   c              #      K   | D ]B}t          |t                    s't          |d          rt          |          D ]}|V  >|V  CdS )zGiven an iterator of which further sub-elements may also be
    iterators, flatten the sub-elements into a single iterator.

    rp   N)rY   rs   r   flatten_iterator)r  elemys      r   r  r  `  sx      
   $$$ 	z)B)B 	%d++   JJJJ r   c                   `    e Zd ZdZdZddZd ZddZd	 Zd
 Z	d Z
d Zed             Zd ZdS )LRUCachezDictionary with 'squishy' removal of least
    recently used items.

    Note that either get() or [] should be used here, but
    generally its not safe to do an "in" check first as the dictionary
    can change subsequent to that call.

    )capacity	threshold
size_alert_counter_mutexd         ?Nc                 n    || _         || _        || _        d| _        t	          j                    | _        d S r   )r  r  r  r  r
   Lockr  )r   r  r  r  s       r   rS   zLRUCache.__init__y  s1     "$n&&r   c                 0    | xj         dz  c_         | j         S Nr   )r  r   s    r   _inc_counterzLRUCache._inc_counter  s    }r   c                     t                               | ||          }||ur|                                 |d<   |d         S |S N   r   )rA   r   r  )r   r0   r   r   s       r   r   zLRUCache.get  sE    xxc7++w''))DG7NNr   c                 v    t                               | |          }|                                 |d<   |d         S r  )rA   r   r  )r   r0   r   s      r   r   zLRUCache.__getitem__  s5    c**##%%QAwr   c                 J    d t                               |           D             S )Nc                     g | ]
}|d          S )r   r   r  s     r   r,   z#LRUCache.values.<locals>.<listcomp>  s    000!000r   )rA   ro   r   s    r   ro   zLRUCache.values  s"    00dkk$//0000r   c                 (    || v r| |         S || |<   |S r)   r   r/   s      r   r`   zLRUCache.setdefault  s#    $;;9DILr   c                     t                               | |          }|4|||                                 g}t                               | ||           n||d<   |                                  d S r  )rA   r   r  rO   _manage_size)r   r0   r1   r   s       r   rO   zLRUCache.__setitem__  sn    xxc""< 1 1 3 34DT3----DGr   c                 0    | j         | j         | j        z  z   S r)   )r  r  r   s    r   size_thresholdzLRUCache.size_threshold  s    }t}t~===r   c                 x   | j                             d          sd S 	 t          | j                  }t	          |           | j        | j        | j        z  z   k    r|rd}|                     |            t          t          	                    |           t          j        d          d          }|| j        d          D ]}	 | |d         = # t          $ r Y w xY wt	          |           | j        | j        | j        z  z   k    | j                                          d S # | j                                          w xY w)NFr  T)r0   reverser   )r  acquirer  r  rk   r  r  sortedrA   ro   r  r  r   release)r   r  
by_counterr   s       r   r  zLRUCache._manage_size  sL   {""5)) 	F	"do..Jd))dmdmdn.LLLL *!&JOOD)))#KK%%8+>q+A+A4  
 't}7 ! !D! aMM# ! ! ! ! d))dmdmdn.LLLL K!!!!!DK!!!!s0   B"D 	C
D 
CD C+D D9)r  r  Nr)   )r   r   r   r8   r   rS   r  r   r   ro   r`   rO   r9   r  r  r   r   r   r  r  m  s          LI' ' ' '       
1 1 1     > > X>" " " " "r   r  r  c           
      D   | ft          |          z   }t                              |          }|r|S t          | t          ft          d t          |          D             dgz                       }||_        t          d |D                       |_        |t          |<   |S )Nc                 6    g | ]\  }}||t           |         fS r)   )_property_getters)r*   r  fields      r   r,   z+lightweight_named_tuple.<locals>.<listcomp>  s7       C$ )#./$$$r   )r   r   c                     g | ]}||S r)   r   )r*   fs     r   r,   z+lightweight_named_tuple.<locals>.<listcomp>  s    ???!Ar   )	r   
_lw_tuplesr   r_  r;   rA   	enumerater>   r   )namefieldshash_tp_clss       r   lightweight_named_tupler    s    GeFmm#E^^E""F 	 "+F"3"3  
 !!"	
 	
 F !F??v???@@FNJuMr   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )ScopedRegistrya  A Registry that can store one or multiple instances of a single
    class on the basis of a "scope" function.

    The object implements ``__call__`` as the "getter", so by
    calling ``myregistry()`` the contained object is returned
    for the current scope.

    :param createfunc:
      a callable that returns a new object to be placed in the registry

    :param scopefunc:
      a callable that will return a key to store/retrieve an object.
    c                 0    || _         || _        i | _        dS )aV  Construct a new :class:`.ScopedRegistry`.

        :param createfunc:  A creation function that will generate
          a new value for the current scope, if none is present.

        :param scopefunc:  A function that returns a hashable
          token representing the current scope (such as, current
          thread identifier).

        N)
createfunc	scopefuncregistry)r   r  r  s      r   rS   zScopedRegistry.__init__  s     %"r   c                     |                                  }	 | j        |         S # t          $ r0 | j                            ||                                           cY S w xY wr)   )r  r  r   r`   r  r   s     r   __call__zScopedRegistry.__call__  sk    nn	D=%% 	D 	D 	D=++C1B1BCCCCC	Ds   # 7AAc                 8    |                                  | j        v S )z9Return True if an object is present in the current scope.)r  r  r   s    r   haszScopedRegistry.has   s     ~~4=00r   c                 >    || j         |                                 <   dS )z$Set the value for the current scope.N)r  r  r   r   s     r   r   zScopedRegistry.set  s      +.dnn&&'''r   c                 ^    	 | j         |                                 = dS # t          $ r Y dS w xY w)z Clear the current scope, if any.N)r  r  r   r   s    r   r^   zScopedRegistry.clear
  sC    	dnn../// 	 	 	DD	s    
,,N	r   r   r   r8   rS   r  r  r   r^   r   r   r   r  r    sl           D D D1 1 1
. . .
    r   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )ThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()``
    variable for storage.

    c                 D    || _         t          j                    | _        d S r)   )r  r
   localr  )r   r  s     r   rS   zThreadLocalRegistry.__init__  s    $!))r   c                     	 | j         j        S # t          $ r% |                                 x}| j         _        |cY S w xY wr)   )r  r1   r.   r  )r   r  s     r   r  zThreadLocalRegistry.__call__  sO    	=&& 	 	 	(,(9(99C$-%JJJ	s    ,==c                 ,    t          | j        d          S )Nr1   )r   r  r   s    r   r  zThreadLocalRegistry.has$  s    t}g...r   c                     || j         _        d S r)   )r  r1   r  s     r   r   zThreadLocalRegistry.set'  s    !r   c                 8    	 | j         `d S # t          $ r Y d S w xY wr)   )r  r1   r.   r   s    r   r^   zThreadLocalRegistry.clear*  s7    	### 	 	 	DD	s    
Nr  r   r   r   r  r    si         
* * *  / / /" " "    r   r  c                 8    d}| D ]}||u r|dz  }|dk    r dS dS )zrGiven a sequence and search object, return True if there's more
    than one, False if zero or one of them.


    r   r   TFr   )sequencetargetcr   s       r   	has_dupesr  1  s@     	
A  6>>FA1uutt5r   r)   )7r8   
__future__r   r  r  rn  compatr   r   r   r   r	   r
   	frozenset	EMPTY_SETr   r   r   r;   rh   rF   rA   rQ   rb   r   r   r   r   r   r  rg  rz  r~  r  r  column_dictordered_column_setr  _gettersr  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   <module>r     s!   & % & & & & & &                # # # # # # ) ) ) ) ) )                         IKK	" " " " " " " "@@ @@ @@ @@ @@# @@ @@ @@F    
   (9 9 9 9 9 9 9 99 9 9 9 9& 9 9 9@L L L L L L L L^1 1 1 1 1
 1 1 1    ,j   ^ ^ ^ ^ ^$ ^ ^ ^Bh! h! h! h! h! h! h! h!VLN LN LN LN LN& LN LN LN^    6   D           4        t   ( 
  <+,, L22  


 

 

 

    V   6  
 
 
 
H H H       
 
 
N" N" N" N" N"t N" N" N"b Xc]]
  45 5 5 5 5V 5 5 5p    .   <    r   