o
    =aq                     @   sp  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 ddlmZ e ZG dd deZdd ZzddlmZ eje W n eyk   e Zdd ZY nw dd Ze ZG dd deeZG dd deZG dd deZG dd deeZdKddZ ereZ!e Z"ndKdd Z"G d!d" d"eZ!G d#d$ d$e#Z$G d%d& d&eZ%G d'd( d(eZ&G d)d* d*e%Z'G d+d, d,eZ(G d-d. d.eZ)e#Z*eZ+e$Z,e(ej-Z.e(d/d0 Z/dKd1d2Z0G d3d4 d4eZ1d5d6 Z2dKd7d8Z3d9d: Z4d;d< Z5d=d> Z6dKd?d@Z7dAdB Z8G dCdD dDeZ9G dEdF dFeZ:G dGdH dHe:Z;dIdJ Z<dS )LzCollection classes and helpers.    )absolute_importN   )binary_types)collections_abc)itertools_filterfalse)py2k)py37)string_types)	threadingc                   @   s    e Zd Zdd Ze Z ZZdS )ImmutableContainerc                 O   s   t d| jj )Nz%s object is immutable)	TypeError	__class____name__)selfargkw r   R/var/www/html/gps/gps/lib/python3.10/site-packages/sqlalchemy/util/_collections.py
_immutable      zImmutableContainer._immutableN)r   
__module____qualname__r   __delitem____setitem____setattr__r   r   r   r   r      s    r   c                  C   s   G dd dt t} | S )Nc                   @   s^   e Zd Zej Z Z Z ZZ	dd Z
dd Zdd Zddd	Zdd
dZdd Zdd ZdS )z1_immutabledict_py_fallback.<locals>.immutabledictc                 W   s    t | }t j|g|R   |S N)dict__new____init__clsargsnewr   r   r   r   *   s   
z9_immutabledict_py_fallback.<locals>.immutabledict.__new__c                 W   s   d S r   r   )r   r!   r   r   r   r   /   s   z:_immutabledict_py_fallback.<locals>.immutabledict.__init__c                 S      t t| ffS r   )_immutabledict_reconstructorr   r   r   r   r   
__reduce__2      z<_immutabledict_py_fallback.<locals>.immutabledict.__reduce__Nc                 S   s0   |s| S t | j}t ||  t || |S r   r   r   r   r   update)r   _immutabledict__dr"   r   r   r   union5   s   z7_immutabledict_py_fallback.<locals>.immutabledict.unionc                 [   sD   |s|s| S t | j}t ||  |rt || t || |S r   r(   )r   r*   r   r"   r   r   r   _union_w_kw>   s   z=_immutabledict_py_fallback.<locals>.immutabledict._union_w_kwc                 W   sN   d }|D ]}|r|d u rt | j}t ||  t || q|d u r%| S |S r   r(   )r   dictsr"   dr   r   r   
merge_withJ   s   z<_immutabledict_py_fallback.<locals>.immutabledict.merge_withc                 S      dt |  S )Nzimmutabledict(%s)r   __repr__r%   r   r   r   r2   W   r'   z:_immutabledict_py_fallback.<locals>.immutabledict.__repr__r   )r   r   r   r   r   clearpoppopitem
setdefaultr)   r   r   r&   r+   r,   r/   r2   r   r   r   r   immutabledict$   s    

	r7   )r   r   r7   r   r   r   _immutabledict_py_fallback#   s   6r9   r8   c                  G   s   t |  S )zdo the pickle dancer8   r   r   r   r   r$   e   s   r$   c                 C   s   | st S t| tr| S t| S r   )
EMPTY_DICT
isinstancer7   r.   r   r   r   coerce_to_immutabledictj   s
   
