o
    gt                     @  s  U d Z ddlmZ ddlZddl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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* ddl%m+Z+ e"d Z,e"d!d"d#Z-e"d$ed%ef d&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Z5G d: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ZCG drds dsZDdtdu ZEedd%dvd\d}d~ZFedddvd]dd~ZFdddvd]dd~ZFd^ddZG	d_d`ddZH	"dadbddZIdaddZJ				dcddddZKdd ZLdd ZM			dedfddZNG dd dZOdd ZPdd ZQ				dgddZRdd ZSdhddZTe"ddd&ZUG dd dee- ZVG dd deVe- ZWG dd deVe- ZXe!r#eVZYeVZZe[Z\e[Z]neX ZYZ\eW ZZZ]diddZ^G dd dZ_e!r>e[Z`ne_jaZ`G dd dZbdjddĄZcdkddȄZddldd̄Ze	"	dmdnddՄZfdoddׄZgdpddڄZhdqdd݄Zi	dTdrddZjdsddZkdd ZlG dd de[ZmG dd dee, ZnG dd dee, ZoG dd dee, ZpG dd deqZrG dd desZtG dd detdZue!rddlmvZv evZwneuZwe"dejxd&Zy	dtdud dZzda{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Zi Zded< d{ddZe
dZ		d|d}dd Zd~d$d%Ze
d&Ze
d'Zeefdd,d-ZesdZd.d/ Ze
d0ZG d1d2 d2ZG d3d4 d4Zd5d6 Zd7d8 Zdd:d;Zdd<d=ZddAdBZe
dCZddGdHZddJdKZdtdLdMZG dNdO dOejxZejZe#e,e*ej f ZdS (  zRoutines 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_MPzmemoized_property[Any]_MAz#HasMemoized.memoized_attribute[Any]_HPzhybridproperty[Any]_HMzhybridmethod[Any]objr   returnMapping[str, Any]c                 C  s
   t | S N)inspectget_annotationsr)    r0   ]/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.pyr.   A      
r.   c                 C  s>   t | tr| jdd }nt| dd }|d u rtjS td|S )N__annotations__r+   )
isinstancetype__dict__getgetattrr   
EMPTY_DICTr   )r)   annr0   r0   r1   r.   F   s   

xstrc                 C  s*   |  d} t }||  tt| S )Nzutf-8)encoder   md5_not_for_securityupdater   r<   	hexdigest)r;   mr0   r0   r1   md5_hexW   s   

rB   c                   @  s2   e Zd ZU dZdZded< dddZdddZdS )safe_reraisea  Reraise 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]]rD   r*   Nonec                 C  s   t  | _d S r,   )sysexc_inforD   selfr0   r0   r1   	__enter__      zsafe_reraise.__enter__type_Optional[Type[BaseException]]valueOptional[BaseException]	tracebackOptional[types.TracebackType]r   c                 C  sZ   | j d usJ |d u r| j \}}}|d usJ d | _ ||d | _ |d us(J ||r,   )rD   with_traceback)rI   rL   rN   rP   exc_type	exc_valueexc_tbr0   r0   r1   __exit__   s   

zsafe_reraise.__exit__Nr*   rE   )rL   rM   rN   rO   rP   rQ   r*   r   )__name__
__module____qualname____doc__	__slots__r3   rJ   rV   r0   r0   r0   r1   rC   ^   s   
 

rC   clsType[_T]Iterator[Type[_T]]c                 c  sN    t  }| g}|r%| } | |v rq||  ||   | V  |s	d S d S r,   )setpopaddextend__subclasses__)r]   seenstackr0   r0   r1   walk_subclasses   s   
rg   elementc                 C  s4   t | tr| S zt| W S  ty   d|   Y S w )Nzunprintable element %r)r4   r<   	Exception)rh   r0   r0   r1   string_or_unprintable   s   

rj   	Type[Any]use_nameOptional[str]c                 C  s&   |p| j }ddd td|D S )N c                 s  s    | ]}|  V  qd S r,   )lower).0nr0   r0   r1   	<genexpr>       z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+|SQL))rX   joinrefindall)r]   rl   namer0   r0   r1   clsname_as_plain_name   s   
rx   instance_or_clsUnion[Type[Any], object]against_methodCallable[..., Any]boolc                 C  s.   t | ts	| j}n| }|j}t||}||kS )z1Return True if the two class methods don't match.)r4   r5   	__class__rX   r8   )ry   r{   current_clsmethod_namecurrent_methodr0   r0   r1   method_is_overridden   s   

r   slcsliceTuple[Any, ...]c                 C  s>   g }| j | j| jfD ]}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;   r0   r0   r1   decode_slice   s   
r   usedSequence[str]basesIterator[str]c                 '  sj    t | }|D ]+ t ft fddtd}|D ]}||vr+|| |V   nqtd  qd S )Nc                   s    t |  S r,   r<   )ibaser0   r1   <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symr0   r   r1   _unique_symbols   s    
r   fnCallable[[int], Any]rq   intIterator[Any]c                 c  s2    |r|| d @ }| |V  ||N }|sdS dS )z6Call the given function given each nonzero bit from n.r   Nr0   )r   rq   br0   r0   r1   map_bits   s   
r   _FntargetCallable[[_Fn], _Fn]c                   s   d fdd}t | S )z'A signature-matching decorator factory.r   r   r*   c           
        sN  t | st | stdt| }i }t||}ttd|d td|dd  | j	f }t
|dd\}}t||d}|t|d	d
 | j	|d< t | rZd|d< d|d< nd|d< d|d< dt|d v rod| }nd| }tj| j }|t| || || d| ji ttjt||| j	}	t| d| j|	_| |	_t|	| S )Nznot a decoratable functionzTuple[str, ...]r   r      r   r   )r   r   Fgroupedrw   zasync prefixzawait 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ismethodri   r   inspect_getfullargspec!_update_argspec_defaults_into_envr   r   rX   r   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   r0   r1   decorate   sN   





	
zdecorator.<locals>.decorateN)r   r   r*   r   r   )r   r   r0   r   r1   	decorator   s   
Ar   c                 C  sx   | j r:g }d}| j D ] }t|jdvr%d| }|||< || |d7 }q
|| q
t| }t||d< tj| S | S )zCgiven a FullArgSpec, convert defaults to be symbol names in an env.r   )builtins__builtin__zx%dr   r   )defaultsr5   rY   r   listr   r   FullArgSpec)r   r   new_defaultsr   argrw   elemr0   r0   r1   r   =  s   



r   r   Union[str, types.CodeType]r   Dict[str, Any]r   c                 C  s   t | | || S r,   )exec)r   r   r   r0   r0   r1   r   R  s   
r   _PF_TEc                   @  s6   e Zd Z	ddddZdd	 ZdddZdddZdS )PluginLoaderNgroupr<   auto_fnOptional[Callable[..., Any]]c                 C  s   || _ i | _|| _d S r,   )r   implsr   )rI   r   r   r0   r0   r1   __init__^  s   
zPluginLoader.__init__c                 C  s   | j   d S r,   )r   clearrH   r0   r0   r1   r   e  rK   zPluginLoader.clearrw   r*   r   c                 C  s   || j v r| j |  S | jr| |}|r|| j |< | S t| jD ]}|j|kr6|j| j |< |   S q#td| j|f )NzCan't load plugin: %s:%s)	r   r   r   importlib_metadata_getr   rw   loadr   NoSuchModuleError)rI   rw   loaderimplr0   r0   r1   r   h  s   



zPluginLoader.load
modulepathobjnamerE   c                   s    fdd}|| j |< d S )Nc                    s4   t  }  ddd  D ]}t| |} qt| S )N.r   )
__import__splitr8   )r   tokenr   r   r0   r1   r   |  s   
z#PluginLoader.register.<locals>.load)r   )rI   rw   r   r   r   r0   r   r1   register{  s   zPluginLoader.registerr,   )r   r<   r   r   )rw   r<   r*   r   )rw   r<   r   r<   r   r<   r*   rE   )rX   rY   rZ   r   r   r   r   r0   r0   r0   r1   r   ]  s    
r   c                 C  sh   zt j}W n ty   t| }|d t|d f Y S w | j}|j}t|j	d | t|j
|@ fS )Nr   r   )r-   CO_VARKEYWORDSAttributeErrorr   r   r}   __code__co_argcountr   co_varnamesco_flags)r   co_varkeywordsr   conargsr0   r0   r1   _inspect_func_args  s   

	r   )_setraiseerrr5   r   Optional[Set[str]]r   Literal[True]Set[str]c                C     d S r,   r0   r]   r   r   r0   r0   r1   get_cls_kwargs  s   r   Fc                C  r   r,   r0   r   r0   r0   r1   r     s   c          	      C  s   |du }|r	t  }|dusJ | jdd}|o$t|tjo$t|jtj}|rCt|\}}|	| |sB|sB|r@t
d|  ddS nd}|rI|rY| jD ]}t||ddu rX nqL|d |S )ae  Return 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`   r6   r7   r4   r   r   r   r   r   r?   	TypeError	__bases__r   discard)	r]   r   r   toplevelctrhas_initr   has_kwcr0   r0   r1   r     s8   




