HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/util/__pycache__/_collections.cpython-310.pyc
o

���gnN�@sUdZddlmZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlm Z ej!s�es�ddl"m#Z#ddl"m$Z$ddl"m%Z%dd l"m&Z&dd!l"m'Z'dd"l"m(Z(n$ddl)m%Z%dd l)m&Z&ddl)m#Z#ddl*m$Z$dd!l*m'Z'dd"l*m(Z(ed#ed$�Z+ed%ed$�Z,ed&ed$�Z-ed'd(d)�Z.e/�Z0d*e1d+<e/dg�Z2d*e1d,<dwd1d2�Z3dxd6d7�Z4e#�Z5d8e1d9<Gd:d;�d;e&e,e-f�Z6ed<ed$�Z7ed=ed$�Z8Gd>d?�d?e
e+�Z9Gd@dA�dAe9e+�Z:GdBdC�dCe%e9e+�Z;dydDdE�Z<e=Z>e<Z?GdFdG�dGee+�Z@GdHdI�dIe$�ZAGdJdK�dKee,e-f�ZBGdLdM�dMee,e-f�ZCeDZEe=ZFe'ZGGdNdO�dOe
e+�ZHdzdRdS�ZIdyd{dWdX�ZJd|d^d_�ZKd`da�ZLd}dcdd�ZMdydedf�ZNd~didj�ZOGdkdl�dlejPe,e-f�ZQGdmdn�dne e.�ZRGdodp�dpe �ZSGdqdr�dre
e+�ZTGdsdt�dteTe+�ZUdudv�ZVdS)zCollection 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)�	covariantzFrozenSet[Any]�	EMPTY_SET�NONE_SET�a�	List[Any]�b�returncCslt|��|�}g}t|�t|�}}	|D]}||vr'|�|�||}}n|�|�q|�|�	|Sq)afmerge 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�G/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/_collections.py�merge_lists_w_orderingLs#


�r;�d�Mapping[_KT, _VT]�immutabledict[_KT, _VT]cCs|stSt|t�r|St|�S�N)�
EMPTY_DICT�
isinstancer�r<r9r9r:�coerce_to_immutabledict�s

rCzimmutabledict[Any, Any]r@c@sBeZdZdZddd�Zdd	d
�Zddd�Zddd�Zddd�ZdS)�
FacadeDictz*A dictionary that is not publicly mutable.�argsrr-�FacadeDict[Any, Any]cGst�|�}|Sr?)r�__new__)�clsrE�newr9r9r:rG�s
zFacadeDict.__new__rcCstd��)Nz\an immutabledict shouldn't need to be copied.  use dict(d) if you need a mutable dictionary.)�NotImplementedError��selfr9r9r:�copy�s�zFacadeDict.copycCstt|�ffSr?)rD�dictrKr9r9r:�
__reduce__��zFacadeDict.__reduce__�keyr$�valuer%�NonecCst�|||�dS)z,insert an item into the dictionary directly.N)rN�__setitem__�rLrQrRr9r9r:�_insert_item��zFacadeDict._insert_item�strcCsdt�|�S)NzFacadeDict(%s))rN�__repr__rKr9r9r:rY�rPzFacadeDict.__repr__N)rErr-rF)r-r�r-r�rQr$rRr%r-rS)r-rX)	�__name__�
__module__�__qualname__�__doc__rGrMrOrVrYr9r9r9r:rD�s



rD�_DT�_FcseZdZUdZdZded<dKdd�ZdLd
d�ZdMd
d�ZdN�fdd�Z	dOdd�Z
dPdd�ZdQdd�ZdRd d!�Z
dPd"d#�ZdSd%d&�ZdTd(d)�ZdQd*d+�ZdUd-d.�ZdVd0d1�ZdWd3d4�ZedXd6d7��ZedYd:d7��Z	;dZd[d>d7�ZdNd?d@�Zd\dBdC�Zd]dEdF�ZdUdGdH�Zd^dIdJ�Z�ZS)_�
Propertiesz8Provide a __getattr__/__setattr__ interface over a dict.��_data�
Dict[str, _T]rd�datacCst�|d|�dS�Nrd��object�__setattr__)rLrfr9r9r:�__init__��zProperties.__init__r-�intcC�
t|j�Sr?��lenrdrKr9r9r:�__len__��
zProperties.__len__�Iterator[_T]cCstt|j����Sr?)r0�listrd�valuesrKr9r9r:�__iter__�rlzProperties.__iter__�	List[str]cstt��dd�|j��D�S)NcSsg|]}t|��qSr9)rX��.0�kr9r9r:�
<listcomp>�sz&Properties.__dir__.<locals>.<listcomp>)�dir�superrd�keysrK��	__class__r9r:�__dir__�szProperties.__dir__r7�Properties[_F]�List[Union[_T, _F]]cCst|�t|�Sr?)rt)rLr7r9r9r:�__add__��zProperties.__add__rQrX�objr"rScC�||j|<dSr?rc�rLrQr�r9r9r:rT�rPzProperties.__setitem__cCs
|j|Sr?rc�rLrQr9r9r:�__getitem__�rrzProperties.__getitem__cC�|j|=dSr?rcr�r9r9r:�__delitem__��zProperties.__delitem__cCr�r?rcr�r9r9r:rj�rPzProperties.__setattr__�Dict[str, Any]cCs
d|jiSrgrcrKr9r9r:�__getstate__�rrzProperties.__getstate__�statecCst�|d|d�dSrgrh)rLr�r9r9r:�__setstate__�szProperties.__setstate__cCs$z|j|WStyt|��wr?)rd�KeyError�AttributeErrorr�r9r9r:�__getattr__�s
�zProperties.__getattr__�boolcC�
||jvSr?rcr�r9r9r:�__contains__�rrzProperties.__contains__�ReadOnlyProperties[_T]cCrn)z8Return an immutable proxy for this :class:`.Properties`.)�ReadOnlyPropertiesrdrKr9r9r:�as_readonly�s
zProperties.as_readonlyrRcCs|j�|�dSr?)rd�update)rLrRr9r9r:r��r�zProperties.update�Optional[_T]cC�dSr?r9r�r9r9r:�get��zProperties.get�default�Union[_DT, _T]cCr�r?r9�rLrQr�r9r9r:r��r�N�Optional[Union[_DT, _T]]�Optional[Union[_T, _DT]]cCs||vr||S|Sr?r9r�r9r9r:r��scCrnr?)rtrdrKr9r9r:r~�rrzProperties.keys�List[_T]cC�t|j���Sr?)rtrdrurKr9r9r:ru�rPzProperties.values�List[Tuple[str, _T]]cCr�r?)rtrd�itemsrKr9r9r:r��rPzProperties.itemscCr�r?rcr�r9r9r:�has_key�rrzProperties.has_keycCs|j��dSr?)rd�clearrKr9r9r:r�rPzProperties.clear)rfre�r-rm�r-rs)r-rw)r7r�r-r�)rQrXr�r"r-rS)rQrXr-r")rQrXr-rS)r-r�)r�r�r-rS)rQrXr-r�)r-r�)rRrer-rS)rQrXr-r�)rQrXr�r�r-r�r?)rQrXr�r�r-r�)r-r�)r-r��r-rS)r\r]r^r_�	__slots__�__annotations__rkrqrvr�r�rTr�r�rjr�r�r�r�r�r�rr�r~rur�r�r��
__classcell__r9r9rr:rb�s<














�



rbc@seZdZdZdZdd�ZdS)�OrderedPropertieszUProvide a __getattr__/__setattr__ interface with an OrderedDict
    as backing store.r9cCst�|t��dSr?)rbrk�OrderedDictrKr9r9r:rk
rlzOrderedProperties.__init__N)r\r]r^r_r�rkr9r9r9r:r�sr�c@seZdZdZdZdS)r�zDProvide immutable dict/object attribute to an underlying dictionary.r9N)r\r]r^r_r�r9r9r9r:r�sr�cs0�fdd�t�|d�D�}�����|�dS)zSort an OrderedDict in-place.csg|]}|�|f�qSr9r9rxrBr9r:r{sz,_ordered_dictionary_sort.<locals>.<listcomp>)rQN)�sortedr�r�)r<rQr�r9rBr:�_ordered_dictionary_sortsr�c@s8eZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�WeakSequencer9�_WeakSequence__elements�Sequence[_T]cs0t�|�fdd���|_�fdd�|D�|_dS)NcSs"|�}|dur|j�|�dSdSr?)�_storage�remove)�item�selfrefrLr9r9r:�_remove&s�z&WeakSequence.__init__.<locals>._removecsg|]}t�|���qSr9)�weakref�ref)ryr8�r�r9r:r{,s�z)WeakSequence.__init__.<locals>.<listcomp>)r�r�r�r�)rLr�r9r�r:rk#s

�zWeakSequence.__init__cCs|j�t�||j��dSr?)r�r2r�r�r�)rLr�r9r9r:r20�zWeakSequence.appendcCrnr?)rpr�rKr9r9r:rq3rrzWeakSequence.__len__cCsdd�dd�|jD�D�S)Ncss�|]	}|dur|VqdSr?r9)ryr�r9r9r:�	<genexpr>7s��z(WeakSequence.__iter__.<locals>.<genexpr>css�|]}|�VqdSr?r9)ryr�r9r9r:r�8s�)r�rKr9r9r:rv6s�zWeakSequence.__iter__cCs.z	|j|}W|�Stytd|��w)NzIndex %s out of range)r�r��
IndexError)rL�indexr�r9r9r:r�;s��zWeakSequence.__getitem__N)r9)r�r�)r\r]r^rkr2rqrvr�r9r9r9r:r�"s
r�c@seZdZdddd�ZdS)�OrderedIdentitySetN�iterable�Optional[Iterable[Any]]cCs2t�|�t�|_|r|D]	}|�|�q
dSdSr?)rrkr��_members�add)rLr��or9r9r:rkEs
�zOrderedIdentitySet.__init__r?)r�r�)r\r]r^rkr9r9r9r:r�Dsr�c@�$eZdZdZddd�Zd
d	d
�ZdS)�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]cCs
||_dSr?�r�)rLr�r9r9r:rkUrrzPopulateDict.__init__rQrr-cCs|�|�||<}|Sr?r��rLrQ�valr9r9r:�__missing__XszPopulateDict.__missing__N)r�r��rQrr-r�r\r]r^r_rkr�r9r9r9r:r�Ms
r�c@r�)�WeakPopulateDictzaLike PopulateDict, but assumes a self + a method and does not create
    a reference cycle.

    �creator_method�types.MethodTypecCs|j|_|j}t�|�|_dSr?)�__func__r��__self__r�r��weakself)rLr�r�r9r9r:rkcszWeakPopulateDict.__init__rQrr-cCs|�|��|�||<}|Sr?)r�r�r�r9r9r:r�hszWeakPopulateDict.__missing__N)r�r�r�r�r9r9r9r:r�]s
r�c@sPeZdZUdZdZded<ded<ded<		dddd
�Zddd�Zddd�Zd	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]]rfzCallable[[_T], None]r�zDict[int, Literal[True]]r�N�via�
Optional[str]cCs\||_i|_|rt||�|_dSt|d�rtd|�j|_dSt|d�r,td|�j|_dSdS)Nr2r�r�zSet[_T])rfr��getattrr��hasattrrr2r�)rLrfr�r9r9r:rk�s

�zUniqueAppender.__init__r�r"r-rScCs.t|�}||jvr|�|�d|j|<dSdS)NT)�idr�r�)rLr��id_r9r9r:r2�s


�zUniqueAppender.appendrscCrnr?)r0rfrKr9r9r:rv�rrzUniqueAppender.__iter__r?)rfr�r�r�)r�r"r-rSr�)	r\r]r^r_r�r�rkr2rvr9r9r9r:r�vs
�
r��argrcCs2t|�dkrt|dtj�rt|d�Std|�S)Nrrr+)rprA�types�
GeneratorTypertr)r�r9r9r:�coerce_generator_arg�s
r��xr��Optional[List[Any]]cCs0|dur|St|�s
|gSt|t�r|St|�Sr?)rrArt)r�r�r9r9r:�to_list�s
r��set_�Container[Any]r��
Iterable[Any]r�cst�fdd�|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.

    c3s�|]
}|jr|�vVqdSr?)�__hash__)ry�i�r�r9r:r��s�z#has_intersection.<locals>.<genexpr>)�any)r�r�r9r�r:�has_intersection�sr�cC�(|durt�St|t�stt|��S|Sr?)r.rAr��r�r9r9r:�to_set��

r��Set[Any]cCr�r?)�
column_setrAr�r�r9r9r:�
to_column_set�r�r�cKs*|��}|r|�|�|jdi|��|S)z5Copy the given dict and update with the given values.Nr9)rMr�)r<�_new�kwr9r9r:�update_copy�s

r��Iterable[_T]rsccs:�|D]}t|t�st|d�rt|�EdHq|VqdS)z�Given an iterator of which further sub-elements may also be
    iterators, flatten the sub-elements into a single iterator.

    rvN)rArXr��flatten_iterator)r��elemr9r9r:r��s��r�c@s�eZdZUdZdZded<ded<ded<			
	d2d3d
d�Zdd�Zed4dd��Z	ed5dd��Z		d6d7dd�Z	d8dd�Z
d9d d!�Zd:d"d#�Zd;d%d&�Z
d<d)d*�Zd=d,d-�Zed>d.d/��Zd?d0d1�ZdS)@�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�_mutexrmr�floatrz.Optional[Callable[[LRUCache[_KT, _VT]], None]]r�d��?N�Optional[Callable[..., None]]cCs,||_||_||_d|_t��|_i|_dS)Nr)rrrr�	threading�Lockrrd)rLrrrr9r9r:rk�s

zLRUCache.__init__cCs|jd7_|jS)Nr)rrKr9r9r:�_inc_counterszLRUCache._inc_counterrQr$r-�
Optional[_VT]cCr�r?r9r�r9r9r:r�r�zLRUCache.getr��Union[_VT, _T]cCr�r?r9r�r9r9r:r�r��Optional[Union[_VT, _T]]cCs0|j�|�}|dur|��|dd<|dS|S�N�rr)rdr�r)rLrQr�r�r9r9r:r�s
r%cCs"|j|}|��|dd<|dSr)rdr)rLrQr�r9r9r:r�s
zLRUCache.__getitem__�
Iterator[_KT]cCrnr?)r0rdrKr9r9r:rvrrzLRUCache.__iter__cCrnr?rorKr9r9r:rq rrzLRUCache.__len__�ValuesView[_VT]cCst�dd�|j��D��S)NcSsi|]	\}}||d�qS)rr9)ryrzr�r9r9r:�
<dictcomp>$sz#LRUCache.values.<locals>.<dictcomp>)�typingrrdr�rKr9r9r:ru#r�zLRUCache.valuesrRrScCs"|||��gf|j|<|��dSr?)rrd�_manage_sizerUr9r9r:rT&szLRUCache.__setitem__�_LRUCache__vcCr�r?rc)rLrr9r9r:r�*r�zLRUCache.__delitem__cCs|j|j|jSr?)rrrKr9r9r:�size_threshold-rWzLRUCache.size_thresholdc	Cs�|j�d�sdSz`t|j�}t|�|j|j|jkra|r$d}|�|�t|j�	�t
�d�dd�}||jd�D]}z|j|d=Wq8tyKYq8wt|�|j|j|jksW|j�
�dSW|j�
�dS|j�
�w)NFrT)rQ�reverser)r�acquirer�rrprrr�rdru�operator�
itemgetterr��release)rLr�
by_counterr�r9r9r:r1s.

