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__/langhelpers.cpython-310.pyc
o

���gt��@s�UdZddlmZddlZddlZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$Z$ddl%m&Z&ddl%m'Z'ddl(m)Z)ddlm*Z*ddl%m+Z+e"d �Z,e"d!d"d#�Z-e"d$ed%efd&�Z.e"d'd(d&�Z/e"d)d*d&�Z0e"d+d,d&�Z1e"d-d.d&�Z2e'j3�r�dPd3d4�Z4n�dPd5d4�Z4�dQd8d9�Z5Gd:d;�d;�Z6�dRd?d@�Z7�dSdBdC�Z8	�dT�dUdGdH�Z9�dVdNdO�Z:�dWdSdT�Z;�dXdYdZ�Z<�dYd`da�Z=e"dbdLd&�Z>�dZdedf�Z?dgdh�Z@�d[dndo�ZAe"dp�ZBe"dq�ZCGdrds�ds�ZDdtdu�ZEedd%dv��d\d}d~��ZFedddv��d]d�d~��ZFdddv��d]d�d~�ZF�d^d�d��ZG	�d_�d`d�d��ZH	"�da�dbd�d��ZI�dad�d��ZJ	�	�	�	��dc�ddd�d��ZKd�d��ZLd�d��ZM	�		��de�dfd�d��ZNGd�d��d��ZOd�d��ZPd�d��ZQ			�	�dgd�d��ZRd�d��ZS�dhd�d��ZTe"d�d�d&�ZUGd�d��d�ee-�ZVGd�d��d�eVe-�ZWGd�d��d�eVe-�ZXe!�r#eVZYeVZZe[Z\e[Z]neXZYZ\eWZZZ]�did�d��Z^Gd�d��d��Z_e!�r>e[Z`ne_jaZ`Gd�d„dƒZb�djd�dĄZc�dkd�dȄZd�dld�d̄Ze	"	�dm�dnd�dՄZf�dod�dׄZg�dpd�dڄZh�dqd�d݄Zi	�dT�drd�d�Zj�dsd�d�Zkd�d�ZlGd�d�d�e[�ZmGd�d�d�ee,�ZnGd�d�d�ee,�ZoGd�d�d�ee,�ZpGd�d�d�eq�ZrGd�d��d�es�ZtGd�d��d�etd��Zue!�r�dd�lmvZvevZwneuZwe"d�ejxd&�Zy	�dt�du�d�d�Zzda{�dv�d�d�Z|�dw�d�d�Z}�dx�d	�d
�Z~G�d�d��de�Z��dT�dy�d�d�Z��dz�d�d�Z�iZ��de��d<�d{�d�d�Z�e
���d�Z�		�d|�d}�d�d �Z��d~�d$�d%�Z�e
���d&�Z�e
���d'�Z�e�e�f�d�d,�d-�Z�esd�Z��d.�d/�Z�e
���d0�Z�G�d1�d2��d2�Z�G�d3�d4��d4�Z��d5�d6�Z��d7�d8�Z��d��d:�d;�Z��d��d<�d=�Z��d��dA�dB�Z�e
���dC�Z��d��dG�dH�Z��d��dJ�dK�Z��dt�dL�dM�Z�G�dN�dO��dOejx�Z�e�j�Z�e#e,e*e�j�fZ�dS(�z�Routines to help with the creation, loading and introspection of
modules, classes, hierarchies, attributes, functions, and methods.

�)�annotationsN��update_wrapper)�CodeType)�Any)�Callable)�cast)�Dict)�	FrozenSet)�Generic)�Iterator)�List)�Mapping)�NoReturn)�Optional)�overload)�Sequence)�Set)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�_collections)�compat)�HAS_CYEXTENSION)�Literal�)�exc�_T�_T_coT)�	covariant�_F.)�bound�_MPzmemoized_property[Any]�_MAz#HasMemoized.memoized_attribute[Any]�_HPzhybridproperty[Any]�_HMzhybridmethod[Any]�objr�return�Mapping[str, Any]cCs
t�|�S�N)�inspect�get_annotations�r)�r0�F/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/langhelpers.pyr.A�
r.cCs>t|t�r
|j�dd�}nt|dd�}|durtjStd|�S)N�__annotations__r+)�
isinstance�type�__dict__�get�getattrr�
EMPTY_DICTr)r)�annr0r0r1r.Fs

�x�strcCs*|�d�}t��}|�|�tt|���S)Nzutf-8)�encoder�md5_not_for_security�updaterr<�	hexdigest)r;�mr0r0r1�md5_hexWs

rBc@s2eZdZUdZdZded<ddd�Zddd�ZdS)�safe_reraiseaReraise an exception after invoking some
    handler code.

    Stores the existing exception info before
    invoking so that it is maintained across a potential
    coroutine context switch.

    e.g.::

        try:
            sess.commit()
        except:
            with safe_reraise():
                sess.rollback()

    TODO: we should at some point evaluate current behaviors in this regard
    based on current greenlet, gevent/eventlet implementations in Python 3, and
    also see the degree to which our own asyncio (based on greenlet also) is
    impacted by this. .rollback() will cause IO / context switch to occur in
    all these scenarios; what happens to the exception context from an
    "except:" block if we don't explicitly store it? Original issue was #2703.

    )�	_exc_infozdUnion[None, Tuple[Type[BaseException], BaseException, types.TracebackType], Tuple[None, None, None]]rDr*�NonecCst��|_dSr,)�sys�exc_inforD��selfr0r0r1�	__enter__��zsafe_reraise.__enter__�type_�Optional[Type[BaseException]]�value�Optional[BaseException]�	traceback�Optional[types.TracebackType]rcCsZ|jdusJ�|dur|j\}}}|dusJ�d|_|�|��d|_|dus(J�|�|��r,)rD�with_traceback)rIrLrNrP�exc_type�	exc_value�exc_tbr0r0r1�__exit__�s

zsafe_reraise.__exit__N�r*rE)rLrMrNrOrPrQr*r)�__name__�
__module__�__qualname__�__doc__�	__slots__r3rJrVr0r0r0r1rC^s


rC�cls�Type[_T]�Iterator[Type[_T]]ccsN�t�}|g}|r%|��}||vrq|�|�|�|���|V|s	dSdSr,)�set�pop�add�extend�__subclasses__)r]�seen�stackr0r0r1�walk_subclasses�s�
�rg�elementcCs4t|t�r|Szt|�WStyd|YSw)Nzunprintable element %r)r4r<�	Exception)rhr0r0r1�string_or_unprintable�s

�rj�	Type[Any]�use_name�
Optional[str]cCs&|p|j}d�dd�t�d|�D��S)N� css�|]}|��VqdSr,)�lower)�.0�nr0r0r1�	<genexpr>���z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+|SQL))rX�join�re�findall)r]rl�namer0r0r1�clsname_as_plain_name�s
rx�instance_or_cls�Union[Type[Any], object]�against_method�Callable[..., Any]�boolcCs.t|t�s	|j}n|}|j}t||�}||kS)z1Return True if the two class methods don't match.)r4r5�	__class__rXr8)ryr{�current_cls�method_name�current_methodr0r0r1�method_is_overridden�s

