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formatannotateann r5   N/var/www/html/venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py_get_and_call_annotateF   s   
r7   __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 )Nr8   z+.__annotations__ is neither a dict nor None)r.   type_BASE_GET_ANNOTATIONSAttributeErrorr-   r/   r0   r1   r4   r5   r5   r6   _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/   r7   r.   r9   callable	TypeError)r1   r2   r4   r5   r5   r6   _vendored_get_annotationsd   s"   
rC   c                 C  s   t | tjdS )N)r2   )rC   r*   
FORWARDREFr1   r5   r5   r6   get_annotations   s   rF   c                 C  s
   t | S N)inspectrF   rE   r5   r5   r6   rF         
c                 C  s>   t | tr| jdd }nt| dd }|d u rtjS td|S )Nr8   r?   )r.   r9   __dict__getr-   r   
EMPTY_DICTr   r<   r5   r5   r6   rF      s   

xstrc                 C  s*   |  d} t }||  tt| S )Nzutf-8)encoder   md5_not_for_securityupdater   rN   	hexdigest)rM   mr5   r5   r6   md5_hex   s   

rT   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]]rV   r>   Nonec                 C  s   t  | _d S rG   )sysexc_inforV   selfr5   r5   r6   	__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 ||rG   )rV   with_traceback)r[   r^   r`   rb   exc_type	exc_valueexc_tbr5   r5   r6   __exit__   s   

zsafe_reraise.__exit__Nr>   rW   )r^   r_   r`   ra   rb   rc   r>   r   )__name__
__module____qualname____doc__	__slots__r8   r\   rh   r5   r5   r5   r6   rU      s   
 

rU   clsType[_T]Iterator[Type[_T]]c                 c  sN    t  }| g}|r%| } | |v rq||  ||   | V  |s	d S d S rG   )setpopaddextend__subclasses__)ro   seenstackr5   r5   r6   walk_subclasses   s   
ry   elementc                 C  s4   t | tr| S zt| W S  ty   d|   Y S w )Nzunprintable element %r)r.   rN   r@   )rz   r5   r5   r6   string_or_unprintable   s   

r{   	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 rG   )lower).0nr5   r5   r6   	<genexpr>      z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+|SQL))rj   joinrefindall)ro   r}   namer5   r5   r6   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.   r9   	__class__rj   r-   )r   r   current_clsmethod_namecurrent_methodr5   r5   r6   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   retrM   r5   r5   r6   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 rG   rN   )ibaser5   r6   <lambda>+      z!_unique_symbols.<locals>.<lambda>i  z&exhausted namespace for symbol base %s)rr   	itertoolschainmaprangert   	NameError)r   r   used_setpoolsymr5   r   r6   _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   Nr5   )r   r   br5   r5   r6   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+   rG   r5   )r   defaultskwonlydefaultszTuple[str, ...]r   r      r   r   )r   r   Fgroupedr   zasync prefixzawait target_prefix __zf%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_pos)s)
ze%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_kw)s)
rj   )rH   
isfunctionismethodr@   r-   r+   r   inspect_getfullargspeclenr   r/   fromkeysr   _replacer   r   rj   r   rQ   format_argspec_plusiscoroutinefunctionreprrk   typesFunctionType_exec_code_in_env__defaults____kwdefaults__r   )r   annofuncspecempty_defaultsempty_kwdefaultsnames	targ_namefn_namemetadatacodeenv	decoratedr   r5   r6   decorateG  sf   




		
zdecorator.<locals>.decorateN)r   r   r>   r   r   )r   r   r5   r   r6   	decoratorD  s   
Vr   r   Union[str, types.CodeType]r   Dict[str, Any]r   c                 C  s   t | | || S rG   )exec)r   r   r   r5   r5   r6   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grouprN   auto_fnOptional[Callable[..., Any]]c                 C  s   || _ i | _|| _d S rG   )r   implsr   )r[   r   r   r5   r5   r6   __init__  s   
zPluginLoader.__init__c                 C  s   | j   d S rG   )r   clearrZ   r5   r5   r6   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)r[   r   loaderimplr5   r5   r6   r     s   



zPluginLoader.load
modulepathobjnamerW   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   r5   r6   r     s   
z#PluginLoader.register.<locals>.loadr   )r[   r   r   r   r   r5   r   r6   register  s   zPluginLoader.registerc                 C  s   | j |= d S rG   r   )r[   r   r5   r5   r6   
deregister  s   zPluginLoader.deregisterrG   )r   rN   r   r   )r   rN   r>   r   )r   rN   r   rN   r   rN   r>   rW   )r   rN   r>   rW   )rj   rk   rl   r   r   r   r   r   r5   r5   r5   r6   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   )rH   CO_VARKEYWORDSr;   r   r   r   __code__co_argcountlistco_varnamesco_flags)r   co_varkeywordsr   conargsr5   r5   r6   _inspect_func_args  s   

	r  )_setraiseerrr9   r  Optional[Set[str]]r  Literal[True]Set[str]c                C     d S rG   r5   ro   r  r  r5   r5   r6   get_cls_kwargs  s   r  Fc                C  r  rG   r5   r  r5   r5   r6   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  r[   )rr   rJ   rK   r.   r   r   r   r   r  rQ   rB   	__bases__r  discard)	ro   r  r  toplevelctrhas_initr   has_kwcr5   r5   r6   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  r5   r5   r6   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)rH   	isbuiltinrB   r   r   r   FullArgSpecargsvarargsvarkwr   
