o
    ŠågnN  ã                   @  s  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!s²e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( n$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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,< dwd1d2„Z3dxd6d7„Z4e#ƒ Z5d8e1d9< G d:d;„ d;e&e,e-f ƒZ6ed<ed$�Z7ed=ed$�Z8G d>d?„ d?ee+ ƒZ9G d@dA„ dAe9e+ ƒZ:G dBdC„ dCe%e9e+ ƒZ;dydDdE„Z<e=Z>e<Z?G dFdG„ dGee+ ƒZ@G dHdI„ dIe$ƒZAG dJdK„ dKee,e-f ƒZBG dLdM„ dMee,e-f ƒZCeDZEe=ZFe'ZGG dNdO„ dOee+ ƒZHdzdRdS„ZIdyd{dWdX„ZJd|d^d_„ZKd`da„ ZLd}dcdd„ZMdydedf„ZNd~didj„ZOG dkdl„ dlejPe,e-f ƒZQG dmdn„ dne e. ƒZRG dodp„ dpe ƒZSG dqdr„ dree+ ƒZTG dsdt„ dteTe+ ƒZUdudv„ ZVdS )z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Úaú	List[Any]ÚbÚreturnc                 C  sl   t | ƒ |¡}g }t| ƒt|ƒ}}	 |D ]}||v r'| |¡ ||}} n| |¡ q| |¡ 	 |S q)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   úX/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/util/_collections.pyÚmerge_lists_w_orderingL   s   #


ôr;   ÚdúMapping[_KT, _VT]úimmutabledict[_KT, _VT]c                 C  s   | st S t| tƒr| S t| ƒS ©N)Ú
EMPTY_DICTÚ
isinstancer   ©r<   r9   r9   r:   Úcoerce_to_immutabledict„   s
   
rC   zimmutabledict[Any, Any]r@   c                   @  sB   e Zd ZdZddd„Zdd	d
„Zddd„Zddd„Zddd„ZdS )Ú
FacadeDictz*A dictionary that is not publicly mutable.Úargsr   r-   úFacadeDict[Any, Any]c                 G  s   t  | ¡}|S r?   )r   Ú__new__)ÚclsrE   Únewr9   r9   r:   rG   “   s   
zFacadeDict.__new__r   c                 C  s   t dƒ‚)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?   )rD   ÚdictrK   r9   r9   r:   Ú
__reduce__�   ó   zFacadeDict.__reduce__Úkeyr$   Úvaluer%   ÚNonec                 C  s   t  | ||¡ dS )z,insert an item into the dictionary directly.N)rN   Ú__setitem__©rL   rQ   rR   r9   r9   r:   Ú_insert_item    ó   zFacadeDict._insert_itemÚstrc                 C  s   dt  | ¡ S )NzFacadeDict(%s))rN   Ú__repr__rK   r9   r9   r:   rY   ¤   rP   zFacadeDict.__repr__N)rE   r   r-   rF   )r-   r   ©r-   r   ©rQ   r$   rR   r%   r-   rS   )r-   rX   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rG   rM   rO   rV   rY   r9   r9   r9   r:   rD   �   s    



rD   Ú_DTÚ_Fc                      s  e Zd ZU dZdZded< dKdd„ZdLd
d„ZdMdd„ZdN‡ fdd„Z	dOdd„Z
dPdd„ZdQdd„ZdRd d!„ZdPd"d#„ZdSd%d&„ZdTd(d)„ZdQd*d+„ZdUd-d.„ZdVd0d1„ZdWd3d4„ZedXd6d7„ƒZedYd:d7„ƒZ	;dZd[d>d7„ZdNd?d@„Zd\dBdC„Zd]dEdF„ZdUdGdH„Zd^dIdJ„Z‡  ZS )_Ú
Propertiesz8Provide a __getattr__/__setattr__ interface over a dict.©Ú_dataúDict[str, _T]rd   Údatac                 C  s   t  | d|¡ d S ©Nrd   ©ÚobjectÚ__setattr__)rL   rf   r9   r9   r:   Ú__init__´   ó   zProperties.__init__r-   Úintc                 C  ó
   t | jƒS r?   ©Úlenrd   rK   r9   r9   r:   Ú__len__·   ó   
