o
    ?ÊÆhÉN  ã                   @  s  U d Z ddlm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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/e0ƒ Z1d(e2d)< e0dgƒZ3d(e2d*< dpd/d0„Z4dqd4d5„Z5e$ƒ Z6d6e2d7< G d8d9„ d9e'e-e.f ƒZ7ed:e
d"�Z8ed;e
d"�Z9G d<d=„ d=ee, ƒZ:G d>d?„ d?e:e, ƒZ;G d@dA„ dAe&e:e, ƒZ<drdBdC„Z=e>Z?e=Z@G dDdE„ dEee, ƒZAG dFdG„ dGe%ƒZBG dHdI„ dIee-e.f ƒZCG dJdK„ dKee-e.f ƒZDeEZFe>ZGe(ZHG dLdM„ dMee, ƒZIdsdPdQ„ZJdrdtdUdV„ZKdWdX„ ZLdYdZ„ ZMdud\d]„ZNdrd^d_„ZOdvdbdc„ZPG ddde„ dee	jQe-e.f ƒZRG dfdg„ dge!e/ ƒZSG dhdi„ die!ƒZTG djdk„ dkee, ƒZUG dldm„ dmeUe, ƒZVdndo„ ZWdS )wzCollection classes and helpers.é    )ÚannotationsN)ÚAny)ÚCallable)Úcast)ÚDict)Ú	FrozenSet)ÚGeneric)ÚIterable)ÚIterator)ÚList)ÚMapping)ÚNoReturn)ÚOptional)Úoverload)ÚSequence)ÚSet)ÚTuple)ÚTypeVar)ÚUnion)Ú
ValuesViewé   )ÚHAS_CYEXTENSION)Ú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© r7   úi/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/sqlalchemy/util/_collections.pyÚmerge_lists_w_orderingK   s   #


ôr9   ÚdúMapping[_KT, _VT]úimmutabledict[_KT, _VT]c                 C  s   | st S t| tƒr| S t| ƒS ©N)Ú
EMPTY_DICTÚ
isinstancer   ©r:   r7   r7   r8   Úcoerce_to_immutabledictƒ   s
   
rA   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__)ÚclsrC   Únewr7   r7   r8   rE   ’   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©Úselfr7   r7   r8   Úcopy–   s   ÿzFacadeDict.copyc                 C  s   t t| ƒffS r=   )rB   ÚdictrI   r7   r7   r8   Ú
__reduce__œ   ó   zFacadeDict.__reduce__Úkeyr"   Úvaluer#   ÚNonec                 C  s   t  | ||¡ dS )z,insert an item into the dictionary directly.N)rL   Ú__setitem__©rJ   rO   rP   r7   r7   r8   Ú_insert_itemŸ   ó   zFacadeDict._insert_itemÚstrc                 C  s   dt  | ¡ S )NzFacadeDict(%s))rL   Ú__repr__rI   r7   r7   r8   rW   £   rN   zFacadeDict.__repr__N)rC   r   r+   rD   )r+   r   ©r+   r   ©rO   r"   rP   r#   r+   rQ   )r+   rV   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rE   rK   rM   rT   rW   r7   r7   r7   r8   rB   �   s    



rB   Ú_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]rb   Údatac                 C  s   t  | d|¡ d S ©Nrb   ©ÚobjectÚ__setattr__)rJ   rd   r7   r7   r8   Ú__init__³   ó   zProperties.__init__r+   Úintc                 C  ó
   t | jƒS r=   ©Úlenrb   rI   r7   r7   r8   Ú__len__¶   ó   