kwonlyargsr   r   r   __self__r  isclassget_callable_argspecr   r   r  )r   r  r  r   r5   r5   r6   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   r5   c                 S     dt |  S N=r   rM   r5   r5   r6   r     r   z%format_argspec_plus.<locals>.<lambda>)formatvaluec                 S  r*  r+  r   r-  r5   r5   r6   r     r   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	rA   r   r   inspect_formatargspecr   r   r   r   r/   )r   r   r   r   r1  r0  r3  num_defaults	name_argsdefaulted_valsr2  r4  r5   r5   r6   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)r[   z()r   r   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r0  r/  r1  r2  r3  r4  )objectr   r   rB   r/   )methodr   r/  r   proxiedr5   r5   r6   format_argspec_init  s&   
r=  r5   
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 rG   r5   )ro   r5   r5   r6   r        z&create_proxy_methods.<locals>.decorater5   )r>  r?  r@  rA  rB  rC  rD  r   r5   r5   r6   create_proxy_methods  s   rG  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)

    r[   Nr   kwargs)r   r   rB   r:  r   )r;  r5   r5   r6   getargspec_init   s   
rI  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  )func_or_clsr5   r5   r6   unbound_method_to_callable4  s   rL  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 r5   r5   r   arg)missingr5   r6   
<listcomp>d      z generic_repr.<locals>.<listcomp>c                 S  s   g | ]\}}||fqS r5   r5   )r   rS  defaultr5   r5   r6   rU  j  s    c                 3  s     | ]}t t |d V  qd S rG   )r   r-   rR  rE   r5   r6   r   s  s    zgeneric_repr.<locals>.<genexpr>c                 S  s   g | ]}t |qS r5   r   )r   valr5   r5   r6   rU  v  rV  z%s=%rz%s(%s), )r   to_listr:  OrderedDict	enumerater   r   r   rB   r   r   r!  ru   r   rQ   zipr   r-   itemsr   r@   r   rj   r   )r1   rM  rO  rQ  pos_argskw_argsvargsr   inspr   default_lenoutputrS  defvalrY  r5   )rT  r1   r6   generic_repr@  sv   


