o
    fqi                    @  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   b/home/app/PaddleOCR-VL/.venv_paddleocr/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*   Z
FORWARDREFr1   r4   r4   r5   get_annotations   s   rD   c                 C  s
   t | S N)inspectrD   rC   r4   r4   r5   rD         
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   rD      s   

xstrc                 C  s*   |  d} t }||  tt| S )Nzutf-8)encoder   Zmd5_not_for_securityupdater   rL   	hexdigest)rK   mr4   r4   r5   md5_hex   s   

rQ   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]]rS   r=   Nonec                 C  s   t  | _d S rE   )sysexc_inforS   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 ||rE   )rS   with_traceback)rX   r[   r]   r_   exc_type	exc_valueexc_tbr4   r4   r5   __exit__   s   

zsafe_reraise.__exit__Nr=   rT   )r[   r\   r]   r^   r_   r`   r=   r   )__name__
__module____qualname____doc__	__slots__r7   rY   re   r4   r4   r4   r5   rR      s   
 

rR   clsType[_T]Iterator[Type[_T]]c                 c  sN    t  }| g}|r%| } | |v rq||  ||   | V  |s	d S d S rE   )setpopaddextend__subclasses__)rl   seenstackr4   r4   r5   walk_subclasses   s   
rv   elementc                 C  s4   t | tr| S zt| W S  ty   d|   Y S w )Nzunprintable element %r)r.   rL   r?   )rw   r4   r4   r5   string_or_unprintable   s   

rx   	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 rE   )lower).0nr4   r4   r5   	<genexpr>      z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+|SQL))rg   joinrefindall)rl   rz   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__rg   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   retrK   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 rE   rL   )ibaser4   r5   <lambda>+      z!_unique_symbols.<locals>.<lambda>i  z&exhausted namespace for symbol base %s)ro   	itertoolschainmaprangerq   	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+   rE   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)
rg   )rF   
isfunctionismethodr?   r-   r+   r   inspect_getfullargspeclenr   r/   fromkeysr   _replacer   r   rg   r   rN   format_argspec_plusiscoroutinefunctionreprrh   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 rE   )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grouprL   auto_fnOptional[Callable[..., Any]]c                 C  s   || _ i | _|| _d S rE   )r   implsr   )rX   r   r   r4   r4   r5   __init__  s   
zPluginLoader.__init__c                 C  s   | j   d S rE   )r   clearrW   r4   r4   r5   r     rZ   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   Zimportlib_metadata_getr   r   loadr   ZNoSuchModuleError)rX   r   loaderimplr4   r4   r5   r     s   



zPluginLoader.load
modulepathobjnamerT   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   )rX   r   r   r   r   r4   r   r5   register  s   zPluginLoader.registerc                 C  s   | j |= d S rE   r   )rX   r   r4   r4   r5   
deregister  s   zPluginLoader.deregisterrE   )r   rL   r   r   )r   rL   r=   r   )r   rL   r   rL   r   rL   r=   rT   )r   rL   r=   rT   )rg   rh   ri   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   )rF   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 rE   r4   rl   r   r   r4   r4   r5   get_cls_kwargs  s   r   Fc                C  r   rE   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   rX   )ro   rH   rI   r.   r   r   r   r   r   rN   rA   	__bases__r   discard)	rl   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)rF   	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   rK   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)rX   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 rE   r4   )rl   r4   r4   r5   r        z&create_proxy_methods.<locals>.decorater4   )r)  r*  r+  r,  r-  r.  r/  r   r4   r4   r5   create_proxy_methods  s   r2  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)

    rX   Nr  kwargs)r   r   rA   r&  r   )r'  r4   r4   r5   getargspec_init   s   
r4  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   r6  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~   r=  defaultr4   r4   r5   r?  j  s    c                 3  s     | ]}t t |d V  qd S rE   )r   r-   r<  rC   r4   r5   r   s  s    zgeneric_repr.<locals>.<genexpr>c                 S  s   g | ]}t |qS r4   r   )r~   valr4   r4   r5   r?  v  r@  z%s=%rz%s(%s), )r   to_listr&  OrderedDict	enumerater   r   r   rA   r   r   r  rr   r  rN   zipr   r-   itemsr   r?   r   rg   r   )r1   r7  r9  r;  Zpos_argsZkw_argsZvargsr   Zinspr   Zdefault_lenoutputr=  ZdefvalrC  r4   )r>  r1   r5   generic_repr@  sv   


rK  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   r3  __weakref__c                 C  s   | j | j| jdS )Nr   r   r3  rN  rW   r4   r4   r5   __getstate__  s   z$portable_instancemethod.__getstate__c                 C  s&   |d | _ |d | _|dd| _d S )Nr   r   r3  r4   )r   r   rI   r3  )rX   stater4   r4   r5   __setstate__  s   

z$portable_instancemethod.__setstate__r4   c                 C  s   |j | _|j| _|| _d S rE   )r  r   rg   r   r3  )rX   methr3  r4   r4   r5   r     s   
z portable_instancemethod.__init__c                 O  s$   | | j t| j| j|i |S rE   )rN   r3  r-   r   r   )rX   r=  kwr4   r4   r5   r    s   z portable_instancemethod.__call__N)r4   )	rg   rh   ri   rj   rk   rO  rQ  r   r  r4   r4   r4   r5   rL    s    
rL  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 rE   r4   r~   _Zhierr4   r5   r         z"class_hierarchy.<locals>.<genexpr>builtinsrs   c                   s   g | ]}| vr|qS r4   r4   rT  rV  r4   r5   r?    s
    z#class_hierarchy.<locals>.<listcomp>)r   __mro__rp   r   r   rq   rh   r   
issubclassr8   rs   )rl   processr  r   r   sr4   rV  r5   class_hierarchy  s&   





	r]  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)dirrY  rH   )rl   keyskeyr  r4   r4   r5   iterate_attributes  s   

ra  
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)rk   __del____getattribute____metaclass__rO  rQ  c                   s6   g | ]}| d r|d rt |s|vr|qS )r   )
startswithendswithr   r~   rP   into_clsskipr4   r5   r?    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)r^  r-   r   r   r   r   r:   r   r   r$  rA   localsr   r   setattr)rj  Zfrom_clsrk  onlyr   Zfrom_instanceZdundersr'  Zmaybe_fnr   r   Zfn_argsZd_argspyr   r4   ri  r5   monkeypatch_proxied_specials  sN   




rp  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   rq  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 )rU  )rf  rh  r4   r4   r5   r?  T  s    z as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srD  c                   @     e Zd ZdZdS )z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.Nrg   rh   ri   rj   r4   r4   r4   r5   AnonymousInterfacek      rt  Z	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %s)rA   r.   r8   ro   r^  operatorgegtintersectionr/   r   rg   dictlike_iteritemsr@   rm  staticmethodrq   )r1   rl   r-  requiredZ	interfaceZimplementedZcompliesZ	qualifierrt  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{   rj   rL   rg   Ndocc                 C     || _ |p|j| _|j| _d S rE   r  rj   rg   rX   r  r  r4   r4   r5   r        zgeneric_fn_descriptor.__init__rX   r  r1   rT   rl   r   r=   c                 C  r   rE   r4   rX   r1   rl   r4   r4   r5   __get__  r1  zgeneric_fn_descriptor.__get__r&  r!   c                 C  r   rE   r4   r  r4   r4   r5   r    r1  Union[_GFD, _T_co]c                 C     t  rE   NotImplementedErrorr  r4   r4   r5   r       instancer]   c                 C  r   rE   r4   rX   r  r]   r4   r4   r5   __set__      zgeneric_fn_descriptor.__set__c                 C  r   rE   r4   )rX   r  r4   r4   r5   
__delete__  r  z generic_fn_descriptor.__delete__c                 C  r  rE   r  rX   r1   r4   r4   r5   _reset  r  zgeneric_fn_descriptor._resetr   c                 C  r  rE   r  rl   r1   r   r4   r4   r5   reset  s   zgeneric_fn_descriptor.resetrE   )r  r  r  r{   )rX   r  r1   rT   rl   r   r=   r  )r1   r&  rl   r   r=   r!   )rX   r  r1   r   rl   r   r=   r  r  r   r]   r   r=   rT   r  r   r=   rT   )r1   r   r=   rT   )r1   r   r   rL   r=   rT   )rg   rh   ri   rj   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 rE   r  r  r4   r4   r5   r    s   
z_non_memoized_property.__get__N)rg   rh   ri   rj   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 rE   )r  rH   rg   rX   r1   rl   resultr4   r4   r5   r    s   z_memoized_property.__get__c                 C  s   t || j d S rE   )r  r  rg   r  r4   r4   r5   r    s   z_memoized_property._resetc                 C  s   |j |d  d S rE   )rH   rp   r  r4   r4   r5   r    s   z_memoized_property.resetN)	rg   rh   ri   rj   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 rE   r4   arS  r  r4   r5   memo  r1  z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)rg   rj   rH   rX   r  rS  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=   rT   c                 C  s   | j D ]	}| j|d  qd S rE   )r  rH   rp   rX   elemr4   r4   r5   _reset_memoizations     
zHasMemoized._reset_memoizationsc                 C  s   | j D ]	}|| jvsJ qd S rE   )r  rH   r  r4   r4   r5   _assert_no_memoizations  r  z#HasMemoized._assert_no_memoizationsr`  rL   r]   r   c                 C  s   || j |< |  j|hO  _d S rE   )rH   r  )rX   r`  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{   rj   rL   rg   Nr  c                 C  r  rE   r  r  r4   r4   r5   r   ,  r  z'HasMemoized.memoized_attribute.__init__rX   r&   r1   rT   rl   r   r=   c                 C  r   rE   r4   r  r4   r4   r5   r  1  r1  z&HasMemoized.memoized_attribute.__get__r    c                 C  r   rE   r4   r  r4   r4   r5   r  4  r1  c                 C  s8   |d u r| S |  | |j| j< }| j| jhO  _|S rE   )r  rH   rg   r  r  r4   r4   r5   r  7  s
   rE   )r  r  r  r{   )rX   r&   r1   rT   rl   r   r=   r&   )r1   r   rl   r   r=   r    )rg   rh   ri   rj   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:

        rX   r   r  rS  r=   c                   sT   | g|R i |  fdd}j |_ j|_|| jj < |  jj hO  _ S )Nc                    r  rE   r4   r  r  r4   r5   r  I  r1  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)rg   rj   rH   r  r  r  r  r5   r  F  s   z4HasMemoized.memoized_instancemethod.<locals>.oneshotN)rX   r   r  r   rS  r   r=   r   r   )rl   r   r  r4   r  r5   r  >  s   
z#HasMemoized.memoized_instancemethodNrf   )r`  rL   r]   r   r=   rT   r   r#   r=   r#   )rg   rh   ri   rj   r   rk   	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 )MemoizedSlotsaT  Apply memoized items to an object using a __getattr__ scheme.

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

    The memoized get is not threadsafe under freethreading and the
    creator method may in extremely rare cases be called more than once.

    r4   c                 C  s   t |rE   )r:   )rX   r`  r4   r4   r5   _fallback_getattrh     zMemoizedSlots._fallback_getattrr`  rL   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  rE   r4   r  r  r4   r5   r  }  r1  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)rg   rj   rm  )r  rS  r  r`  rR  rX   r  r5   r  z  s   z*MemoizedSlots.__getattr__.<locals>.oneshot)rf  r:   r   r   r-   rm  rj   r  )rX   r`  r]   r  r4   r  r5   __getattr__k  s   