r>   c                   @   sN   e Zd ZdZej Z Z Z Z	Z
dd Zdd Zdd Zdd	 Zd
d ZdS )
FacadeDictz*A dictionary that is not publicly mutable.c                 G   s   t | }|S r   )r   r   r   r   r   r   r   {   s   
zFacadeDict.__new__c                 C      t d)Nz\an immutabledict shouldn't need to be copied.  use dict(d) if you need a mutable dictionary.)NotImplementedErrorr%   r   r   r   copy   s   zFacadeDict.copyc                 C   r#   r   )r?   r   r%   r   r   r   r&      r'   zFacadeDict.__reduce__c                 C   s   t | || dS )z,insert an item into the dictionary directly.N)r   r   r   keyvaluer   r   r   _insert_item      zFacadeDict._insert_itemc                 C   r0   )NzFacadeDict(%s)r1   r%   r   r   r   r2      r'   zFacadeDict.__repr__N)r   r   r   __doc__r   r   r3   r4   r5   r6   r)   r   rB   r&   rF   r2   r   r   r   r   r?   v   s    r?   c                       s   e Zd ZdZdZdd Zdd Zdd Z fd	d
Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd.d"d#Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Z  ZS )/
Propertiesz8Provide a __getattr__/__setattr__ interface over a dict._datac                 C   s   t | d| d S NrK   objectr   )r   datar   r   r   r         zProperties.__init__c                 C   
   t | jS r   )lenrK   r%   r   r   r   __len__      
zProperties.__len__c                 C   s   t t| j S r   )iterlistrK   valuesr%   r   r   r   __iter__   rP   zProperties.__iter__c                    s"   t tt| dd | j D  S )Nc                 S   s   g | ]}t |qS r   )str.0kr   r   r   
<listcomp>   s    z&Properties.__dir__.<locals>.<listcomp>)dirsuperrI   rK   keysr%   r   r   r   __dir__   s   zProperties.__dir__c                 C   s   t | t | S r   rV   r   otherr   r   r   __add__   r   zProperties.__add__c                 C      || j |< d S r   rJ   r   rD   objr   r   r   r      r'   zProperties.__setitem__c                 C   
   | j | S r   rJ   r   rD   r   r   r   __getitem__   rT   zProperties.__getitem__c                 C   s   | j |= d S r   rJ   rk   r   r   r   r         zProperties.__delitem__c                 C   rg   r   rJ   rh   r   r   r   r      r'   zProperties.__setattr__c                 C   s
   d| j iS rL   rJ   r%   r   r   r   __getstate__   rT   zProperties.__getstate__c                 C   s   t | d|d  d S rL   rM   )r   stater   r   r   __setstate__      zProperties.__setstate__c                 C   s$   z| j | W S  ty   t|w r   )rK   KeyErrorAttributeErrorrk   r   r   r   __getattr__   s
   zProperties.__getattr__c                 C   
   || j v S r   rJ   rk   r   r   r   __contains__   rT   zProperties.__contains__c                 C   rQ   )z8Return an immutable proxy for this :class:`.Properties`.)ImmutablePropertiesrK   r%   r   r   r   as_immutable   s   
zProperties.as_immutablec                 C   s   | j | d S r   )rK   r)   r   rE   r   r   r   r)      r   zProperties.updateNc                 C   s   || v r| | S |S r   r   )r   rD   defaultr   r   r   get   s   zProperties.getc                 C   rQ   r   )rV   rK   r%   r   r   r   r`      rT   zProperties.keysc                 C      t | j S r   )rV   rK   rW   r%   r   r   r   rW      r'   zProperties.valuesc                 C   r|   r   )rV   rK   itemsr%   r   r   r   r}      r'   zProperties.itemsc                 C   ru   r   rJ   rk   r   r   r   has_key   rT   zProperties.has_keyc                 C      | j   d S r   )rK   r3   r%   r   r   r   r3      r'   zProperties.clearr   )r   r   r   rH   	__slots__r   rS   rX   rb   rf   r   rl   r   r   rn   rp   rt   rv   rx   r)   r{   r`   rW   r}   r~   r3   __classcell__r   r   ra   r   rI      s0    
rI   c                   @   s   e Zd ZdZdZdd ZdS )OrderedPropertieszUProvide a __getattr__/__setattr__ interface with an OrderedDict
    as backing store.r   c                 C   s   t | t  d S r   )rI   r   OrderedDictr%   r   r   r   r      rP   zOrderedProperties.__init__N)r   r   r   rH   r   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdZdS )rw   zDProvide immutable dict/object attribute to an underlying dictionary.r   N)r   r   r   rH   r   r   r   r   r   rw      s    rw   c                    s0    fddt  |dD }    | dS )zSort an OrderedDict in-place.c                       g | ]}| | fqS r   r   rZ   r=   r   r   r]          z,_ordered_dictionary_sort.<locals>.<listcomp>rD   N)sortedr3   r)   )r.   rD   r}   r   r=   r   _ordered_dictionary_sort   s   r   c                 C   s   | j |d dS )zSort an OrderedDict in place.r   Nr   )r.   rD   r   r   r   sort_dictionary  s   r   c                   @   s   e Zd ZdZdZd*ddZdd Zd*dd	Zd