zProperties.__len__úIterator[_T]c                 C  s   t t| j ¡ ƒƒS r?   )r0   Úlistrd   ÚvaluesrK   r9   r9   r:   Ú__iter__º   rl   zProperties.__iter__ú	List[str]c                   s   t tƒ ƒdd„ | j ¡ D ƒ S )Nc                 S  s   g | ]}t |ƒ‘qS r9   )rX   ©Ú.0Úkr9   r9   r:   Ú
<listcomp>¾   s    z&Properties.__dir__.<locals>.<listcomp>)ÚdirÚsuperrd   ÚkeysrK   ©Ú	__class__r9   r:   Ú__dir__½   s   zProperties.__dir__r7   úProperties[_F]úList[Union[_T, _F]]c                 C  s   t | ƒt |ƒ S r?   )rt   )rL   r7   r9   r9   r:   Ú__add__À   ó   zProperties.__add__rQ   rX   Úobjr"   rS   c                 C  ó   || j |< d S r?   rc   ©rL   rQ   r†   r9   r9   r:   rT   Ã   rP   zProperties.__setitem__c                 C  s
   | j | S r?   rc   ©rL   rQ   r9   r9   r:   Ú__getitem__Æ   rr   zProperties.__getitem__c                 C  ó   | j |= d S r?   rc   r‰   r9   r9   r:   Ú__delitem__É   ó   zProperties.__delitem__c                 C  r‡   r?   rc   rˆ   r9   r9   r:   rj   Ì   rP   zProperties.__setattr__úDict[str, Any]c                 C  s
   d| j iS rg   rc   rK   r9   r9   r:   Ú__getstate__Ï   rr   zProperties.__getstate__Ústatec                 C  s   t  | d|d ¡ d S rg   rh   )rL   r�   r9   r9   r:   Ú__setstate__Ò   s   zProperties.__setstate__c                 C  s$   z| j | W S  ty   t|ƒ‚w r?   )rd   ÚKeyErrorÚAttributeErrorr‰   r9   r9   r:   Ú__getattr__Õ   s
   ÿzProperties.__getattr__Úboolc                 C  ó
   || j v S r?   rc   r‰   r9   r9   r:   Ú__contains__Û   rr   zProperties.__contains__úReadOnlyProperties[_T]c                 C  rn   )z8Return an immutable proxy for this :class:`.Properties`.)ÚReadOnlyPropertiesrd   rK   r9   r9   r:   Úas_readonlyÞ   s   
zProperties.as_readonlyrR   c                 C  s   | j  |¡ d S r?   )rd   Úupdate)rL   rR   r9   r9   r:   r›   ã   r…   zProperties.updateúOptional[_T]c                 C  ó   d S r?   r9   r‰   r9   r9   r:   Úgetæ   ó   zProperties.getÚdefaultúUnion[_DT, _T]c                 C  r�   r?   r9   ©rL   rQ   r    r9   r9   r:   rž   é   rŸ   NúOptional[Union[_DT, _T]]úOptional[Union[_T, _DT]]c                 C  s   || v r| | S |S r?   r9   r¢   r9   r9   r:   rž   ì   s   c                 C  rn   r?   )rt   rd   rK   r9   r9   r:   r~   ô   rr   zProperties.keysúList[_T]c                 C  ó   t | j ¡ ƒS r?   )rt   rd   ru   rK   r9   r9   r:   ru   ÷   rP   zProperties.valuesúList[Tuple[str, _T]]c                 C  r¦   r?   )rt   rd   ÚitemsrK   r9   r9   r:   r¨   ú   rP   zProperties.itemsc                 C  r–   r?   rc   r‰   r9   r9   r:   Úhas_keyý   rr   zProperties.has_keyc                 C  s   | j  ¡  d S r?   )rd   ÚclearrK   r9   r9   r:   rª      rP   zProperties.clear)rf   re   ©r-   rm   ©r-   rs   )r-   rw   )r7   r‚   r-   rƒ   )rQ   rX   r†   r"   r-   rS   )rQ   rX   r-   r"   )rQ   rX   r-   rS   )r-   rŽ   )r�   rŽ   r-   rS   )rQ   rX   r-   r•   )r-   r˜   )rR   re   r-   rS   )rQ   rX   r-   rœ   )rQ   rX   r    r¡   r-   r¡   r?   )rQ   rX   r    r£   r-   r¤   )r-   r¥   )r-   r§   ©r-   rS   )r\   r]   r^   r_   Ú	__slots__Ú__annotations__rk   rq   rv   r�   r„   rT   rŠ   rŒ   rj   r�   r‘   r”   r—   rš   r›   r   rž   r~   ru   r¨   r©   rª   Ú__classcell__r9   r9   r   r:   rb   ­   s<   
 