func	List[str]c                 C  s   t | d S )zReturn the set of legal kwargs for the given `func`.

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

    r   )r   r   )r	  r0   r0   r1   get_func_kwargs  s   r  no_self_is_initcompat.FullArgSpecc              	   C  s0  t | rtd|  t | r4|r/|r/t| }t|jdd |j|j	|j
|j|j|jS t| S t | rb|r\|s@| jr\t| j}t|jdd |j|j	|j
|j|j|jS t| jS t | rot| j|ddS t| drzt| jS t| drt | jrt| j|dS td	|  td	|  )
zReturn 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.

    zCan't inspect builtin: %sr   NT)r  r  r   __call__)r  zCan't inspect callable: %s)r-   	isbuiltinr  r   r   r   r   argsvarargsvarkwr   
kwonlyargskwonlydefaultsr   r   __self__r   isclassget_callable_argspecr   r   r  )r   r  r  r   r0   r0   r1   r    sN   









r  -Union[Callable[..., Any], compat.FullArgSpec]r   Dict[str, Optional[str]]c              	   C  s  t | r
t| }n| }tj| }t|d |d |d d|d }|d rB|d d }t|d dd |d |d d|d }n|d rOd|d  }|}nd}|}d}|d rf|tttt |d 7 }|d rr|t|d 7 }|d |d  }|r|d| d }	nd}	tj||d |d |	d	d
 d}
|d rtj|dd |d |d |	dd
 d}n|
}|rt||||
||dS t|||dd |
dd |dd |dd dS )a  Returns 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)'}

    r   r   r   N   z%s[0]r   r0   c                 S     dt |  S N=r   r;   r0   r0   r1   r   s  r   z%format_argspec_plus.<locals>.<lambda>)formatvaluec                 S  r  r  r   r  r0   r0   r1   r   |  r   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	callabler   r   inspect_formatargspeclenr   r   r   r   )r   r   r   r  r#  r"  r%  num_defaults	name_argsdefaulted_valsr$  r&  r0   r0   r1   r      sv   $
"
	



r   c                 C  sz   | t ju rd}|rdnd}|rdnd}nzt| |dW S  ty2   d}|r(|nd}|r.dnd	}Y nw td|||||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)rI   z()r   r   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r"  r!  r#  r$  r%  r&  )objectr   r   r  r   )methodr   r!  r  proxiedr0   r0   r1   format_argspec_init  s&   
r1  r0   
target_clstarget_cls_sphinx_nameproxy_cls_sphinx_nameclassmethodsmethods
attributesuse_intermediate_variableCallable[[_T], _T]c                 C  s   dd }|S )aS  A 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.

    c                 S  s   | S r,   r0   )r]   r0   r0   r1   r        z&create_proxy_methods.<locals>.decorater0   )r2  r3  r4  r5  r6  r7  r8  r   r0   r0   r1   create_proxy_methods  s   r;  c                 C  sJ   zt | W S  ty$   | tju rdgdddf Y S dgdddf Y S w )a  inspect.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)

    rI   Nr  kwargs)r   r   r  r.  r   )r/  r0   r0   r1   getargspec_init  s   