d Zdd Z	dd Z
d*ddZdd Zdd Zdd Zdd Zdd ZerIdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) ZdS )+r   zhDictionary that maintains insertion order.

        Superseded by Python dict as of Python 3.7

        _listNc                 C   s   t | |d d S )Nr   r   rk   r   r   r   r     r   z$OrderedDict._ordered_dictionary_sortc                 C   s   t |  ffS r   )r   r}   r%   r   r   r   r&     r'   zOrderedDict.__reduce__c                 K   s@   g | _ |d u r|r| jdi | d S d S | j|fi | d S )Nr   )r   r)   )r   _OrderedDict____sequencekwargsr   r   r   r     s   zOrderedDict.__init__c                 C   s   g | _ t|  d S r   )r   r   r3   r%   r   r   r   r3        zOrderedDict.clearc                 C   s   |   S r   )__copy__r%   r   r   r   rB   !     zOrderedDict.copyc                 C      t | S r   )r   r%   r   r   r   r   $  r   zOrderedDict.__copy__c                 K   s^   |d ur$t |dr| D ]
}| |||  qn|D ]\}}|| |< q|r-| | d S d S )Nr`   )hasattrr`   r   r)   )r   r   r   rD   rE   r   r   r   r)   '  s   

zOrderedDict.updatec                 C   s"   || vr|  || |S | |S r   )r   rl   rC   r   r   r   r6   2  s   
zOrderedDict.setdefaultc                 C   rQ   r   rU   r   r%   r   r   r   rX   9  rT   zOrderedDict.__iter__c                 C   r   r   rc   r%   r   r   r   r`   <  r   zOrderedDict.keysc                        fdd j D S )Nc                    s   g | ]} | qS r   r   r[   rD   r%   r   r   r]   @      z&OrderedDict.values.<locals>.<listcomp>r   r%   r   r%   r   rW   ?     zOrderedDict.valuesc                    r   )Nc                    r   r   r   r   r%   r   r   r]   C  r   z%OrderedDict.items.<locals>.<listcomp>r   r%   r   r%   r   r}   B  r   zOrderedDict.itemsc                 C      t |  S r   )rU   rW   r%   r   r   r   
itervaluesG  rm   zOrderedDict.itervaluesc                 C   r   r   )rU   r%   r   r   r   iterkeysJ  r   zOrderedDict.iterkeysc                 C   r   r   )rU   r}   r%   r   r   r   	iteritemsM  rm   zOrderedDict.iteritemsc                 C   sF   || vrz| j | W n ty   |g| _ Y nw t| || d S r   )r   appendrs   r   r   rh   r   r   r   r   P  s   zOrderedDict.__setitem__c                 C   s   t | | | j| d S r   )r   r   r   removerk   r   r   r   r   Z     zOrderedDict.__delitem__c                 G   s0   || v }t j| |g|R  }|r| j| |S r   )r   r4   r   r   )r   rD   rz   presentrE   r   r   r   r4   ^  s
   zOrderedDict.popc                 C   s   t | }| j|d  |S Nr   )r   r5   r   r   r   itemr   r   r   r5   e  s   
zOrderedDict.popitemr   )r   r   r   rH   r   r   r&   r   r3   rB   r   r)   r6   rX   r`   rW   r}   r   r   r   r   r   r   r4   r5   r   r   r   r   r     s.    