ÿ



rb   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?   )rb   rk   ÚOrderedDictrK   r9   r9   r:   rk   
  rl   zOrderedProperties.__init__N)r\   r]   r^   r_   r®   rk   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)r\   r]   r^   r_   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   rx   rB   r9   r:   r{     s    z,_ordered_dictionary_sort.<locals>.<listcomp>)rQ   N)Úsortedrª   r›   )r<   rQ   r¨   r9   rB   r:   Ú_ordered_dictionary_sort  s   r´   c                   @  s8   e Zd Zdddd„Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚWeakSequencer9   Ú_WeakSequence__elementsúSequence[_T]c                   s0   t  | ¡fdd„‰ ˆ | _‡ fdd„|D ƒ| _d S )Nc                 S  s"   |ƒ }|d ur|j  | ¡ d S d S r?   )Ú_storageÚremove)ÚitemÚselfrefrL   r9   r9   r:   Ú_remove&  s   ÿz&WeakSequence.__init__.<locals>._removec                   s   g | ]}t  |ˆ ¡‘qS r9   )ÚweakrefÚref)ry   r8   ©r¼   r9   r:   r{   ,  s    ÿz)WeakSequence.__init__.<locals>.<listcomp>)r½   r¾   r¼   r¸   )rL   r¶   r9   r¿   r:   rk   #  s
   
ÿzWeakSequence.__init__c                 C  s   | j  t || j¡¡ d S r?   )r¸   r2   r½   r¾   r¼   )rL   rº   r9   r9   r:   r2   0  ó   zWeakSequence.appendc                 C  rn   r?   )rp   r¸   rK   r9   r9   r:   rq   3  rr   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   )ry   r†   r9   r9   r:   Ú	<genexpr>7  s   € ÿz(WeakSequence.__iter__.<locals>.<genexpr>c                 s  s   � | ]}|ƒ V  qd S r?   r9   )ry   r¾   r9   r9   r:   rÁ   8  s   € )r¸   rK   r9   r9   r:   rv   6  s   ÿzWeakSequence.__iter__c                 C  s.   z	| j | }W |ƒ S  ty   td| ƒ‚w )NzIndex %s out of range)r¸   r’   Ú
IndexError)rL   Úindexr†   r9   r9   r:   rŠ   ;  s   ýÿzWeakSequence.__getitem__N)r9   )r¶   r·   )r\   r]   r^   rk   r2   rq   rv   rŠ   r9   r9   r9   r:   rµ   "  s    rµ   c                   @  s   e Zd Zdddd„ZdS )ÚOrderedIdentitySetNÚiterableúOptional[Iterable[Any]]c                 C  s2   t  | ¡ tƒ | _|r|D ]	}|  |¡ qd S d S r?   )r   rk   r²   Ú_membersÚadd)rL   rÅ   Úor9   r9   r:   rk   E  s   
þzOrderedIdentitySet.__init__r?   )rÅ   rÆ   )r\   r]   r^   rk   r9   r9   r9   r:   rÄ   D  s    rÄ   c                   @  ó$   e Zd ZdZddd„Z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.

    ÚcreatorúCallable[[_KT], _VT]c                 C  s
   || _ d S r?   ©rÌ   )rL   rÌ   r9   r9   r:   rk   U  rr   zPopulateDict.__init__rQ   r   r-   c                 C  s   |   |¡ | |< }|S r?   rÎ   ©rL   rQ   Úvalr9   r9   r:   Ú__missing__X  s   zPopulateDict.__missing__N)rÌ   rÍ   ©rQ   r   r-   r   ©r\   r]   r^   r_   rk   rÑ   r9   r9   r9   r:   rË   M  s    