r=  c                 C  s   t | tjr| js| jS | S )zSAdjust the incoming callable such that a 'self' argument is not
    required.

    )r4   r   
MethodTyper  r   )func_or_clsr0   r0   r1   unbound_method_to_callable  s   r@  additional_kwSequence[Tuple[str, Any]]
to_inspect%Optional[Union[object, List[object]]]
omit_kwargc              	     s6  |du rg}nt |}t  g }t  }d}t|D ]p\}}zt|j}	W n	 ty1   Y qw |	j	r:t
|	j	nd}
|dkr_|	jrF|	j}|
rT||	jd|
   n||	jdd  n| fdd|	jd|
  D  |
r|	j	sxJ |dd t|	j|
 d |	j	D  qg }|fdd|D  |durt|r|d	d t|D  | D ]+\}}||v rqzt| }| ur||kr|d
||f  W q ty   Y qw |r|D ])\}}zt| }| ur||kr|d
||f  W q ty   Y qw djjd|f S )z}Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    Nr   r   c                   s   g | ]}| fqS r0   r0   rp   r   )missingr0   r1   
<listcomp>      z generic_repr.<locals>.<listcomp>c                 S  s   g | ]\}}||fqS r0   r0   )rp   r   defaultr0   r0   r1   rH    s    c                 3  s     | ]}t t |d V  qd S r,   )r   r8   rF  r/   r0   r1   rr   "  s    zgeneric_repr.<locals>.<genexpr>c                 S  s   g | ]}t |qS r0   r   )rp   valr0   r0   r1   rH  %  rI  z%s=%rz%s(%s), )r   to_listr.  OrderedDict	enumerater   r   r   r  r   r*  r  rc   r  r?   zipr   r8   itemsr   ri   r~   rX   rt   )r)   rA  rC  rE  pos_argskw_argsvargsr   inspr   default_lenoutputr   defvalrL  r0   )rG  r)   r1   generic_repr  sv   


rZ  c                   @  s6   e Zd ZdZdZdd Zdd Zddd	Zd
d ZdS )portable_instancemethodz_Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    )r   rw   r<  __weakref__c                 C  s   | j | j| jdS )Nr   rw   r<  r]  rH   r0   r0   r1   __getstate__E  s   z$portable_instancemethod.__getstate__c                 C  s&   |d | _ |d | _|dd| _d S )Nr   rw   r<  r0   )r   rw   r7   r<  )rI   stater0   r0   r1   __setstate__L  s   

z$portable_instancemethod.__setstate__r0   c                 C  s   |j | _|j| _|| _d S r,   )r  r   rX   rw   r<  )rI   methr<  r0   r0   r1   r   Q  s   
z portable_instancemethod.__init__c                 O  s$   | | j t| j| j|i |S r,   )r?   r<  r8   r   rw   )rI   r   kwr0   r0   r1   r  V  s   z portable_instancemethod.__call__N)r0   )	rX   rY   rZ   r[   r\   r^  r`  r   r  r0   r0   r0   r1   r[  =  s    
r[  c                   s   | h t | j}|rV| } fdd|jD }|D ]}||  | q|jdks1t|ds2q fdd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.

    c                 3  s    | ]	}| vr|V  qd S r,   r0   rp   _hierr0   r1   rr   j      z"class_hierarchy.<locals>.<genexpr>r   rd   c                   s   g | ]}| vr|qS r0   r0   rc  re  r0   r1   rH  s  s
    z#class_hierarchy.<locals>.<listcomp>)r   __mro__ra   r  r   rb   rY   r   
issubclassr5   rd   )r]   processr  r   r   sr0   re  r1   class_hierarchy[  s&   





	rl  c                 c  sB    t | }|D ]}| jD ]}||jv r||j| fV   nqqdS )ziterate 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)dirrh  r6   )r]   keyskeyr  r0   r0   r1   iterate_attributes  s   

rp  
self.proxyc              	     s.  |r|}ndu rd fddt |D }|D ]{}zt||}t|ds(W qt|d|}ttj|}	W n	 ty>   Y qw zt|	}
t	|
d }t	|
d dd }W n t
ye   d	}d
}Y nw dt  }|durs||ipti }t|| z|	j|| _W n	 ty   Y nw t |||  qdS )z9Automates delegation of __specials__ for a proxying type.N)r\   __del____getattribute____metaclass__r^  r`  c                   s6   g | ]}| d r|d rt |s|vr|qS )r   )
startswithendswithr   rp   rA   into_clsskipr0   r1   rH    s    z0monkeypatch_proxied_specials.<locals>.<listcomp>r  r   r   r   z(self, *args, **kw)z(*args, **kw)z?def %(method)s%(fn_args)s: return %(name)s.%(method)s%(d_args)s)rm  r8   r   r   r   r   r   r   r   r)  r  localsr   r   setattr)ry  from_clsrz  onlyrw   from_instancedundersr/  maybe_fnr   r   fn_argsd_argspyr   r0   rx  r1   monkeypatch_proxied_specials  sN   




r  c                 C  s   t | d| t |d|u S )z;Return True if the two methods are the same implementation.r   )r8   )meth1meth2r0   r0   r1   methods_equivalent  s   r  c                 C  sf  |s|st dt|trt| |r| S t|pdd t|D }tt| }tj}t|tr2|}n|s;t }tj}nt|}||||rI| S t| t	sc|tju rUdpVd}t d| |d
|f G dd	 d	}|rrd
|j |_t }	t| D ]'\}
}|
|vrt d|
 t|st d|