zMemoizedSlots.__getattr__N)r`  rL   r=   r   )rg   rh   ri   rj   rk   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.   rL   stripr}   r0   r   rC   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   rL   r=   Union[str, bool]c                   s   |  v r| S t | S rE   )r  rC   r  r4   r5   bool_or_value  s   z"bool_or_str.<locals>.bool_or_valueN)r1   rL   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  rS  r`  r[   
flexi_booldestOptional[Dict[str, Any]]rT   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  )rS  r`  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 rE   rH   r~   krC   r4   r5   r         z"constructor_key.<locals>.<genexpr>)r   r   )r1   rl   r   r4   rC   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  rE   r  r  rC   r4   r5   r     r  z#constructor_copy.<locals>.<genexpr>)r   rN   
difference)r1   rl   r  rS  r   r4   rC   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 rE   )nextr4   counterlockr4   r5   _next  s   $zcounter.<locals>._next)	threadingLockr   count)r  r4   r  r5   r    s   
r  specimenrA  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   rq   ro   )r   r  rZ  ro   r.   r8   r   r/   )r  rA  Zisar4   r4   r5   duck_type_collection  s(   






r  r=  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   )r=  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.rI  __getitem__rI   NzObject '%r' is not dict-likeiterkeysc                  3  s.       D ]} d usJ | | fV  qd S rE   )r  )r`  dictlikegetterr4   r5   iterator1  s
   z$dictlike_iteritems.<locals>.iteratorr_  c                 3  s    | ]	}| |fV  qd S rE   r4   )r~   r`  )r  r4   r5   r   8  rW  z%dictlike_iteritems.<locals>.<genexpr>)r   r   rI  r-   rA   iterr_  )r  r  r4   r  r5   rz  %  s   


rz  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   rS  c                   s&   t  j|g|R i | |j| _d S rE   )superr   rj   )rX   r  r=  rS  r   r4   r5   r   J  s   zclassproperty.__init__Nr1   rl   Optional[type]r=   c                 C  s
   |  |S rE   r  r  r4   r4   r5   r  N  rG   zclassproperty.__get__)r  r  r=  r   rS  r   rE   )r1   r   rl   r  r=   r   )rg   rh   ri   rj   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 rE   )r  clslevelrX   r  r4   r4   r5   r   S  s   
zhybridproperty.__init__r  r   r,   r=   r    c                 C      |d u r|  |}|S | |S rE   r  r  rX   r  r,   Zclsvalr4   r4   r5   r  W     

zhybridproperty.__get__r   hybridproperty[_T]c                 C  
   || _ | S rE   r  r  r4   r4   r5   
classlevel^     zhybridproperty.classlevelNr  r  r  r   r,   r   r=   r    )r  r   r=   r  )rg   rh   ri   r   r  r  r4   r4   r4   r5   r  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 rE   )r  r  setfnr  r4   r4   r5   r   d  s   
zrw_hybridproperty.__init__r  r   r,   r=   r    c                 C  r  rE   r  r  r4   r4   r5   r  i  r   zrw_hybridproperty.__get__r]   rT   c                 C  s   | j d usJ |  || d S rE   r	  r  r4   r4   r5   r  p  s   zrw_hybridproperty.__set__r   rw_hybridproperty[_T]c                 C  r  rE   r
  r  r4   r4   r5   settert  r  zrw_hybridproperty.setterc                 C  r  rE   r  r  r4   r4   r5   r  x  r  zrw_hybridproperty.classlevelNr  r  r  )r  r   r=   r  )rg   rh   ri   r   r  r  r  r  r4   r4   r4   r5   r  c  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 rE   )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 rE   )r  r  r   r  )rX   r  r,   r4   r4   r5   r    s   zhybridmethod.__get__r   hybridmethod[_T]c                 C  r  rE   r  r  r4   r4   r5   r    r  zhybridmethod.classlevelNr  )r  r   r,   r   r=   r  )r  r   r=   r  )rg   rh   ri   rj   r   r  r  r4   r4   r4   r5   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.

    rL   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  rI   r.   rL   hashr   __new__r  r   rj   rA   )rl   r   r  r  r   r4   r4   r5   r    s&   $zsymbol.__new__c                 C  s   t | jdt| ffS )NrK   )r  r   r   rW   r4   r4   r5   
__reduce__  s   zsymbol.__reduce__c                 C  s   t | S rE   rB  rW   r4   r4   r5   __str__  r  zsymbol.__str__c                 C  s   d| j dS )Nzsymbol()r   rW   r4   r4   r5   __repr__  rZ   zsymbol.__repr__)NN)r   rL   r  r{   r  r  r=   r  )rg   rh   ri   rj   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	classnamerL   r   Tuple[Type[Any], ...]dict_r   rS  r   r=   rT   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  rU  z#Expected integer values for IntFlagc                 S  s   i | ]}|j |qS r4   r  )r~   r   r4   r4   r5   
<dictcomp>  r@  z)_IntFlagMeta.__init__.<locals>.<dictcomp>)Z_itemsrI  r   matchr.   r   r  rf  rA   rm  r   r   Zimmutabledict__members__)	rl   r  r   r  rS  rI  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  rW   r4   r4   r5   __iter__  s   z_IntFlagMeta.__iter__N)
r  rL   r   r  r  r   rS  r   r=   rT   )r=   r"  )rg   rh   ri   r   r#  r4   r4   r4   r5   r    s    
r  c                   @  rr  )_FastIntFlagzAn 'IntFlag' copycat that isn't slow when performing bitwise
    operations.

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

    Nrs  r4   r4   r4   r5   r$    ru  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': )rI  r   r   r  )r=  r(  r   r*  Z
enum_valuechoicer4   r4   r5   parse_user_argument_for_enum  s   r-  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   	r/  r3  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?   warnrU   rV   )r  r  r3  r4   r4   r5   warn_exception4  s
   r1     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   r3  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]   rL   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  r5  )rl   r]   r6  r  ZinterpolatedrX   r  r4   r5   r  V  s   z_hash_limit_string.__new__c                 C  s   | j S rE   )r5  rW   r4   r4   r5   __hash__`  r  z_hash_limit_string.__hash__otherr   r   c                 C  s   t | t |kS rE   )r  )rX   r9  r4   r4   r5   __eq__c  s   z_hash_limit_string.__eq__)r]   rL   r6  r   r  r7  r=   r4  )r=   r   )r9  r   r=   r   )	rg   rh   ri   rj   r7   r  r8  r:  r  r4   r4   r  r5   r4  I  s   
 