r��slc�slice�Tuple[Any, ...]cCs>g}|j|j|jfD]}t|d�r|��}|�|�q
t|�S)zrdecode a slice object as sent to __getitem__.

    takes into account the 2.5 __index__() method, basically.

    �	__index__)�start�stop�step�hasattrr��append�tuple)r��retr;r0r0r1�decode_slice�s
r��used�
Sequence[str]�bases�
Iterator[str]c'sj�t|�}|D]+�t��ft�fdd�td���}|D]}||vr+|�|�|Vnqtd���qdS)Ncs�t|�Sr,�r<)�i��baser0r1�<lambda>��z!_unique_symbols.<locals>.<lambda>i�z&exhausted namespace for symbol base %s)r`�	itertools�chain�map�rangerb�	NameError)r�r��used_set�pool�symr0r�r1�_unique_symbols�s ��
���r��fn�Callable[[int], Any]rq�int�
Iterator[Any]ccs2�|r||d@}||�V||N}|sdSdS)z6Call the given function given each nonzero bit from n.rNr0)r�rq�br0r0r1�map_bits�s�
�r��_Fn�target�Callable[[_Fn], _Fn]csd�fdd�}t|��S)z'A signature-matching decorator factory.r�r�r*c
sNt�|�st�|�std��t�|�}i}t||�}ttd|d��td|dd��|j	f}t
|dd�\}}t||d�}|�t
|d	d
��|j	|d<t�|�rZd|d
<d|d<nd|d
<d|d<dt|d�vrod|}nd|}tj|j}|�t|��|�|�||d|ji�ttjt|||j	��}	t|d|�j|	_||	_t|	|�S)Nznot a decoratable functionzTuple[str, ...]rr�r�r�)r�r�F��groupedrwzasync �prefixzawait �
target_prefix��__zf%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_pos)s)
ze%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_kw)s)
rX�__func__)r-�
isfunction�ismethodrir�inspect_getfullargspec�!_update_argspec_defaults_into_envr�rrXr��dictr?�format_argspec_plus�iscoroutinefunction�reprrF�modulesrY�vars�types�FunctionType�_exec_code_in_envr8�__defaults__�__wrapped__r)
r��spec�env�names�	targ_name�fn_name�metadata�code�mod�	decorated�r�r0r1�decorate�sN

���



��	���
zdecorator.<locals>.decorateN)r�r�r*r�r)r�r�r0r�r1�	decorator�s
Ar�cCsx|jr:g}d}|jD] }t|�jdvr%d|}|||<|�|�|d7}q
|�|�q
t|�}t|�|d<tj|�S|S)zCgiven a FullArgSpec, convert defaults to be symbol names in an env.r)�builtins�__builtin__zx%drr�)�defaultsr5rYr��listr�r�FullArgSpec)r�r��new_defaultsr��argrw�elemr0r0r1r�=s



r�r��Union[str, types.CodeType]r��Dict[str, Any]r�cCst||�||Sr,)�exec)r�r�r�r0r0r1r�Rs
r��_PF�_TEc@s6eZdZ	dddd�Zdd	�Zdd
d�Zddd�ZdS)�PluginLoaderN�groupr<�auto_fn�Optional[Callable[..., Any]]cCs||_i|_||_dSr,)r��implsr�)rIr�r�r0r0r1�__init__^s
zPluginLoader.__init__cCs|j��dSr,)r��clearrHr0r0r1r�erKzPluginLoader.clearrwr*rcCs�||jvr|j|�S|jr|�|�}|r||j|<|�St�|j�D]}|j|kr6|j|j|<|��Sq#t�d|j|f��)NzCan't load plugin: %s:%s)	r�r�r�importlib_metadata_getr�rw�loadr�NoSuchModuleError)rIrw�loader�implr0r0r1r�hs



��zPluginLoader.load�
modulepath�objnamerEcs��fdd�}||j|<dS)Ncs4t��}��d�dd�D]}t||�}q
t|��S)N�.r)�
__import__�splitr8)r��token�r�r�r0r1r�|s
z#PluginLoader.register.<locals>.load)r�)rIrwr�r�r�r0r�r1�register{szPluginLoader.registerr,)r�r<r�r�)rwr<r*r)rwr<r�r<r�r<r*rE)rXrYrZr�r�r�r�r0r0r0r1r�]s�
r�cCshztj}Wntyt�|�}|dt|d�fYSw|j}|j}t|j	d|��t|j
|@�fS)Nrr)r-�CO_VARKEYWORDS�AttributeErrorrr�r}�__code__�co_argcountr��co_varnames�co_flags)r��co_varkeywordsr��co�nargsr0r0r1�_inspect_func_args�s

�	�r�)�_set�raiseerrr5r��Optional[Set[str]]r��
Literal[True]�Set[str]cC�dSr,r0�r]r�r�r0r0r1�get_cls_kwargs�srFcCr�r,r0r�r0r0r1r�sc	Cs�|du}|r	t�}|dusJ�|j�dd�}|o$t|tj�o$t|jtj�}|rCt|�\}}|�	|�|sB|sB|r@t
d|�d���dSnd}|rI|rY|jD]}t||d�durXnqL|�
d�|S)aeReturn the full set of inherited kwargs for the given `cls`.

    Probes a class's __init__ method, collecting all named arguments.  If the
    __init__ defines a \**kwargs catch-all, then the constructor is presumed
    to pass along unrecognized keywords to its base classes, and the
    collection process is repeated recursively on each of the bases.

    Uses a subset of inspect.getfullargspec() to cut down on method overhead,
    as this is used within the Core typing system to create copies of type
    objects which is a performance-sensitive operation.

    No anonymous tuple arguments please !

    Nr�Fz
given cls z  doesn't have an __init__ method)r�rI)r`r6r7r4r�r�r�rr�r?�	TypeError�	__bases__r�discard)	r]r�r��toplevel�ctr�has_initr��has_kw�cr0r0r1r�s8
��

��
�
�func�	List[str]cCst�|�dS)z�Return the set of legal kwargs for the given `func`.

    Uses getargspec so is safe to call for methods, functions,
    etc.

    r)rr�)r	r0r0r1�get_func_kwargs�sr�no_self�_is_init�compat.FullArgSpecc	Cs0t�|�rtd|��t�|�r4|r/|r/t�|�}t�|jdd�|j|j	|j
|j|j|j
�St�|�St�|�rb|r\|s@|jr\t�|j�}t�|jdd�|j|j	|j
|j|j|j
�St�|j�St�|�rot|j|dd�St|d�rzt�|j�St|d�r�t�|j�r�t|j|d�Std	|��td	|��)
z�Return the argument signature for any callable.

    All pure-Python callables are accepted, including
    functions, methods, classes, objects with __call__;
    builtins and other edge cases like functools.partial() objects
    raise a TypeError.

    zCan't inspect builtin: %srNT)rr