r   c                   @   s   e Zd Zd&ddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd ZeZdd ZeZdd ZeZdd ZeZdd ZeZdd ZeZd d! ZeZd"d# ZeZd$d% ZeZdS )'
OrderedSetNc                 C   s8   t |  |d urt|| _t | | j d S g | _d S r   )setr   unique_listr   r)   )r   r.   r   r   r   r   l  s
   


zOrderedSet.__init__c                 C   s$   || vr
| j | t| | d S r   r   r   r   addr   elementr   r   r   r   t  s   zOrderedSet.addc                 C   s   t | | | j| d S r   )r   r   r   r   r   r   r   r   y  r   zOrderedSet.removec                 C   s&   || vr| j || t| | d S r   )r   insertr   r   )r   posr   r   r   r   r   }  s   zOrderedSet.insertc                 C   s(   || v r| j | t| | d S d S r   )r   r   r   r   r   r   r   discard  s   zOrderedSet.discardc                 C   s   t |  g | _d S r   )r   r3   r   r%   r   r   r   r3     s   

zOrderedSet.clearc                 C   rj   r   r   rk   r   r   r   rl     rT   zOrderedSet.__getitem__c                 C   rQ   r   r   r%   r   r   r   rX     rT   zOrderedSet.__iter__c                 C   s
   |  |S r   )r+   rd   r   r   r   rf     rT   zOrderedSet.__add__c                 C   s   d| j j| jf S Nz%s(%r))r   r   r   r%   r   r   r   r2     rP   zOrderedSet.__repr__c                 C   s.   |D ]}|| vr| j | t| | q| S r   r   )r   iterableer   r   r   r)     s   zOrderedSet.updatec                 C   s   |  | }|| |S r   )r   r)   r   re   resultr   r   r   r+     s   

zOrderedSet.unionc                        t   |  fdd| D S )Nc                 3   s    | ]	}| v r|V  qd S r   r   r[   are   r   r   	<genexpr>      z*OrderedSet.intersection.<locals>.<genexpr>r   r   rd   r   r   r   intersection     zOrderedSet.intersectionc                    s<   t    fddD }|fdd D  |S )Nc                 3       | ]	}| vr|V  qd S r   r   r   r   r   r   r     r   z2OrderedSet.symmetric_difference.<locals>.<genexpr>c                 3   r   r   r   r   r%   r   r   r     r   )r   r   r)   r   r   )re   r   r   symmetric_difference  s   zOrderedSet.symmetric_differencec                    r   )Nc                 3   r   r   r   r   r   r   r   r     r   z(OrderedSet.difference.<locals>.<genexpr>r   rd   r   r   r   
difference  r   zOrderedSet.differencec                    s.   t   t |    fdd| jD | _| S )Nc                       g | ]}| v r|qS r   r   r   r   r   r   r]     r   z2OrderedSet.intersection_update.<locals>.<listcomp>)r   intersection_updater   rd   r   r   r   r     s   zOrderedSet.intersection_updatec                    sD   t  |  fdd jD  _  j fdd|jD 7  _ S )Nc                    r   r   r   r   r%   r   r   r]     r   z:OrderedSet.symmetric_difference_update.<locals>.<listcomp>c                    r   r   r   r   r%   r   r   r]     r   )r   symmetric_difference_updater   rd   r   r%   r   r     s   z&OrderedSet.symmetric_difference_updatec                    s&   t  |  fdd jD  _ S )Nc                    r   r   r   r   r%   r   r   r]     r   z0OrderedSet.difference_update.<locals>.<listcomp>)r   difference_updater   rd   r   r%   r   r     s   zOrderedSet.difference_updater   )r   r   r   r   r   r   r   r   r3   rl   rX   rf   r2   __str__r)   __ior__r+   __or__r   __and__r   __xor__r   __sub__r   __iand__r   __ixor__r   __isub__r   r   r   r   r   k  s8    
r   c                   @   s>  e Zd ZdZdMddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$e$Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dS )N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                 C   s   t  | _|r| | d S d S r   )r   _membersr)   r   r   r   r   r   r     s   zIdentitySet.__init__c                 C   s   || j t|< d S r   r   idry   r   r   r   r     rP   zIdentitySet.addc                 C   s   t || jv S r   )r   r   ry   r   r   r   rv     r'   zIdentitySet.__contains__c                 C   s   | j t|= d S r   r   ry   r   r   r   r     r   zIdentitySet.removec                 C   s&   z|  | W d S  ty   Y d S w r   )r   rr   ry   r   r   r   r     s
   zIdentitySet.discardc                 C   s,   z