|f t||
t| |	|
 qy||	|r|S t d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 requiredc                 S  s   g | ]	}| d s|qS )rd  )ru  rw  r0   r0   r1   rH    s    z as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srM  c                   @     e Zd ZdZdS )z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.NrX   rY   rZ   r[   r0   r0   r0   r1   AnonymousInterface      r  	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %s)r  r4   r5   r`   rm  operatorgegtintersectionr   rt   rX   dictlike_iteritemsr(  r|  staticmethodrb   )r)   r]   r6  required	interfaceimplementedcomplies	qualifierr  foundr/  r   r0   r0   r1   as_interface  sP   !


r  _GFDzgeneric_fn_descriptor[Any]c                   @  s   e Zd ZU dZded< ded< ded< d%d&d
dZed'ddZed(ddZd)ddZer8d*ddZ	d+ddZ
d,d d!Zed-d#d$ZdS ).generic_fn_descriptorag  Descriptor 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]fgetrm   r[   r<   rX   Ndocc                 C     || _ |p|j| _|j| _d S r,   r  r[   rX   rI   r  r  r0   r0   r1   r   D     zgeneric_fn_descriptor.__init__rI   r  r)   rE   r]   r   r*   c                 C  r   r,   r0   rI   r)   r]   r0   r0   r1   __get__I  r:  zgeneric_fn_descriptor.__get__r.  r!   c                 C  r   r,   r0   r  r0   r0   r1   r  L  r:  Union[_GFD, _T_co]c                 C     t  r,   NotImplementedErrorr  r0   r0   r1   r  O     instancerN   c                 C  r   r,   r0   rI   r  rN   r0   r0   r1   __set__T      zgeneric_fn_descriptor.__set__c                 C  r   r,   r0   )rI   r  r0   r0   r1   
__delete__V  r  z generic_fn_descriptor.__delete__c                 C  r  r,   r  rI   r)   r0   r0   r1   _resetX  r  zgeneric_fn_descriptor._resetrw   c                 C  r  r,   r  r]   r)   rw   r0   r0   r1   reset[  s   zgeneric_fn_descriptor.resetr,   )r  r  r  rm   )rI   r  r)   rE   r]   r   r*   r  )r)   r.  r]   r   r*   r!   )rI   r  r)   r   r]   r   r*   r  r  r   rN   r   r*   rE   r  r   r*   rE   )r)   r   r*   rE   )r)   r   rw   r<   r*   rE   )rX   rY   rZ   r[   r3   r   r   r  r   r  r  r  classmethodr  r0   r0   r0   r1   r  5  s"   
 




r  c                   @  s    e Zd ZdZesdd ZdS dS )_non_memoized_propertyza 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.

    c                 C  s   |d u r| S |  |S r,   r  r  r0   r0   r1   r  k  s   
z_non_memoized_property.__get__N)rX   rY   rZ   r[   r   r  r0   r0   r0   r1   r  `  s
    r  c                   @  s0   e Zd ZdZesdd Zdd Zedd ZdS )	_memoized_propertyz2A read-only @property that is only evaluated once.c                 C  s&   |d u r| S |  | |j| j< }|S r,   )r  r6   rX   rI   r)   r]   resultr0   r0   r1   r  v  s   z_memoized_property.__get__c                 C  s   t || j d S r,   )r  r  rX   r  r0   r0   r1   r  |  s   z_memoized_property._resetc                 C  s   |j |d  d S r,   )r6   ra   r  r0   r0   r1   r    s   z_memoized_property.resetN)	rX   rY   rZ   r[   r   r  r  r  r  r0   r0   r0   r1   r  q  s    r  c                   s    fdd}t | S )zDecorate 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.

    c                   sB   | g|R i |  fdd}j |_ j|_|| jj <  S )Nc                        S r,   r0   arb  r  r0   r1   memo  r:  z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)rX   r[   r6   rI   r  rb  r  r   r  r1   oneshot  s   z(memoized_instancemethod.<locals>.oneshotr   )r   r  r0   r  r1   memoized_instancemethod  s   	
r  c                   @  sh   e Zd ZU dZesdZe Zded< dddZ	dd	d
Z
dddZG dd dee ZedddZdS )HasMemoizedzA mixin class that maintains the names of memoized elements in a
    collection for easy cache clearing, generative, etc.

    r0   zFrozenSet[str]_memoized_keysr*   rE   c                 C  s   | j D ]	}| j|d  qd S r,   )r  r6   ra   rI   r   r0   r0   r1   _reset_memoizations     
zHasMemoized._reset_memoizationsc                 C  s   | j D ]	}|| jvsJ qd S r,   )r  r6   r  r0   r0   r1   _assert_no_memoizations  r  z#HasMemoized._assert_no_memoizationsro  r<   rN   r   c                 C  s   || j |< |  j|hO  _d S r,   )r6   r  )rI   ro  rN   r0   r0   r1   _set_memoized_attribute  s   
z#HasMemoized._set_memoized_attributec                   @  sZ   e Zd ZU dZded< ded< ded< ddd
dZedddZedddZdd ZdS )zHasMemoized.memoized_attributezTA read-only @property that is only evaluated once.

        :meta private:

        Callable[..., _T]r  rm   r[   r<   rX   Nr  c                 C  r  r,   r  r  r0   r0   r1   r     r  z'HasMemoized.memoized_attribute.__init__rI   r&   r)   rE   r]   r   r*   c                 C  r   r,   r0   r  r0   r0   r1   r    r:  z&HasMemoized.memoized_attribute.__get__r    c                 C  r   r,   r0   r  r0   r0   r1   r    r:  c                 C  s8   |d u r| S |  | |j| j< }| j| jhO  _|S r,   )r  r6   rX   r  r  r0   r0   r1   r    s
   r,   )r  r  r  rm   )rI   r&   r)   rE   r]   r   r*   r&   )r)   r   r]   r   r*   r    )rX   rY   rZ   r[   r3   r   r   r  r0   r0   r0   r1   memoized_attribute  s   
 r  r   r#   c                   s   d	 fdd}t | S )
zMDecorate a method memoize its return value.

        :meta private:

        rI   r   r  rb  r*   c                   sT   | g|R i |  fdd}j |_ j|_|| jj < |  jj hO  _ S )Nc                    r  r,   r0   r  r  r0   r1   r    r:  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)rX   r[   r6   r  r  r  r  r1   r    s   z4HasMemoized.memoized_instancemethod.<locals>.oneshotN)rI   r   r  r   rb  r   r*   r   r   )r]   r   r  r0   r  r1   r    s   
