o
    . h                    @  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(dd/l4m5Z5 dd0l4m6Z6 d1d2 Z7e8j9d3 j:Z;d4d5 Z<dZd<d=Z=d[d>d?Z>ne'j?r3d[d@d?Z>nd[dAd?Z>d\dDdEZ@G dFdG dGZAd]dKdLZBd^dNdOZC	d_d`dSdTZDdadZd[ZEdbd_d`ZFdcdedfZGdddldmZHe"dndXd&ZIdedqdrZJdfdxdyZKe"dzZLe"d{ZMG d|d} d}ZNd~d ZOedd%ddgddZPeddddhddZPddddhddZPdiddZQ	djdkddZR	"dldmddZSdlddZT				dndoddZUdd ZVdd ZW			dpdqddZXG dd dZYdd ZZdd Z[				drddZ\dd Z]dsddZ^e"ddd&Z_G dd dee- Z`G ddĄ de`e- ZaG ddƄ de`e- Zbe!rJe`Zce`ZdeeZfeeZgneb ZcZfea ZdZgdtddȄZhG ddʄ dʃZie!reeeZjneijkZjG dd̄ d̃Zldudd΄Zmdvdd҄ZndwddքZo	"	dxdydd߄ZpdzddZqd{ddZrd|ddZs	d_d}ddZtd~ddZudd ZvG dd deeZwG dd dee, ZxG dd dee, ZyG dd dee, ZzG dd de{Z|G dd  d e8Z}G dd de}dZ~e!rddlmZ eZne~Ze"dejd&Z	ddd
dZdadddZdddZdddZG dd deZd_dddZdddZi Zded< dd#d$Ze
d%Z		ddd)d*Zdd.d/Ze
d0Ze
d1Zeefdd6d7Ze8dZd8d9 Ze
d:ZG d;d< d<ZG d=d> d>Zd?d@ ZdAdB ZddDdEZddFdGZddKdLZe
dMZddQdRZddTdUZddVdWZG dXdY dYej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])call_annotate_function)Formatc                 C  sB   t | dd }|d urt||| d}t|tst| d|S d S )N__annotate__)ownerz!.__annotate__ returned a non-dict)getattrr)   
isinstancedict
ValueError)objformatZannotateann r4   c/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py_get_and_call_annotateF   s   
r6   __annotations__c                 C  sf   t | trzt| }W n ty   i  Y S w t| dd }|d u r#i S t |ts/t| dt|S )Nr7   z+.__annotations__ is neither a dict nor None)r.   type_BASE_GET_ANNOTATIONSAttributeErrorr-   r/   r0   r1   r3   r4   r4   r5   _get_dunder_annotationsR   s   

r<   r1   r   r2   r*   returnMapping[str, Any]c                C  s   zt | }W n	 ty   Y n	w |durt|S t| |}|du r%t | }|du r;t| ts2t| r4i S t| d|s?i S t|S )z:A sparse implementation of annotationlib.get_annotations()Nz does not have annotations)r<   	Exceptionr/   r6   r.   r8   callable	TypeError)r1   r2   r3   r4   r4   r5   _vendored_get_annotationsd   s"   
rB   c                 C  s   t | tjdS )N)r2   )rB   r*   
FORWARDREFr1   r4   r4   r5   get_annotations   s   rE   c                 C  s
   t | S N)inspectrE   rD   r4   r4   r5   rE         
c                 C  s>   t | tr| jdd }nt| dd }|d u rtjS td|S )Nr7   r>   )r.   r8   __dict__getr-   r   
EMPTY_DICTr   r;   r4   r4   r5   rE      s   

xstrc                 C  s*   |  d} t }||  tt| S )Nzutf-8)encoder   md5_not_for_securityupdater   rM   	hexdigest)rL   mr4   r4   r5   md5_hex   s   

rS   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]]rU   r=   Nonec                 C  s   t  | _d S rF   )sysexc_inforU   selfr4   r4   r5   	__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 ||rF   )rU   with_traceback)rZ   r]   r_   ra   exc_type	exc_valueexc_tbr4   r4   r5   __exit__   s   