r��__call__)rzCan't inspect callable: %s)r-�	isbuiltinrr�rr�r��args�varargs�varkwr��
kwonlyargs�kwonlydefaultsrr��__self__r��isclass�get_callable_argspecr�r�r)r�rr
r�r0r0r1r�sN


�


�

�

r�-Union[Callable[..., Any], compat.FullArgSpec]r��Dict[str, Optional[str]]c	Cs�t|�r
t�|�}n|}tj|�}t�|d|d|dd|d�}|drB|dd}t�|ddd�|d|dd|d�}n|drOd|d}|}nd}|}d}|drf|tttt|d��7}|drr|t|d�7}|d|d}|r�|d|d�}	nd}	tj||d|d|	d	d
�d�}
|dr�tj|dd�|d|d|	dd
�d�}n|
}|r�t||||
||d
�St|||dd�|
dd�|dd�|dd�d
�S)aReturns a dictionary of formatted, introspected function arguments.

    A enhanced variant of inspect.formatargspec to support code generation.

    fn
       An inspectable callable or tuple of inspect getargspec() results.
    grouped
      Defaults to True; include (parens, around, argument) lists

    Returns:

    args
      Full inspect.formatargspec for fn
    self_arg
      The name of the first positional argument, varargs[0], or None
      if the function defines no positional arguments.
    apply_pos
      args, re-written in calling rather than receiving syntax.  Arguments are
      passed positionally.
    apply_kw
      Like apply_pos, except keyword-ish args are passed as keywords.
    apply_pos_proxied
      Like apply_pos but omits the self/cls argument

    Example::

      >>> format_argspec_plus(lambda self, a, b, c=3, **d: 123)
      {'grouped_args': '(self, a, b, c=3, **d)',
       'self_arg': 'self',
       'apply_kw': '(self, a, b, c=c, **d)',
       'apply_pos': '(self, a, b, c, **d)'}

    rrrN�z%s[0]r�r0cS�dt|�S�N�=r��r;r0r0r1r�sr�z%format_argspec_plus.<locals>.<lambda>)�formatvaluecSrrr�rr0r0r1r�|r�)�grouped_args�self_arg�	apply_pos�apply_kw�apply_pos_proxied�apply_kw_proxied���)	�callablerr��inspect_formatargspec�lenrrrr�)r�r�r�rr#r"r%�num_defaults�	name_args�defaulted_valsr$r&r0r0r1r� sv$
�"��
��	



�r�cCsz|tjurd}|rdnd}|rdnd}nzt||d�WSty2d}|r(|nd}|r.dnd	}Ynwtd|||||d
�S)a$format_argspec_plus with considerations for typical __init__ methods

    Wraps format_argspec_plus with error handling strategies for typical
    __init__ cases:

    .. sourcecode:: text

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    z(self)rIz()r�r�z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r"r!r#r$r%r&)�objectr�r�rr�)�methodr�r!r�proxiedr0r0r1�format_argspec_init�s&
��r1r0�
target_cls�target_cls_sphinx_name�proxy_cls_sphinx_name�classmethods�methods�
attributes�use_intermediate_variable�Callable[[_T], _T]cCsdd�}|S)aSA class decorator indicating attributes should refer to a proxy
    class.

    This decorator is now a "marker" that does nothing at runtime.  Instead,
    it is consumed by the tools/generate_proxy_methods.py script to
    statically generate proxy methods and attributes that are fully
    recognized by typing tools such as mypy.

    cSs|Sr,r0)r]r0r0r1r���z&create_proxy_methods.<locals>.decorater0)r2r3r4r5r6r7r8r�r0r0r1�create_proxy_methods�sr;cCsJzt�|�WSty$|tjurdgdddfYSdgdddfYSw)ainspect.getargspec with considerations for typical __init__ methods

    Wraps inspect.getargspec with error handling for typical __init__ cases:

    .. sourcecode:: text

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    rINr�kwargs)rr�rr.r�)r/r0r0r1�getargspec_init�s
�r=cCst|tj�r|js|jS|S)zSAdjust the incoming callable such that a 'self' argument is not
    required.

    )r4r��
MethodTyperr�)�func_or_clsr0r0r1�unbound_method_to_callable�sr@�
additional_kw�Sequence[Tuple[str, Any]]�
to_inspect�%Optional[Union[object, List[object]]]�
omit_kwargc	s6|dur�g}nt�|�}t��g}t��}d}t|�D]p\}}zt�|j�}	Wn	ty1Yqw|	j	r:t
|	j	�nd}
|dkr_|	jrF|	j}|
rT|�|	j
d|
��n|�|	j
dd��n|��fdd�|	j
d|
�D��|
r�|	j	sxJ�|�dd�t|	j
|
d�|	j	�D��qg}|��fdd�|D��|dur�t�|�r�|�d	d�t�|�D��|��D]+\}}
||vr�q�zt�|��}|�ur�||
kr�|�d
||f�Wq�ty�Yq�w|�r|D])\}}
zt�|��}|�u�r||
k�r|�d
||f�Wq�t�yYq�wd�jjd�|�fS)
z}Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    Nrrcsg|]}|�f�qSr0r0�rpr�)�missingr0r1�
<listcomp>�z generic_repr.<locals>.<listcomp>cSsg|]\}}||f�qSr0r0)rpr��defaultr0r0r1rHs��c3s �|]}tt�|d��VqdSr,)r�r8rFr/r0r1rr"s�zgeneric_repr.<locals>.<genexpr>cSsg|]}t|��qSr0�r�)rp�valr0r0r1rH%rIz%s=%rz%s(%s)�, )r�to_listr.�OrderedDict�	enumeraterr�r�rr�r*rrcrr?�zipr�r8�itemsr�rir~rXrt)r)rArCrE�pos_args�kw_args�vargsr��inspr��default_len�outputr��defvalrLr0)rGr)r1�generic_repr�sv

��
��������rZc@s6eZdZdZdZdd�Zdd�Zd
dd	�Zd
d�ZdS)�portable_instancemethodz_Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    )r�rwr<�__weakref__cCs|j|j|jd�S)N�r�rwr<r]rHr0r0r1�__getstate__Es�z$portable_instancemethod.__getstate__cCs&|d|_|d|_|�dd�|_dS)Nr�rwr<r0)r�rwr7r<)rI�stater0r0r1�__setstate__Ls