| j  }|d W S  ty   tdw )Nr   zpop from an empty set)r   r5   rr   )r   pairr   r   r   r4     s   

zIdentitySet.popc                 C   r   r   )r   r3   r%   r   r   r   r3     r'   zIdentitySet.clearc                 C   r@   )Nzcannot compare sets using cmp()r   rd   r   r   r   __cmp__  r   zIdentitySet.__cmp__c                 C   s   t |tr| j|jkS dS )NFr<   r   r   rd   r   r   r   __eq__     
zIdentitySet.__eq__c                 C   s   t |tr| j|jkS dS NTr   rd   r   r   r   __ne__  r   zIdentitySet.__ne__c                 C   sV   t || jr	|}n| |}t| t|krdS t|jjt| j D ]} dS dS NFTr<   r   rR   r   r   rv   rU   r`   r   r   re   mr   r   r   issubset
  s   
zIdentitySet.issubsetc                 C      t |tstS | |S r   )r<   r   NotImplementedr   rd   r   r   r   __le__     

zIdentitySet.__le__c                 C   s(   t |tstS t| t|k o| |S r   )r<   r   r   rR   r   rd   r   r   r   __lt__     
zIdentitySet.__lt__c                 C   sV   t || jr	|}n| |}t| t|k rdS t| jjt|j D ]} dS dS r   r   r   r   r   r   
issuperset"  s   
zIdentitySet.issupersetc                 C   r   r   )r<   r   r   r   rd   r   r   r   __ge__1  r   zIdentitySet.__ge__c                 C   s(   t |tstS t| t|ko| |S r   )r<   r   r   rR   r   rd   r   r   r   __gt__6  r   zIdentitySet.__gt__c                 C   s4   |   }| j}|j| |jdd |D  |S )Nc                 s       | ]	}t ||fV  qd S r   r   r[   ri   r   r   r   r   ?  r   z$IdentitySet.union.<locals>.<genexpr>)r   r   r)   r   r   r   membersr   r   r   r+   ;  s
   zIdentitySet.unionc                 C   r   r   )r<   r   r   r+   rd   r   r   r   r   B  r   zIdentitySet.__or__c                 C   s   | j dd |D  d S )Nc                 s   r   r   r   r   r   r   r   r   H  r   z%IdentitySet.update.<locals>.<genexpr>)r   r)   r   r   r   r   r)   G     zIdentitySet.updatec                 C      t |tstS | | | S r   )r<   r   r   r)   rd   r   r   r   r   J     

zIdentitySet.__ior__c                    Z   |   }| j}t|| j rt|j  ndd |D  |j fdd| D  |S )Nc                 S      h | ]}t |qS r   r   r   r   r   r   	<setcomp>V  r   z)IdentitySet.difference.<locals>.<setcomp>c                 3   $    | ]\}}| vr||fV  qd S r   r   r[   r\   vr   r   r   r   X     " z)IdentitySet.difference.<locals>.<genexpr>r   r   r<   r   r`   r)   r}   r   r   r   r   r   P  s   zIdentitySet.differencec                 C   r   r   )r<   r   r   r   rd   r   r   r   r   \  r   zIdentitySet.__sub__c                 C      |  |j| _d S r   )r   r   r   r   r   r   r   a  rP   zIdentitySet.difference_updatec                 C   r   r   )r<   r   r   r   rd   r   r   r   r   d  r   zIdentitySet.__isub__c                    r   )Nc                 S   r   r   r   r   r   r   r   r   p  r   z+IdentitySet.intersection.<locals>.<setcomp>c                 3   s$    | ]\}}| v r||fV  qd S r   r   r   r   r   r   r   q  s    
z+IdentitySet.intersection.<locals>.<genexpr>r   r   r   r   r   r   j  s   zIdentitySet.intersectionc                 C   r   r   )r<   r   r   r   rd   r   r   r   r   v  r   zIdentitySet.__and__c                 C   r   r   )r   r   r   r   r   r   r   {  rP   zIdentitySet.intersection_updatec                 C   r   r   )r<   r   r   r   rd   r   r   r   r   ~  r   zIdentitySet.__iand__c                    sp   |   }| j t|| j r|jndd |D |jfdd  D  |j fdd D  |S )Nc                 S   s   i | ]}t ||qS r   r   r   r   r   r   
<dictcomp>      z4IdentitySet.symmetric_difference.<locals>.<dictcomp>c                 3   r   r   r   r   r   r   r   r     r   z3IdentitySet.symmetric_difference.<locals>.<genexpr>c                 3   r   r   r   r   )r   r   r   r     r   )r   r   r<   r)   r}   )r   r   r   r   )r   re   r   r     s   z IdentitySet.symmetric_differencec                 C   r   r   r<   r   r   r   rd   r   r   r   r     r   zIdentitySet.__xor__c                 C   r   r   )r   r   r   r   r   r   r     rP   z'IdentitySet.symmetric_difference_updatec                 C   r   r   r   rd   r   r   r   r     r   zIdentitySet.__ixor__c                 C   s   t | t| j S r   )typerU   r   rW   r%   r   r   r   rB     rq   zIdentitySet.copyc                 C   rQ   r   )rR   r   r%   r   r   r   rS     rT   zIdentitySet.__len__c                 C   r|   r   )rU   r   rW   r%   r   r   r   rX     r'   zIdentitySet.__iter__c                 C   r@   )Nzset objects are unhashabler   r%   r   r   r   __hash__  r   zIdentitySet.__hash__c                 C   s   dt | jt| j f S r   )r   r   rV   r   rW   r%   r   r   r   r2     s   zIdentitySet.__repr__r   )*r   r   r   rH   r   r   rv   r   r   r4   r3   r   r   r   r   r   r   r   r   r   r+   r   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   r   rS   rX   r   r2   r   r   r   r   r     sP    
r   c                   @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )WeakSequencer   c                    s0   t | fdd  | _ fdd|D | _d S )Nc                 S   s"   | }|d ur|j |  d S d S r   )_storager   )r   selfrefr   r   r   r   _remove  s   z&WeakSequence.__init__.<locals>._removec                    s   g | ]}t | qS r   )weakrefref)r[   r   r   r   r   r]     s    z)WeakSequence.__init__.<locals>.<listcomp>)r  r  r   r   )r   _WeakSequence__elementsr   r  r   r     s
   