z#HasMemoized.memoized_instancemethodNrW   )ro  r<   rN   r   r*   rE   r   r#   r*   r#   )rX   rY   rZ   r[   r   r\   	frozensetr  r3   r  r  r  memoized_propertyr    r  r  r  r0   r0   r0   r1   r    s   
 


r  c                   @  s&   e Zd ZdZdZdd Zdd	d
ZdS )MemoizedSlotszApply 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__.

    r0   c                 C  s   t |r,   )r   )rI   ro  r0   r0   r1   _fallback_getattr     zMemoizedSlots._fallback_getattrro  r<   r*   r   c                   s    ds
 drttjd r(td  }t| |S tjd rGtd   fdd} j|_|S S )N_memoized_attr__memoized_method_c                    s:   | i |  fdd}j |_ j|_t|  S )Nc                    r  r,   r0   r  r  r0   r1   r  )  r:  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)rX   r[   r|  )r  rb  r  r   ro  rI   r  r1   r  &  s   z*MemoizedSlots.__getattr__.<locals>.oneshot)ru  r   r   r~   r8   r|  r[   r  )rI   ro  rN   r  r0   r  r1   __getattr__  s   
zMemoizedSlots.__getattr__N)ro  r<   r*   r   )rX   rY   rZ   r[   r\   r  r  r0   r0   r0   r1   r  
  s
    r  c                 C  sB   t | tr|   } | dv rdS | dv rdS td|  t| S )N)trueyesonyt1T)falsenooffrq   f0FzString is not true/false: %r)r4   r<   stripro   
ValueErrorr}   r/   r0   r0   r1   asbool8  s   
r  text!Callable[[str], Union[str, bool]]c                    s   d fdd}|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]c                   s   |  v r| S t | S r,   )r  r/   r  r0   r1   bool_or_valueJ  s   z"bool_or_str.<locals>.bool_or_valueN)r)   r<   r*   r  r0   )r  r  r0   r  r1   bool_or_strD  s   r  rN   Optional[int]c                 C  s   | du r| S t | S )zCoerce to integer.N)r   )rN   r0   r0   r1   asintS  s   r  rb  ro  rL   
flexi_booldestOptional[Dict[str, Any]]rE   c                 C  sx   |du r| }|| v r6t |trt | | |s:| | dur8|tu r,|r,t| | ||< dS || | ||< dS dS dS dS )zIf '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)r4   r5   r}   r  )rb  ro  rL   r  r  r0   r0   r1   coerce_kw_type[  s   r  c                   s$   t |}|ft fdd|D  S )zbProduce a tuple structure that is cacheable using the __dict__ of
    obj to retrieve values

    c                 3  (    | ]}| j v r| j | fV  qd S r,   r6   rp   kr/   r0   r1   rr   {      z"constructor_key.<locals>.<genexpr>)r   r   )r)   r]   r   r0   r/   r1   constructor_keyu  s   
r  r  c                   s4   t |}| fdd||D  ||i |S )zInstantiate cls using the __dict__ of obj as constructor arguments.

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

    c                 3  r  r,   r  r  r/   r0   r1   rr     r  z#constructor_copy.<locals>.<genexpr>)r   r?   
difference)r)   r]   r  rb  r   r0   r/   r1   constructor_copy  s
   r  Callable[[], int]c                    s$   t  td  fdd} | S )z%Return a threadsafe counter function.r   c                     s0    t  W  d    S 1 sw   Y  d S r,   )nextr0   counterlockr0   r1   _next  s   $zcounter.<locals>._next)	threadingLockr   count)r  r0   r  r1   r    s   
r  specimenrJ  Optional[Type[Any]]c                 C  s   t | dr| jdurt| jtrtS | jS t| trtnt}|| tr%tS || tr,tS || tr3tS t | dr:tS t | drAtS t | drHtS |S )zGiven 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   rb   r`   )r   r  ri  r`   r4   r5   r   r   )r  rJ  isar0   r0   r1   duck_type_collection  s(   






r  r   argtype'Union[Tuple[Type[Any], ...], Type[Any]]rw   c                 C  sX   t | |r| S t |tr td|ddd |D t| f td||t| f )Nz8Argument '%s' is expected to be one of type %s, got '%s'z or c                 s  s    | ]}d | V  qdS )z'%s'Nr0   )rp   r  r0   r0   r1   rr     rs   z"assert_arg_type.<locals>.<genexpr>z6Argument '%s' is expected to be of type '%s', got '%s')r4   r   r   ArgumentErrorrt   r5   )r   r  rw   r0   r0   r1   assert_arg_type  s   

r  c                   s   t  drt  S t dt dddu rtd  t  dr. fdd}| S t  d	r@tfd
d  D S td  )z?Return a (key, value) iterator for almost any dict-like object.rR  __getitem__r7   NzObject '%r' is not dict-likeiterkeysc                  3  s.       D ]} d usJ | | fV  qd S r,   )r  )ro  dictlikegetterr0   r1   iterator  s
   z$dictlike_iteritems.<locals>.iteratorrn  c                 3  s    | ]	}| |fV  qd S r,   r0   )rp   ro  )r  r0   r1   rr     rg  z%dictlike_iteritems.<locals>.<genexpr>)r   r   rR  r8   r  iterrn  )r  r  r0   r  r1   r    s   


r  c                      s8   e Zd ZU dZded< d fddZddddZ  ZS )classpropertyaA  A 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   r   rb  c                   s&   t  j|g|R i | |j| _d S r,   )superr   r[   )rI   r  r   rb  r~   r0   r1   r     s   zclassproperty.__init__Nr)   r]   Optional[type]r*   c                 C  s
   |  |S r,   r  r  r0   r0   r1   r    r2   zclassproperty.__get__)r  r  r   r   rb  r   r,   )r)   r   r]   r  r*   r   )rX   rY   rZ   r[   r3   r   r  __classcell__r0   r0   r  r1   r    s
   
 
r  c                   @  s*   e Zd ZdddZdd
dZdddZdS )hybridpropertyr	  r  c                 C  s   || _ || _d S r,   )r	  clslevelrI   r	  r0   r0   r1   r     s   
zhybridproperty.__init__r  r   ownerr*   r    c                 C      |d u r|  |}|S | |S r,   r  r	  rI   r  r  clsvalr0   r0   r1   r       