zsafe_reraise.__exit__Nr=   rV   )r]   r^   r_   r`   ra   rb   r=   r   )__name__
__module____qualname____doc__	__slots__r7   r[   rg   r4   r4   r4   r5   rT      s   
 

rT   clsType[_T]Iterator[Type[_T]]c                 c  sN    t  }| g}|r%| } | |v rq||  ||   | V  |s	d S d S rF   )setpopaddextend__subclasses__)rn   seenstackr4   r4   r5   walk_subclasses   s   
rx   elementc                 C  s4   t | tr| S zt| W S  ty   d|   Y S w )Nzunprintable element %r)r.   rM   r?   )ry   r4   r4   r5   string_or_unprintable   s   

rz   	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 rF   )lower).0nr4   r4   r5   	<genexpr>      z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+|SQL))ri   joinrefindall)rn   r|   namer4   r4   r5   clsname_as_plain_name   s   
r   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.)r.   r8   	__class__ri   r-   )r   r   Zcurrent_clsmethod_nameZcurrent_methodr4   r4   r5   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   retrL   r4   r4   r5   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 rF   rM   )ibaser4   r5   <lambda>+      z!_unique_symbols.<locals>.<lambda>i  z&exhausted namespace for symbol base %s)rq   	itertoolschainmaprangers   	NameError)r   r   Zused_setpoolsymr4   r   r5   _unique_symbols&  s    
r   fnCallable[[int], Any]r   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   Nr4   )r   r   br4   r4   r5   map_bits6  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                   s  t | st | stdt| dd }|d ur*d | _z
t| }W || _n	|| _w t| }dt|j	p5d }t
|jp>d}|ji ||d}ttd|d td|dd	  | jf }t|d
d\}}t
||d}|t|dd | j|d< t | rd|d< d|d< nd|d< d|d< dt|d v rd| }	nd| }	| || d| ji}
ttjt|	|
| j}| j|_| j|_t|| S )Nznot a decoratable functionr+   rF   r4   )r   defaultskwonlydefaultszTuple[str, ...]r   r      r   r   )r   r   Fgroupedr   zasync prefixzawait Z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)
ri   )rG   
isfunctionismethodr?   r-   r+   r   inspect_getfullargspeclenr   r/   fromkeysr   _replacer   r   ri   r   rP   format_argspec_plusiscoroutinefunctionreprrj   typesFunctionType_exec_code_in_env__defaults____kwdefaults__r   )r   ZannofuncspecZempty_defaultsZempty_kwdefaultsnamesZ	targ_namefn_namemetadatacodeenvZ	decoratedr   r4   r5   decorateG  sf   




		
zdecorator.<locals>.decorateN)r   r   r=   r   r   )r   r   r4   r   r5   	decoratorD  s   
Vr   r   Union[str, types.CodeType]r   Dict[str, Any]r   c                 C  s   t | | || S rF   )exec)r   r   r   r4   r4   r5   r     s   
r   _PF_TEc                   @  s@   e Zd Z	ddddZdd	 ZdddZdddZdddZdS )PluginLoaderNgrouprM   auto_fnOptional[Callable[..., Any]]c                 C  s   || _ i | _|| _d S rF   )r   implsr   )rZ   r   r   r4   r4   r5   __init__  s   
zPluginLoader.__init__c                 C  s   | j   d S rF   )r   clearrY   r4   r4   r5   r     r\   zPluginLoader.clearr   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   r   loadr   NoSuchModuleError)rZ   r   loaderimplr4   r4   r5   r     s   



zPluginLoader.load
modulepathobjnamerV   c                   s    fdd}|| j |< d S )Nc                    s4   t  }  ddd  D ]}t| |} qt| S )N.r   )
__import__splitr-   )modtokenr   r   r4   r5   r     s   
z#PluginLoader.register.<locals>.loadr   )rZ   r   r   r   r   r4   r   r5   register  s   zPluginLoader.registerc                 C  s   | j |= d S rF   r   )rZ   r   r4   r4   r5   
deregister  s   zPluginLoader.deregisterrF   )r   rM   r   r   )r   rM   r=   r   )r   rM   r   rM   r   rM   r=   rV   )r   rM   r=   rV   )ri   rj   rk   r   r   r   r   r   r4   r4   r4   r5   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   )rG   CO_VARKEYWORDSr:   r   r   r   __code__co_argcountlistco_varnamesco_flags)r   Zco_varkeywordsr   conargsr4   r4   r5   _inspect_func_args  s   

	r   )_setraiseerrr8   r   Optional[Set[str]]r   Literal[True]Set[str]c                C     d S rF   r4   rn   r   r   r4   r4   r5   get_cls_kwargs  s   r  Fc                C  r  rF   r4   r  r4   r4   r5   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   rZ   )rq   rI   rJ   r.   r   r   r   r   r   rP   rA   	__bases__r  discard)	rn   r   r   toplevelZctrZhas_initr   Zhas_kwcr4   r4   r5   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  r4   r4   r5   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  __func____call__)r  zCan't inspect callable: %s)rG   	isbuiltinrA   r   r   r   FullArgSpecargsvarargsvarkwr   
kwonlyargsr   r   r   __self__r  isclassget_callable_argspecr   r   r  )r   r  r  r   r4   r4   r5   r  9  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   r4   c                 S     dt |  S N=r   rL   r4   r4   r5   r     r   z%format_argspec_plus.<locals>.<lambda>)formatvaluec                 S  r  r  r   r  r4   r4   r5   r     r   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	r@   r   r   inspect_formatargspecr   r   r   r   r/   )r   r   r   r  r#  r"  r%  num_defaultsZ	name_argsZdefaulted_valsr$  r&  r4   r4   r5   r   q  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)rZ   z()r   r   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r"  r!  r#  r$  r%  r&  )objectr   r   rA   r/   )methodr   r!  r  Zproxiedr4   r4   r5   format_argspec_init  s&   
r,  r4   
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 rF   r4   )rn   r4   r4   r5   r        z&create_proxy_methods.<locals>.decorater4   )r-  r.  r/  r0  r1  r2  r3  r   r4   r4   r5   create_proxy_methods  s   r6  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)

    rZ   Nr  kwargs)r   r   rA   r*  r   )r+  r4   r4   r5   getargspec_init   s   
r8  c                 C  s   t | tjr| js| jS | S )zSAdjust the incoming callable such that a 'self' argument is not
    required.

    )r.   r   
MethodTyper  r  )Zfunc_or_clsr4   r4   r5   unbound_method_to_callable4  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 r4   r4   r   arg)missingr4   r5   
<listcomp>d      z generic_repr.<locals>.<listcomp>c                 S  s   g | ]\}}||fqS r4   r4   )r   rA  defaultr4   r4   r5   rC  j  s    c                 3  s     | ]}t t |d V  qd S rF   )r   r-   r@  rD   r4   r5   r   s  s    zgeneric_repr.<locals>.<genexpr>c                 S  s   g | ]}t |qS r4   r   )r   valr4   r4   r5   rC  v  rD  z%s=%rz%s(%s), )r   to_listr*  OrderedDict	enumerater   r   r   rA   r   r   r  rt   r  rP   zipr   r-   itemsr   r?   r   ri   r   )r1   r;  r=  r?  Zpos_argsZkw_argsZvargsr   Zinspr   Zdefault_lenoutputrA  ZdefvalrG  r4   )rB  r1   r5   generic_repr@  sv   


rO  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   r   r7  __weakref__c                 C  s   | j | j| jdS )Nr   r   r7  rR  rY   r4   r4   r5   __getstate__  s   z$portable_instancemethod.__getstate__c                 C  s&   |d | _ |d | _|dd| _d S )Nr   r   r7  r4   )r   r   rJ   r7  )rZ   stater4   r4   r5   __setstate__  s   

z$portable_instancemethod.__setstate__r4   c                 C  s   |j | _|j| _|| _d S rF   )r  r   ri   r   r7  )rZ   methr7  r4   r4   r5   r     s   
z portable_instancemethod.__init__c                 O  s$   | | j t| j| j|i |S rF   )rP   r7  r-   r   r   )rZ   rA  kwr4   r4   r5   r    s   z portable_instancemethod.__call__N)r4   )	ri   rj   rk   rl   rm   rS  rU  r   r  r4   r4   r4   r5   rP    s    
rP  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 rF   r4   r   _Zhierr4   r5   r         z"class_hierarchy.<locals>.<genexpr>builtinsru   c                   s   g | ]}| vr|qS r4   r4   rX  rZ  r4   r5   rC    s
    z#class_hierarchy.<locals>.<listcomp>)r   __mro__rr   r  r   rs   rj   r   
issubclassr8   ru   )rn   processr  r   r   sr4   rZ  r5   class_hierarchy  s&   





	ra  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)dirr]  rI   )rn   keyskeyr  r4   r4   r5   iterate_attributes  s   

re  
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)rm   __del____getattribute____metaclass__rS  rU  c                   s6   g | ]}| d r|d rt |s|vr|qS )r   )
startswithendswithr   r   rR   into_clsskipr4   r5   rC    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)rb  r-   r   r   r   r   r:   r   r   r(  rA   localsr   r   setattr)rn  Zfrom_clsro  onlyr   Zfrom_instanceZdundersr+  Zmaybe_fnr   r   Zfn_argsZd_argspyr   r4   rm  r5   monkeypatch_proxied_specials  sN   




rt  c                 C  s   t | d| t |d|u S )z;Return True if the two methods are the same implementation.r  )r-   )Zmeth1Zmeth2r4   r4   r5   methods_equivalent%  s   ru  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 )rY  )rj  rl  r4   r4   r5   rC  T  s    z as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srH  c                   @     e Zd ZdZdS )z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.Nri   rj   rk   rl   r4   r4   r4   r5   AnonymousInterfacek      rx  Z	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %s)rA   r.   r8   rq   rb  operatorgegtintersectionr/   r   ri   dictlike_iteritemsr@   rq  staticmethodrs   )r1   rn   r1  requiredZ	interfaceZimplementedZcompliesZ	qualifierrx  foundr+  r   r4   r4   r5   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]fgetr}   rl   rM   ri   Ndocc                 C     || _ |p|j| _|j| _d S rF   r  rl   ri   rZ   r  r  r4   r4   r5   r        zgeneric_fn_descriptor.__init__rZ   r  r1   rV   rn   r   r=   c                 C  r  rF   r4   rZ   r1   rn   r4   r4   r5   __get__  r5  zgeneric_fn_descriptor.__get__r*  r!   c                 C  r  rF   r4   r  r4   r4   r5   r    r5  Union[_GFD, _T_co]c                 C     t  rF   NotImplementedErrorr  r4   r4   r5   r       instancer_   c                 C  r  rF   r4   rZ   r  r_   r4   r4   r5   __set__      zgeneric_fn_descriptor.__set__c                 C  r  rF   r4   )rZ   r  r4   r4   r5   
__delete__  r  z generic_fn_descriptor.__delete__c                 C  r  rF   r  rZ   r1   r4   r4   r5   _reset  r  zgeneric_fn_descriptor._resetr   c                 C  r  rF   r  rn   r1   r   r4   r4   r5   reset  s   zgeneric_fn_descriptor.resetrF   )r  r  r  r}   )rZ   r  r1   rV   rn   r   r=   r  )r1   r*  rn   r   r=   r!   )rZ   r  r1   r   rn   r   r=   r  r  r   r_   r   r=   rV   r  r   r=   rV   )r1   r   r=   rV   )r1   r   r   rM   r=   rV   )ri   rj   rk   rl   r7   r   r   r  r   r  r  r  classmethodr  r4   r4   r4   r5   r    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 rF   r  r  r4   r4   r5   r    s   
z_non_memoized_property.__get__N)ri   rj   rk   rl   r   r  r4   r4   r4   r5   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 rF   )r  rI   ri   rZ   r1   rn   resultr4   r4   r5   r    s   z_memoized_property.__get__c                 C  s   t || j d S rF   )r  r  ri   r  r4   r4   r5   r    s   z_memoized_property._resetc                 C  s   |j |d  d S rF   )rI   rr   r  r4   r4   r5   r    s   z_memoized_property.resetN)	ri   rj   rk   rl   r   r  r  r  r  r4   r4   r4   r5   r    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 rF   r4   arW  r  r4   r5   memo  r5  z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)ri   rl   rI   rZ   r  rW  r  r   r  r5   oneshot  s   z(memoized_instancemethod.<locals>.oneshotr   )r   r  r4   r  r5   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.

    r4   zFrozenSet[str]_memoized_keysr=   rV   c                 C  s   | j D ]	}| j|d  qd S rF   )r  rI   rr   rZ   elemr4   r4   r5   _reset_memoizations     
zHasMemoized._reset_memoizationsc                 C  s   | j D ]	}|| jvsJ qd S rF   )r  rI   r  r4   r4   r5   _assert_no_memoizations  r  z#HasMemoized._assert_no_memoizationsrd  rM   r_   r   c                 C  s   || j |< |  j|hO  _d S rF   )rI   r  )rZ   rd  r_   r4   r4   r5   _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  r}   rl   rM   ri   Nr  c                 C  r  rF   r  r  r4   r4   r5   r   ,  r  z'HasMemoized.memoized_attribute.__init__rZ   r&   r1   rV   rn   r   r=   c                 C  r  rF   r4   r  r4   r4   r5   r  1  r5  z&HasMemoized.memoized_attribute.__get__r    c                 C  r  rF   r4   r  r4   r4   r5   r  4  r5  c                 C  s8   |d u r| S |  | |j| j< }| j| jhO  _|S rF   )r  rI   ri   r  r  r4   r4   r5   r  7  s
   rF   )r  r  r  r}   )rZ   r&   r1   rV   rn   r   r=   r&   )r1   r   rn   r   r=   r    )ri   rj   rk   rl   r7   r   r   r  r4   r4   r4   r5   memoized_attribute!  s   
 r  r   r#   c                   s   d	 fdd}t | S )
zMDecorate a method memoize its return value.

        :meta private:

        rZ   r   r  rW  r=   c                   sT   | g|R i |  fdd}j |_ j|_|| jj < |  jj hO  _ S )Nc                    r  rF   r4   r  r  r4   r5   r  I  r5  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)ri   rl   rI   r  r  r  r  r5   r  F  s   z4HasMemoized.memoized_instancemethod.<locals>.oneshotN)rZ   r   r  r   rW  r   r=   r   r   )rn   r   r  r4   r  r5   r  >  s   
z#HasMemoized.memoized_instancemethodNrh   )rd  rM   r_   r   r=   rV   r   r#   r=   r#   )ri   rj   rk   rl   r   rm   	frozensetr  r7   r  r  r  memoized_propertyr    r  r  r  r4   r4   r4   r5   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__.

    r4   c                 C  s   t |rF   )r:   )rZ   rd  r4   r4   r5   _fallback_getattre     zMemoizedSlots._fallback_getattrrd  rM   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 )NZ_memoized_attr_Z_memoized_method_c                    s:   | i |  fdd}j |_ j|_t|  S )Nc                    r  rF   r4   r  r  r4   r5   r  z  r5  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)ri   rl   rq  )r  rW  r  r   rd  rZ   r  r5   r  w  s   z*MemoizedSlots.__getattr__.<locals>.oneshot)rj  r:   r   r   r-   rq  rl   r  )rZ   rd  r_   r  r4   r  r5   __getattr__h  s   
zMemoizedSlots.__getattr__N)rd  rM   r=   r   )ri   rj   rk   rl   rm   r  r  r4   r4   r4   r5   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offr   f0FzString is not true/false: %r)r.   rM   stripr   r0   r   rD   r4   r4   r5   asbool  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.

    r1   rM   r=   Union[str, bool]c                   s   |  v r| S t | S rF   )r  rD   r  r4   r5   bool_or_value  s   z"bool_or_str.<locals>.bool_or_valueN)r1   rM   r=   r  r4   )r  r  r4   r  r5   bool_or_str  s   r  r_   Optional[int]c                 C  s   | du r| S t | S )zCoerce to integer.N)r   )r_   r4   r4   r5   asint  s   r  rW  rd  r]   
flexi_booldestOptional[Dict[str, Any]]rV   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)r.   r8   r   r  )rW  rd  r]   r  r  r4   r4   r5   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 rF   rI   r   krD   r4   r5   r         z"constructor_key.<locals>.<genexpr>)r  r   )r1   rn   r   r4   rD   r5   constructor_key  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  rF   r  r  rD   r4   r5   r     r  z#constructor_copy.<locals>.<genexpr>)r  rP   
difference)r1   rn   r  rW  r   r4   rD   r5   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 rF   )nextr4   counterlockr4   r5   _next  s   $zcounter.<locals>._next)	threadingLockr   count)r  r4   r  r5   r    s   
r  specimenrE  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   rs   rq   )r   r  r^  rq   r.   r8   r   r/   )r  rE  Zisar4   r4   r5   duck_type_collection  s(   






r  rA  argtype'Union[Tuple[Type[Any], ...], Type[Any]]r   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'Nr4   )r   r  r4   r4   r5   r     r   z"assert_arg_type.<locals>.<genexpr>z6Argument '%s' is expected to be of type '%s', got '%s')r.   r   r   ArgumentErrorr   r8   )rA  r  r   r4   r4   r5   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.rM  __getitem__rJ   NzObject '%r' is not dict-likeiterkeysc                  3  s.       D ]} d usJ | | fV  qd S rF   )r  )rd  dictlikegetterr4   r5   iterator.  s
   z$dictlike_iteritems.<locals>.iteratorrc  c                 3  s    | ]	}| |fV  qd S rF   r4   )r   rd  )r  r4   r5   r   5  r[  z%dictlike_iteritems.<locals>.<genexpr>)r   r   rM  r-   rA   iterrc  )r  r  r4   r  r5   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  rA  r   rW  c                   s&   t  j|g|R i | |j| _d S rF   )superr   rl   )rZ   r  rA  rW  r   r4   r5   r   G  s   zclassproperty.__init__Nr1   rn   Optional[type]r=   c                 C  s
   |  |S rF   r  r  r4   r4   r5   r  K  rH   zclassproperty.__get__)r  r  rA  r   rW  r   rF   )r1   r   rn   r  r=   r   )ri   rj   rk   rl   r7   r   r  __classcell__r4   r4   r  r5   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 rF   )r  clslevelrZ   r  r4   r4   r5   r   P  s   
zhybridproperty.__init__r  r   r,   r=   r    c                 C      |d u r|  |}|S | |S rF   r  r  rZ   r  r,   Zclsvalr4   r4   r5   r  T     

zhybridproperty.__get__r   hybridproperty[_T]c                 C  
   || _ | S rF   r  r   r4   r4   r5   
classlevel[     zhybridproperty.classlevelNr  r  r  r   r,   r   r=   r    )r  r   r=   r  )ri   rj   rk   r   r  r  r4   r4   r4   r5   r  O  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 rF   )r  r  setfnr   r4   r4   r5   r   a  s   
zrw_hybridproperty.__init__r  r   r,   r=   r    c                 C  r  rF   r  r  r4   r4   r5   r  f  r  zrw_hybridproperty.__get__r_   rV   c                 C  s   | j d usJ |  || d S rF   r  r  r4   r4   r5   r  m  s   zrw_hybridproperty.__set__r   rw_hybridproperty[_T]c                 C  r  rF   r  r   r4   r4   r5   setterq  r	  zrw_hybridproperty.setterc                 C  r  rF   r  r   r4   r4   r5   r  u  r	  zrw_hybridproperty.classlevelNr
  r  r  )r  r   r=   r  )ri   rj   rk   r   r  r  r  r  r4   r4   r4   r5   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 rF   )r  r  r  r   r4   r4   r5   r   }  s   
zhybridmethod.__init__r  r   r,   r=   c                 C  s&   |d u r| j ||jS | j||S rF   )r  r  r   r  )rZ   r  r,   r4   r4   r5   r    s   zhybridmethod.__get__r   hybridmethod[_T]c                 C  r  rF   r  r   r4   r4   r5   r    r	  zhybridmethod.classlevelNr
  )r  r   r,   r   r=   r  )r  r   r=   r  )ri   rj   rk   rl   r   r  r  r4   r4   r4   r5   r  z  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.

    rM   r   zDict[str, symbol]symbolsNr  r}   	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 )_lockr  rJ   r.   rM   hashr   __new__r  r   rl   rA   )rn   r   r  r  r   r4   r4   r5   r    s&   $zsymbol.__new__c                 C  s   t | jdt| ffS )NrL   )r  r   r   rY   r4   r4   r5   
__reduce__  s   zsymbol.__reduce__c                 C  s   t | S rF   rF  rY   r4   r4   r5   __str__  r  zsymbol.__str__c                 C  s   d| j dS )Nzsymbol()r   rY   r4   r4   r5   __repr__  r\   zsymbol.__repr__)NN)r   rM   r  r}   r  r  r=   r  )ri   rj   rk   rl   r7   r  r  r  r  r  r  r  r  r4   r4   r4   r5   r    s   
 r  c                   @  s    e Zd ZdddZdddZdS )_IntFlagMeta	classnamerM   r   Tuple[Type[Any], ...]dict_r   rW  r   r=   rV   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^__.*__$)r  rY  z#Expected integer values for IntFlagc                 S  s   i | ]}|j |qS r4   r  )r   r   r4   r4   r5   
<dictcomp>  rD  z)_IntFlagMeta.__init__.<locals>.<dictcomp>)Z_itemsrM  r   matchr.   r   r  rj  rA   rq  r   r   immutabledict__members__)	rn   r  r   r!  rW  rM  r  vr   r4   r4   r5   r     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  rY   r4   r4   r5   __iter__  s   z_IntFlagMeta.__iter__N)
r  rM   r   r   r!  r   rW  r   r=   rV   )r=   r'  )ri   rj   rk   r   r(  r4   r4   r4   r5   r    s    
r  c                   @  rv  )_FastIntFlagzAn 'IntFlag' copycat that isn't slow when performing bitwise
    operations.

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

    Nrw  r4   r4   r4   r5   r)    ry  r)  )	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': )rM  r   r   r  )rA  r-  r   r/  Z
enum_valuechoicer4   r4   r5   parse_user_argument_for_enum  s   r2  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  r4   r4   r5   set_creation_order$  s   	r4  r7  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)r?   warnrW   rX   )r  r  r7  r4   r4   r5   warn_exception1  s
   r6     c                 C  s<   zt | |krd| d|  W S | W S  ty   |  Y S w )Nz%s...r   )r   rA   )r_   Zlen_r4   r4   r5   ellipses_string<  s   r8  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   _hashr_   rM   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  r  r  r:  )rn   r_   r;  r  ZinterpolatedrZ   r  r4   r5   r  S  s   z_hash_limit_string.__new__c                 C  s   | j S rF   )r:  rY   r4   r4   r5   __hash__]  r  z_hash_limit_string.__hash__otherr   r   c                 C  s   t | t |kS rF   )r  )rZ   r>  r4   r4   r5   __eq__`  s   z_hash_limit_string.__eq__)r_   rM   r;  r   r  r<  r=   r9  )r=   r   )r>  r   r=   r   )	ri   rj   rk   rl   r7   r  r=  r?  r  r4   r4   r  r5   r9  F  s   
 