zWeakSequence.__init__c                 C   s   | j t|| j d S r   )r   r   r  r  r   r   r   r   r   r     r   zWeakSequence.appendc                 C   rQ   r   )rR   r   r%   r   r   r   rS     rT   zWeakSequence.__len__c                 C   s   dd dd | j D D S )Nc                 s   s    | ]	}|d ur|V  qd S r   r   r   r   r   r   r     s    
z(WeakSequence.__iter__.<locals>.<genexpr>c                 s   s    | ]}| V  qd S r   r   )r[   r  r   r   r   r     s    )r   r%   r   r   r   rX     s   zWeakSequence.__iter__c                 C   s.   z	| j | }W | S  ty   td| w )NzIndex %s out of range)r   rr   
IndexError)r   indexri   r   r   r   rl     s   zWeakSequence.__getitem__N)r   )r   r   r   r   r   rS   rX   rl   r   r   r   r   r     s    
r   c                   @   s   e Zd ZdddZdS )OrderedIdentitySetNc                 C   s2   t |  t | _|r|D ]	}| | qd S d S r   )r   r   r   r   r   )r   r   or   r   r   r     s   
zOrderedIdentitySet.__init__r   )r   r   r   r   r   r   r   r   r    s    r  c                   @       e Zd ZdZdd Zd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                 C   s
   || _ d S r   creator)r   r  r   r   r   r     rT   zPopulateDict.__init__c                 C   s   |  | | |< }|S r   r  r   rD   valr   r   r   __missing__  s   zPopulateDict.__missing__Nr   r   r   rH   r   r  r   r   r   r   r
    s    r
  c                   @   r	  )WeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create
    a reference cycle.

    c                 C   s   |j | _|j}t|| _d S r   )__func__r  __self__r  r  weakself)r   creator_methodr  r   r   r   r     s   zWeakPopulateDict.__init__c                 C   s   |  |  | | |< }|S r   )r  r  r  r   r   r   r    s   zWeakPopulateDict.__missing__Nr  r   r   r   r   r    s    r  c                 C   s   t t| S r   )propertyoperator