rg  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   rH  __weakref__c                 C  s   | j | j| jdS )Nr   r   rH  rj  rZ   r5   r5   r6   __getstate__  s   z$portable_instancemethod.__getstate__c                 C  s&   |d | _ |d | _|dd| _d S )Nr   r   rH  r5   )r   r   rK   rH  )r[   stater5   r5   r6   __setstate__  s   

z$portable_instancemethod.__setstate__r5   c                 C  s   |j | _|j| _|| _d S rG   )r$  r   rj   r   rH  )r[   methrH  r5   r5   r6   r     s   
z portable_instancemethod.__init__c                 O  s$   | | j t| j| j|i |S rG   )rQ   rH  r-   r   r   )r[   rS  kwr5   r5   r6   r    s   z portable_instancemethod.__call__N)r5   )	rj   rk   rl   rm   rn   rk  rm  r   r  r5   r5   r5   r6   rh    s    
rh  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 rG   r5   r   _hierr5   r6   r         z"class_hierarchy.<locals>.<genexpr>builtinsrv   c                   s   g | ]}| vr|qS r5   r5   rp  rr  r5   r6   rU    s
    z#class_hierarchy.<locals>.<listcomp>)r   __mro__rs   r  r   rt   rk   r   
issubclassr9   rv   )ro   processr  r   r   sr5   rr  r6   class_hierarchy  s&   





	rz  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)dirrv  rJ   )ro   keyskeyr  r5   r5   r6   iterate_attributes  s   

r~  
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)rn   __del____getattribute____metaclass__rk  rm  c                   s6   g | ]}| d r|d rt |s|vr|qS )r   )
startswithendswithr   r   rS   into_clsskipr5   r6   rU    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   r6  rB   localsr   r   setattr)r  from_clsr  onlyr   from_instancedundersr;  maybe_fnr   r   fn_argsd_argspyr   r5   r  r6   monkeypatch_proxied_specials  sN   




r  c                 C  s   t | d| t |d|u S )z;Return True if the two methods are the same implementation.r  )r-   )meth1meth2r5   r5   r6   methods_equivalent%  s   r  c                 C  sf  |s|st dt|trt| |r| S t|pdd t|D }tt| }tj}t|tr2|}n|s;t }tj}nt|}||||rI| S t| t	sc|tju rUdpVd}t d| |d
|f G dd	 d	}|rrd
|j |_t }	t| D ]'\}
}|
|vrt d|
 t|st d|
|f t||
t| |	|
 qy||	|r|S t dd
