a
    •˜ëj+N  ã                   @  sT  U d Z ddlmZ ddl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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ZddlmZ ddlmZ ddlmZ ddlm Z  ej!�she�s²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( nHd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d#ed$�Z+ed%ed$�Z,ed&ed$�Z-ed'd(d)�Z.e/ƒ Z0d*e1d+< e/dgƒZ2d*e1d,< d-d-d-d.œd/d0„Z3d1d2d3œd4d5„Z4e#ƒ Z5d6e1d7< G d8d9„ d9e&e,e-f ƒZ6ed:ed$�Z7ed;ed$�Z8G d<d=„ d=ee+ ƒZ9G d>d?„ d?e9e+ ƒZ:G d@dA„ dAe%e9e+ ƒZ;dwdBdC„Z<e=Z>e<Z?G dDdE„ dEee+ ƒZ@G dFdG„ dGe$ƒZAG dHdI„ dIee,e-f ƒZBG dJdK„ dKee,e-f ƒZCeDZEe=ZFe'ZGG dLdM„ dMee+ ƒZHdNd-dOœdPdQ„ZIdxdNdRd-dSœdTdU„ZJdVdWdXdYœdZd[„ZKd\d]„ ZLdNd^d_œd`da„ZMdydbdcdNdbddœdedf„ZNdgdhd_œdidj„ZOG dkdl„ dlejPe,e-f ƒZQG dmdn„ dne e. ƒZRG dodp„ dpe ƒZSG dqdr„ dree+ ƒZTG dsdt„ dteTe+ ƒZUdudv„ ZVdS )zzCollection classes and helpers.é    )ÚannotationsN)ÚAny)ÚCallable)Úcast)Ú	Container)ÚDict)Ú	FrozenSet)ÚGeneric)ÚIterable)ÚIterator)ÚList)ÚMapping)ÚNoReturn)ÚOptional)Úoverload)ÚSequence)ÚSet)ÚTuple)ÚTypeVar)ÚUnion)Ú
ValuesViewé   )ÚHAS_CYEXTENSION)Úis_non_string_iterable)ÚLiteral)ÚProtocol)Úimmutabledict)ÚIdentitySet)ÚReadOnlyContainer)ÚImmutableDictBase)Ú
OrderedSet)Úunique_listÚ_T)ÚboundÚ_KTÚ_VTÚ_T_coT)Ú	covariantzFrozenSet[Any]Ú	EMPTY_SETÚNONE_SETú	List[Any])ÚaÚbÚreturnc                 C  sj   t | ƒ |¡}g }t| ƒt|ƒ }}|D ].}||v rL| |¡ || }} q$| |¡ q(| |¡ qfq$|S )af  merge two lists, maintaining ordering as much as possible.

    this is to reconcile vars(cls) with cls.__annotations__.

    Example::

        >>> a = ["__tablename__", "id", "x", "created_at"]
        >>> b = ["id", "name", "data", "y", "created_at"]
        >>> merge_lists_w_ordering(a, b)
        ['__tablename__', 'id', 'name', 'data', 'y', 'x', 'created_at']

    This is not necessarily the ordering that things had on the class,
    in this case the class is::

        class User(Base):
            __tablename__ = "users"

            id: Mapped[int] = mapped_column(primary_key=True)
            name: Mapped[str]
            data: Mapped[Optional[str]]
            x = Column(Integer)
            y: Mapped[int]
            created_at: Mapped[datetime.datetime] = mapped_column()

    But things are *mostly* ordered.

    The algorithm could also be done by creating a partial ordering for
    all items in both lists and then using topological_sort(), but that
    is too much overhead.

    Background on how I came up with this is at:
    https://gist.github.com/zzzeek/89de958cf0803d148e74861bd682ebae

    )ÚsetÚintersectionÚiterÚdiscardÚappendÚextend)r+   r,   ÚoverlapÚresultÚcurrentÚotherÚelement© r9   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/util/_collections.pyÚmerge_lists_w_orderingL   s    #