rË   c                   @  rÊ   )ÚWeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create
    a reference cycle.

    Úcreator_methodútypes.MethodTypec                 C  s   |j | _|j}t |¡| _d S r?   )Ú__func__rÌ   Ú__self__r½   r¾   Úweakself)rL   rÕ   rÙ   r9   r9   r:   rk   c  s   zWeakPopulateDict.__init__rQ   r   r-   c                 C  s   |   |  ¡ |¡ | |< }|S r?   )rÌ   rÙ   rÏ   r9   r9   r:   rÑ   h  s   zWeakPopulateDict.__missing__N)rÕ   rÖ   rÒ   rÓ   r9   r9   r9   r:   rÔ   ]  s    
rÔ   c                   @  sP   e Zd ZU dZdZded< ded< ded< 		dddd„Zddd„Z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 (``==``).
    )rf   Ú_data_appenderÚ_uniqueú&Union[Iterable[_T], Set[_T], List[_T]]rf   zCallable[[_T], None]rÛ   zDict[int, Literal[True]]rÜ   NÚviaúOptional[str]c                 C  s\   || _ i | _|rt||ƒ| _d S t|dƒrtd|ƒj| _d S t|dƒr,td|ƒj| _d S d S )Nr2   r¥   rÈ   zSet[_T])rf   rÜ   ÚgetattrrÛ   Úhasattrr   r2   rÈ   )rL   rf   rÞ   r9   r9   r:   rk   ƒ  s   

ÿzUniqueAppender.__init__rº   r"   r-   rS   c                 C  s.   t |ƒ}|| jvr|  |¡ d| j|< d S d S )NT)ÚidrÜ   rÛ   )rL   rº   Úid_r9   r9   r:   r2   ‘  s
   

þzUniqueAppender.appendrs   c                 C  rn   r?   )r0   rf   rK   r9   r9   r:   rv   —  rr   zUniqueAppender.__iter__r?   )rf   rÝ   rÞ   rß   )rº   r"   r-   rS   r¬   )	r\   r]   r^   r_   r®   r¯   rk   r2   rv   r9   r9   r9   r:   rÚ   v  s   
 ý
rÚ   Úargr   c                 C  s2   t | ƒdkrt| d tjƒrt| d ƒS td| ƒS )Nr   r   r+   )rp   rA   ÚtypesÚGeneratorTypert   r   )rä   r9   r9   r:   Úcoerce_generator_arg›  s   
rç   Úxr    úOptional[List[Any]]c                 C  s0   | d u r|S t | ƒs| gS t| tƒr| S t| ƒS r?   )r   rA   rt   )rè   r    r9   r9   r:   Úto_list¢  s   
rê   Úset_úContainer[Any]rÅ   úIterable[Any]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__)ry   Úi©rë   r9   r:   rÁ   ´  s   € z#has_intersection.<locals>.<genexpr>)Úany)rë   rÅ   r9   rð   r:   Úhas_intersection­  s   rò   c                 C  ó(   | d u rt ƒ S t| t ƒst t| ƒƒS | S r?   )r.   rA   rê   ©rè   r9   r9   r:   Úto_set·  ó
   
rõ   úSet[Any]c                 C  ró   r?   )Ú
column_setrA   rê   rô   r9   r9   r:   Úto_column_setÀ  rö   rù   c                 K  s*   |   ¡ } |r|  |¡ | jdi |¤Ž | S )z5Copy the given dict and update with the given values.Nr9   )rM   r›   )r<   Ú_newÚkwr9   r9   r:   Úupdate_copyÉ  s
   