||	  )a  Ensure basic interface compliance for an instance or dict of callables.

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

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

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

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

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

    z2a class or collection of method names are requiredc                 S  s   g | ]	}| d s|qS )rq  )r  r  r5   r5   r6   rU  T  s    z as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srZ  c                   @     e Zd ZdZdS )z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.Nrj   rk   rl   rm   r5   r5   r5   r6   AnonymousInterfacek      r  	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %s)rB   r.   r9   rr   r{  operatorgegtintersectionr/   r   rj   dictlike_iteritemsrA   r  staticmethodrt   )r1   ro   rB  required	interfaceimplementedcomplies	qualifierr  foundr;  r   r5   r5   r6   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~   rm   rN   rj   Ndocc                 C     || _ |p|j| _|j| _d S rG   r  rm   rj   r[   r  r  r5   r5   r6   r        zgeneric_fn_descriptor.__init__r[   r  r1   rW   ro   r   r>   c                 C  r  rG   r5   r[   r1   ro   r5   r5   r6   __get__  rF  zgeneric_fn_descriptor.__get__r:  r!   c                 C  r  rG   r5   r  r5   r5   r6   r    rF  Union[_GFD, _T_co]c                 C     t  rG   NotImplementedErrorr  r5   r5   r6   r       instancer`   c                 C  r  rG   r5   r[   r  r`   r5   r5   r6   __set__      zgeneric_fn_descriptor.__set__c                 C  r  rG   r5   )r[   r  r5   r5   r6   
__delete__  r  z generic_fn_descriptor.__delete__c                 C  r  rG   r  r[   r1   r5   r5   r6   _reset  r  zgeneric_fn_descriptor._resetr   c                 C  r  rG   r  ro   r1   r   r5   r5   r6   reset  s   zgeneric_fn_descriptor.resetrG   )r  r  r  r~   )r[   r  r1   rW   ro   r   r>   r  )r1   r:  ro   r   r>   r!   )r[   r  r1   r   ro   r   r>   r  r  r   r`   r   r>   rW   r  r   r>   rW   )r1   r   r>   rW   )r1   r   r   rN   r>   rW   )rj   rk   rl   rm   r8   r   r   r  r   r  r  r  classmethodr  r5   r5   r5   r6   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 rG   r  r  r5   r5   r6   r    s   
z_non_memoized_property.__get__N)rj   rk   rl   rm   r   r  r5   r5   r5   r6   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 rG   )r  rJ   rj   r[   r1   ro   resultr5   r5   r6   r    s   z_memoized_property.__get__c                 C  s   t || j d S rG   )r  r  rj   r  r5   r5   r6   r    s   z_memoized_property._resetc                 C  s   |j |d  d S rG   )rJ   rs   r  r5   r5   r6   r    s   z_memoized_property.resetN)	rj   rk   rl   rm   r   r  r  r  r  r5   r5   r5   r6   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 rG   r5   aro  r  r5   r6   memo  rF  z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)rj   rm   rJ   r[   r   ro  r  r   r  r6   oneshot  s   z(memoized_instancemethod.<locals>.oneshotr   )r   r  r5   r  r6   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.

    r5   zFrozenSet[str]_memoized_keysr>   rW   c                 C  s   | j D ]	}| j|d  qd S rG   )r  rJ   rs   r[   elemr5   r5   r6   _reset_memoizations     
zHasMemoized._reset_memoizationsc                 C  s   | j D ]	}|| jvsJ qd S rG   )r  rJ   r  r5   r5   r6   _assert_no_memoizations  r  z#HasMemoized._assert_no_memoizationsr}  rN   r`   r   c                 C  s   || j |< |  j|hO  _d S rG   )rJ   r  )r[   r}  r`   r5   r5   r6   _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~   rm   rN   rj   Nr  c                 C  r  rG   r  r  r5   r5   r6   r   ,  r  z'HasMemoized.memoized_attribute.__init__r[   r&   r1   rW   ro   r   r>   c                 C  r  rG   r5   r  r5   r5   r6   r  1  rF  z&HasMemoized.memoized_attribute.__get__r    c                 C  r  rG   r5   r  r5   r5   r6   r  4  rF  c                 C  s8   |d u r| S |  | |j| j< }| j| jhO  _|S rG   )r  rJ   rj   r  r  r5   r5   r6   r  7  s
   rG   )r  r  r  r~   )r[   r&   r1   rW   ro   r   r>   r&   )r1   r   ro   r   r>   r    )rj   rk   rl   rm   r8   r   r   r  r5   r5   r5   r6   memoized_attribute!  s   
 r  r   r#   c                   s   d	 fdd}t | S )
zMDecorate a method memoize its return value.

        :meta private:

        r[   r   r   ro  r>   c                   sT   | g|R i |  fdd}j |_ j|_|| jj < |  jj hO  _ S )Nc                    r  rG   r5   r  r  r5   r6   r  I  rF  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)rj   rm   rJ   r  r  r  r  r6   r  F  s   z4HasMemoized.memoized_instancemethod.<locals>.oneshotN)r[   r   r   r   ro  r   r>   r   r   )ro   r   r  r5   r  r6   r  >  s   
z#HasMemoized.memoized_instancemethodNri   )r}  rN   r`   r   r>   rW   r   r#   r>   r#   )rj   rk   rl   rm   r   rn   	frozensetr  r8   r  r  r  memoized_propertyr    r  r  r  r5   r5   r5   r6   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__.

    r5   c                 C  s   t |rG   )r;   )r[   r}  r5   r5   r6   _fallback_getattre     zMemoizedSlots._fallback_getattrr}  rN   r>   r   c                   s    ds
 drttjd r(td  }t| |S tjd rGtd   fdd} j|_|S S )N_memoized_attr__memoized_method_c                    s:   | i |  fdd}j |_ j|_t|  S )Nc                    r  rG   r5   r  r  r5   r6   r  z  rF  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)rj   rm   r  )r   ro  r  r   r}  r[   r  r6   r  w  s   z*MemoizedSlots.__getattr__.<locals>.oneshot)r  r;   r   r   r-   r  rm   r  )r[   r}  r`   r  r5   r  r6   __getattr__h  s   
zMemoizedSlots.__getattr__N)r}  rN   r>   r   )rj   rk   rl   rm   rn   r  r  r5   r5   r5   r6   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.   rN   stripr   r0   r   rE   r5   r5   r6   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   rN   r>   Union[str, bool]c                   s   |  v r| S t | S rG   )r  rE   r  r5   r6   bool_or_value  s   z"bool_or_str.<locals>.bool_or_valueN)r1   rN   r>   r  r5   )r  r  r5   r  r6   bool_or_str  s   r  r`   Optional[int]c                 C  s   | du r| S t | S )zCoerce to integer.N)r   )r`   r5   r5   r6   asint  s   r  ro  r}  r^   
flexi_booldestOptional[Dict[str, Any]]rW   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.   r9   r   r  )ro  r}  r^   r  r  r5   r5   r6   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 rG   rJ   r   krE   r5   r6   r         z"constructor_key.<locals>.<genexpr>)r  r   )r1   ro   r   r5   rE   r6   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   rG   r  r  rE   r5   r6   r     r  z#constructor_copy.<locals>.<genexpr>)r  rQ   
difference)r1   ro   r   ro  r   r5   rE   r6   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 rG   )nextr5   counterlockr5   r6   _next  s   $zcounter.<locals>._next)	threadingLockr   count)r  r5   r
  r6   r    s   
r  specimenrW  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   rt   rr   )r   r  rw  rr   r.   r9   r   r/   )r  rW  isar5   r5   r6   duck_type_collection  s(   






r  rS  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'Nr5   )r   r  r5   r5   r6   r     r   z"assert_arg_type.<locals>.<genexpr>z6Argument '%s' is expected to be of type '%s', got '%s')r.   r   r   ArgumentErrorr   r9   )rS  r  r   r5   r5   r6   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.r_  __getitem__rK   NzObject '%r' is not dict-likeiterkeysc                  3  s.       D ]} d usJ | | fV  qd S rG   )r  )r}  dictlikegetterr5   r6   iterator.  s
   z$dictlike_iteritems.<locals>.iteratorr|  c                 3  s    | ]	}| |fV  qd S rG   r5   )r   r}  )r  r5   r6   r   5  rt  z%dictlike_iteritems.<locals>.<genexpr>)r   r   r_  r-   rB   iterr|  )r  r  r5   r  r6   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  rS  r   ro  c                   s&   t  j|g|R i | |j| _d S rG   )superr   rm   )r[   r  rS  ro  r   r5   r6   r   G  s   zclassproperty.__init__Nr1   ro   Optional[type]r>   c                 C  s
   |  |S rG   r  r  r5   r5   r6   r  K  rI   zclassproperty.__get__)r  r"  rS  r   ro  r   rG   )r1   r   ro   r%  r>   r   )rj   rk   rl   rm   r8   r   r  __classcell__r5   r5   r$  r6   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 rG   )r  clslevelr[   r  r5   r5   r6   r   P  s   
zhybridproperty.__init__r  r   r,   r>   r    c                 C      |d u r|  |}|S | |S rG   r(  r  r[   r  r,   clsvalr5   r5   r6   r  T     

zhybridproperty.__get__r   hybridproperty[_T]c                 C  
   || _ | S rG   r(  r)  r5   r5   r6   
classlevel[     zhybridproperty.classlevelNr  r  r  r   r,   r   r>   r    )r  r   r>   r/  )rj   rk   rl   r   r  r2  r5   r5   r5   r6   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 rG   )r  r(  setfnr)  r5   r5   r6   r   a  s   
zrw_hybridproperty.__init__r  r   r,   r>   r    c                 C  r*  rG   r+  r,  r5   r5   r6   r  f  r.  zrw_hybridproperty.__get__r`   rW   c                 C  s   | j d usJ |  || d S rG   r7  r  r5   r5   r6   r  m  s   zrw_hybridproperty.__set__r   rw_hybridproperty[_T]c                 C  r0  rG   r8  r)  r5   r5   r6   setterq  r3  zrw_hybridproperty.setterc                 C  r0  rG   r1  r)  r5   r5   r6   r2  u  r3  zrw_hybridproperty.classlevelNr4  r5  r  )r  r   r>   r9  )rj   rk   rl   r   r  r  r:  r2  r5   r5   r5   r6   r6  `  s    



r6  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 rG   )r  r  r(  r)  r5   r5   r6   r   }  s   
zhybridmethod.__init__r  r   r,   r>   c                 C  s&   |d u r| j ||jS | j||S rG   )r(  r  r   r  )r[   r  r,   r5   r5   r6   r    s   zhybridmethod.__get__r   hybridmethod[_T]c                 C  r0  rG   r1  r)  r5   r5   r6   r2    r3  zhybridmethod.classlevelNr4  )r  r   r,   r   r>   r  )r  r   r>   r<  )rj   rk   rl   rm   r   r  r2  r5   r5   r5   r6   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.

    rN   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>  rK   r.   rN   hashr   __new__r=  r   rm   rB   )ro   r   r  r?  r   r5   r5   r6   rB    s&   $zsymbol.__new__c                 C  s   t | jdt| ffS )NrM   )r=  r   r   rZ   r5   r5   r6   
__reduce__  s   zsymbol.__reduce__c                 C  s   t | S rG   rX  rZ   r5   r5   r6   __str__  r  zsymbol.__str__c                 C  s   d| j dS )Nzsymbol()r   rZ   r5   r5   r6   __repr__  r]   zsymbol.__repr__)NN)r   rN   r  r~   r?  r  r>   r=  )rj   rk   rl   rm   r8   r>  r  r  r@  rB  rC  rD  rG  r5   r5   r5   r6   r=    s   
 r=  c                   @  s    e Zd ZdddZdddZdS )_IntFlagMeta	classnamerN   r   Tuple[Type[Any], ...]dict_r   ro  r   r>   rW   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?  rq  z#Expected integer values for IntFlagc                 S  s   i | ]}|j |qS r5   rF  )r   r   r5   r5   r6   
<dictcomp>  rV  z)_IntFlagMeta.__init__.<locals>.<dictcomp>)_itemsr_  r   matchr.   r   r=  r  rB   r  r   r   immutabledict__members__)	ro   rI  r   rK  ro  r_  r  vr   r5   r5   r6   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  rZ   r5   r5   r6   __iter__  s   z_IntFlagMeta.__iter__N)
rI  rN   r   rJ  rK  r   ro  r   r>   rW   )r>   rR  )rj   rk   rl   r   rS  r5   r5   r5   r6   rH    s    
rH  c                   @  r  )_FastIntFlagzAn 'IntFlag' copycat that isn't slow when performing bitwise
    operations.

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

    Nr  r5   r5   r5   r6   rT    r  rT  )	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': )r_  r   r   r  )rS  rX  r   rZ  
enum_valuechoicer5   r5   r6   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  r5   r5   r6   set_creation_order$  s   	r`  rH  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@   warnrX   rY   )r  r   rH  r5   r5   r6   warn_exception1  s
   rb     c                 C  s<   zt | |krd| d|  W S | W S  ty   |  Y S w )Nz%s...r   )r   rB   )r`   len_r5   r5   r6   ellipses_string<  s   re  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`   rN   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#  rB  rA  rg  )ro   r`   rh  r   interpolatedr[   r$  r5   r6   rB  S  s   z_hash_limit_string.__new__c                 C  s   | j S rG   )rg  rZ   r5   r5   r6   __hash__]  r  z_hash_limit_string.__hash__otherr   r   c                 C  s   t | t |kS rG   )rA  )r[   rl  r5   r5   r6   __eq__`  s   z_hash_limit_string.__eq__)r`   rN   rh  r   r   ri  r>   rf  )r>   r   )rl  r   r>   r   )	rj   rk   rl   rm   r8   rB  rk  rm  r&  r5   r5   r$  r6   rf  F  s   
 