z$portable_instancemethod.__setstate__r0cCs|j|_|j|_||_dSr,)rr�rXrwr<)rI�methr<r0r0r1r�Qs
z portable_instancemethod.__init__cOs$|�|j�t|j|j�|i|��Sr,)r?r<r8r�rw)rIr��kwr0r0r1rVsz portable_instancemethod.__call__N)r0)	rXrYrZr[r\r^r`r�rr0r0r0r1r[=s
r[cs�|h�t|j�}|rV|��}�fdd�|jD�}|D]}|�|���|�q|jdks1t|d�s2q�fdd�t|t	�s@|�
�n|�
|�D�D]}|�|���|�qG|s
t��S)a'Return an unordered sequence of all classes related to cls.

    Traverses diamond hierarchies.

    Fibs slightly: subclasses of builtin types are not returned.  Thus
    class_hierarchy(class A(object)) returns (A, object), not A plus every
    class systemwide that derives from object.

    c3s�|]	}|�vr|VqdSr,r0�rp�_��hierr0r1rrj��z"class_hierarchy.<locals>.<genexpr>r�rdcsg|]}|�vr|�qSr0r0rcrer0r1rHss
�z#class_hierarchy.<locals>.<listcomp>)r��__mro__rarr�rbrYr��
issubclassr5rd)r]�processrr�r��sr0rer1�class_hierarchy[s&



�
�
	�rlccsB�t|�}|D]}|jD]}||jvr||j|fVnqqdS)z�iterate all the keys and attributes associated
    with a class, without using getattr().

    Does not use getattr() so that class-sensitive
    descriptors (i.e. property.__get__()) are not called.

    N)�dirrhr6)r]�keys�keyrr0r0r1�iterate_attributes�s�

���rp�
self.proxyc	s.|r|}n�durd���fdd�t|�D�}|D]{}zt||�}t|d�s(Wqt|d|�}ttj|�}	Wn	ty>Yqwzt�|	�}
t�	|
d�}t�	|
ddd��}Wn
t
yed	}d
}Ynwdt�}
|durs||ipti}t|
|�z|	j
||_
Wn	ty�Ynwt�|||�qdS)z9Automates delegation of __specials__ for a proxying type.N)r\�__del__�__getattribute__�
__metaclass__r^r`cs6g|]}|�d�r|�d�rt�|�s|�vr|�qS)r�)�
startswith�endswithr��rprA��into_cls�skipr0r1rH�s����z0monkeypatch_proxied_specials.<locals>.<listcomp>rr�rrz(self, *args, **kw)z
(*args, **kw)z?def %(method)s%(fn_args)s: return %(name)s.%(method)s%(d_args)s)rmr8r�rr�r�r�rr�r)r�localsr�r��setattr)ry�from_clsrz�onlyrw�
from_instance�dundersr/�maybe_fnr�r��fn_args�d_args�pyr�r0rxr1�monkeypatch_proxied_specials�sN
�

�
����
��r�cCst|d|�t|d|�uS)z;Return True if the two methods are the same implementation.r�)r8)�meth1�meth2r0r0r1�methods_equivalent�s�r�cCsf|s|std��t|t�rt||�r|St|pdd�t|�D��}tt|��}tj}t|t�r2|}n
|s;t�}tj}nt|�}||�|�|�rI|St|t	�sc|tjurUdpVd}td||d�
|�f��Gdd	�d	�}|rrd
|j|_t�}	t|�D]'\}
}|
|vr�td|
��t
|�s�td|
|f��t||
t|��|	�|
�qy||	|�r�|Std
d�
||	���)a�Ensure basic interface compliance for an instance or dict of callables.

    Checks that ``obj`` implements public methods of ``cls`` or has members
    listed in ``methods``. If ``required`` is not supplied, implementing at
    least one interface method is sufficient. Methods present on ``obj`` that
    are not in the interface are ignored.

    If ``obj`` is a dict and ``dict`` does not meet the interface
    requirements, the keys of the dictionary are inspected. Keys present in
    ``obj`` that are not in the interface will raise TypeErrors.

    Raises TypeError if ``obj`` does not meet the interface criteria.

    In all passing cases, an object with callable members is returned.  In the
    simple case, ``obj`` is returned as-is; if dict processing kicks in then
    an anonymous class is returned.

    obj
      A type, instance, or dictionary of callables.
    cls
      Optional, a type.  All public methods of cls are considered the
      interface.  An ``obj`` instance of cls will always pass, ignoring
      ``required``..
    methods
      Optional, a sequence of method names to consider as the interface.
    required
      Optional, a sequence of mandatory implementations. If omitted, an
      ``obj`` that provides at least one interface method is considered
      sufficient.  As a convenience, required may be a type, in which case
      all public methods of the type are required.

    z2a class or collection of method names are requiredcSsg|]	}|�d�s|�qS)rd)rurwr0r0r1rHsz as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srMc@�eZdZdZdS)z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.N�rXrYrZr[r0r0r0r1�AnonymousInterface�r��	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %s)rr4r5r`rm�operator�ge�gt�intersectionr�rtrX�dictlike_iteritemsr(r|�staticmethodrb)r)r]r6�required�	interface�implemented�complies�	qualifierr��foundr/r�r0r0r1�as_interface�sP!

��
��r��_GFDzgeneric_fn_descriptor[Any]c@s�eZdZUdZded<ded<ded<d%d&d
d�Zed'dd��Zed(dd��Zd)dd�Zer8d*dd�Z	d+dd�Z
d,d d!�Zed-d#d$��Z
dS).�generic_fn_descriptoragDescriptor which proxies a function when the attribute is not
    present in dict

    This superclass is organized in a particular way with "memoized" and
    "non-memoized" implementation classes that are hidden from type checkers,
    as Mypy seems to not be able to handle seeing multiple kinds of descriptor
    classes used for the same attribute.

    �Callable[..., _T_co]�fgetrmr[r<rXN�doccC�||_|p|j|_|j|_dSr,�r�r[rX�rIr�r�r0r0r1r�D�zgeneric_fn_descriptor.__init__rIr�r)rEr]rr*cCr�r,r0�rIr)r]r0r0r1�__get__Ir:zgeneric_fn_descriptor.__get__r.r!cCr�r,r0r�r0r0r1r�Lr:�Union[_GFD, _T_co]cC�t��r,��NotImplementedErrorr�r0r0r1r�O��instancerNcCr�r,r0�rIr�rNr0r0r1�__set__T�zgeneric_fn_descriptor.__set__cCr�r,r0)rIr�r0r0r1�
__delete__Vr�z generic_fn_descriptor.__delete__cCr�r,r��rIr)r0r0r1�_resetXr�zgeneric_fn_descriptor._resetrwcCr�r,r��r]r)rwr0r0r1�reset[szgeneric_fn_descriptor.resetr,)r�r�r�rm)rIr�r)rEr]rr*r�)r)r.r]rr*r!)rIr�r)rr]rr*r��r�rrNrr*rE�r�rr*rE)r)rr*rE)r)rrwr<r*rE)rXrYrZr[r3r�rr�rr�r�r��classmethodr�r0r0r0r1r�5s"





r�c@s eZdZdZesdd�ZdSdS)�_non_memoized_propertyz�a plain descriptor that proxies a function.

    primary rationale is to provide a plain attribute that's
    compatible with memoized_property which is also recognized as equivalent
    by mypy.

    cCs|dur|S|�|�Sr,�r�r�r0r0r1r�ks
z_non_memoized_property.__get__N)rXrYrZr[rr�r0r0r0r1r�`s
�r�c@s0eZdZdZesdd�Zdd�Zedd��ZdS)	�_memoized_propertyz2A read-only @property that is only evaluated once.cCs&|dur|S|�|�|j|j<}|Sr,)r�r6rX�rIr)r]�resultr0r0r1r�vsz_memoized_property.__get__cCst�||j�dSr,)r�r�rXr�r0r0r1r�|sz_memoized_property._resetcCs|j�|d�dSr,)r6rar�r0r0r1r�sz_memoized_property.resetN)	rXrYrZr[rr�r�r�r�r0r0r0r1r�qsr�cs�fdd�}t|��S)z�Decorate a method memoize its return value.

    Best applied to no-arg methods: memoization is not sensitive to
    argument values, and will always return the same value even when
    called with different arguments.

    csB�|g|�Ri|����fdd�}�j|_�j|_||j�j<�S)Nc��Sr,r0��arb�r�r0r1�memo�r:z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)rXr[r6�rIrrbr��r�r�r1�oneshot�sz(memoized_instancemethod.<locals>.oneshotr)r�r�r0r�r1�memoized_instancemethod�s	
r�c@sheZdZUdZesdZe�Zded<ddd�Z	dd	d
�Z
ddd�ZGdd�dee
�Zeddd��ZdS)�HasMemoizedzA mixin class that maintains the names of memoized elements in a
    collection for easy cache clearing, generative, etc.

    r0zFrozenSet[str]�_memoized_keysr*rEcCs|jD]	}|j�|d�qdSr,)r�r6ra�rIr�r0r0r1�_reset_memoizations��
�zHasMemoized._reset_memoizationscCs|jD]	}||jvsJ�qdSr,)r�r6r�r0r0r1�_assert_no_memoizations�r�z#HasMemoized._assert_no_memoizationsror<rNrcCs||j|<|j|hO_dSr,)r6r�)rIrorNr0r0r1�_set_memoized_attribute�s
z#HasMemoized._set_memoized_attributec@sZeZdZUdZded<ded<ded<ddd
d�Zeddd��Zeddd��Zdd�ZdS)zHasMemoized.memoized_attributezTA read-only @property that is only evaluated once.

        :meta private:

        �Callable[..., _T]r�rmr[r<rXNr�cCr�r,r�r�r0r0r1r��r�z'HasMemoized.memoized_attribute.__init__rIr&r)rEr]rr*cCr�r,r0r�r0r0r1r��r:z&HasMemoized.memoized_attribute.__get__r cCr�r,r0r�r0r0r1r��r:cCs8|dur|S|�|�|j|j<}|j|jhO_|Sr,)r�r6rXr�r�r0r0r1r��s
r,)r�r�r�rm)rIr&r)rEr]rr*r&)r)rr]rr*r )rXrYrZr[r3r�rr�r0r0r0r1�memoized_attribute�s
r�r�r#csd	�fdd�}t|��S)
zMDecorate a method memoize its return value.

        :meta private:

        rIrrrbr*csT�|g|�Ri|����fdd�}�j|_�j|_||j�j<|j�jhO_�S)Ncr�r,r0r�r�r0r1r��r:zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)rXr[r6r�r�r�r�r1r��sz4HasMemoized.memoized_instancemethod.<locals>.oneshotN)rIrrrrbrr*rr)r]r�r�r0r�r1r��s
z#HasMemoized.memoized_instancemethodNrW)ror<rNrr*rE�r�r#r*r#)rXrYrZr[rr\�	frozensetr�r3r�r�r��memoized_propertyr r�r�r�r0r0r0r1r��s



r�c@s&eZdZdZdZdd�Zdd	d
�ZdS)
�
MemoizedSlotsz�Apply memoized items to an object using a __getattr__ scheme.

    This allows the functionality of memoized_property and
    memoized_instancemethod to be available to a class using __slots__.

    r0cCst|��r,)r�)rIror0r0r1�_fallback_getattr�zMemoizedSlots._fallback_getattrror<r*rcs���d�s
��d�rt���t�jd����r(t�d�����}t��|�|St�jd����rGt�d��������fdd�}�j|_|S����S)N�_memoized_attr_�_memoized_method_cs:�|i|����fdd�}�j|_�j|_t��|��S)Ncr�r,r0r�r�r0r1r�)r:z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)rXr[r|)rrbr��r�rorIr�r1r�&sz*MemoizedSlots.__getattr__.<locals>.oneshot)rur�r�r~r8r|r[r�)rIrorNr�r0r�r1�__getattr__s�
zMemoizedSlots.__getattr__N)ror<r*r)rXrYrZr[r\r�r�r0r0r0r1r�
s
r�cCsBt|t�r|����}|dvrdS|dvrdStd|��t|�S)N)�true�yes�on�y�t�1T)�false�no�offrq�f�0FzString is not true/false: %r)r4r<�stripro�
ValueErrorr}r/r0r0r1�asbool8s
r��text�!Callable[[str], Union[str, bool]]csd�fdd�}|S)	zqReturn a callable that will evaluate a string as
    boolean, or one of a set of "alternate" string values.

    r)r<r*�Union[str, bool]cs|�vr|St|�Sr,)r�r/�r�r0r1�
bool_or_valueJsz"bool_or_str.<locals>.bool_or_valueN)r)r<r*r�r0)r�r�r0r�r1�bool_or_strDsr�rN�
Optional[int]cCs|dur|St|�S)zCoerce to integer.N)r�)rNr0r0r1�asintSsr�rbrorL�
flexi_bool�dest�Optional[Dict[str, Any]]rEcCsx|dur|}||vr6t|t�rt|||�s:||dur8|tur,|r,t||�||<dS|||�||<dSdSdSdS)z�If 'key' is present in dict 'kw', coerce its value to type 'type\_' if
    necessary.  If 'flexi_bool' is True, the string '0' is considered false
    when coercing to boolean.
    N)r4r5r}r�)rbrorLr�r�r0r0r1�coerce_kw_type[s����r�cs$t|�}|ft�fdd�|D��S)zbProduce a tuple structure that is cacheable using the __dict__ of
    obj to retrieve values

    c3�(�|]}|�jvr|�j|fVqdSr,�r6�rp�kr/r0r1rr{���z"constructor_key.<locals>.<genexpr>)rr�)r)r]r�r0r/r1�constructor_keyus
�r�rcs4t|�}|��fdd�|�|�D��||i|��S)z�Instantiate cls using the __dict__ of obj as constructor arguments.

    Uses inspect to match the named arguments of ``cls``.

    c3r�r,r�r�r/r0r1rr�r�z#constructor_copy.<locals>.<genexpr>)rr?�
difference)r)r]rrbr�r0r/r1�constructor_copy�s
�r��Callable[[], int]cs$t���t�d����fdd�}|S)z%Return a threadsafe counter function.rcs0��t��Wd�S1swYdSr,)�nextr0��counter�lockr0r1�_next�s$�zcounter.<locals>._next)�	threading�Lockr��count)r�r0r�r1r��s
r��specimenrJ�Optional[Type[Any]]cCs�t|d�r|jdurt|jt�rtS|jSt|t�rtnt}||t�r%tS||t�r,tS||t�r3tSt|d�r:tSt|d�rAtSt|d�rHtS|S)z�Given an instance or class, guess if it is or is acting as one of
    the basic collection types: list, set and dict.  If the __emulates__
    property is present, return that preferentially.
    �__emulates__Nr�rbr`)r�rrir`r4r5r�r�)rrJ�isar0r0r1�duck_type_collection�s(
�





rr��argtype�'Union[Tuple[Type[Any], ...], Type[Any]]rwcCsXt||�r|St|t�r t�d|d�dd�|D��t|�f��t�d||t|�f��)Nz8Argument '%s' is expected to be one of type %s, got '%s'z or css�|]}d|VqdS)z'%s'Nr0)rpr�r0r0r1rr�rsz"assert_arg_type.<locals>.<genexpr>z6Argument '%s' is expected to be of type '%s', got '%s')r4r�r�
ArgumentErrorrtr5)r�rrwr0r0r1�assert_arg_type�s

����rcs�t�d�rt����St�dt�dd����durtd���t�d�r.��fdd�}|�St�d	�r@t�fd
d����D��Std���)z?Return a (key, value) iterator for almost any dict-like object.rR�__getitem__r7NzObject '%r' is not dict-like�iterkeysc3s.����D]}�dus
J�|�|�fVqdSr,)r
)ro��dictlike�getterr0r1�iterator�s
��z$dictlike_iteritems.<locals>.iteratorrnc3s�|]	}|�|�fVqdSr,r0)rpro)rr0r1rr�rgz%dictlike_iteritems.<locals>.<genexpr>)r�r�rRr8r�iterrn)rrr0rr1r��s


r�cs8eZdZUdZded<d�fdd�Zdddd�Z�ZS)�
classpropertyaAA decorator that behaves like @property except that operates
    on classes rather than instances.

    The decorator is currently special when using the declarative
    module, but note that the
    :class:`~.sqlalchemy.ext.declarative.declared_attr`
    decorator should be used for this purpose with declarative.

    �Callable[[Any], Any]r�r�rrbcs&t�j|g|�Ri|��|j|_dSr,)�superr�r[)rIr�r�rb�r~r0r1r��szclassproperty.__init__Nr)r]�Optional[type]r*cCs
|�|�Sr,r�r�r0r0r1r��r2zclassproperty.__get__)r�rr�rrbrr,)r)rr]rr*r)rXrYrZr[r3r�r��
__classcell__r0r0rr1r�s


rc@s*eZdZddd�Zdd
d�Zddd�ZdS)�hybridpropertyr	r�cCs||_||_dSr,)r	�clslevel�rIr	r0r0r1r��s
zhybridproperty.__init__r�r�ownerr*r cC� |dur|�|�}|S|�|�Sr,�rr	�rIr�r�clsvalr0r0r1r��

zhybridproperty.__get__r|�hybridproperty[_T]cC�
||_|Sr,�rrr0r0r1�
classlevel
�zhybridproperty.classlevelN�r	r��r�rrrr*r )r	r|r*r")rXrYrZr�r�r%r0r0r0r1r�s

rc@s>eZdZddd�Zdd
d�Zddd�Zddd�Zddd�ZdS)�rw_hybridpropertyr	r�cCs||_||_d|_dSr,)r	r�setfnrr0r0r1r�s
zrw_hybridproperty.__init__r�rrr*r cCrr,rrr0r0r1r�r!zrw_hybridproperty.__get__rNrEcCs|jdusJ�|�||�dSr,�r*r�r0r0r1r�szrw_hybridproperty.__set__r|�rw_hybridproperty[_T]cCr#r,r+rr0r0r1�setter r&zrw_hybridproperty.settercCr#r,r$rr0r0r1r%$r&zrw_hybridproperty.classlevelNr'r(r�)r	r|r*r,)rXrYrZr�r�r�r-r%r0r0r0r1r)s



r)c@s.eZdZdZddd�Zdd
d�Zddd�ZdS)�hybridmethodz/Decorate a function as cls- or instance- level.r	r�cCs||_|_||_dSr,)r	r�rrr0r0r1r�,s
zhybridmethod.__init__r�rrr*cCs&|dur|j�||j�S|j�||�Sr,)rr�r~r	)rIr�rr0r0r1r�0szhybridmethod.__get__r|�hybridmethod[_T]cCr#r,r$rr0r0r1r%6r&zhybridmethod.classlevelNr')r�rrrr*r�)r	r|r*r/)rXrYrZr[r�r�r%r0r0r0r1r.)s


r.c@sVeZdZUdZded<iZded<e��Z		dddd
�Z	dd�Z
dd�Zdd�ZdS)�symbolaIA constant symbol.

    >>> symbol("foo") is symbol("foo")
    True
    >>> symbol("foo")
    <symbol 'foo>

    A slight refinement of the MAGICCOOKIE=object() pattern.  The primary
    advantage of symbol() is its repr().  They are also singletons.

    Repeated calls of symbol('name') will all return the same instance.

    r<rwzDict[str, symbol]�symbolsNr�rm�	canonicalr�r*cCs�|j�G|j�|�}|dur1t|t�sJ�|durt|�}t�t|�}||_	|r+||_
||j|<n|rA||krAtd|�d|����|Wd�S1sMwYdS)Nz#Can't replace canonical symbol for z with new int value )�_lockr1r7r4r<�hashr��__new__r0rwr[r)r]rwr�r2r�r0r0r1r5Os&��$�zsymbol.__new__cCst|jdt|�ffS)Nr;)r0rwr�rHr0r0r1�
__reduce__mszsymbol.__reduce__cCst|�Sr,rKrHr0r0r1�__str__pr�zsymbol.__str__cCsd|j�d�S)Nzsymbol(�)�rwrHr0r0r1�__repr__srKzsymbol.__repr__)NN)rwr<r�rmr2r�r*r0)
rXrYrZr[r3r1rrr3r5r6r7r:r0r0r0r1r0;s
�r0c@s eZdZddd�Zddd�ZdS)�_IntFlagMeta�	classnamer<r��Tuple[Type[Any], ...]�dict_r�rbrr*rEc	Ks�g|_}|��D],\}}t�d|�rq	t|t�r t||d�}n
|�d�s)td��q	t	|||�|�
|�q	t�dd�|D��|_
dS)Nz^__.*__$)r2rdz#Expected integer values for IntFlagcSsi|]}|j|�qSr0r9)rpr�r0r0r1�
<dictcomp>�rIz)_IntFlagMeta.__init__.<locals>.<dictcomp>)�_itemsrRru�matchr4r�r0rurr|r�r�
immutabledict�__members__)	r]r<r�r>rbrRr��vr�r0r0r1r�xs