r4  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   r0  g  s   r0  r7  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)r4  r<  r   r=  )r;  r  r4   r4   r5   warn_limitedt  s   r?  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 rE   )r@  r   r  rB  rA  r4   r5   go  s   z#tag_method_for_warnings.<locals>.gor4   )rA  rB  rF  r4   rE  r5   tag_method_for_warnings  s   rG  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   Frg   r   Tz (r  r   )rJ  )rU   	_getframer0   r   r  _not_sa_pattern	f_globalsrI   f_coder@  f_backwarningsr0  )rA  rB  rJ  frameZstacklevel_foundZwarning_tag_foundZ_suffixZ	_categoryr4   r4   r5   r<    s4   

r<  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   rS  r=   Optional[_T]c                    s>    }r  }z|| i |W S    rd|  d S )Nr   )rp   insert)r=  rS  Z	strong_fnZonce_fnr   oncerR  r4   r5   rF    s   zonly_once.<locals>.goN)r=  r   rS  r   r=   rT  r4   )r   rR  rF  r4   rV  r5   	only_once  s   rX  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)rY  rZ  r\  r   endr4   r4   r5   chop_traceback  s   r_  c                 C  s$   d|  }t   }t|| |d S )Nz&def set(obj, value):    obj.%s = valuero   )rl  copyr   )attrnamer   r   r4   r4   r5   
attrsetter  s   