����zLRUCache._manage_size)rrN)rrmrrrr	)rQr$r-r
)rQr$r�rr-rr?)rQr$r�rr-r)rQr$r-r%)r-rr�)r-rr[)rr$r-rS)r-rr�)r\r]r^r_r�r�rkrrr�r�rvrqrurTr��propertyrrr9r9r9r:r�s4
		�
�






rc@�eZdZddd�ZdS)�_CreateFuncTyper-r&cCr�r?r9rKr9r9r:�__call__J�z_CreateFuncType.__call__N)r-r&�r\r]r^r"r9r9r9r:r!I�r!c@r )�_ScopeFuncTyper-rcCr�r?r9rKr9r9r:r"Nr#z_ScopeFuncType.__call__NrZr$r9r9r9r:r&Mr%r&c@s`eZdZUdZdZded<ded<ded<ddd�Zddd�Zddd�Zddd�Z	ddd�Z
dS) �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*rr+�Callable[[], _T]�Callable[[], Any]cCs||_||_i|_dS)aVConstruct 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()rLr)r*r9r9r:rkfs

zScopedRegistry.__init__r-r"cCs:|��}z|j|WSty|j�||���YSwr?)r*r+r��
setdefaultr)r�r9r9r:r"ws�zScopedRegistry.__call__r�cCs|��|jvS)z9Return True if an object is present in the current scope.)r*r+rKr9r9r:�has~szScopedRegistry.hasr�rScCs||j|��<dS)z$Set the value for the current scope.N)r+r*�rLr�r9r9r:r.�szScopedRegistry.setcCs(z	|j|��=WdStyYdSw)z Clear the current scope, if any.N)r+r*r�rKr9r9r:r��s
�zScopedRegistry.clearN)r)r,r*r-�r-r"�r-r��r�r"r-rSr�)r\r]r^r_r�r�rkr"r/r.r�r9r9r9r:r'Qs