rf  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)rn  r   r5   r5   r6   ra  d  s   ra  ri  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)rf  ro  r   rp  )rn  r   r5   r5   r6   warn_limitedq  s   rr  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 rG   )rs  r   r  ru  rt  r5   r6   go  s   z#tag_method_for_warnings.<locals>.gor5   )rt  ru  ry  r5   rx  r6   tag_method_for_warnings~  s   rz  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   Frj   r   Tz (rE  r   )r}  )rX   	_getframer0   r   rN  _not_sa_pattern	f_globalsrK   f_coders  f_backwarningsra  )rt  ru  r}  framestacklevel_foundwarning_tag_found_suffix	_categoryr5   r5   r6   ro    s4   

ro  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.rS  r   ro  r>   Optional[_T]c                    s>    }r  }z|| i |W S    rd|  d S )Nr   )rs   insert)rS  ro  	strong_fnonce_fnr   oncer  r5   r6   ry    s   zonly_once.<locals>.goN)rS  r   ro  r   r>   r  r5   )r   r  ry  r5   r  r6   	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  r  r   endr5   r5   r6   chop_traceback  s   r  c                 C  s$   d|  }t   }t|| |d S )Nz&def set(obj, value):    obj.%s = valuerr   )r  copyr   )attrnamer   r   r5   r5   r6   
attrsetter  s   