zhybridproperty.__get__r|   hybridproperty[_T]c                 C  
   || _ | S r,   r  r  r0   r0   r1   
classlevel
     zhybridproperty.classlevelNr	  r  r  r   r  r   r*   r    )r	  r|   r*   r"  )rX   rY   rZ   r   r  r%  r0   r0   r0   r1   r    s    

r  c                   @  s>   e 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 )rw_hybridpropertyr	  r  c                 C  s   || _ || _d | _d S r,   )r	  r  setfnr  r0   r0   r1   r     s   
zrw_hybridproperty.__init__r  r   r  r*   r    c                 C  r  r,   r  r  r0   r0   r1   r    r!  zrw_hybridproperty.__get__rN   rE   c                 C  s   | j d usJ |  || d S r,   r*  r  r0   r0   r1   r    s   zrw_hybridproperty.__set__r|   rw_hybridproperty[_T]c                 C  r#  r,   r+  r  r0   r0   r1   setter   r&  zrw_hybridproperty.setterc                 C  r#  r,   r$  r  r0   r0   r1   r%  $  r&  zrw_hybridproperty.classlevelNr'  r(  r  )r	  r|   r*   r,  )rX   rY   rZ   r   r  r  r-  r%  r0   r0   r0   r1   r)    s    



r)  c                   @  s.   e Zd ZdZdddZdd
dZdddZdS )hybridmethodz/Decorate a function as cls- or instance- level.r	  r  c                 C  s   | | _ | _|| _d S r,   )r	  r   r  r  r0   r0   r1   r   ,  s   
zhybridmethod.__init__r  r   r  r*   c                 C  s&   |d u r| j ||jS | j||S r,   )r  r  r~   r	  )rI   r  r  r0   r0   r1   r  0  s   zhybridmethod.__get__r|   hybridmethod[_T]c                 C  r#  r,   r$  r  r0   r0   r1   r%  6  r&  zhybridmethod.classlevelNr'  )r  r   r  r   r*   r  )r	  r|   r*   r/  )rX   rY   rZ   r[   r   r  r%  r0   r0   r0   r1   r.  )  s
    

r.  c                   @  sV   e Zd ZU dZded< i Zded< e Z		ddddZ	dd Z
dd Zdd ZdS )symbolaI  A 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<   rw   zDict[str, symbol]symbolsNr  rm   	canonicalr  r*   c                 C  s   | j G | j|}|d u r1t|tsJ |d u rt|}tt|}||_	|r+||_
|| j|< n|rA||krAtd|d| |W  d    S 1 sMw   Y  d S )Nz#Can't replace canonical symbol for z with new int value )_lockr1  r7   r4   r<   hashr   __new__r0  rw   r[   r  )r]   rw   r  r2  r   r0   r0   r1   r5  O  s&   $zsymbol.__new__c                 C  s   t | jdt| ffS )Nr;   )r0  rw   r   rH   r0   r0   r1   
__reduce__m  s   zsymbol.__reduce__c                 C  s   t | S r,   rK  rH   r0   r0   r1   __str__p  r  zsymbol.__str__c                 C  s   d| j dS )Nzsymbol()rw   rH   r0   r0   r1   __repr__s  rK   zsymbol.__repr__)NN)rw   r<   r  rm   r2  r  r*   r0  )rX   rY   rZ   r[   r3   r1  r   r  r3  r5  r6  r7  r:  r0   r0   r0   r1   r0  ;  s   
 r0  c                   @  s    e Zd ZdddZdddZdS )_IntFlagMeta	classnamer<   r   Tuple[Type[Any], ...]dict_r   rb  r   r*   rE   c           	      K  s   g  | _ }| D ],\}}td|rq	t|tr t||d}n
|ds)tdq	t	| || |
| q	tdd |D | _d S )Nz^__.*__$)r2  rd  z#Expected integer values for IntFlagc                 S  s   i | ]}|j |qS r0   r9  )rp   r   r0   r0   r1   
<dictcomp>  rI  z)_IntFlagMeta.__init__.<locals>.<dictcomp>)_itemsrR  ru   matchr4   r   r0  ru  r  r|  r   r   immutabledict__members__)	r]   r<  r   r>  rb  rR  r  vr   r0   r0   r1   r   x  s   



z_IntFlagMeta.__init__Iterator[symbol]c                 C  s   t d)Nziter not implemented to ensure compatibility with Python 3.11 IntFlag.  Please use __members__.  See https://github.com/python/cpython/issues/99304r  rH   r0   r0   r1   __iter__  s   z_IntFlagMeta.__iter__N)
r<  r<   r   r=  r>  r   rb  r   r*   rE   )r*   rE  )rX   rY   rZ   r   rF  r0   r0   r0   r1   r;  w  s    
r;  c                   @  r  )_FastIntFlagzAn 'IntFlag' copycat that isn't slow when performing bitwise
    operations.

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

    Nr  r0   r0   r0   r1   rG    r  rG  )	metaclass)IntFlag_EchoicesDict[_E, List[Any]]resolve_symbol_namesOptional[_E]c                 C  sj   |  D ]\}}| |u r|  S |r| |jkr|  S | |v r#|  S q| du r*dS td| d| )aO  Given 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.

    NzInvalid value for 'z': )rR  rw   r   r
  )r   rK  rw   rM  
enum_valuechoicer0   r0   r1   parse_user_argument_for_enum  s   rQ  r  c                 C  s   t | _ t d7 a dS )zAssign 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).

    r   N)_creation_order)r  r0   r0   r1   set_creation_order  s   	rS  r<  c                 O  s>   z| |i |W S  t y   tdt dd   Y dS w )zXexecutes the given function, catches all exceptions and converts to
    a warning.

    z%s('%s') ignoredr   r   N)ri   warnrF   rG   )r	  r  r<  r0   r0   r1   warn_exception  s
   rU     c                 C  s<   zt | |krd| d|  W S | W S  ty   |  Y S w )Nz%s...r   )r*  r  )rN   len_r0   r0   r1   ellipses_string  s   rX  c                      s@   e Zd ZU dZded< d fd