itemgetter)idxr   r   r   <lambda>
  s    r  c                    s:   t  j sfdd| D S  fdd| D S )Nc                    s    g | ]}| vr|s|qS r   r   r[   x)seenseen_addr   r   r]     s     zunique_list.<locals>.<listcomp>c                    s(   g | ]} |vr |s|qS r   r   r  hashfuncr  r  r   r   r]     s    

)r   r   )seqr   r   r  r   r     s   r   c                   @   s*   e Zd ZdZd	ddZdd Zd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                 C   sP   || _ i | _|rt||| _d S t|dr|j| _d S t|dr&|j| _d S d S )Nr   r   )rO   _uniquegetattr_data_appenderr   r   r   )r   rO   viar   r   r   r   "  s   

zUniqueAppender.__init__c                 C   s.   t |}|| jvr| | d| j|< d S d S r   )r   r#  r%  )r   r   id_r   r   r   r   ,  s
   

zUniqueAppender.appendc                 C   rQ   r   )rU   rO   r%   r   r   r   rX   2  rT   zUniqueAppender.__iter__r   )r   r   r   rH   r   r   rX   r   r   r   r   r"    s
    

r"  c                 C   s,   t | dkrt| d tjrt| d S | S )Nr   r   )rR   r<   typesGeneratorTyperV   r:   r   r   r   coerce_generator_arg6  s   r*  c                 C   sB   | d u r|S t | tjrt | tt r| gS t | tr| S t| S r   )r<   r   Iterabler	   r   rV   )r  rz   r   r   r   to_list=  s   
r,  c                 C   s   t | d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                 S   s   g | ]}|j r|qS r   )r   r[   ir   r   r   r]   R  r   z$has_intersection.<locals>.<listcomp>)boolr   )set_r   r   r   r   has_intersectionJ  s   r1  c                 C   (   | d u rt  S t| t st t| S | S r   )r   r<   r,  r  r   r   r   to_setU  
   
r4  c                 C   r2  r   )
column_setr<   r,  r3  r   r   r   to_column_set^  r5  r7  c                 K   s*   |   } |r| | | jdi | | S )z5Copy the given dict and update with the given values.Nr   )rB   r)   )r.   _newr   r   r   r   update_copyg  s
   
r9  c                 c   s@    | D ]}t |tst|drt|D ]}|V  qq|V  qdS )zGiven an iterator of which further sub-elements may also be
    iterators, flatten the sub-elements into a single iterator.

    rX   N)r<   rY   r   flatten_iterator)r  elemyr   r   r   r:  q  s   r:  c                   @   sd   e Zd ZdZdZdddZdd	 Zdd