r9  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)r@  r   r4   r4   r5   r5  d  s   r5  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)r9  rA  r   rB  )r@  r  r4   r4   r5   warn_limitedq  s   rD  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 rF   )rE  r   r  rG  rF  r4   r5   go  s   z#tag_method_for_warnings.<locals>.gor4   )rF  rG  rK  r4   rJ  r5   tag_method_for_warnings~  s   rL  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   Fri   r   Tz (r  r   )rO  )rW   	_getframer0   r   r#  _not_sa_pattern	f_globalsrJ   f_coderE  f_backwarningsr5  )rF  rG  rO  frameZstacklevel_foundZwarning_tag_foundZ_suffixZ	_categoryr4   r4   r5   rA    s4   

rA  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.rA  r   rW  r=   Optional[_T]c                    s>    }r  }z|| i |W S    rd|  d S )Nr   )rr   insert)rA  rW  Z	strong_fnZonce_fnr   oncerW  r4   r5   rK    s   zonly_once.<locals>.goN)rA  r   rW  r   r=   rY  r4   )r   rW  rK  r4   r[  r5   	only_once  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_  ra  r   endr4   r4   r5   chop_traceback  s   rd  c                 C  s$   d|  }t   }t|| |d S )Nz&def set(obj, value):    obj.%s = valuerq   )rp  copyr   )attrnamer   r   r4   r4   r5   
attrsetter  s   