�z_IntFlagMeta.__init__�Iterator[symbol]cCstd��)Nz�iter not implemented to ensure compatibility with Python 3.11 IntFlag.  Please use __members__.  See https://github.com/python/cpython/issues/99304r�rHr0r0r1�__iter__�s�z_IntFlagMeta.__iter__N)
r<r<r�r=r>r�rbrr*rE)r*rE)rXrYrZr�rFr0r0r0r1r;ws
r;c@r�)�_FastIntFlagz�An 'IntFlag' copycat that isn't slow when performing bitwise
    operations.

    the ``FastIntFlag`` class will return ``enum.IntFlag`` under TYPE_CHECKING
    and ``_FastIntFlag`` otherwise.

    Nr�r0r0r0r1rG�r�rG)�	metaclass)�IntFlag�_E�choices�Dict[_E, List[Any]]�resolve_symbol_names�Optional[_E]cCsj|��D]\}}||ur|S|r||jkr|S||vr#|Sq|dur*dSt�d|�d|����)aOGiven a user parameter, parse the parameter into a chosen value
    from a list of choice objects, typically Enum values.

    The user argument can be a string name that matches the name of a
    symbol, or the symbol object itself, or any number of alternate choices
    such as True/False/ None etc.

    :param arg: the user argument.
    :param choices: dictionary of enum values to lists of possible
        entries for each.
    :param name: name of the argument.   Used in an :class:`.ArgumentError`
        that is raised if the parameter doesn't match any available argument.

    NzInvalid value for 'z': )rRrwrr
)r�rKrwrM�
enum_value�choicer0r0r1�parse_user_argument_for_enum�s�rQr�cCst|_td7adS)z�Assign a '_creation_order' sequence to the given instance.

    This allows multiple instances to be sorted in order of creation
    (typically within a single thread; the counter is not particularly
    threadsafe).

    rN)�_creation_order)r�r0r0r1�set_creation_order�s	rSr<cOs>z||i|��WStytdt��dd��YdSw)zXexecutes the given function, catches all exceptions and converts to
    a warning.

    z%s('%s') ignoredrrN)ri�warnrFrG)r	rr<r0r0r1�warn_exception�s
�rU�cCs<zt|�|krd|d|�WS|WSty|YSw)Nz%s...r)r*r)rN�len_r0r0r1�ellipses_string�s�rXcs@eZdZUdZded<d�fd
d�Zddd
�Zddd�Z�ZS)�_hash_limit_stringa/A string subclass that can only be hashed on a maximum amount
    of unique values.

    This is used for warnings so that we can send out parameterized warnings
    without the __warningregistry__ of the module,  or the non-overridable
    "once" registry within warnings.py, overloading memory,


    r��_hashrNr<�numr�
Sequence[Any]r*cs<||d|}t��||�}td|t|�|f�|_|S)Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)rr5r4rZ)r]rNr[r�interpolatedrIrr0r1r5s�z_hash_limit_string.__new__cCs|jSr,)rZrHr0r0r1�__hash__r�z_hash_limit_string.__hash__�otherrr}cCst|�t|�kSr,)r4)rIr_r0r0r1�__eq__sz_hash_limit_string.__eq__)rNr<r[r�rr\r*rY)r*r�)r_rr*r})	rXrYrZr[r3r5r^r`rr0r0rr1rY�s



rY�msgcCs*|r
ttj||d��dSt|tj�dS)zdIssue a warning.

    If msg is a string, :class:`.exc.SAWarning` is used as
    the category.

    )r�N)�_warnings_warnr�	SAWarning)rar�r0r0r1rTsrTr\cCs |rt|d|�}t|tj�dS)z\Issue a warning with a parameterized string, limiting the number
    of registrations.

    �
N)rYrbrrc)rarr0r0r1�warn_limited srez)Dict[CodeType, Tuple[str, Type[Warning]]]�
_warning_tags�message�category�
Type[Warning]�Callable[[_F], _F]cs��fdd�}|S)Ncs��ft|j<|Sr,)rfr�r��rhrgr0r1�go0sz#tag_method_for_warnings.<locals>.gor0)rgrhrlr0rkr1�tag_method_for_warnings-srmz&^(?:sqlalchemy\.(?!testing)|alembic\.)�Union[str, Warning]�Optional[Type[Warning]]�
stacklevelcCs�zt�|�}Wntyd}YnKd}YnDd}}|dur]|s0t�t|j�dd��s0d}|jt	vrJd}t	|j\}}|pA|}|�d|�d�}|j
}|sT|d7}n|rY|rYn|dus!|durmtj|||dd	�dStj||dd	�dS)
NrFrXr�Tz (r8r)rp)
rF�	_getframer�rurA�_not_sa_pattern�	f_globalsr7�f_coderf�f_back�warningsrT)rgrhrp�frame�stacklevel_found�warning_tag_found�_suffix�	_categoryr0r0r1rb:s4�

�rbr��retry_on_exception�Callable[..., Optional[_T]]cs�g�d	���fdd�}|S)
zNDecorate the given function to be a no-op after it is called exactly
    once.r�rrbr*�Optional[_T]cs>�}�r���}z||i|��WS�r��d|��dS)Nr)ra�insert)r�rb�	strong_fn�once_fn�r��oncer|r0r1rluszonly_once.<locals>.goN)r�rrbrr*r~r0)r�r|rlr0r�r1�	only_oncemsr�z%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)�tb�exclude_prefix�re.Pattern[str]�exclude_suffixcCs�d}t|�d}||kr"|�||�r"|d7}||kr"|�||�s||kr<|�||�r<|d8}||kr<|�||�s-|||d�S)atChop extraneous lines off beginning and end of a traceback.

    :param tb:
      a list of traceback lines as returned by ``traceback.format_stack()``

    :param exclude_prefix:
      a regular expression object matching lines to skip at beginning of
      ``tb``

    :param exclude_suffix:
      a regular expression object matching lines to skip at end of ``tb``
    rr)r*�search)r�r�r�r��endr0r0r1�chop_traceback�s��r�cCs$d|}t���}t||�|dS)Nz&def set(obj, value):    obj.%s = valuer`)r{�copyr�)�attrnamer�r�r0r0r1�
attrsetter�s

r�z^__.+__$cs&eZdZdZdZd�fdd�Z�ZS)�
TypingOnlyz�A mixin class that marks a class as 'typing only', meaning it has
    absolutely no methods, attributes, or runtime functionality whatsoever.

    r0r*rEcsBt|jvrdd�|jD�}|rtd|�d|�d���t���dS)NcSsh|]	}t�|�s|�qSr0)�_dundersrA�rprwr0r0r1�	<setcomp>�s

��z/TypingOnly.__init_subclass__.<locals>.<setcomp>zClass z< directly inherits TypingOnly but has additional attributes r�)r�rr6�AssertionErrorr�__init_subclass__)r]�	remainingrr0r1r��s
���zTypingOnly.__init_subclass__rW)rXrYrZr[r\r�rr0r0rr1r��sr�cs<eZdZUdZded<	d�fdd�Zed
d
d��Z�ZS)�EnsureKWArga6Apply translation of functions to accept \**kw arguments if they
    don't already.

    Used to ensure cross-compatibility with third party legacy code, for things
    like compiler visit methods that need to accept ``**kw`` arguments,
    but may have been copied from old code that didn't accept them.

    r<�ensure_kwargr*rEcsf|j}|j}|r,|D]!}t�||�}|r+||}t�|�}|js+|�|�}t|||�q
t	��
�dSr,)r�r6rurArr�r�
_wrap_w_kwr|rr�)r]�fn_reg�clsdictrorAr�r��wrappedrr0r1r��s