r'c@sBeZdZdZddd�Zddd	�Zddd�Zddd�Zddd�ZdS)�ThreadLocalRegistryz\A :class:`.ScopedRegistry` that uses a ``threading.local()``
    variable for storage.

    r)r,cCs||_t��|_dSr?)r)r
�localr+)rLr)r9r9r:rk�szThreadLocalRegistry.__init__r-r"cCs2z|jjWSty|��}|j_|YSwr?)r+rRr�r))rLr�r9r9r:r"�s
�zThreadLocalRegistry.__call__r�cCst|jd�S)NrR)r�r+rKr9r9r:r/�r�zThreadLocalRegistry.hasr�rScCs||j_dSr?)r+rRr0r9r9r:r.�r�zThreadLocalRegistry.setcCs"z|j`WdStyYdSwr?)r+rRr�rKr9r9r:r��s
�zThreadLocalRegistry.clearN)r)r,r1r2r3r�)	r\r]r^r_rkr"r/r.r�r9r9r9r:r4�s



r4cCs0d}|D]}||ur|d7}|dkrdSqdS)zrGiven a sequence and search object, return True if there's more
    than one, False if zero or one of them.


    rrTFr9)�sequence�target�cr�r9r9r:�	has_dupes�s
�r9)r*r+r,r+r-r+)r<r=r-r>r?)r�rr-r+)r�rr�r�r-r+)r�r�r�r�r-r�)r�rr-r�)r�r�r-rs)Wr_�
__future__rrr
r�rrrrrrrr	r
rrr
rrrrrrrrrr��_has_cyrrrr�
TYPE_CHECKING�_py_collectionsrrrrr r!�$sqlalchemy.cyextension.immutabledict�"sqlalchemy.cyextension.collectionsr"r$r%r&�	frozensetr(r�r)r;rCr@rDr`rarbr�r�r�rNr��sort_dictionaryr�r�r�r�r.r��column_dict�ordered_column_setr�r�r�r�r�r�r�r��MutableMappingrr!r&r'r4r9r9r9r9r:�<module>s�


8	W


"	
%


	
	


i@