rü   úIterable[_T]rs   c                 c  s:   � | 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.

    rv   N)rA   rX   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< 			
	d2d3dd„Zdd„ Zed4dd„ƒZ	ed5dd„ƒZ		d6d7dd„Z	d8dd„Z
d9d d!„Zd:d"d#„Zd;d%d&„Zd<d)d*„Zd=d,d-„Zed>d.d/„ƒZd?d0d1„ZdS )@Ú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_alertrd   Ú_counterÚ_mutexrm   r  Úfloatr  z.Optional[Callable[[LRUCache[_KT, _VT]], None]]r  éd   ç      à?NúOptional[Callable[..., None]]c                 C  s,   || _ || _|| _d| _t ¡ | _i | _d S )Nr   )r  r  r  r  Ú	threadingÚLockr  rd   )rL   r  r  r  r9   r9   r:   rk   ÷  s   

zLRUCache.__init__c                 C  s   |  j d7  _ | j S )Nr   )r  rK   r9   r9   r:   Ú_inc_counter  s   zLRUCache._inc_counterrQ   r$   r-   úOptional[_VT]c                 C  r�   r?   r9   r‰   r9   r9   r:   rž     rŸ   zLRUCache.getr    úUnion[_VT, _T]c                 C  r�   r?   r9   r¢   r9   r9   r:   rž     rŸ   úOptional[Union[_VT, _T]]c                 C  s0   | j  |¡}|d ur|  ¡ |d d< |d S |S ©Né   r   r   )rd   rž   r  )rL   rQ   r    rº   r9   r9   r:   rž     s
   r%   c                 C  s"   | j | }|  ¡ |d d< |d S r  )rd   r  )rL   rQ   rº   r9   r9   r:   rŠ     s   
zLRUCache.__getitem__úIterator[_KT]c                 C  rn   r?   )r0   rd   rK   r9   r9   r:   rv     rr   zLRUCache.__iter__c                 C  rn   r?   ro   rK   r9   r9   r:   rq      rr   zLRUCache.__len__úValuesView[_VT]c                 C  s   t  dd„ | j ¡ D ƒ¡S )Nc                 S  s   i | ]	\}}||d  “qS )r   r9   )ry   rz   rï   r9   r9   r:   Ú
<dictcomp>$  s    z#LRUCache.values.<locals>.<dictcomp>)Útypingr   rd   r¨   rK   r9   r9   r:   ru   #  rÀ   zLRUCache.valuesrR   rS   c                 C  s"   |||   ¡ gf| j|< |  ¡  d S r?   )r  rd   Ú_manage_sizerU   r9   r9   r:   rT   &  s   zLRUCache.__setitem__Ú_LRUCache__vc                 C  r‹   r?   rc   )rL   r  r9   r9   r:   rŒ   *  r�   zLRUCache.__delitem__c                 C  s   | j | j | j  S r?   )r  r  rK   r9   r9   r:   Úsize_threshold-  rW   zLRUCache.size_thresholdc              	   C  sÞ   | j  d¡sd S z`t| jƒ}t| ƒ| j| j| j  kra|r$d}|  | ¡ t| j 	¡ t
 d¡dd�}|| jd … D ]}z| j|d = W q8 tyK   Y q8w t| ƒ| j| j| j  ksW | j  ¡  d S W | j  ¡  d S | j  ¡  w )NFr  T)rQ   Úreverser   )r  Úacquirer•   r  rp   r  r  r³   rd   ru   ÚoperatorÚ
itemgetterr’   Úrelease)rL   r  Ú
by_counterrº   r9   r9   r:   r  1  s.   

ýþôðzLRUCache._manage_size)r  r  N)r  rm   r  r  r  r	  )rQ   r$   r-   r  )rQ   r$   r    r  r-   r  r?   )rQ   r$   r    r  r-   r  )rQ   r$   r-   r%   )r-   r  r«   )r-   r  r[   )r  r$   r-   rS   )r-   r  r­   )r\   r]   r^   r_   r®   r¯   rk   r  r   rž   rŠ   rv   rq   ru   rT   rŒ   Úpropertyr  r  r9   r9   r9   r:   r   à  s4   
 		üÿ