r;   zMapping[_KT, _VT]zimmutabledict[_KT, _VT])Údr-   c                 C  s"   | st S t| tƒr| S t| ƒS d S ©N)Ú
EMPTY_DICTÚ
isinstancer   ©r<   r9   r9   r:   Úcoerce_to_immutabledict„   s
    
rA   zimmutabledict[Any, Any]r>   c                   @  s\   e Zd ZdZdddœdd„Zddœd	d
„Zddœdd„Zddddœdd„Zddœdd„ZdS )Ú
FacadeDictz*A dictionary that is not publicly mutable.r   zFacadeDict[Any, Any])Úargsr-   c                 G  s   t  | ¡}|S r=   )r   Ú__new__)ÚclsrC   Únewr9   r9   r:   rD   “   s    
zFacadeDict.__new__r   ©r-   c                 C  s   t dƒ‚d S )Nz\an immutabledict shouldn't need to be copied.  use dict(d) if you need a mutable dictionary.)ÚNotImplementedError©Úselfr9   r9   r:   Úcopy—   s    ÿzFacadeDict.copyc                 C  s   t t| ƒffS r=   )rB   ÚdictrI   r9   r9   r:   Ú
__reduce__�   s    zFacadeDict.__reduce__r$   r%   ÚNone©ÚkeyÚvaluer-   c                 C  s   t  | ||¡ dS )z,insert an item into the dictionary directly.N)rL   Ú__setitem__©rJ   rP   rQ   r9   r9   r:   Ú_insert_item    s    zFacadeDict._insert_itemÚstrc                 C  s   dt  | ¡ S )NzFacadeDict(%s))rL   Ú__repr__rI   r9   r9   r:   rV   ¤   s    zFacadeDict.__repr__N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rD   rK   rM   rT   rV   r9   r9   r9   r:   rB   �   s   rB   Ú_DTÚ_Fc                      s”  e Zd ZU dZdZded< ddœdd„Zdd	œd
d„Zdd	œdd„Zdd	œ‡ fdd„Z	dddœdd„Z
ddddœdd„Zdddœdd„Zdddœd d!„Zddddœd"d#„Zd$d	œd%d&„Zd$dd'œd(d)„Zdddœd*d+„Zdd,dœd-d.„Zd/d	œd0d1„Zddd2œd3d4„Zedd5dœd6d7„ƒZedd8d8d9œd:d7„ƒZdKdd<d=d9œd>d7„Zdd	œd?d@„ZdAd	œdBdC„ZdDd	œdEdF„Zdd,dœdGdH„Zdd	œdIdJ„Z‡  ZS )LÚ
Propertiesz8Provide a __getattr__/__setattr__ interface over a dict.©Ú_datazDict[str, _T]r_   )Údatac                 C  s   t  | d|¡ d S ©Nr_   ©ÚobjectÚ__setattr__)rJ   r`   r9   r9   r:   Ú__init__´   s    zProperties.__init__ÚintrG   c                 C  s
   t | jƒS r=   ©Úlenr_   rI   r9   r9   r:   Ú__len__·   s    zProperties.__len__úIterator[_T]c                 C  s   t t| j ¡ ƒƒS r=   )r0   Úlistr_   ÚvaluesrI   r9   r9   r:   Ú__iter__º   s    zProperties.__iter__z	List[str]c                   s   t tƒ ƒdd„ | j ¡ D ƒ S )Nc                 S  s   g | ]}t |ƒ‘qS r9   )rU   ©Ú.0Úkr9   r9   r:   Ú
<listcomp>¾   ó    z&Properties.__dir__.<locals>.<listcomp>)ÚdirÚsuperr_   ÚkeysrI   ©Ú	__class__r9   r:   Ú__dir__½   s    zProperties.__dir__zProperties[_F]zList[Union[_T, _F]])r7   r-   c                 C  s   t | ƒt |ƒ S r=   )rk   )rJ   r7   r9   r9   r:   Ú__add__À   s    zProperties.__add__rU   r"   rN   )rP   Úobjr-   c                 C  s   || j |< d S r=   r^   ©rJ   rP   rz   r9   r9   r:   rR   Ã   s    zProperties.__setitem__©rP   r-   c                 C  s
   | j | S r=   r^   ©rJ   rP   r9   r9   r:   Ú__getitem__Æ   s    zProperties.__getitem__c                 C  s   | j |= d S r=   r^   r}   r9   r9   r:   Ú__delitem__É   s    zProperties.__delitem__c                 C  s   || j |< d S r=   r^   r{   r9   r9   r:   rd   Ì   s    zProperties.__setattr__zDict[str, Any]c                 C  s
   d| j iS ra   r^   rI   r9   r9   r:   Ú__getstate__Ï   s    zProperties.__getstate__)Ústater-   c                 C  s   t  | d|d ¡ d S ra   rb   )rJ   r�   r9   r9   r:   Ú__setstate__Ò   s    zProperties.__setstate__c                 C  s,   z| j | W S  ty&   t|ƒ‚Y n0 d S r=   )r_   ÚKeyErrorÚAttributeErrorr}   r9   r9   r:   Ú__getattr__Õ   s    zProperties.__getattr__Úboolc                 C  s
   || j v S r=   r^   r}   r9   r9   r:   Ú__contains__Û   s    zProperties.__contains__zReadOnlyProperties[_T]c                 C  s
   t | jƒS )z8Return an immutable proxy for this :class:`.Properties`.)ÚReadOnlyPropertiesr_   rI   r9   r9   r:   Úas_readonlyÞ   s    zProperties.as_readonly)rQ   r-   c                 C  s   | j  |¡ d S r=   )r_   Úupdate)rJ   rQ   r9   r9   r:   rŠ   ã   s    zProperties.updatezOptional[_T]c                 C  s   d S r=   r9   r}   r9   r9   r:   Úgetæ   s    zProperties.getzUnion[_DT, _T]©rP   Údefaultr-   c                 C  s   d S r=   r9   ©rJ   rP   r�   r9   r9   r:   r‹   é   s    NzOptional[Union[_DT, _T]]zOptional[Union[_T, _DT]]c                 C  s   || v r| | S |S d S r=   r9   rŽ   r9   r9   r:   r‹   ì   s    c                 C  s
   t | jƒS r=   )rk   r_   rI   r9   r9   r:   ru   ô   s    zProperties.keysúList[_T]c                 C  s   t | j ¡ ƒS r=   )rk   r_   rl   rI   r9   r9   r:   rl   ÷   s    zProperties.valueszList[Tuple[str, _T]]c                 C  s   t | j ¡ ƒS r=   )rk   r_   ÚitemsrI   r9   r9   r:   r�   ú   s    zProperties.itemsc                 C  s
   || j v S r=   r^   r}   r9   r9   r:   Úhas_keyý   s    zProperties.has_keyc                 C  s   | j  ¡  d S r=   )r_   ÚclearrI   r9   r9   r:   r’      s    zProperties.clear)N)rW   rX   rY   rZ   Ú	__slots__Ú__annotations__re   ri   rm   rx   ry   rR   r~   r   rd   r€   r‚   r…   r‡   r‰   rŠ   r   r‹   ru   rl   r�   r‘   r’   Ú__classcell__r9   r9   rv   r:   r]   ­   s:   
 ÿr]   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.r9   c                 C  s   t  | tƒ ¡ d S r=   )r]   re   ÚOrderedDictrI   r9   r9   r:   re   
  s    zOrderedProperties.__init__N)rW   rX   rY   rZ   r“   re   r9   r9   r9   r:   r–     s   r–   c                   @  s   e Zd ZdZdZdS )rˆ   zDProvide immutable dict/object attribute to an underlying dictionary.r9   N)rW   rX   rY   rZ   r“   r9   r9   r9   r:   rˆ     s   rˆ   c                   s0   ‡ fdd„t ˆ |d�D ƒ}ˆ  ¡  ˆ  |¡ dS )zSort an OrderedDict in-place.c                   s   g | ]}|ˆ | f‘qS r9   r9   rn   r@   r9   r:   rq     rr   z,_ordered_dictionary_sort.<locals>.<listcomp>)rP   N)Úsortedr’   rŠ   )r<   rP   r�   r9   r@   r:   Ú_ordered_dictionary_sort  s    r™   c                   @  s<   e Zd Zdddœdd„Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚWeakSequencer9   zSequence[_T])Ú_WeakSequence__elementsc                   s0   t  | ¡fdd„‰ ˆ | _‡ fdd„|D ƒ| _d S )Nc                 S  s   |ƒ }|d ur|j  | ¡ d S r=   )Ú_storageÚremove)ÚitemÚselfrefrJ   r9   r9   r:   Ú_remove&  s    z&WeakSequence.__init__.<locals>._removec                   s   g | ]}t  |ˆ ¡‘qS r9   )ÚweakrefÚref)ro   r8   ©r    r9   r:   rq   ,  s   z)WeakSequence.__init__.<locals>.<listcomp>)r¡   r¢   r    rœ   )rJ   r›   r9   r£   r:   re   #  s
    
ÿzWeakSequence.__init__c                 C  s   | j  t || j¡¡ d S r=   )rœ   r2   r¡   r¢   r    )rJ   rž   r9   r9   r:   r2   0  s    zWeakSequence.appendc                 C  s
   t | jƒS r=   )rh   rœ   rI   r9   r9   r:   ri   3  s    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=   r9   )ro   rz   r9   r9   r:   Ú	<genexpr>7  s   z(WeakSequence.__iter__.<locals>.<genexpr>c                 s  s   | ]}|ƒ V  qd S r=   r9   )ro   r¢   r9   r9   r:   r¤   8  rr   ©rœ   rI   r9   r9   r:   rm   6  s    ÿzWeakSequence.__iter__c                 C  s   | j | ƒ S r=   r¥   )rJ   Úindexr9   r9   r:   r~   ;  s    zWeakSequence.__getitem__N)r9   )rW   rX   rY   re   r2   ri   rm   r~   r9   r9   r9   r:   rš   "  s
   rš   c                   @  s   e Zd Zdddœdd„ZdS )ÚOrderedIdentitySetNzOptional[Iterable[Any]])Úiterablec                 C  s.   t  | ¡ tƒ | _|r*|D ]}|  |¡ qd S r=   )r   re   r—   Z_membersÚadd)rJ   r¨   Úor9   r9   r:   re   @  s
    
zOrderedIdentitySet.__init__)N)rW   rX   rY   re   r9   r9   r9   r:   r§   ?  s   r§   c                   @  s.   e Zd ZdZddœdd„Zdddœdd	„Zd
S )ÚPopulateDictz•A dict which populates missing values via a creation function.

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

    zCallable[[_KT], _VT]©Úcreatorc                 C  s
   || _ d S r=   r¬   )rJ   r­   r9   r9   r:   re   P  s    zPopulateDict.__init__r   r|   c                 C  s   |   |¡ | |< }|S r=   r¬   ©rJ   rP   Úvalr9   r9   r:   Ú__missing__S  s    zPopulateDict.__missing__N©rW   rX   rY   rZ   re   r°   r9   r9   r9   r:   r«   H  s   r«   c                   @  s.   e Zd ZdZddœdd„Zdddœdd	„Zd
S )ÚWeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create
    a reference cycle.

    ztypes.MethodType)Úcreator_methodc                 C  s   |j | _|j}t |¡| _d S r=   )Ú__func__r­   Ú__self__r¡   r¢   Úweakself)rJ   r³   r¶   r9   r9   r:   re   ^  s    zWeakPopulateDict.__init__r   r|   c                 C  s   |   |  ¡ |¡ | |< }|S r=   )r­   r¶   r®   r9   r9   r:   r°   c  s    zWeakPopulateDict.__missing__Nr±   r9   r9   r9   r:   r²   X  s   r²   c                   @  s^   e Zd ZU dZdZded< ded< ded< ddd
dœdd„Zdddœdd„Zddœdd„Zd	S )ÚUniqueAppenderz½Appends items to a collection ensuring uniqueness.

    Additional appends() of the same object are ignored.  Membership is
    determined by identity (``is a``) not equality (``==``).
    )r`   Ú_data_appenderÚ_uniquez&Union[Iterable[_T], Set[_T], List[_T]]r`   zCallable[[_T], None]r¸   zDict[int, Literal[True]]r¹   NzOptional[str])r`   Úviac                 C  sT   || _ i | _|rt||ƒ| _n2t|dƒr8td|ƒj| _nt|dƒrPtd|ƒj| _d S )Nr2   r�   r©   zSet[_T])r`   r¹   Úgetattrr¸   Úhasattrr   r2   r©   )rJ   r`   rº   r9   r9   r:   re   ~  s    