rb  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=   rT   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   )rc  r   rH   AssertionErrorr  __init_subclass__)rl   	remainingr  r4   r5   rh    s   
zTypingOnly.__init_subclass__rf   )rg   rh   ri   rj   rk   rh  r  r4   r4   r  r5   rc    s    rc  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.

    rL   ensure_kwargr=   rT   c                   sf   | j }| j}|r,|D ]!}t||}|r+|| }t|}|js+| |}t| || q
t	 
  d S rE   )rk  rH   r   r  r   r   r  
_wrap_w_kwrm  r  rh  )rl   Zfn_regZclsdictr`  rP   r   r   wrappedr  r4   r5   rh  .  s   

zEnsureKWArg.__init_subclass__r   r   c                   s   d fdd}t | S )Nr=  r   rS  r=   c                    s    |  S rE   r4   )r=  rS  r  r4   r5   wrap>  r  z$EnsureKWArg._wrap_w_kw.<locals>.wrap)r=  r   rS  r   r=   r   r   )rl   r   rn  r4   r  r5   rl  <  s   
zEnsureKWArg._wrap_w_kwrf   )r   r   r=   r   )	rg   rh   ri   rj   r7   rh  r  rl  r  r4   r4   r  r5   rj    s   
 	rj  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

    rg   rh   rj   )r   r   r   rg   rh   r  rj   )wrapperr   Z_fr4   r4   r5   wrap_callableD  s   




rp  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   r?    s    z'quoted_token_parser.<locals>.<listcomp>)r   r   r   )r]   rP  r  idxlvcharr4   r4   r5   quoted_token_parser\  s&   
$

ru  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>)rj   inject_param_text)r   r  rv  r  r4   r5   r     s
   z$add_parameter_text.<locals>.decorate)r   rE  )rv  r  r   r4   ry  r5   add_parameter_text  s   
rz  c                 C  sJ   |  dd}t|dkr| S |\}}|ds |d t| S t| S )N
r   r|   )r   r   rf  textwrapdedent)r  Z
split_text	firstlineri  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~   r6  liner4   r4   r5   r?    s    z)inject_docstring_text.<locals>.<listcomp>)
r  r   r   r   r|  r}  rU  rG  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   rr   rstriprg  r   r   )
r  r  Zdoclinesr  Z	to_injectr  rP   rw  indentm2r4   r4   r5   rx    s:   



!rx  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   re  r4   r4   r5   r?    s   , z$repr_tuple_names.<locals>.<listcomp>rD  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)rg   rh   ri   enumautoMissingr4   r4   r4   r5   r    s    r  )r1   r   r2   r*   r=   r>   )r1   r   r=   r>   )rK   r   r=   rL   )rl   rm   r=   rn   )rw   r   r=   rL   rE   )rl   ry   rz   r{   r=   rL   )r   r   r   r   r=   r   )r   r   r=   r   )r   r   r   rL   r=   r   )r   r   r   r   r=   r   )r   r   r=   r   )r   r   r   r   r   rL   r=   r   )rl   r8   r   r   r   r   r=   r   )rl   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)  ry   r*  rL   r+  rL   r,  r   r-  r   r.  r   r/  r   r=   r0  )r4   Nr4   )
r1   r   r7  r8  r9  r:  r;  r   r=   rL   )NNrb  N)NNNr  )r1   r   r=   r   )r  rL   r=   r  )r]   r   r=   r  )TN)rS  r   r`  rL   r[   ry   r  r   r  r  r=   rT   )r1   r   rl   ry   r=   r   )
r1   r    rl   rm   r  r   rS  r   r=   r    )r=   r  )r  r   rA  r  r=   r  )r=  r   r  r  r   rL   r=   r   )F)
r=  r   r(  r)  r   rL   r*  r   r=   r+  r  )r  r   r  r   r3  r   r=   r   )r2  )r;  rL   r   r{   r=   rT   )r;  rL   r  r7  r=   rT   )rA  rL   rB  rC  r=   rD  )Nr   )rA  rH  rB  rI  rJ  r   r=   rT   )r   r  rR  r   r=   rS  )rY  r  rZ  r[  r\  r[  r=   r  )rv  r   r  rL   r=   rD  )r  rL   r=   rL   )r  r{   r  rL   r  r   r=   rL   )r  rL   r  r  r=   rL   )r   r  r=   r{   )rj   
__future__r   r  r  	functoolsr   rF   r   rv  r   rU   r|  r  r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rP  r   r   r   Z_has_cyr   r   r   r    r!   r#   r%   r&   r'   r(   Zpy314Zannotationlibr)   r*   r6   r8   rH   r  r9   r<   rB   rD   Zpy310rQ   rR   rv   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r(  r2  r4  r6  rK  rL  r]  ra  rp  rq  r~  r  r  r  r  r  Znon_memoized_propertypropertyZro_memoized_propertyZro_non_memoized_propertyr  r  Z!HasMemoized_ro_memoized_attributer  r  r  r  r  r  r  r  r  r  r  rz  r  r  r  r  r   r  r  r$  r&  ZFastIntFlagEnumr'  r-  r.  r/  r1  r3  rL   r4  r0  r?  r@  r7   rG  compilerL  r<  rX  Z_SQLA_REZ_UNITTEST_REr_  NoneTyperb  rd  rc  rj  rp  ru  rz  r  r  r  rx  r  r  r  r  Z	MissingOrr4   r4   r4   r5   <module>   s|  
!;	\+59u%N&CV+M1#<"
"


3),+