r  z^__.+__$c                      s&   e Zd ZdZdZd fddZ  ZS )
TypingOnlyzA mixin class that marks a class as 'typing only', meaning it has
    absolutely no methods, attributes, or runtime functionality whatsoever.

    r5   r>   rW   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 r5   )_dundersrN  r   r   r5   r5   r6   	<setcomp>  s
    
z/TypingOnly.__init_subclass__.<locals>.<setcomp>zClass z< directly inherits TypingOnly but has additional attributes r   )r  r  rJ   AssertionErrorr#  __init_subclass__)ro   	remainingr$  r5   r6   r    s   
zTypingOnly.__init_subclass__ri   )rj   rk   rl   rm   rn   r  r&  r5   r5   r$  r6   r    s    r  c                      s<   e Zd ZU dZded< 	 d fddZedd
dZ  ZS )EnsureKWArga6  Apply translation of functions to accept \**kw arguments if they
    don't already.

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

    rN   ensure_kwargr>   rW   c                   sf   | j }| j}|r,|D ]!}t||}|r+|| }t|}|js+| |}t| || q
t	 
  d S rG   )r  rJ   r   rN  r   r   r"  
_wrap_w_kwr  r#  r  )ro   fn_regclsdictr}  rS   r   r   wrappedr$  r5   r6   r  +  s   