zUniqueAppender.__init__r"   rN   )rž   r-   c                 C  s*   t |ƒ}|| jvr&|  |¡ d| j|< d S )NT)Úidr¹   r¸   )rJ   rž   Zid_r9   r9   r:   r2   Œ  s    

zUniqueAppender.appendrj   rG   c                 C  s
   t | jƒS r=   )r0   r`   rI   r9   r9   r:   rm   ’  s    zUniqueAppender.__iter__)N)	rW   rX   rY   rZ   r“   r”   re   r2   rm   r9   r9   r9   r:   r·   q  s   
 ýr·   r   )Úargr-   c                 C  s6   t | ƒdkr(t| d tjƒr(t| d ƒS td| ƒS d S )Nr   r   r*   )rh   r?   ÚtypesÚGeneratorTyperk   r   )r¾   r9   r9   r:   Úcoerce_generator_arg–  s    rÁ   zOptional[List[Any]])Úxr�   r-   c                 C  s4   | d u r|S t | ƒs| gS t| tƒr(| S t| ƒS d S r=   )r   r?   rk   )rÂ   r�   r9   r9   r:   Úto_list�  s    
rÃ   zContainer[Any]zIterable[Any]r†   )Úset_r¨   r-   c                   s   t ‡ fdd„|D ƒƒS )z²return 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                 3  s   | ]}|j r|ˆ v V  qd S r=   )Ú__hash__)ro   Úi©rÄ   r9   r:   r¤   ¯  rr   z#has_intersection.<locals>.<genexpr>)Úany)rÄ   r¨   r9   rÇ   r:   Úhas_intersection¨  s    rÉ   c                 C  s,   | d u rt ƒ S t| t ƒs$t t| ƒƒS | S d S r=   )r.   r?   rÃ   ©rÂ   r9   r9   r:   Úto_set²  s
    
rË   zSet[Any])rÂ   r-   c                 C  s,   | d u rt ƒ S t| t ƒs$t t| ƒƒS | S d S r=   )Ú
column_setr?   rÃ   rÊ   r9   r9   r:   Úto_column_set»  s
    
rÍ   zDict[Any, Any]zOptional[Dict[Any, Any]])r<   Ú_newÚkwr-   c                 K  s*   |   ¡ } |r|  |¡ | jf i |¤Ž | S )z5Copy the given dict and update with the given values.)rK   rŠ   )r<   rÎ   rÏ   r9   r9   r:   Úupdate_copyÄ  s
    
rÐ   zIterable[_T]rj   c                 c  s8   | D ].}t |tƒs,t|dƒr,t|ƒE dH  q|V  qdS )z�Given an iterator of which further sub-elements may also be
    iterators, flatten the sub-elements into a single iterator.

    rm   N)r?   rU   r¼   Úflatten_iterator)rÂ   Úelemr9   r9   r:   rÑ   Ð  s    rÑ   c                   @  s  e Zd ZU dZdZded< ded< ded< d3ddddœdd„Zdd„ Zedddœdd„ƒZ	eddddœdd„ƒZ	d4ddddœdd„Z	dddœdd„Z
dd œd!d"„Zdd œd#d$„Zd%d œd&d'„Zddd(d)œd*d+„Zdd(d,œd-d.„Zedd œd/d0„ƒZd(d œd1d2„ZdS )5ÚLRUCachezóDictionary 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_alertr_   Ú_counterÚ_mutexrf   rÔ   ÚfloatrÕ   z.Optional[Callable[[LRUCache[_KT, _VT]], None]]rÖ   éd   ç      à?NzOptional[Callable[..., None]])rÔ   rÕ   rÖ   c                 C  s,   || _ || _|| _d| _t ¡ | _i | _d S )Nr   )rÔ   rÕ   rÖ   r×   Ú	threadingÚLockrØ   r_   )rJ   rÔ   rÕ   rÖ   r9   r9   r:   re   ô  s    
zLRUCache.__init__c                 C  s   |  j d7  _ | j S )Nr   )r×   rI   r9   r9   r:   Ú_inc_counter  s    zLRUCache._inc_counterr$   zOptional[_VT]r|   c                 C  s   d S r=   r9   r}   r9   r9   r:   r‹     s    zLRUCache.getzUnion[_VT, _T]rŒ   c                 C  s   d S r=   r9   rŽ   r9   r9   r:   r‹     s    zOptional[Union[_VT, _T]]c                 C  s4   | j  |¡}|d ur,|  ¡ |d d< |d S |S d S ©Né   r   r   )r_   r‹   rÞ   )rJ   rP   r�   rž   r9   r9   r:   r‹     s
    r%   c                 C  s"   | j | }|  ¡ |d d< |d S rß   )r_   rÞ   )rJ   rP   rž   r9   r9   r:   r~     s    
zLRUCache.__getitem__zIterator[_KT]rG   c                 C  s
   t | jƒS r=   )r0   r_   rI   r9   r9   r:   rm     s    zLRUCache.__iter__c                 C  s
   t | jƒS r=   rg   rI   r9   r9   r:   ri     s    zLRUCache.__len__zValuesView[_VT]c                 C  s   t  dd„ | j ¡ D ƒ¡S )Nc                 S  s   i | ]\}}||d  “qS )r   r9   )ro   rp   rÆ   r9   r9   r:   Ú
<dictcomp>!  rr   z#LRUCache.values.<locals>.<dictcomp>)Útypingr   r_   r�   rI   r9   r9   r:   rl      s    zLRUCache.valuesrN   rO   c                 C  s"   |||   ¡ gf| j|< |  ¡  d S r=   )rÞ   r_   Ú_manage_sizerS   r9   r9   r:   rR   #  s    zLRUCache.__setitem__)Ú_LRUCache__vr-   c                 C  s   | j |= d S r=   r^   )rJ   rä   r9   r9   r:   r   '  s    zLRUCache.__delitem__c                 C  s   | j | j | j  S r=   )rÔ   rÕ   rI   r9   r9   r:   Úsize_threshold*  s    zLRUCache.size_thresholdc              	   C  s¾   | j  d¡sd S zœt| jƒ}t| ƒ| j| j| j  kr |rHd}|  | ¡ t| j 	¡ t
 d¡dd�}|| jd … D ],}z| j|d = W qp tyš   Y qpY qp0 qpqW | j  ¡  n| j  ¡  0 d S )NFrà   T)rP   Úreverser   )rØ   Úacquirer†   rÖ   rh   rÔ   rÕ   r˜   r_   rl   ÚoperatorÚ
itemgetterrƒ   Úrelease)rJ   rÖ   Z
by_counterrž   r9   r9   r:   rã   .  s&    

ýzLRUCache._manage_size)rÚ   rÛ   N)N)rW   rX   rY   rZ   r“   r”   re   rÞ   r   r‹   r~   rm   ri   rl   rR   r   Úpropertyrå   rã   r9   r9   r9   r:   rÓ   Ý  s2   
		   ü ÿ
rÓ   c                   @  s   e Zd Zddœdd„ZdS )Ú_CreateFuncTyper&   rG   c                 C  s   d S r=   r9   rI   r9   r9   r:   Ú__call__G  rr   z_CreateFuncType.__call__N©rW   rX   rY   rí   r9   r9   r9   r:   rì   F  s   rì   c                   @  s   e Zd Zddœdd„ZdS )Ú_ScopeFuncTyper   rG   c                 C  s   d S r=   r9   rI   r9   r9   r:   rí   K  rr   z_ScopeFuncType.__call__Nrî   r9   r9   r9   r:   rï   J  s   rï   c                   @  sx   e Zd ZU dZdZded< ded< ded< d	d
dœdd„Zddœdd„Zddœdd„Zdddœdd„Z	ddœ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.
    ©Ú
createfuncÚ	scopefuncÚregistryz_CreateFuncType[_T]rò   rï   ró   r   rô   úCallable[[], _T]zCallable[[], Any])rò   ró   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).

        Nrñ   )rJ   rò   ró   r9   r9   r:   re   c  s    zScopedRegistry.__init__r"   rG   c                 C  s>   |   ¡ }z| j| W S  ty8   | j ||  ¡ ¡ Y S 0 d S r=   )ró   rô   rƒ   Ú
setdefaultrò   r}   r9   r9   r:   rí   t  s
    zScopedRegistry.__call__r†   c                 C  s   |   ¡ | jv S )z9Return True if an object is present in the current scope.)ró   rô   rI   r9   r9   r:   Úhas{  s    zScopedRegistry.hasrN   ©rz   r-   c                 C  s   || j |  ¡ < dS )z$Set the value for the current scope.N)rô   ró   ©rJ   rz   r9   r9   r:   r.   €  s    zScopedRegistry.setc                 C  s(   z| j |  ¡ = W n ty"   Y n0 dS )z Clear the current scope, if any.N)rô   ró   rƒ   rI   r9   r9   r:   r’   …  s    zScopedRegistry.clearN)rW   rX   rY   rZ   r“   r”   re   rí   r÷   r.   r’   r9   r9   r9   r:   rð   N  s   
rð   c                   @  sX   e Zd ZdZddœdd„Zddœdd	„Zd
dœdd„Zdddœdd„Zddœdd„ZdS )ÚThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()``
    variable for storage.

    rõ   )rò   c                 C  s   || _ t ¡ | _d S r=   )rò   rÜ   Úlocalrô   )rJ   rò   r9   r9   r:   re   ”  s    zThreadLocalRegistry.__init__r"   rG   c                 C  s6   z
| j jW S  ty0   |  ¡  }| j _| Y S 0 d S r=   )rô   rQ   r„   rò   )rJ   r¯   r9   r9   r:   rí   ˜  s
    
zThreadLocalRegistry.__call__r†   c                 C  s   t | jdƒS )NrQ   )r¼   rô   rI   r9   r9   r:   r÷   Ÿ  s    zThreadLocalRegistry.hasrN   rø   c                 C  s   || j _d S r=   )rô   rQ   rù   r9   r9   r:   r.   ¢  s    zThreadLocalRegistry.setc                 C  s"   z
| j `W n ty   Y n0 d S r=   )rô   rQ   r„   rI   r9   r9   r:   r’   ¥  s    
zThreadLocalRegistry.clearN)	rW   rX   rY   rZ   re   rí   r÷   r.   r’   r9   r9   r9   r:   rú   Ž  s   rú   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   TFr9   )ÚsequenceÚtargetÚcrž   r9   r9   r:   Ú	has_dupes¬  s    
rÿ   )N)N)N)WrZ   Ú
__future__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   r¡   Z_has_cyr   r   r   r   ÚTYPE_CHECKINGZ_py_collectionsr   r   r   r   r    r!   Z$sqlalchemy.cyextension.immutabledictZ"sqlalchemy.cyextension.collectionsr"   r$   r%   r&   Ú	frozensetr(   r”   r)   r;   rA   r>   rB   r[   r\   r]   r–   rˆ   r™   rL   r—   Zsort_dictionaryrš   r§   r«   r²   r.   rÌ   Zcolumn_dictZordered_column_setr·   rÁ   rÃ   rÉ   rË   rÍ   rÐ   rÑ   ÚMutableMappingrÓ   rì   rï   rð   rú   rÿ   r9   r9   r9   r:   Ú<module>	   s¦   8	W


	%
	
 ÿi@