rg  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.

    r4   r=   rV   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 r4   )_dundersr#  r   r   r4   r4   r5   	<setcomp>  s
    
z/TypingOnly.__init_subclass__.<locals>.<setcomp>zClass z< directly inherits TypingOnly but has additional attributes r   )rh  r  rI   AssertionErrorr  __init_subclass__)rn   	remainingr  r4   r5   rm    s   
zTypingOnly.__init_subclass__rh   )ri   rj   rk   rl   rm   rm  r  r4   r4   r  r5   rh    s    rh  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.

    rM   ensure_kwargr=   rV   c                   sf   | j }| j}|r,|D ]!}t||}|r+|| }t|}|js+| |}t| || q
t	 
  d S rF   )rp  rI   r   r#  r   r   r  
_wrap_w_kwrq  r  rm  )rn   Zfn_regZclsdictrd  rR   r   r   wrappedr  r4   r5   rm  +  s   

zEnsureKWArg.__init_subclass__r   r   c                   s   d fdd}t | S )NrA  r   rW  r=   c                    s    |  S rF   r4   )rA  rW  r  r4   r5   wrap;  r  z$EnsureKWArg._wrap_w_kw.<locals>.wrap)rA  r   rW  r   r=   r   r   )rn   r   rs  r4   r  r5   rq  9  s   
zEnsureKWArg._wrap_w_kwrh   )r   r   r=   r   )	ri   rj   rk   rl   r7   rm  r  rq  r  r4   r4   r  r5   ro    s   
 	ro  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

    ri   rj   rl   )r   r   r   ri   rj   r  rl   )wrapperr   _fr4   r4   r5   wrap_callableA  s   