dZdddZdddZ  ZS )_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   _hashrN   r<   numr  Sequence[Any]r*   c                   s<   || d|  }t  | |}td|t|| f |_|S )Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)r  r5  r4  rZ  )r]   rN   r[  r  interpolatedrI   r  r0   r1   r5    s   z_hash_limit_string.__new__c                 C  s   | j S r,   )rZ  rH   r0   r0   r1   __hash__  r  z_hash_limit_string.__hash__otherr   r}   c                 C  s   t | t |kS r,   )r4  )rI   r_  r0   r0   r1   __eq__  s   z_hash_limit_string.__eq__)rN   r<   r[  r   r  r\  r*   rY  )r*   r   )r_  r   r*   r}   )	rX   rY   rZ   r[   r3   r5  r^  r`  r  r0   r0   r  r1   rY    s   
 


rY  msgc                 C  s*   |rt tj| |d dS t | tj dS )zdIssue a warning.

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

    )r   N)_warnings_warnr   	SAWarning)ra  r   r0   r0   r1   rT    s   rT  r\  c                 C  s    |rt | d|} t| tj dS )z\Issue a warning with a parameterized string, limiting the number
    of registrations.

    
   N)rY  rb  r   rc  )ra  r  r0   r0   r1   warn_limited   s   re  z)Dict[CodeType, Tuple[str, Type[Warning]]]_warning_tagsmessagecategoryType[Warning]Callable[[_F], _F]c                   s    fdd}|S )Nc                   s    ft | j< | S r,   )rf  r   r  rh  rg  r0   r1   go0  s   z#tag_method_for_warnings.<locals>.gor0   )rg  rh  rl  r0   rk  r1   tag_method_for_warnings-  s   rm  z&^(?:sqlalchemy\.(?!testing)|alembic\.)Union[str, Warning]Optional[Type[Warning]]
stacklevelc                 C  s   zt |}W n ty   d}Y nK   d}Y nDd }}|d ur]|s0tt|jdds0d}|jt	v rJd}t	|j \}}|pA|}|  d| d} |j
}|sT|d7 }n|rY|rYn|d us!|d urmtj| ||d d	 d S tj| |d d	 d S )
Nr   FrX   r   Tz (r8  r   )rp  )rF   	_getframer  ru   rA  _not_sa_pattern	f_globalsr7   f_coderf  f_backwarningsrT  )rg  rh  rp  framestacklevel_foundwarning_tag_found_suffix	_categoryr0   r0   r1   rb  :  s4   

rb  r  retry_on_exceptionCallable[..., Optional[_T]]c                   s    gd	 fdd}|S )
zNDecorate the given function to be a no-op after it is called exactly
    once.r   r   rb  r*   Optional[_T]c                    s>    }r  }z|| i |W S    rd|  d S )Nr   )ra   insert)r   rb  	strong_fnonce_fnr   oncer|  r0   r1   rl  u  s   zonly_once.<locals>.goN)r   r   rb  r   r*   r~  r0   )r   r|  rl  r0   r  r1   	only_oncem  s   r  z%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)tbexclude_prefixre.Pattern[str]exclude_suffixc                 C  s   d}t | d }||kr"|| | r"|d7 }||kr"|| | s||kr<|| | r<|d8 }||kr<|| | s-| ||d  S )at  Chop 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``
    r   r   )r*  search)r  r  r  r   endr0   r0   r1   chop_traceback  s   r  c                 C  s$   d|  }t   }t|| |d S )Nz&def set(obj, value):    obj.%s = valuer`   )r{  copyr   )attrnamer   r   r0   r0   r1   
attrsetter  s   

r  z^__.+__$c                      s&   e Zd ZdZdZd fddZ  ZS )
TypingOnlyzA mixin class that marks a class as 'typing only', meaning it has
    absolutely no methods, attributes, or runtime functionality whatsoever.

    r0   r*   rE   c                   sB   t | jv rdd | jD }|rtd|  d| dt   d S )Nc                 S  s   h | ]	}t |s|qS r0   )_dundersrA  rp   rw   r0   r0   r1   	<setcomp>  s
    
z/TypingOnly.__init_subclass__.<locals>.<setcomp>zClass z< directly inherits TypingOnly but has additional attributes r   )r  r  r6   AssertionErrorr  __init_subclass__)r]   	remainingr  r0   r1   r    s   
zTypingOnly.__init_subclass__rW   )rX   rY   rZ   r[   r\   r  r  r0   r0   r  r1   r    s    r  c                      s<   e Zd ZU dZded< 	 d fddZedd
dZ  ZS )EnsureKWArga6  Apply 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*   rE   c                   sf   | j }| j}|r,|D ]!}t||}|r+|| }t|}|js+| |}t| || q
t	 
  d S r,   )r  r6   ru   rA  r   r   r  
_wrap_w_kwr|  r  r  )r]   fn_regclsdictro  rA   r   r   wrappedr  r0   r1   r    s   

zEnsureKWArg.__init_subclass__r   r|   c                   s   d fdd}t | S )Nr   r   rb  r*   c                    s    |  S r,   r0   )r   rb  r  r0   r1   wrap  r  z$EnsureKWArg._wrap_w_kw.<locals>.wrap)r   r   rb  r   r*   r   r   )r]   r   r  r0   r  r1   r    s   
zEnsureKWArg._wrap_w_kwrW   )r   r|   r*   r|   )	rX   rY   rZ   r[   r3   r  r  r  r  r0   r0   r  r1   r    s   
 	r  c                 C  sh   t |dr
t| |S | }|jj|_t |dr|j|_t |jdr+|jjr+|jj|_|S |jr2|j|_|S )zAugment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    rX   rY   r[   )r   r   r~   rX   rY   r  r[   )wrapperr   _fr0   r0   r1   wrap_callable  s   