dZdd Zdd Z	dd Z
dd Zedd Zd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                 C   s&   || _ || _|| _d| _t | _d S r   )r>  r?  r@  rA  r
   LockrB  )r   r>  r?  r@  r   r   r   r     s
   zLRUCache.__init__c                 C   s   |  j d7  _ | j S Nr   )rA  r%   r   r   r   _inc_counter  s   zLRUCache._inc_counterc                 C   s.   t | ||}||ur|  |d< |d S |S N   r   )r   r{   rG  )r   rD   rz   r   r   r   r   r{     s
   zLRUCache.getc                 C   s    t | |}|  |d< |d S rH  )r   rl   rG  )r   rD   r   r   r   r   rl     s   zLRUCache.__getitem__c                 C   s   dd t | D S )Nc                 S   s   g | ]}|d  qS )r   r   r-  r   r   r   r]     r   z#LRUCache.values.<locals>.<listcomp>)r   rW   r%   r   r   r   rW     r   zLRUCache.valuesc                 C   s   || v r| | S || |< |S r   r   rC   r   r   r   r6     s   zLRUCache.setdefaultc                 C   sF   t | |}|d u r|||  g}t | || n||d< |   d S rF  )r   r{   rG  r   _manage_size)r   rD   rE   r   r   r   r   r     s   zLRUCache.__setitem__c                 C   s   | j | j | j  S r   )r>  r?  r%   r   r   r   size_threshold  rG   zLRUCache.size_thresholdc              	   C   s   | j dsd S z_t| j}t| | j| j| j  kr`|r$d}| |  tt	| t
ddd}|| jd  D ]}z| |d = W q8 tyJ   Y q8w t| | j| j| j  ksW | j   d S W | j   d S | j   w )NFrI  T)rD   reverser   )rB  acquirer/  r@  rR   r>  r?  r   r   rW   r  r  rr   release)r   r@  
by_counterr   r   r   r   rJ    s*   

zLRUCache._manage_size)rC  rD  Nr   )r   r   r   rH   r   r   rG  r{   rl   rW   r6   r   r  rK  rJ  r   r   r   r   r=  ~  s    	

	
r=  c                   @   8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
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                 C   s   || _ || _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   rR  rS  r   r   r   r     s   
zScopedRegistry.__init__c                 C   s:   |   }z| j| W S  ty   | j||   Y S w r   )rS  rT  rr   r6   rR  rk   r   r   r   __call__  s   zScopedRegistry.__call__c                 C   s   |   | jv S )z9Return True if an object is present in the current scope.)rS  rT  r%   r   r   r   has  s   zScopedRegistry.hasc                 C   s   || j |  < dS )z$Set the value for the current scope.N)rT  rS  r   ri   r   r   r   r     s   zScopedRegistry.setc                 C   s(   z	| j |  = W dS  ty   Y dS w )z Clear the current scope, if any.N)rT  rS  rr   r%   r   r   r   r3     s
   zScopedRegistry.clearN	r   r   r   rH   r   rU  rV  r   r3   r   r   r   r   rQ    s    rQ  c                   @   rP  )ThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()``
    variable for storage.

    c                 C   s   || _ t | _d S r   )rR  r
   localrT  )r   rR  r   r   r   r     r   zThreadLocalRegistry.__init__c                 C   s2   z| j jW S  ty   |   }| j _| Y S w r   )rT  rE   rs   rR  )r   r  r   r   r   rU    s   
zThreadLocalRegistry.__call__c                 C   s   t | jdS )NrE   )r   rT  r%   r   r   r   rV    rm   zThreadLocalRegistry.hasc                 C   s   || j _d S r   )rT  rE   rW  r   r   r   r     rm   zThreadLocalRegistry.setc                 C   s"   z| j `W d S  ty   Y d S w r   )rT  rE   rs   r%   r   r   r   r3     s
   zThreadLocalRegistry.clearNrX  r   r   r   r   rY    s    rY  c                 C   s0   d}| D ]}||u r|d7 }|dkr dS q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   r   r   r   	has_dupes%  s   
r^  r   )=rH   
__future__r   r  r(  r  compatr   r   r   r   r   r	   r
   	frozenset	EMPTY_SETrN   r   r9   sqlalchemy.cimmutabledictr7   MappingregisterImportErrorr$   r>   r;   r   r?   rI   r   rw   r   r   r   r   r   r   r   r  r
  r  r6  column_dictordered_column_setr  _getters_property_gettersr   r"  r*  r,  r1  r4  r7  r9  r:  r=  rQ  rY  r^  r   r   r   r   <module>   sz   :	O



ej _"	


	
	
Q8