rv  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   )r   )r   r   r4   r4   r5   rC    s    z'quoted_token_parser.<locals>.<listcomp>)r   r   r   )r_   rT  r  idxlvcharr4   r4   r5   quoted_token_parserY  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 r4   r4   )r   paramr  r4   r5   r"    s    z8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>)rl   inject_param_text)r   r  r|  r  r4   r5   r     s
   z$add_parameter_text.<locals>.decorate)r   rI  )r|  r  r   r4   r  r5   add_parameter_text  s   
r  c                 C  sJ   |  dd}t|dkr| S |\}}|ds |d t| S t| S )N
r   r~   )r   r   rj  textwrapdedent)r  Z
split_text	firstlinern  r4   r4   r5   _dedent_docstring  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 r4   )r  )r   r;  liner4   r4   r5   rC    s    z)inject_docstring_text.<locals>.<listcomp>)
r  r   r   r   r  r  rZ  rK  minr   )r  r  r  doctextlinesZinjectlinesZblanksZ
inject_posr4   r4   r5   inject_docstring_text  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   *r~   r   z(\s+)\Sr   r  z::)collectionsdeque
splitlinespopleft
_param_regr#  r   lstripr   r   rt   rstriprk  r   r   )
r  r  Zdoclinesr  Z	to_injectr  rR   r}  indentZm2r4   r4   r5   r~    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   rj  r4   r4   r5   rC    s   , z$repr_tuple_names.<locals>.<listcomp>rH  z%s, ..., %s)r   r   )r   flagresr4   r4   r5   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)Zraise_r4   r4   r5   has_compiled_ext  s   r  c                   @  s   e Zd Ze ZdS )_MissingN)ri   rj   rk   enumautoMissingr4   r4   r4   r5   r    s    r  )r1   r   r2   r*   r=   r>   )r1   r   r=   r>   )rL   r   r=   rM   )rn   ro   r=   rp   )ry   r   r=   rM   rF   )rn   r{   r|   r}   r=   rM   )r   r   r   r   r=   r   )r   r   r=   r   )r   r   r   rM   r=   r   )r   r   r   r   r=   r   )r   r   r=   r   )r   r   r   r   r   rM   r=   r   )rn   r8   r   r   r   r   r=   r   )rn   r8   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  )r4   r4   r4   r4   )r-  r{   r.  rM   r/  rM   r0  r   r1  r   r2  r   r3  r   r=   r4  )r4   Nr4   )
r1   r   r;  r<  r=  r>  r?  r   r=   rM   )NNrf  N)NNNr  )r1   r   r=   r   )r  rM   r=   r  )r_   r   r=   r  )TN)rW  r   rd  rM   r]   r{   r  r   r  r  r=   rV   )r1   r   rn   r{   r=   r   )
r1   r    rn   ro   r  r   rW  r   r=   r    )r=   r  )r  r   rE  r  r=   r  )rA  r   r  r  r   rM   r=   r   )F)
rA  r   r-  r.  r   rM   r/  r   r=   r0  r  )r  r   r  r   r7  r   r=   r   )r7  )r@  rM   r   r}   r=   rV   )r@  rM   r  r<  r=   rV   )rF  rM   rG  rH  r=   rI  )Nr   )rF  rM  rG  rN  rO  r   r=   rV   )r   r  rW  r   r=   rX  )r^  r	  r_  r`  ra  r`  r=   r	  )r|  r   r  rM   r=   rI  )r  rM   r=   rM   )r  r}   r  rM   r  r   r=   rM   )r  rM   r  r  r=   rM   )r   r	  r=   r}   )rl   
__future__r   r  r  	functoolsr   rG   r   rz  r   rW   r  r  r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU  r   r   r   _has_cyr   r   r   r    r!   r#   r%   r&   r'   r(   py314annotationlibr)   r*   r6   r8   rI   r  r9   r<   rB   rE   py310rS   rT   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r   r,  r6  r8  r:  rO  rP  ra  re  rt  ru  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   r  r  r)  r+  FastIntFlagEnumr,  r2  r3  r4  r6  r8  rM   r9  r5  rD  rE  r7   rL  compilerQ  rA  r]  Z_SQLA_REZ_UNITTEST_RErd  NoneTyperg  ri  rh  ro  rv  r{  r  r  r  r  r~  r  r  r  r  Z	MissingOrr4   r4   r4   r5   <module>   s|  
!;	\+59u%N&CV+M.#<"
"


3),+