r  c                 C  s   d| vr	|  dS d}g g}d}t| }||k r`| | }|dkrC|dkr>||d k r>| |d  dkr>|d d |d7 }n|dN }n|dkrQ|dkrQ|g  n|d | |d7 }||k sdd |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   r   r   r'  c                 S  s   g | ]}d  |qS )r   )rt   )rp   r   r0   r0   r1   rH  1  s    z'quoted_token_parser.<locals>.<listcomp>)r   r*  r   )rN   r_  r  idxlvcharr0   r0   r1   quoted_token_parser  s&   
$

r  paramsc                   s   t    fdd}|S )Nc                   s:   | j d ur| j p	d}|rt|fdd D }|| _ | S )Nr   c                   s   i | ]}| qS r0   r0   )rp   paramr  r0   r1   r?  :  s    z8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>)r[   inject_param_text)r   r  r  r  r0   r1   r   7  s
   z$add_parameter_text.<locals>.decorate)r   rN  )r  r  r   r0   r  r1   add_parameter_text4  s   
r  c                 C  sJ   |  dd}t|dkr| S |\}}|ds |d t| S t| S )N
r   rn   )r   r*  ru  textwrapdedent)r  
split_text	firstliner  r0   r0   r1   _dedent_docstringA  s   

r  given_doctext
injecttextposc                 C  s   t | pd}|d}t|dkr|d t|d}|d r(|dd dd t|D }|dd |t|t|d  }|d| | ||d   }d	|S )Nr   r  r   r   c                 S  s   g | ]
\}}|  s|qS r0   )r  )rp   r[  liner0   r0   r1   rH  X  s    z)inject_docstring_text.<locals>.<listcomp>)
r  r   r*  r   r  r  r  rP  minrt   )r  r  r  doctextlinesinjectlinesblanks
inject_posr0   r0   r1   inject_docstring_textM  s   


r  z(\s+):param (.+?):r  inject_paramsDict[str, str]c           
      C  s  t |  }g }d }|r| }t|}|d u rO|rN|dd}||v rNdt|d d }|rHt	d|d }	|	rHdt|	d }|||  }n+|r\|
d|dg d }n| sk|
||dg d }n|drz|
|| g q|| |sd|S )	Nr   *rn   r   z(\s+)\Sr   r  z::)collectionsdeque
splitlinespopleft
_param_regrA  r   lstripr*  ru   rc   rstriprv  r   rt   )
r  r  doclinesr  	to_injectr  rA   r  indentm2r0   r0   r1   r  d  s:   



!r  r   c                 C  s~   t | dkrdS t | dk}|r| dd n| dd | dd  } dd | D }|r0d|S d	d|dd |d f S )
zTrims a list of strings from the middle and return a string of up to
    four elements. Strings greater than 11 characters will be truncatedr   Nr  r   r'  c                 S  s,   g | ]}t |d krd|dd   n|qS )   z%s..N)r*  r  r0   r0   r1   rH    s   , z$repr_tuple_names.<locals>.<listcomp>rM  z%s, ..., %s)r*  rt   )r   flagresr0   r0   r1   repr_tuple_names  s   (
r  c                 C  s   t rdS | r
tddS )NTzDcython extensions were expected to be installed, but are not presentF)r   ImportError)raise_r0   r0   r1   has_compiled_ext  s   r  c                   @  s   e Zd Ze ZdS )_MissingN)rX   rY   rZ   enumautoMissingr0   r0   r0   r1   r    s    r  )r)   r   r*   r+   )r;   r   r*   r<   )r]   r^   r*   r_   )rh   r   r*   r<   r,   )r]   rk   rl   rm   r*   r<   )ry   rz   r{   r|   r*   r}   )r   r   r*   r   )r   r   r   r<   r*   r   )r   r   rq   r   r*   r   )r   r|   r*   r   )r   r   r   r   r   r<   r*   r|   )r]   r5   r   r   r   r   r*   r   )r]   r5   r   r   r   r}   r*   r   )r	  r|   r*   r
  )FF)r   r|   r  r}   r  r}   r*   r  )T)r   r  r   r}   r*   r  )r0   r0   r0   r0   )r2  rk   r3  r<   r4  r<   r5  r   r6  r   r7  r   r8  r   r*   r9  )r0   Nr0   )
r)   r   rA  rB  rC  rD  rE  r   r*   r<   )NNrq  N)NNNr  )r)   r   r*   r}   )r  r<   r*   r  )rN   r   r*   r  )TN)rb  r   ro  r<   rL   rk   r  r}   r  r  r*   rE   )r)   r   r]   rk   r*   r   )
r)   r    r]   r^   r  r   rb  r   r*   r    )r*   r  )r  r   rJ  r  r*   r  )r   r   r  r	  rw   r<   r*   r   )F)
r   r   rK  rL  rw   r<   rM  r}   r*   rN  r  )r	  r|   r  r   r<  r   r*   r   )rV  )ra  r<   r   rm   r*   rE   )ra  r<   r  r\  r*   rE   )rg  r<   rh  ri  r*   rj  )Nr   )rg  rn  rh  ro  rp  r   r*   rE   )r   r  r|  r}   r*   r}  )r  r
  r  r  r  r  r*   r
  )r  r   r  r<   r*   rj  )r  r<   r*   r<   )r  rm   r  r<   r  r   r*   r<   )r  r<   r  r  r*   r<   )r   r
  r*   rm   )r[   
__future__r   r  r  	functoolsr   r-   r   r  ru   rF   r  r   r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rv  r   r   r   _has_cyr   r   r   r    r!   r#   r%   r&   r'   r(   py310r.   rB   rC   rg   rj   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r1  r;  r=  r@  rZ  r[  rl  rp  r  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  r  r  r  r  r  r)  r.  r   r0  r5   r;  rG  rI  FastIntFlagEnumrJ  rQ  rR  rS  rU  rX  r<   rY  rT  re  rf  r3   rm  compilerr  rb  r  _SQLA_RE_UNITTEST_REr  NoneTyper  r  r  r  r  r  r  r  r  r  r  r  r  r  r  	MissingOrr0   r0   r0   r1   <module>   sn  ;	G(59u%N&CV+M.#<"
"


3),+