zProperties.__len__úIterator[_T]c                 C  s   t t| j ¡ ƒƒS r=   )r.   Úlistrb   ÚvaluesrI   r7   r7   r8   Ú__iter__¹   rj   zProperties.__iter__ú	List[str]c                   s   t tƒ ƒdd„ | j ¡ D ƒ S )Nc                 S  s   g | ]}t |ƒ‘qS r7   )rV   ©Ú.0Úkr7   r7   r8   Ú
<listcomp>½   s    z&Properties.__dir__.<locals>.<listcomp>)ÚdirÚsuperrb   ÚkeysrI   ©Ú	__class__r7   r8   Ú__dir__¼   s   zProperties.__dir__r5   úProperties[_F]úList[Union[_T, _F]]c                 C  s   t | ƒt |ƒ S r=   )rr   )rJ   r5   r7   r7   r8   Ú__add__¿   ó   zProperties.__add__rO   rV   Úobjr    rQ   c                 C  ó   || j |< d S r=   ra   ©rJ   rO   r„   r7   r7   r8   rR   Â   rN   zProperties.__setitem__c                 C  s
   | j | S r=   ra   ©rJ   rO   r7   r7   r8   Ú__getitem__Å   rp   zProperties.__getitem__c                 C  ó   | j |= d S r=   ra   r‡   r7   r7   r8   Ú__delitem__È   ó   zProperties.__delitem__c                 C  r…   r=   ra   r†   r7   r7   r8   rh   Ë   rN   zProperties.__setattr__úDict[str, Any]c                 C  s
   d| j iS re   ra   rI   r7   r7   r8   Ú__getstate__Î   rp   zProperties.__getstate__Ústatec                 C  s   t  | d|d ¡ d S re   rf   )rJ   rŽ   r7   r7   r8   Ú__setstate__Ñ   s   zProperties.__setstate__c                 C  s$   z| j | W S  ty   t|ƒ‚w r=   )rb   ÚKeyErrorÚAttributeErrorr‡   r7   r7   r8   Ú__getattr__Ô   s
   ÿzProperties.__getattr__Úboolc                 C  ó
   || j v S r=   ra   r‡   r7   r7   r8   Ú__contains__Ú   rp   zProperties.__contains__úReadOnlyProperties[_T]c                 C  rl   )z8Return an immutable proxy for this :class:`.Properties`.)ÚReadOnlyPropertiesrb   rI   r7   r7   r8   Úas_readonlyÝ   s   