zEnsureKWArg.__init_subclass__r   r   c                   s   d fdd}t | S )NrS  r   ro  r>   c                    s    |  S rG   r5   )rS  ro  r  r5   r6   wrap;  r  z$EnsureKWArg._wrap_w_kw.<locals>.wrap)rS  r   ro  r   r>   r   r   )ro   r   r  r5   r  r6   r  9  s   
zEnsureKWArg._wrap_w_kwri   )r   r   r>   r   )	rj   rk   rl   rm   r8   r  r  r  r&  r5   r5   r$  r6   r    s   
 	r  c                 C  sh   t |dr
t| |S | }|jj|_t |dr|j|_t |jdr+|jjr+|jj|_|S |jr2|j|_|S )zAugment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    rj   rk   rm   )r   r   r   rj   rk   r  rm   )wrapperr   _fr5   r5   r6   wrap_callableA  s   




r  c                 C  s   d| vr	|  dS d}g g}d}t| }||k r`| | }|dkrC|dkr>||d k r>| |d  dkr>|d d |d7 }n|dN }n|dkrQ|dkrQ|g  n|d | |d7 }||k sdd |D S )a  Parse a dotted identifier with accommodation for quoted names.

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

    E.g.::

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

    "r   r   r   r5  c                 S  s   g | ]}d  |qS )r   )r   )r   r   r5   r5   r6   rU    s    z'quoted_token_parser.<locals>.<listcomp>)r   r   r   )r`   rl  r  idxlvcharr5   r5   r6   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 r5   r5   )r   paramr  r5   r6   rL    s    z8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>)rm   inject_param_text)r   r  r  r  r5   r6   r     s
   z$add_parameter_text.<locals>.decorate)r   r[  )r  r  r   r5   r  r6   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   r  textwrapdedent)r  