r   c                   @  ó   e Zd Zddd„ZdS )Ú_CreateFuncTyper-   r&   c                 C  r�   r?   r9   rK   r9   r9   r:   Ú__call__J  ó    z_CreateFuncType.__call__N)r-   r&   ©r\   r]   r^   r"  r9   r9   r9   r:   r!  I  ó    r!  c                   @  r   )Ú_ScopeFuncTyper-   r   c                 C  r�   r?   r9   rK   r9   r9   r:   r"  N  r#  z_ScopeFuncType.__call__NrZ   r$  r9   r9   r9   r:   r&  M  r%  r&  c                   @  s`   e Zd ZU dZdZded< ded< ded< ddd„Zddd„Zddd„Zddd„Z	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]úCallable[[], Any]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(  )rL   r)  r*  r9   r9   r:   rk   f  s   
zScopedRegistry.__init__r-   r"   c                 C  s:   |   ¡ }z| j| W S  ty   | j ||  ¡ ¡ Y S w r?   )r*  r+  r’   Ú
setdefaultr)  r‰   r9   r9   r:   r"  w  s   ÿzScopedRegistry.__call__r•   c                 C  s   |   ¡ | jv S )z9Return True if an object is present in the current scope.)r*  r+  rK   r9   r9   r:   Úhas~  s   zScopedRegistry.hasr†   rS   c                 C  s   || j |  ¡ < dS )z$Set the value for the current scope.N)r+  r*  ©rL   r†   r9   r9   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)r+  r*  r’   rK   r9   r9   r:   rª   ˆ  s
   ÿzScopedRegistry.clearN)r)  r,  r*  r-  ©r-   r"   ©r-   r•   ©r†   r"   r-   rS   r­   )r\   r]   r^   r_   r®   r¯   rk   r"  r/  r.   rª   r9   r9   r9   r:   r'  Q  s   
 



r'  c                   @  sB   e Zd ZdZddd„Zddd	„Zddd„Zddd„Z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+  )rL   r)  r9   r9   r:   rk   —  s   zThreadLocalRegistry.__init__r-   r"   c                 C  s2   z| j jW S  ty   |  ¡  }| j _| Y S w r?   )r+  rR   r“   r)  )rL   rÐ   r9   r9   r:   r"  ›  s   
þzThreadLocalRegistry.__call__r•   c                 C  s   t | jdƒS )NrR   )rá   r+  rK   r9   r9   r:   r/  ¢  r�   zThreadLocalRegistry.hasr†   rS   c                 C  s   || j _d S r?   )r+  rR   r0  r9   r9   r:   r.   ¥  r�   zThreadLocalRegistry.setc                 C  s"   z| j `W d S  ty   Y d S w r?   )r+  rR   r“   rK   r9   r9   r:   rª   ¨  s
   ÿzThreadLocalRegistry.clearN)r)  r,  r1  r2  r3  r­   )	r\   r]   r^   r_   rk   r"  r/  r.   rª   r9   r9   r9   r:   r4  ‘  s    



r4  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   
€r9  )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-   r•   )rè   r   r-   r÷   )rè   rý   r-   rs   )Wr_   Ú
__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½   Ú_has_cyr   r   r   r   ÚTYPE_CHECKINGÚ_py_collectionsr   r   r   r   r    r!   Ú$sqlalchemy.cyextension.immutabledictÚ"sqlalchemy.cyextension.collectionsr"   r$   r%   r&   Ú	frozensetr(   r¯   r)   r;   rC   r@   rD   r`   ra   rb   r±   r™   r´   rN   r²   Úsort_dictionaryrµ   rÄ   rË   rÔ   r.   rø   Úcolumn_dictÚordered_column_setrÚ   rç   rê   rò   rõ   rù   rü   rþ   ÚMutableMappingr   r!  r&  r'  r4  r9  r9   r9   r9   r:   Ú<module>   s¦   


8	W


"	
%


	
	

i@