�zEnsureKWArg.__init_subclass__r�r|csd�fdd�}t|��S)Nr�rrbr*cs�|�Sr,r0)r�rbr�r0r1�wrap�r�z$EnsureKWArg._wrap_w_kw.<locals>.wrap)r�rrbrr*rr)r]r�r�r0r�r1r��s
zEnsureKWArg._wrap_w_kwrW)r�r|r*r|)	rXrYrZr[r3r�r�r�rr0r0rr1r��s
	r�cCsht|d�r
t||�S|}|jj|_t|d�r|j|_t|jd�r+|jjr+|jj|_|S|jr2|j|_|S)z�Augment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    rXrYr[)r�rr~rXrYrr[)�wrapperr��_fr0r0r1�
wrap_callable�s




�r�cCs�d|vr	|�d�Sd}gg}d}t|�}||kr`||}|dkrC|dkr>||dkr>||ddkr>|d�d�|d7}n|dN}n|dkrQ|dkrQ|�g�n|d�|�|d7}||ksdd�|D�S)a�Parse a dotted identifier with accommodation for quoted names.

    Includes support for SQL-style double quotes as a literal character.

    E.g.::

        >>> quoted_token_parser("name")
        ["name"]
        >>> quoted_token_parser("schema.name")
        ["schema", "name"]
        >>> quoted_token_parser('"Schema"."Name"')
        ['Schema', 'Name']
        >>> quoted_token_parser('"Schema"."Name""Foo"')
        ['Schema', 'Name""Foo']

    �"r�rrr'cSsg|]}d�|��qS)r�)rt)rpr�r0r0r1rH1sz'quoted_token_parser.<locals>.<listcomp>)r�r*r�)rNr_r��idx�lv�charr0r0r1�quoted_token_parsers&
$

�r��paramscst������fdd�}|S)Ncs:|jdur|jp	d}|rt|�fdd��D��}||_|S)Nr�csi|]}|��qSr0r0)rp�paramr�r0r1r?:sz8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>)r[�inject_param_text)r�r��r�r�r0r1r�7s
z$add_parameter_text.<locals>.decorate)rrN)r�r�r�r0r�r1�add_parameter_text4s
r�cCsJ|�dd�}t|�dkr|S|\}}|�d�s |dt�|�St�|�S)N�
rrn)r�r*ru�textwrap�dedent)r��
split_text�	firstliner�r0r0r1�_dedent_docstringAs

r��
given_doctext�
injecttext�poscCs�t|pd�}|�d�}t|�dkr|�d�t�|��d�}|dr(|�dd�dd�t|�D�}|�dd�|t|t|�d�}|d|�|||d�}d�	|�S)Nr�r�rrcSsg|]
\}}|��s|�qSr0)r�)rpr[�liner0r0r1rHXsz)inject_docstring_text.<locals>.<listcomp>)
r�r�r*r�r�r�rrP�minrt)r�r�r��doctext�lines�injectlines�blanks�
inject_posr0r0r1�inject_docstring_textMs


r�z(\s+):param (.+?):r��
inject_params�Dict[str, str]c
Cst�|���}g}d}|r�|��}t�|�}|durO|rN|�d��d�}||vrNdt|�d��d}|rHt	�d|d�}	|	rHdt|	�d��}|||}n+|r\|�
d|dg�d}n|��sk|�
||dg�d}n|�d�rz|�
||��g�q|�
|�|s
d�|�S)	Nr�*rnrz(\s+)\Srr�z::)�collections�deque�
splitlines�popleft�
_param_regrAr��lstripr*rurc�rstriprvr�rt)
r�r��doclinesr��	to_injectr�rAr��indent�m2r0r0r1r�ds:
�

�
!r�r�cCs~t|�dkrdSt|�dk}|r|dd�n|dd�|dd�}dd�|D�}|r0d�|�Sd	d�|dd��|dfS)
z�Trims a list of strings from the middle and return a string of up to
    four elements. Strings greater than 11 characters will be truncatedrNrr�r'cSs,g|]}t|�dkrd|dd�n|�qS)�z%s..N)r*r�r0r0r1rH�s,z$repr_tuple_names.<locals>.<listcomp>rMz%s, ..., %s)r*rt)r��flag�resr0r0r1�repr_tuple_names�s(
r�cCstrdS|r
td��dS)NTzDcython extensions were expected to be installed, but are not presentF)r�ImportError)�raise_r0r0r1�has_compiled_ext�s�r�c@seZdZe��ZdS)�_MissingN)rXrYrZ�enum�auto�Missingr0r0r0r1r��sr�)r)rr*r+)r;rr*r<)r]r^r*r_)rhrr*r<r,)r]rkrlrmr*r<)ryrzr{r|r*r})r�r�r*r�)r�r�r�r<r*r�)r�r�rqr�r*r�)r�r|r*r�)r�r�r�r�r�r<r*r|)r]r5r�r�r�r�r*r�)r]r5r�r�r�r}r*r�)r	r|r*r
)FF)r�r|rr}r
r}r*r)T)r�rr�r}r*r)r0r0r0r0)r2rkr3r<r4r<r5r�r6r�r7r�r8r�r*r9)r0Nr0)
r)rrArBrCrDrEr�r*r<)NNrqN)NNNr�)r)rr*r})r�r<r*r�)rNrr*r�)TN)rbr�ror<rLrkr�r}r�r�r*rE)r)rr]rkr*r�)
r)r r]r^rrrbrr*r )r*r�)rrrJrr*r)r�rrr	rwr<r*r)F)
r�rrKrLrwr<rMr}r*rNr�)r	r|rrr<rr*r)rV)rar<r�rmr*rE)rar<rr\r*rE)rgr<rhrir*rj)Nr)rgrnrhrorpr�r*rE)r�r�r|r}r*r})r�r
r�r�r�r�r*r
)r�rr�r<r*rj)r�r<r*r<)r�rmr�r<r�r�r*r<)r�r<r�r�r*r<)r�r
r*rm)�r[�
__future__rr�r��	functoolsrr-r�r�rurFr�rr�r�typingrrrr	r
rrr
rrrrrrrrrrrrvr�rr�_has_cyrrrr r!r#r%r&r'r(�py310r.rBrCrgrjrxr�r�r�r�r�r�r�r�r�r�r�r�rrrr�r1r;r=r@rZr[rlrpr�r�r�r�r�r�r�r��non_memoized_property�property�ro_memoized_property�ro_non_memoized_propertyr�r��!HasMemoized_ro_memoized_attributer�r�r�r�r�r�r�r�r�rrr�rrr)r.r�r0r5r;rGrI�FastIntFlag�EnumrJrQrRrSrUrXr<rYrTrerfr3rm�compilerrrbr��_SQLA_RE�_UNITTEST_REr��NoneTyper�r�r�r�r�r�r�r�r�r�r�r�r�r�r��	MissingOrr0r0r0r1�<module>sn;�	G(���5�9�u%��N&�CV+M.��#<"
�"




�3�),
+