split_text	firstliner  r5   r5   r6   _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 r5   )r  )r   rh  liner5   r5   r6   rU    s    z)inject_docstring_text.<locals>.<listcomp>)
r  r   r   r   r  r  r  r]  minr   )r  r  r  doctextlinesinjectlinesblanks
inject_posr5   r5   r6   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_regrN  r   lstripr   r   ru   rstripr  r   r   )
r  r  doclinesr  	to_injectr  rS   r  indentm2r5   r5   r6   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   r5  c                 S  s,   g | ]}t |d krd|dd   n|qS )   z%s..N)r   r  r5   r5   r6   rU    s   , z$repr_tuple_names.<locals>.<listcomp>rZ  z%s, ..., %s)r   r   )r   flagresr5   r5   r6   repr_tuple_names  s   (
r  c                 C  s   t rdS | r
tddS )NTzDcython extensions were expected to be installed, but are not presentF)r   ImportError)raise_r5   r5   r6   has_compiled_ext  s   r  c                   @  s   e Zd Ze ZdS )_MissingN)rj   rk   rl   enumautoMissingr5   r5   r5   r6   r    s    r  )r1   r   r2   r*   r>   r?   )r1   r   r>   r?   )rM   r   r>   rN   )ro   rp   r>   rq   )rz   r   r>   rN   rG   )ro   r|   r}   r~   r>   rN   )r   r   r   r   r>   r   )r   r   r>   r   )r   r   r   rN   r>   r   )r   r   r   r   r>   r   )r   r   r>   r   )r   r   r   r   r   rN   r>   r   )ro   r9   r  r	  r  r
  r>   r  )ro   r9   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(  )r5   r5   r5   r5   )r>  r|   r?  rN   r@  rN   rA  r   rB  r   rC  r   rD  r   r>   rE  )r5   Nr5   )
r1   r   rM  rN  rO  rP  rQ  r   r>   rN   )NNr  N)NNNr  )r1   r   r>   r   )r  rN   r>   r  )r`   r   r>   r  )TN)ro  r   r}  rN   r^   r|   r  r   r  r  r>   rW   )r1   r   ro   r|   r>   r   )
r1   r    ro   rp   r   r   ro  r   r>   r    )r>   r  )r  r   rW  r  r>   r  )rS  r   r  r  r   rN   r>   r   )F)
rS  r   rX  rY  r   rN   rZ  r   r>   r[  r  )r  r   r   r   rH  r   r>   r   )rc  )rn  rN   r   r~   r>   rW   )rn  rN   r   ri  r>   rW   )rt  rN   ru  rv  r>   rw  )Nr   )rt  r{  ru  r|  r}  r   r>   rW   )r   r  r  r   r>   r  )r  r  r  r  r  r  r>   r  )r  r   r  rN   r>   rw  )r  rN   r>   rN   )r  r~   r  rN   r  r   r>   rN   )r  rN   r  r  r>   rN   )r   r  r>   r~   )rm   
__future__r   r  r  	functoolsr   rH   r   r  r   rX   r  r  r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   _has_cyr   r   r   r    r!   r#   r%   r&   r'   r(   py314annotationlibr)   r*   r7   r9   rJ   r  r:   r=   rC   rF   py310rT   rU   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r&  r   r=  rG  rI  rL  rg  rh  rz  r~  r  r  r  r  r  r  r  r  non_memoized_propertypropertyro_memoized_propertyro_non_memoized_propertyr  r  !HasMemoized_ro_memoized_attributer  r  r  r  r  r  r  r  r  r  r  r  r!  r'  r6  r;  r   r=  rH  rT  rV  FastIntFlagEnumrW  r^  r_  r`  rb  re  rN   rf  ra  rr  rs  r8   rz  compiler  ro  r  _SQLA_RE_UNITTEST_REr  NoneTyper  r  r  r  r  r  r  r  r  r  r  r  r  r  r  	MissingOrr5   r5   r5   r6   <module>   s|  
!;	\+59u%N&CV+M.#<"
"


3),+