zProperties.as_readonlyrP   c                 C  s   | j  |¡ d S r=   )rb   Úupdate)rJ   rP   r7   r7   r8   r™   â   rƒ   zProperties.updateúOptional[_T]c                 C  ó   d S r=   r7   r‡   r7   r7   r8   Úgetå   ó   zProperties.getÚdefaultúUnion[_DT, _T]c                 C  r›   r=   r7   ©rJ   rO   rž   r7   r7   r8   rœ   é   r�   NúOptional[Union[_DT, _T]]úOptional[Union[_T, _DT]]c                 C  s   || v r| | S |S r=   r7   r    r7   r7   r8   rœ   í   s   c                 C  rl   r=   )rr   rb   rI   r7   r7   r8   r|   õ   rp   zProperties.keysúList[_T]c                 C  ó   t | j ¡ ƒS r=   )rr   rb   rs   rI   r7   r7   r8   rs   ø   rN   zProperties.valuesúList[Tuple[str, _T]]c                 C  r¤   r=   )rr   rb   ÚitemsrI   r7   r7   r8   r¦   û   rN   zProperties.itemsc                 C  r”   r=   ra   r‡   r7   r7   r8   Úhas_keyþ   rp   zProperties.has_keyc                 C  s   | j  ¡  d S r=   )rb   ÚclearrI   r7   r7   r8   r¨     rN   zProperties.clear)rd   rc   ©r+   rk   ©r+   rq   )r+   ru   )r5   r€   r+   r�   )rO   rV   r„   r    r+   rQ   )rO   rV   r+   r    )rO   rV   r+   rQ   )r+   rŒ   )rŽ   rŒ   r+   rQ   )rO   rV   r+   r“   )r+   r–   )rP   rc   r+   rQ   )rO   rV   r+   rš   )rO   rV   rž   rŸ   r+   rŸ   r=   )rO   rV   rž   r¡   r+   r¢   )r+   r£   )r+   r¥   ©r+   rQ   )rZ   r[   r\   r]   Ú	__slots__Ú__annotations__ri   ro   rt   r   r‚   rR   rˆ   rŠ   rh   r�   r�   r’   r•   r˜   r™   r   rœ   r|   rs   r¦   r§   r¨   Ú__classcell__r7   r7   r}   r8   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.r7   c                 C  s   t  | tƒ ¡ d S r=   )r`   ri   ÚOrderedDictrI   r7   r7   r8   ri     rj   zOrderedProperties.__init__N)rZ   r[   r\   r]   r¬   ri   r7   r7   r7   r8   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.r7   N)rZ   r[   r\   r]   r¬   r7   r7   r7   r8   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 r7   r7   rv   r@   r7   r8   ry     s    z,_ordered_dictionary_sort.<locals>.<listcomp>)rO   N)Úsortedr¨   r™   )r:   rO   r¦   r7   r@   r8   Ú_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 )ÚWeakSequencer7   Ú_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ÚselfrefrJ   r7   r7   r8   Ú_remove'  s   ÿz&WeakSequence.__init__.<locals>._removec                   s   g | ]}t  |ˆ ¡‘qS r7   )ÚweakrefÚref)rw   r6   ©rº   r7   r8   ry   -  s    ÿz)WeakSequence.__init__.<locals>.<listcomp>)r»   r¼   rº   r¶   )rJ   r´   r7   r½   r8   ri   $  s
   
ÿzWeakSequence.__init__c                 C  s   | j  t || j¡¡ d S r=   )r¶   r0   r»   r¼   rº   )rJ   r¸   r7   r7   r8   r0   1  ó   zWeakSequence.appendc                 C  rl   r=   )rn   r¶   rI   r7   r7   r8   ro   4  rp   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=   r7   )rw   r„   r7   r7   r8   Ú	<genexpr>8  s   € ÿz(WeakSequence.__iter__.<locals>.<genexpr>c                 s  s   � | ]}|ƒ V  qd S r=   r7   )rw   r¼   r7   r7   r8   r¿   9  s   € )r¶   rI   r7   r7   r8   rt   7  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)rJ   Úindexr„   r7   r7   r8   rˆ   <  s   ýÿzWeakSequence.__getitem__N)r7   )r´   rµ   )rZ   r[   r\   ri   r0   ro   rt   rˆ   r7   r7   r7   r8   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   ri   r°   Ú_membersÚadd)rJ   rÃ   Úor7   r7   r8   ri   F  s   
þzOrderedIdentitySet.__init__r=   )rÃ   rÄ   )rZ   r[   r\   ri   r7   r7   r7   r8   rÂ   E  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Ê   )rJ   rÊ   r7   r7   r8   ri   V  rp   zPopulateDict.__init__rO   r   r+   c                 C  s   |   |¡ | |< }|S r=   rÌ   ©rJ   rO   Úvalr7   r7   r8   Ú__missing__Y  s   zPopulateDict.__missing__N)rÊ   rË   ©rO   r   r+   r   ©rZ   r[   r\   r]   ri   rÏ   r7   r7   r7   r8   rÉ   N  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)rJ   rÓ   r×   r7   r7   r8   ri   d  s   zWeakPopulateDict.__init__rO   r   r+   c                 C  s   |   |  ¡ |¡ | |< }|S r=   )rÊ   r×   rÍ   r7   r7   r8   rÏ   i  s   zWeakPopulateDict.__missing__N)rÓ   rÔ   rÐ   rÑ   r7   r7   r7   r8   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 (``==``).
    )rd   Ú_data_appenderÚ_uniqueú&Union[Iterable[_T], Set[_T], List[_T]]rd   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 )Nr0   r£   rÆ   zSet[_T])rd   rÚ   ÚgetattrrÙ   Úhasattrr   r0   rÆ   )rJ   rd   rÜ   r7   r7   r8   ri   „  s   

ÿzUniqueAppender.__init__r¸   r    r+   rQ   c                 C  s.   t |ƒ}|| jvr|  |¡ d| j|< d S d S )NT)ÚidrÚ   rÙ   )rJ   r¸   Úid_r7   r7   r8   r0   ’  s
   

þzUniqueAppender.appendrq   c                 C  rl   r=   )r.   rd   rI   r7   r7   r8   rt   ˜  rp   zUniqueAppender.__iter__r=   )rd   rÛ   rÜ   rÝ   )r¸   r    r+   rQ   rª   )	rZ   r[   r\   r]   r¬   r­   ri   r0   rt   r7   r7   r7   r8   rØ   w  s   
 ý
rØ   Úargr   c                 C  s2   t | ƒdkrt| d tjƒrt| d ƒS td| ƒS )Nr   r   r)   )rn   r?   ÚtypesÚGeneratorTyperr   r   )râ   r7   r7   r8   Úcoerce_generator_argœ  s   
rå   Úxrž   úOptional[List[Any]]c                 C  sB   | d u r|S t | tjƒrt | ttfƒr| gS t | tƒr| S t| ƒS r=   )r?   Úcollections_abcr	   rV   Úbytesrr   )ræ   rž   r7   r7   r8   Úto_list£  s   ÿ
rê   c                 C  s   t |  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                 S  s   g | ]}|j r|‘qS r7   )Ú__hash__)rw   Úir7   r7   r8   ry   ¸  s    z$has_intersection.<locals>.<listcomp>)r“   r-   )Úset_rÃ   r7   r7   r8   Úhas_intersection°  s   rî   c                 C  ó(   | d u rt ƒ S t| t ƒst t| ƒƒS | S r=   )r,   r?   rê   ©ræ   r7   r7   r8   Úto_set»  ó
   
rñ   úSet[Any]c                 C  rï   r=   )Ú
column_setr?   rê   rð   r7   r7   r8   Úto_column_setÄ  rò   rõ   c                 K  s*   |   ¡ } |r|  |¡ | jdi |¤Ž | S )z5Copy the given dict and update with the given values.Nr7   )rK   r™   )r:   Ú_newÚkwr7   r7   r8   Úupdate_copyÍ  s
   
rø   úIterable[_T]rq   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.

    rt   N)r?   rV   rß   Úflatten_iterator)ræ   Úelemr7   r7   r8   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_alertrb   Ú_counterÚ_mutexrk   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  rb   )rJ   rý   rþ   rÿ   r7   r7   r8   ri   û  s   

zLRUCache.__init__c                 C  s   |  j d7  _ | j S )Nr   )r   rI   r7   r7   r8   Ú_inc_counter  s   zLRUCache._inc_counterrO   r"   r+   úOptional[_VT]c                 C  r›   r=   r7   r‡   r7   r7   r8   rœ     r�   zLRUCache.getrž   úUnion[_VT, _T]c                 C  r›   r=   r7   r    r7   r7   r8   rœ     r�   úOptional[Union[_VT, _T]]c                 C  s0   | j  |¡}|d ur|  ¡ |d d< |d S |S ©Né   r   r   )rb   rœ   r  )rJ   rO   rž   r¸   r7   r7   r8   rœ     s
   r#   c                 C  s"   | j | }|  ¡ |d d< |d S r  )rb   r  )rJ   rO   r¸   r7   r7   r8   rˆ     s   
zLRUCache.__getitem__úIterator[_KT]c                 C  rl   r=   )r.   rb   rI   r7   r7   r8   rt   #  rp   zLRUCache.__iter__c                 C  rl   r=   rm   rI   r7   r7   r8   ro   &  rp   zLRUCache.__len__úValuesView[_VT]c                 C  s   t  dd„ | j ¡ D ƒ¡S )Nc                 S  s   i | ]	\}}||d  “qS )r   r7   )rw   rx   rì   r7   r7   r8   Ú
<dictcomp>*  s    z#LRUCache.values.<locals>.<dictcomp>)Útypingr   rb   r¦   rI   r7   r7   r8   rs   )  r¾   zLRUCache.valuesrP   rQ   c                 C  s"   |||   ¡ gf| j|< |  ¡  d S r=   )r  rb   Ú_manage_sizerS   r7   r7   r8   rR   ,  s   zLRUCache.__setitem__Ú_LRUCache__vc                 C  r‰   r=   ra   )rJ   r  r7   r7   r8   rŠ   0  r‹   zLRUCache.__delitem__c                 C  s   | j | j | j  S r=   )rý   rþ   rI   r7   r7   r8   Úsize_threshold3  rU   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)rO   Úreverser   )r  Úacquirer“   rÿ   rn   rý   rþ   r±   rb   rs   ÚoperatorÚ
itemgetterr�   Úrelease)rJ   rÿ   Ú
by_counterr¸   r7   r7   r8   r  7  s.   

ýþôðzLRUCache._manage_size)r  r  N)rý   rk   rþ   r  rÿ   r  )rO   r"   r+   r	  )rO   r"   rž   r
  r+   r
  r=   )rO   r"   rž   r  r+   r  )rO   r"   r+   r#   )r+   r  r©   )r+   r  rY   )r  r"   r+   rQ   )r+   r  r«   )rZ   r[   r\   r]   r¬   r­   ri   r  r   rœ   rˆ   rt   ro   rs   rR   rŠ   Úpropertyr  r  r7   r7   r7   r8   rü   ä  s4   
 		üÿ






rü   c                   @  ó   e Zd Zddd„ZdS )Ú_CreateFuncTyper+   r$   c                 C  r›   r=   r7   rI   r7   r7   r8   Ú__call__P  ó   z_CreateFuncType.__call__N)r+   r$   ©rZ   r[   r\   r  r7   r7   r7   r8   r  O  ó    r  c                   @  r  )Ú_ScopeFuncTyper+   r   c                 C  r›   r=   r7   rI   r7   r7   r8   r  U  r  z_ScopeFuncType.__call__NrX   r   r7   r7   r7   r8   r"  T  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$  )rJ   r%  r&  r7   r7   r8   ri   n  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‡   r7   r7   r8   r    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   r7   r7   r8   Úhas†  s   zScopedRegistry.hasr„   rQ   c                 C  s   || j |  ¡ < dS )z$Set the value for the current scope.N)r'  r&  ©rJ   r„   r7   r7   r8   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�   rI   r7   r7   r8   r¨   �  s
   ÿzScopedRegistry.clearN)r%  r(  r&  r)  ©r+   r    ©r+   r“   ©r„   r    r+   rQ   r«   )rZ   r[   r\   r]   r¬   r­   ri   r  r+  r,   r¨   r7   r7   r7   r8   r#  Y  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'  )rJ   r%  r7   r7   r8   ri   Ÿ  s   zThreadLocalRegistry.__init__r+   r    c                 C  s2   z| j jW S  ty   |  ¡  }| j _| Y S w r=   )r'  rP   r‘   r%  )rJ   rÎ   r7   r7   r8   r  £  s   
þzThreadLocalRegistry.__call__r“   c                 C  s   t | jdƒS )NrP   )rß   r'  rI   r7   r7   r8   r+  ª  r‹   zThreadLocalRegistry.hasr„   rQ   c                 C  s   || j _d S r=   )r'  rP   r,  r7   r7   r8   r,   ­  r‹   zThreadLocalRegistry.setc                 C  s"   z| j `W d S  ty   Y d S w r=   )r'  rP   r‘   rI   r7   r7   r8   r¨   °  s
   ÿzThreadLocalRegistry.clearN)r%  r(  r-  r.  r/  r«   )	rZ   r[   r\   r]   ri   r  r+  r,   r¨   r7   r7   r7   r8   r0  ™  s    



r0  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   TFr7   )ÚsequenceÚtargetÚcr¸   r7   r7   r8   Ú	has_dupes·  s   
€r5  )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+   rq   )Xr]   Ú
__future__r   Úcollections.abcÚabcrè   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   ÚTYPE_CHECKINGÚ_py_collectionsr   r   r   r   r   r   Ú$sqlalchemy.cyextension.immutabledictÚ"sqlalchemy.cyextension.collectionsr    r"   r#   r$   Ú	frozensetr&   r­   r'   r9   rA   r>   rB   r^   r_   r`   r¯   r—   r²   rL   r°   Úsort_dictionaryr³   rÂ   rÉ   rÒ   r,   rô   Úcolumn_dictÚordered_column_setrØ   rå   rê   rî   rñ   rõ   rø   rú   ÚMutableMappingrü   r  r"  r#  r0  r5  r7   r7   r7   r8   Ú<module>   s¤   


8	Y

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

k@