
    @
i                   H	   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#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!"          Z, e!d#ed$ef         %          Z- e!d&d'%          Z. e!d(d)%          Z/ e!d*d+%          Z0 e!d,d-%          Z1dd2Z2 G d3 d4          Z3dd8Z4dd:Z5	 ddd>Z6ddDZ7ddHZ8ddMZ9ddSZ: e!dTdB%          Z;ddWZ<dd]Z= e!d^          Z> e!d_          Z? G d` da          Z@db ZAedd$dcddj            ZBeddkdcddl            ZBddkdcddmZBddpZC	 d d!dtZD	 d"d#dxZEd"dyZF	 	 	 	 d$d%dZGd ZHd ZI	 	 	 d&d'dZJ G d d          ZKd ZLd ZM	 	 	 	 d(dZNd ZOd)dZP e!dd%          ZQ G d dee,                   ZR G d deRe,                   ZS G d deRe,                   ZTe r	eRZUeRZVeWZXeWZYneTxZUZXeSxZVZYd*dZZ G d d          Z[e reWZ\ne[j]        Z\ G d d          Z^d+dZ_d,dZ`d-dZa	 	 d.d/dZbd0dZcd1dZdd2dZe	 dd3dZfd4dZgd Zh G d deW          Zi G d dee+                   Zj G dĄ dee+                   Zk G dƄ dee+                   Zl G dȄ dem          Zn G dʄ deo          Zp G d̄ depΦ          Zqe r	ddlmrZr erZsneqZs e!dejt        %          Zu	 d5d6dՄZvdawd7dׄZxd8dلZyd9dۄZz G d܄ de{          Z|dd:d߄Z}d;dZ~i Zded<   d<dZ e
j        d          Z	 	 d=d>dZd?dZ e
j        d          Z e
j        d          Zeefd@dZ eod          Zd Z e
j        d          Z G d d          Z G d d          Zd Zd  ZdAdZdBdZdCdZ e
j        d          ZdDdZdEdZd5dZ G d dejt                  Zej        Ze"e+e)ej                 f         ZdS (F  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)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]xr   returnstrc                    |                      d          } t          j                    }|                    |            t	          t
          |                                          S )Nzutf-8)encoder   md5_not_for_securityupdater	   r+   	hexdigest)r)   ms     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\sqlalchemy/util/langhelpers.pymd5_hexr3   >   sH    	A#%%AHHQKKKQ[[]]###    c                  2    e Zd ZU dZdZded<   ddZ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]]r7   r*   Nonec                6    t          j                    | _        d S N)sysexc_infor7   selfs    r2   	__enter__zsafe_reraise.__enter__j   s    r4   type_Optional[Type[BaseException]]valueOptional[BaseException]	tracebackOptional[types.TracebackType]r   c                    | j         J |+| j         \  }}}|J d | _         |                    |          d | _         |J |                    |          r:   )r7   with_traceback)r>   r@   rB   rD   exc_type	exc_valueexc_tbs          r2   __exit__zsafe_reraise.__exit__m   ss     ~)))=*..'Hi(((!DN**6222!DN$$$&&y111r4   Nr*   r8   )r@   rA   rB   rC   rD   rE   r*   r   )__name__
__module____qualname____doc__	__slots____annotations__r?   rK    r4   r2   r6   r6   E   sc          0 I   ( ( ( (2 2 2 2 2 2r4   r6   clsType[_T]Iterator[Type[_T]]c              #     K   t                      }| g}|r]|                                } | |v r|                    |            |                    |                                            | V  |[d S d S r:   )setpopaddextend__subclasses__)rT   seenstacks      r2   walk_subclassesr_      s      UUDEE
 iikk$;;HHSMMMS''))***			      r4   elementc                z    t          | t                    r| S 	 t          |           S # t          $ r d| z  cY S w xY w)Nzunprintable element %r)
isinstancer+   	Exception)r`   s    r2   string_or_unprintablerd      sV    '3 6	6w<< 	6 	6 	6+g5555	6s   ( ::	Type[Any]use_nameOptional[str]c                x    |p| j         }d                    d t          j        d|          D                       S )N c              3  >   K   | ]}|                                 V  d S r:   )lower).0ns     r2   	<genexpr>z(clsname_as_plain_name.<locals>.<genexpr>   s*      NN!AGGIINNNNNNr4   z([A-Z][a-z]+|SQL))rM   joinrefindall)rT   rf   names      r2   clsname_as_plain_namers      s>     #s|D88NNrz2F'M'MNNNNNNr4   instance_or_clsUnion[Type[Any], object]against_methodCallable[..., Any]boolc                z    t          | t                    s| j        }n| }|j        }t	          ||          }||k    S )z1Return True if the two class methods don't match.)rb   type	__class__rM   getattr)rt   rv   current_clsmethod_namecurrent_methods        r2   method_is_overriddenr      sG     ot,, &%/% )K'.{K'H'HN^++r4   slcsliceTuple[Any, ...]c                    g }| j         | j        | j        fD ];}t          |d          r|                                }|                    |           <t          |          S )zrdecode a slice object as sent to __getitem__.

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

    	__index__)startstopstephasattrr   appendtuple)r   retr)   s      r2   decode_slicer      sa     CY#(*  1k"" 	A

1::r4   usedSequence[str]basesIterator[str]c           
   '    K   t          |           }|D ]lt          j        ft          fdt	          d                              }|D ]!}||vr|                    |           |V   n"t          dz            md S )Nc                (    t          |           z   S r:   r+   )ibases    r2   <lambda>z!_unique_symbols.<locals>.<lambda>   s    $Q- r4   i  z&exhausted namespace for symbol base %s)rX   	itertoolschainmaprangerZ   	NameError)r   r   used_setpoolsymr   s        @r2   _unique_symbolsr      s      4yyH M MG''''t55
 
  	M 	MC(""S!!!			 #
 DtKLLL M Mr4   fnCallable[[int], Any]rm   intIterator[Any]c              #  L   K   |r|| dz   z  } | |          V  ||z  }|dS dS )z6Call the given function given each nonzero bit from n.r   NrS   )r   rm   bs      r2   map_bitsr      sW        !aLbee	Q      r4   _FntargetCallable[[_Fn], _Fn]c                0     d fd}t          |           S )z'A signature-matching decorator factory.r   r   r*   c                P   t          j        |           s#t          j        |           st          d          t	          | dd           }|0d | _        	 t          j        |           }|| _        n # || _        w xY wt          j        |           }dt          |j	        pd          z  }t                              |j        pd          }|                    i ||          }t          t          d|d                             t          d|dd	                   z   | j        fz   }t#          |d
d          \  }}t          ||          }|                    t'          |d                     | j        |d<   t          j        |           rd|d<   d|d<   n
d|d<   d|d<   dt+          |d                   v rd|z  }	nd|z  }	||| d| j        i}
t          t.          j        t3          |	|
| j                            }| j        |_        | j        |_        t9          ||           S )Nznot a decoratable function__annotate__r:   rS   )r   defaultskwonlydefaultszTuple[str, ...]r   r      r   r   )r   r   Fgroupedrr   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)
rM   )inspect
isfunctionismethodrc   r|   r   r   inspect_getfullargspeclenr   dictfromkeysr   _replacer   r	   rM   r   r/   format_argspec_plusiscoroutinefunctionreprrN   typesFunctionType_exec_code_in_env__defaults____kwdefaults__r   )r   annofuncspecempty_defaultsempty_kwdefaultsnames	targ_namefn_namemetadatacodeenv	decoratedr   s               r2   decoratezdecorator.<locals>.decorate   st   !"%% 	:g.>r.B.B 	:8999 2~t44"BO+4R88"*(****044D !3t}':#;#;;==)<)BCC}}#+  
 
 $($q'2233$d1Q3i001{n 	
 -UHdCC	7-1w-O-O-O+D%@@@AAA;&r** 	+!)HX(0H_%%!#HX(*H_% 4Q==   	 D 	  vR
 dC55
 
	 "$	#%#4	 i,,,s   A0 0	A9)r   r   r*   r   r   )r   r   s   ` r2   	decoratorr      s:    T- T- T- T- T- T-l (F+++r4   r   Union[str, types.CodeType]r   Dict[str, Any]r   c                2    t          | |           ||         S r:   )exec)r   r   r   s      r2   r   r   9  s     	sOOOw<r4   _PF_TEc                  8    e Zd Z	 dddZd ZddZddZddZdS )PluginLoaderNgroupr+   auto_fnOptional[Callable[..., Any]]c                0    || _         i | _        || _        d S r:   )r   implsr   )r>   r   r   s      r2   __init__zPluginLoader.__init__E  s     
%'
r4   c                8    | j                                          d S r:   )r   clearr=   s    r2   r   zPluginLoader.clearL  s    
r4   rr   r*   r   c                x   || j         v r | j         |                     S | j        r+|                     |          }|r|| j         |<    |            S t          j        | j                  D ]2}|j        |k    r%|j        | j         |<   |                                c S 3t          j        d| j        d|          )NzCan't load plugin: :)	r   r   r   importlib_metadata_getr   rr   loadr   NoSuchModuleError)r>   rr   loaderimpls       r2   r   zPluginLoader.loadO  s    4:#4:d#%%%< 	 \\$''F  #)
4 vxx1$*== 	# 	#DyD  #'9
4 yy{{""" ! ##*.***dd;
 
 	
r4   
modulepathobjnamer8   c                *    fd}|| j         |<   d S )Nc                     t                    }                     d          dd          D ]}t          | |          } t          |           S )N.r   )
__import__splitr|   )modtokenr   r   s     r2   r   z#PluginLoader.register.<locals>.loadc  sW    Z((C#))#..qrr2 * *c5))3(((r4   r   )r>   rr   r   r   r   s     `` r2   registerzPluginLoader.registerb  s6    	) 	) 	) 	) 	) 	)  
4r4   c                    | j         |= d S r:   r   )r>   rr   s     r2   
deregisterzPluginLoader.deregisterk  s    Jtr4   r:   )r   r+   r   r   )rr   r+   r*   r   )rr   r+   r   r+   r   r+   r*   r8   )rr   r+   r*   r8   )rM   rN   rO   r   r   r   r   r   rS   r4   r2   r   r   D  s{        BF      
 
 
 
&            r4   r   c                    	 t           j        }| j        }|j        }t	          |j        d |                   t          |j        |z            fS # t          $ r4 t          j
        |           }|d         t          |d                   fcY S w xY w)Nr   r   )r   CO_VARKEYWORDS__code__co_argcountlistco_varnamesrx   co_flagsAttributeErrorr   r   )r   co_varkeywordsconargsr   s        r2   _inspect_func_argsr  o  s    
 / ['((~-..
 	
  & & &
 ,R00AwT!W%%%%&s   A ;BB)_setraiseerrrz   r  Optional[Set[str]]r  Literal[True]Set[str]c                   d S r:   rS   rT   r  r  s      r2   get_cls_kwargsr    s	     sr4   Fc                   d S r:   rS   r
  s      r2   r  r    s	     r4   c                  |du }|rt                      }|J | j                            dd          }|o8t          |t          j                  ot          |j        t          j                  }|rCt          |          \  }}|	                    |           |s|s|rt          d|  d          dS nd}|r|r| j        D ]}t          ||           n|                    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>   )rX   __dict__getrb   r   r   r   r   r  r/   	TypeError	__bases__r  discard)	rT   r  r  toplevelctrhas_initr   has_kwcs	            r2   r  r    s=   " t|H uu
,

:u
-
-C 	 	5sE.//	5s|U^44   *3//vE 	h 	 FFFF   t v  	 	Aad+++3 4 	LLKr4   func	List[str]c                6    t          j        |           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  s    r2   get_func_kwargsr    s     (..q11r4   no_self_is_initcompat.FullArgSpecc           	        t          j        |           rt          d| z            t          j        |           rq|r[|rYt	          j        |           }t	          j        |j        dd         |j        |j	        |j
        |j        |j        |j                  S t	          j        |           S t          j        |           r|rg|s| j        r^t	          j        | j                  }t	          j        |j        dd         |j        |j	        |j
        |j        |j        |j                  S t	          j        | j                  S t          j        |           rt%          | j        |d          S t)          | d          rt	          j        | j                  S t)          | d          rAt          j        | j                  rt%          | j        |          S t          d	| z            t          d	| z            )
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)r   	isbuiltinr  r   r   r   FullArgSpecargsvarargsvarkwr   
kwonlyargsr   r   r   __self__r   isclassget_callable_argspecr   r   r!  )r   r  r  r   s       r2   r*  r*    s     *;3b8999		B		 (; 	5 	5044D%	!""
#    0444		"		 ; 	> 	>BK 	>0==D%	!""
#    0===			 ;#K4
 
 
 	
 
Z	 	  ;,R[999	Z	 	  ;BK(( 	?'WEEEE82=>>>4r9:::r4   -Union[Callable[..., Any], compat.FullArgSpec]r   Dict[str, Optional[str]]c           
        t          |           rt          j        |           }n| }t          j        | }t          j        |d         |d         |d         d|d                   }|d         rG|d         d         }t          j        |d         dd         |d         |d         d|d                   }n|d         rd|d         z  }|}nd}|}d}|d         r6|t	          t          t          t                   |d                             z  }|d         r|t	          |d                   z  }|d         |d         z   }|r|d|z
  d         }	nd}	t          j        ||d         |d         |	d	 
          }
|d         r/t          j        |dd         |d         |d         |	d 
          }n|
}|rt          ||||
||          S t          |||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   rS   c                &    dt          |           z   S N=r   r)   s    r2   r   z%format_argspec_plus.<locals>.<lambda>]  s    cCFFl r4   )formatvaluec                &    dt          |           z   S r0  r   r2  s    r2   r   z%format_argspec_plus.<locals>.<lambda>f  s    #A, r4   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	callabler   r   inspect_formatargspecr   r	   r   r   r   )r   r   r   r$  r7  r6  r9  num_defaults	name_argsdefaulted_valsr8  r:  s               r2   r   r   
  sw   H || ,R00'.D,Qa$q'4a I Aw &71:"8GABBKa$q'4a
 
 
a &T!W$%%LAw 7DsT!W55666Aw %DG$Q$q'!I  "1|#3#5#56+QQ**  H Aw 	$!7abbMGG..
 
 
 $ 
/-
 
 
 	
 "oad^/"5-ad3
 
 
 	
r4   c                    | t           j        u rd}|rdnd}|rdnd}n0	 t          | |          S # t          $ r d}|r|nd}|rdnd	}Y nw xY wt	          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)r6  r5  r7  r8  r9  r:  )objectr   r   r  r   )methodr   r5  r$  proxieds        r2   format_argspec_initrE    s       ".xx!)$$r	L&vw???? 	L 	L 	L4L#*G<<0GD-4K)):KGGG	L !!    s   0 A
ArS   
target_clstarget_cls_sphinx_nameproxy_cls_sphinx_nameclassmethodsmethods
attributesuse_intermediate_variableCallable[[_T], _T]c                    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 r:   rS   )rT   s    r2   r   z&create_proxy_methods.<locals>.decorate  s    
r4   rS   )rF  rG  rH  rI  rJ  rK  rL  r   s           r2   create_proxy_methodsrP    s    &   Or4   c                    	 t          j        |           S # t          $ r! | t          j        u r	dgdddfcY S dgdddfcY S w xY 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   r  rB  r   )rC  s    r2   getargspec_initrS    sn    6,V444 6 6 6V_$$HdD$////Hfh5555	6s    AA Ac                V    t          | t          j                  r| j        s| j        S | S )zSAdjust the incoming callable such that a 'self' argument is not
    required.

    )rb   r   
MethodTyper(  r   )func_or_clss    r2   unbound_method_to_callablerW    s2     +u/00 9M ##r4   objadditional_kwSequence[Tuple[str, Any]]
to_inspect%Optional[Union[object, List[object]]]
omit_kwargc           	     h    | g}nt          j        |          }t                      g }t          j                    }d}t	          |          D ]%\  }}	 t          j        |j                  }	|	j        rt          |	j                  nd}
|dk    rW|	j
        r|	j
        }|
r$|                    |	j        d|
                     nR|                    |	j        dd                    n/|                    fd|	j        d|
          D                        |
rI|	j        sJ |                    d t          |	j        |
 d         |	j                  D                        # t          $ r Y #w xY wg }|                     fd|D                        |=t!           |          r-|                    d t#           |          D                        |                                D ]P\  }}||v r
	 t#           |          }|ur ||k    r|                    |d|           A# t(          $ r Y Mw xY w|rN|D ]K\  }}	 t#           |          }|ur ||k    r|                    |d|           <# t(          $ r Y Hw xY w j        j        d	d
                    |          dS )z}Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    Nr   r   c                    g | ]}|fS rS   rS   )rl   argmissings     r2   
<listcomp>z generic_repr.<locals>.<listcomp>  s    IIIc7^IIIr4   c                    g | ]	\  }}||f
S rS   rS   )rl   r`  defaults      r2   rb  z generic_repr.<locals>.<listcomp>  s0       (C g  r4   c              3  T   K   | ]"}t          t          |d                     V  #d S r:   )r   r|   )rl   r`  rX  s     r2   rn   zgeneric_repr.<locals>.<genexpr>  s7      DDC$wsC..//DDDDDDr4   c                ,    g | ]}t          |          S rS   r   )rl   vals     r2   rb  z generic_repr.<locals>.<listcomp>  s    @@@StCyy@@@r4   r1  (, ))r   to_listrB  OrderedDict	enumerater   r   r   r   r   r%  r[   r$  r/   zipr  r   r|   itemsr   rc   r{   rM   ro   )rX  rY  r[  r]  pos_argskw_argsvargsr   inspr   default_lenoutputr`  defvalrh  ra  s   `              @r2   generic_reprrx    sh    U

!)*55
hhGH2>2J2L2LGEZ((  4	0??D 15D#dm,,,1KAvv< ) LE 3OODIan$=>>>>OODIabbM2222IIIItyK</HIII    	}$$} ,/ I{lmm4dm- -    %  	 	 	H	4 F
MMDDDD8DDDDDDWS%00@@GC,?,?@@@AAA}}  V*	#sG,,C'!!cVmmcc2333 	 	 	D	  ( 	 	KCc300g%%#--MMSSS##"6777    }---tyy/@/@/@/@AAs6   E''
E54E595H//
H<;H<	5I??
JJc                  0    e Zd ZdZdZd Zd Zd	dZd ZdS )
portable_instancemethodz_Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    )r   rr   rR  __weakref__c                ,    | j         | j        | j        dS )Nr   rr   rR  r}  r=   s    r2   __getstate__z$portable_instancemethod.__getstate__/  s     kIk
 
 	
r4   c                p    |d         | _         |d         | _        |                    dd          | _        d S )Nr   rr   rR  rS   )r   rr   r  rR  )r>   states     r2   __setstate__z$portable_instancemethod.__setstate__6  s1    Ho&M	ii"--r4   rS   c                D    |j         | _        |j        | _        || _        d S r:   )r(  r   rM   rr   rR  )r>   methrR  s      r2   r   z portable_instancemethod.__init__;  s    mM	r4   c                v    |                     | j                    t          | j        | j                  |i |S r:   )r/   rR  r|   r   rr   )r>   r`  kws      r2   r!  z portable_instancemethod.__call__@  s9    
		$+.wt{DI..:r:::r4   N)rS   )	rM   rN   rO   rP   rQ   r~  r  r   r!  rS   r4   r2   rz  rz  '  sf         
 :I
 
 
. . .
   
; ; ; ; ;r4   rz  c                *   | ht          | j                  }|r|                                }fd|j        D             }|D ],}|                    |                               |           -|j        dk    st          |d          stfdt          |t                    s|
                                n|
                    |          D             D ],}|                    |                               |           -|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  $   K   | ]
}|v|V  d S r:   rS   rl   _hiers     r2   rn   z"class_hierarchy.<locals>.<genexpr>T  s'      99q1D======99r4   builtinsr\   c                    g | ]}|v|	S rS   rS   r  s     r2   rb  z#class_hierarchy.<locals>.<listcomp>]  s.     
 
 

 }}  }}r4   )r   __mro__rY   r  r   rZ   rN   r   
issubclassrz   r\   )rT   processr  r   r   sr  s         @r2   class_hierarchyr  E  s?    5D3;G
 KKMM9999AK999 	 	ANN1HHQKKKK<:%%WQ8H-I-I%
 
 
 
 "!T**)  """%%a((
 
 
 
	 
	A NN1HHQKKKK+  , ::r4   c              #  ~   K   t          |           }|D ](}| j        D ]}||j        v r||j        |         fV   n)dS )ziterate all the keys and attributes associated
    with a class, without using getattr().

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

    N)dirr  r  )rT   keyskeyr  s       r2   iterate_attributesr  k  sl       s88D   	 	Aaj  AJsO,,,, ! r4   
self.proxyc                    |r|}n d fdt          |          D             }|D ]-}	 t          ||          }t          |d          s%t          |d|          }t          t          j        |          }	n# t          $ r Y ]w xY w	 t          j        |	          }
t          j	        |
d                   }t          j	        |
d         dd                   }n# t          $ r d}d	}Y nw xY wd
t                      z  }|dur||ipi }t          ||           	 |	j        ||         _        n# t          $ r Y nw xY wt           |||                    /dS )z9Automates delegation of __specials__ for a proxying type.N)rQ   __del____getattribute____metaclass__r~  r  c                    g | ]B}|                     d           r+|                    d           rt          |          s|v@|CS )r   )
startswithendswithr   )rl   r1   into_clsskips     r2   rb  z0monkeypatch_proxied_specials.<locals>.<listcomp>  sl     	
 	
 	
T""		

 JJt$$	
  !,,	
 TMM  "MMr4   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=  r  localsr   r   setattr)r  from_clsr  onlyrr   from_instancedundersrC  maybe_fnr   r   fn_argsd_argspyr   s   ` `            r2   monkeypatch_proxied_specialsr  {  s     
<D	
 	
 	
 	
 	
]]	
 	
 	
  / /	x00H8Z00 xX>>He((33BB 	 	 	H		%044D247;;G1$q'!""+>>FF 	% 	% 	%+G$FFF	%
35;XX> 	 %?4*?E2 	 	R	')CK$$ 	 	 	D	&#f+....?/ /s<    A;+A;;
BBACC.-C.D00
D=<D=c                F    t          | d|           t          |d|          u S )z;Return True if the two methods are the same implementation.r   )r|   )meth1meth2s     r2   methods_equivalentr    s0     5*e,,z51 1  r4   c           	     J   |s|st          d          t          |t                    rt          | |          r| S t          |pd t	          |          D                       }t          t	          |                     }t
          j        }t          |t                    r|}n,|st                      }t
          j        }nt          |          } ||                    |          |          r| S t          | t                    s<|t
          j        u rdpd}t          | d|dd
                    |                     G d d	          }|rd
|j        z   |_        t                      }	t          |           D ]r\  }
}|
|vrt          d|
z            t          |          st          |
d|d          t          ||
t          |                     |	                    |
           s ||	|          r|S t          dd
                    ||	z
            z            )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                <    g | ]}|                     d           |S )r  )r  )rl   r1   s     r2   rb  z as_interface.<locals>.<listcomp>  s)    MMMa1<<;L;LMMMMr4   zany ofzall ofz does not implement z: rj  c                      e Zd ZdZdS )(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.NrM   rN   rO   rP   rS   r4   r2   AnonymousInterfacer    s        ''''r4   r  	Anonymousz%r: unknown in this interfacer1  z is not callablez,dictionary does not contain required keys %s)r  rb   rz   rX   r  operatorgegtintersectionr   ro   rM   dictlike_iteritemsr<  r  staticmethodrZ   )rX  rT   rJ  required	interfaceimplementedcomplies	qualifierr  foundrC  r   s               r2   as_interfacer    sx   B  Nw NLMMM#t C!5!5 
GMMM3s88MMMNNIc#hh--K{H(D!! ! !55;x==x((33X>> 
 c4   
+8DH	ssIIItyy3335
 
 	

( ( ( ( ( ( ( (  A&1CL&@#EEE*3//  "";fDEEE~~ 	FvvvtttDEEE"FL,>,>???		&xx   "!!
6
))Hu$
%
%	&  r4   _GFDzgeneric_fn_descriptor[Any]c                      e Zd ZU dZded<   ded<   ded<   dd d
Zed!d            Zed"d            Zd#dZerd$dZ	d%dZ
d&dZe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]fgetrg   rP   r+   rM   Ndocc                H    || _         |p|j        | _        |j        | _        d S r:   r  rP   rM   r>   r  r  s      r2   r   zgeneric_fn_descriptor.__init__.  s$    	*dlr4   r>   r  rX  r8   rT   r   r*   c                    d S r:   rS   r>   rX  rT   s      r2   __get__zgeneric_fn_descriptor.__get__3  s    :=#r4   rB  r!   c                    d S r:   rS   r  s      r2   r  zgeneric_fn_descriptor.__get__6  s    7:sr4   Union[_GFD, _T_co]c                    t                      r:   NotImplementedErrorr  s      r2   r  zgeneric_fn_descriptor.__get__9      !###r4   instancerB   c                    d S r:   rS   r>   r  rB   s      r2   __set__zgeneric_fn_descriptor.__set__>        r4   c                    d S r:   rS   )r>   r  s     r2   
__delete__z generic_fn_descriptor.__delete__@  r  r4   c                    t                      r:   r  r>   rX  s     r2   _resetzgeneric_fn_descriptor._resetB  r  r4   rr   c                    t                      r:   r  rT   rX  rr   s      r2   resetzgeneric_fn_descriptor.resetE  s    !###r4   r:   )r  r  r  rg   )r>   r  rX  r8   rT   r   r*   r  )rX  rB  rT   r   r*   r!   )r>   r  rX  r   rT   r   r*   r  r  r   rB   r   r*   r8   r  r   r*   r8   )rX  r   r*   r8   )rX  r   rr   r+   r*   r8   )rM   rN   rO   rP   rR   r   r   r  r   r  r  r  classmethodr  rS   r4   r2   r  r    s           MMM& & & & &
 === X=::: X:$ $ $ $  9AAAA8888$ $ $ $ $ $ $ [$ $ $r4   r  c                       e Zd ZdZes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                4    || S |                      |          S r:   r  r  s      r2   r  z_non_memoized_property.__get__U  s    {99S>>!r4   N)rM   rN   rO   rP   r   r  rS   r4   r2   r  r  J  sA           "	" 	" 	" 	" 	"" "r4   r  c                  8    e Zd ZdZesd Zd Zed             ZdS )_memoized_propertyz2A read-only @property that is only evaluated once.c                V    || S |                      |          x|j        | j        <   }|S r:   )r  r  rM   r>   rX  rT   results       r2   r  z_memoized_property.__get__`  s.    {3799S>>ACL'&Mr4   c                F    t                               || j                   d S r:   )r  r  rM   r  s     r2   r  z_memoized_property._resetf  s       dm44444r4   c                <    |j                             |d            d S r:   )r  rY   r  s      r2   r  z_memoized_property.reseti  s     t$$$$$r4   N)	rM   rN   rO   rP   r   r  r  r  r  rS   r4   r2   r  r  [  s[        << 	 	 	5 5 5 % % [% % %r4   r  c                .      f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                z     | g|R i |fd}j         |_         j        |_        || j        j         <   S )Nc                     S r:   rS   ar  r  s     r2   memoz6memoized_instancemethod.<locals>.oneshot.<locals>.memo  s    Mr4   )rM   rP   r  r>   r$  r  r  r  r   s       @r2   oneshotz(memoized_instancemethod.<locals>.oneshot  sc    D&4&&&2&&	 	 	 	 	 z%)bk"r4   r   )r   r  s   ` r2   memoized_instancemethodr    s.    	 	 	 	 	 '2&&&r4   c                      e Zd ZU dZesdZ e            Zded<   ddZ	ddZ
ddZ G d dee                   Ze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.

    rS   zFrozenSet[str]_memoized_keysr*   r8   c                P    | j         D ]}| j                            |d            d S r:   )r  r  rY   r>   elems     r2   _reset_memoizationszHasMemoized._reset_memoizations  s9    ' 	* 	*DMdD))))	* 	*r4   c                0    | j         D ]}|| j        vsJ d S r:   )r  r  r  s     r2   _assert_no_memoizationsz#HasMemoized._assert_no_memoizations  s4    ' 	- 	-Dt},,,,,	- 	-r4   r  r+   rB   r   c                <    || j         |<   | xj        |hz  c_        d S r:   )r  r  )r>   r  rB   s      r2   _set_memoized_attributez#HasMemoized._set_memoized_attribute  s*    "cu$r4   c                  r    e Zd ZU dZded<   ded<   ded<   ddd
Zedd            Zedd            Zd ZdS )HasMemoized.memoized_attributezTA read-only @property that is only evaluated once.

        :meta private:

        Callable[..., _T]r  rg   rP   r+   rM   Nr  c                H    || _         |p|j        | _        |j        | _        d S r:   r  r  s      r2   r   z'HasMemoized.memoized_attribute.__init__  s$    DI.$,DL MDMMMr4   r>   r&   rX  r8   rT   r   r*   c                    d S r:   rS   r  s      r2   r  z&HasMemoized.memoized_attribute.__get__  s    <?Cr4   r    c                    d S r:   rS   r  s      r2   r  z&HasMemoized.memoized_attribute.__get__  s    58Sr4   c                    || S |                      |          x|j        | j        <   }|xj        | j        hz  c_        |S r:   )r  r  rM   r  r  s       r2   r  z&HasMemoized.memoized_attribute.__get__  sF    {3799S>>ACL'&4=/1Mr4   r:   )r  r  r  rg   )r>   r&   rX  r8   rT   r   r*   r&   )rX  r   rT   r   r*   r    )rM   rN   rO   rP   rR   r   r   r  rS   r4   r2   memoized_attributer    s         	 	 	 	* 	* 	* 	* 	*
 
??? 
?	888 
8	 	 	 	 	r4   r  r   r#   c                0    dfd}t          |          S )zMDecorate a method memoize its return value.

        :meta private:

        r>   r   r$  r  r*   c                     | g|R i |fd}j         |_         j        |_        || j        j         <   | xj        j         hz  c_        S )Nc                     S r:   rS   r  s     r2   r  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo  s    r4   )rM   rP   r  r  r  s       @r2   r  z4HasMemoized.memoized_instancemethod.<locals>.oneshot  s{    R*t***r**F     KDM:DL)-DM"+&BK=0Mr4   )r>   r   r$  r   r  r   r*   r   r   )rT   r   r  s    ` r2   r  z#HasMemoized.memoized_instancemethod  s3    
	 
	 
	 
	 
	 
	 gr***r4   NrL   )r  r+   rB   r   r*   r8   r   r#   r*   r#   )rM   rN   rO   rP   r   rQ   	frozensetr  rR   r   r  r  memoized_propertyr    r  r  r  rS   r4   r2   r  r    s          
   	%.Y[[N0000* * * *- - - -% % % %    .r2   : + + + [+ + +r4   r  c                  $    e Zd ZdZdZd Z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.

    rS   c                     t          |          r:   )r   )r>   r  s     r2   _fallback_getattrzMemoizedSlots._fallback_getattr  s    S!!!r4   r  r+   r*   r   c                                         d          s                     d          rt                    t           j        d           r. t	           d                       }t           |           |S t           j        d           r(t	           d            fd}j        |_        |S                                S )N_memoized_attr__memoized_method_c                 v     | i |fd}j         |_         j        |_        t          |           S )Nc                     S r:   rS   r  s     r2   r  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo  s    !Mr4   )rM   rP   r  )r$  r  r  r  r  r  r>   s      @r2   r  z*MemoizedSlots.__getattr__.<locals>.oneshot  s\    t*r**" " " " " !%#|c4(((r4   )r  r   r   r{   r|   r  rP   r  )r>   r  rB   r  r  s   ``  @r2   __getattr__zMemoizedSlots.__getattr__  s   >>+,, 	/1
 1
 	/ !%%% T^%<s%<%<== 	/:GD"9C"9"9::<<ED#u%%%LT^%>%>%>?? 	/4!:S!:!:;;D	 	 	 	 	 	 	 #lGON))#...r4   N)r  r+   r*   r   )rM   rN   rO   rP   rQ   r  r  rS   r4   r2   r  r    sH          I" " "/ / / / / /r4   r  c                    t          | t                    rD|                                                                 } | dv rdS | dv rdS t	          d| z            t          |           S )N)trueyesonyt1T)falsenooffrm   f0FzString is not true/false: %r)rb   r+   striprk   
ValueErrorrx   )rX  s    r2   asboolr+  %  sp    #s Ciikk!!66649995;cABBB99r4   text!Callable[[str], Union[str, bool]]c                      d fd}|S )zqReturn a callable that will evaluate a string as
    boolean, or one of a set of "alternate" string values.

    rX  r+   r*   Union[str, bool]c                .    | v r| S t          |           S r:   )r+  )rX  r,  s    r2   bool_or_valuez"bool_or_str.<locals>.bool_or_value7  s    $;;J#;;r4   )rX  r+   r*   r/  rS   )r,  r1  s   ` r2   bool_or_strr2  1  s)          r4   rB   Optional[int]c                (    | | S t          |           S )zCoerce to integer.)r   )rB   s    r2   asintr5  @  s     }u::r4   r  r  r@   
flexi_booldestOptional[Dict[str, Any]]r8   c                    || }|| v rnt          |t                    rt          | |         |          sG| |         =|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)rb   rz   rx   r+  )r  r  r@   r6  r7  s        r2   coerce_kw_typer:  H  s     | 	r		E4(( 	0:2c7E0J0J 	sGD==Z=r#wDIIIbgDIII 		 		r4   c                `     t          |          }|ft           fd|D                       z   S )zbProduce a tuple structure that is cacheable using the __dict__ of
    obj to retrieve values

    c              3  H   K   | ]}|j         v |j         |         fV  d S r:   r  rl   krX  s     r2   rn   z"constructor_key.<locals>.<genexpr>h  sC        !"qCL/@/@CLO/@/@/@/@ r4   )r  r   )rX  rT   r   s   `  r2   constructor_keyr@  b  sS    
 3E6E    &+      r4   r$  c                     t          |          }|                     f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  H   K   | ]}|j         v |j         |         fV  d S r:   r=  r>  s     r2   rn   z#constructor_copy.<locals>.<genexpr>u  sC        !"a3<>O>OCLO>O>O>O>O r4   )r  r/   
difference)rX  rT   r$  r  r   s   `    r2   constructor_copyrD  m  ss     3EII    &+&6&6r&:&:      3r4   Callable[[], int]c                 d    t          j                    t          j        d          fd} | S )z%Return a threadsafe counter function.r   c                 Z    5  t                     cd d d            S # 1 swxY w Y   d S r:   )next)counterlocks   r2   _nextzcounter.<locals>._next  sv     	! 	!==	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s    $$)	threadingLockr   count)rK  rI  rJ  s    @@r2   rI  rI  {  sG     >Doa  G! ! ! ! ! ! Lr4   specimenrd  Optional[Type[Any]]c                   t          | d          r/| j        !t          | j        t                    rt          S | j        S t	          | t
                    rt          nt          } || t                    rt          S  || t                    rt          S  || t                    rt          S t          | d          rt          S t          | d          rt          S t          | d          rt          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   rZ   rX   )r   rR  r  rX   rb   rz   r   r   )rO  rd  isas      r2   duck_type_collectionrT    s     x(( ) ,!32
 2
, J(("8T22
B**
C
s8T 	Xs		 
	Xt		 x"" 	5	!	! 
	5	!	! r4   r`  argtype'Union[Tuple[Type[Any], ...], Type[Any]]rr   c           
     6   t          | |          r| S t          |t                    rHt          j        d|dd                    d |D                       dt          |           d          t          j        d|d|dt          |           d          )	Nz
Argument 'z ' is expected to be one of type z or c              3      K   | ]	}d |z  V  
dS )z'%s'NrS   )rl   r  s     r2   rn   z"assert_arg_type.<locals>.<genexpr>  s&      $A$AAVaZ$A$A$A$A$A$Ar4   z, got ''z' is expected to be of type 'z', got ')rb   r   r   ArgumentErrorro   rz   )r`  rU  rr   s      r2   assert_arg_typer[    s     #w 
gu%% 		##44$A$A$A$A$AAAAA49999N  
 ##44$s))))-  r4   c           	         t           d          r!t                                                     S t           dt           dd                    t	          d z            t           d          r fd} |            S t           d          r-t          fd	                                 D                       S t	          d z            )
z?Return a (key, value) iterator for almost any dict-like object.rp  __getitem__r  NzObject '%r' is not dict-likeiterkeysc               3  `   K                                    D ]} J |  |           fV  d S r:   )r^  )r  dictlikegetters    r2   iteratorz$dictlike_iteritems.<locals>.iterator  sT      ((** ' ')))66#;;&&&&&' 'r4   r  c              3  2   K   | ]}| |          fV  d S r:   rS   )rl   r  ra  s     r2   rn   z%dictlike_iteritems.<locals>.<genexpr>  s0      BB3S&&++&BBBBBBr4   )r   r   rp  r|   r  iterr  )r`  rb  ra  s   ` @r2   r  r    s     x!! &HNN$$%%%X}ght.L.LMMF~6ABBBx$$ C	' 	' 	' 	' 	' 	'
 xzz	6	"	" CBBBB(--//BBBBBB6ABBBr4   c                  :     e Zd ZU dZded<   d fdZdddZ x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   r  c                Z     t                      j        |g|R i | |j        | _        d S r:   )superr   rP   )r>   r  r`  r  r{   s       r2   r   zclassproperty.__init__  s7    ****r***|r4   NrX  rT   Optional[type]r*   c                ,    |                      |          S r:   r  r  s      r2   r  zclassproperty.__get__  s    yy~~r4   )r  rg  r`  r   r  r   r:   )rX  r   rT   rj  r*   r   )rM   rN   rO   rP   rR   r   r  __classcell__r{   s   @r2   rf  rf    sp           $ $ $ $ $ $        r4   rf  c                  &    e Zd ZddZdd	ZddZdS )hybridpropertyr  r  c                "    || _         || _        d S r:   )r  clslevelr>   r  s     r2   r   zhybridproperty.__init__  s    	r4   r  r   ownerr*   r    c                ^    ||                      |          }|S |                     |          S r:   rq  r  r>   r  rs  clsvals       r2   r  zhybridproperty.__get__  0    ]]5))FM99X&&&r4   rw   hybridproperty[_T]c                    || _         | S r:   rq  rr  s     r2   
classlevelzhybridproperty.classlevel      r4   Nr  r  r  r   rs  r   r*   r    )r  rw   r*   ry  )rM   rN   rO   r   r  r|  rS   r4   r2   ro  ro    sP           ' ' ' '     r4   ro  c                  6    e Zd ZddZdd	ZddZddZddZdS )rw_hybridpropertyr  r  c                0    || _         || _        d | _        d S r:   )r  rq  setfnrr  s     r2   r   zrw_hybridproperty.__init__  s    	37


r4   r  r   rs  r*   r    c                ^    ||                      |          }|S |                     |          S r:   ru  rv  s       r2   r  zrw_hybridproperty.__get__  rx  r4   rB   r8   c                D    | j         J |                      ||           d S r:   r  r  s      r2   r  zrw_hybridproperty.__set__	  s*    z%%%

8U#####r4   rw   rw_hybridproperty[_T]c                    || _         | S r:   r  rr  s     r2   setterzrw_hybridproperty.setter  s    
r4   c                    || _         | S r:   r{  rr  s     r2   r|  zrw_hybridproperty.classlevel  r}  r4   Nr~  r  r  )r  rw   r*   r  )rM   rN   rO   r   r  r  r  r|  rS   r4   r2   r  r    sx        8 8 8 8
' ' ' '$ $ $ $        r4   r  c                  *    e Zd ZdZddZdd	ZddZdS )hybridmethodz/Decorate a function as cls- or instance- level.r  r  c                0    |x| _         | _        || _        d S r:   )r  r   rq  rr  s     r2   r   zhybridmethod.__init__  s    $((	DMr4   r  r   rs  r*   c                |    | | j                             ||j                  S | j                            ||          S r:   )rq  r  r{   r  )r>   r  rs  s      r2   r  zhybridmethod.__get__  s:    =((@@@9$$Xu555r4   rw   hybridmethod[_T]c                    || _         | S r:   r{  rr  s     r2   r|  zhybridmethod.classlevel#  r}  r4   Nr~  )r  r   rs  r   r*   r  )r  rw   r*   r  )rM   rN   rO   rP   r   r  r|  rS   r4   r2   r  r    sV        99   6 6 6 6     r4   r  c                  j    e Zd ZU dZded<   i Zded<    ej                    Z	 	 dddZ	d Z
d Zd ZdS )symbolaI  A constant symbol.

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

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

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

    r+   rr   zDict[str, symbol]symbolsNr  rg   	canonicalr3  r*   c                   | j         5  | j                            |          }|ct          |t                    sJ |t          |          }t                              t          |          }||_	        |r||_
        || j        |<   n|r||k    rt          d|d|           |cd d d            S # 1 swxY w Y   d S )Nz#Can't replace canonical symbol for z with new int value )_lockr  r  rb   r+   hashr   __new__r  rr   rP   r  )rT   rr   r  r  r   s        r2   r  zsymbol.__new__<  s0    Y 	 	+//$''C{!$,,,,,$ $T

Ikk&)44 &"%CK %(D!! c!1!1#:d : :.7: :   -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB33B7:B7c                >    t           | j        dt          |           ffS )Nr)   )r  rr   r   r=   s    r2   
__reduce__zsymbol.__reduce__Z  s    	3D		222r4   c                     t          |           S r:   rg  r=   s    r2   __str__zsymbol.__str__]  s    Dzzr4   c                    d| j         dS )Nzsymbol(rk  rr   r=   s    r2   __repr__zsymbol.__repr__`  s    '''''r4   )NN)rr   r+   r  rg   r  r3  r*   r  )rM   rN   rO   rP   rR   r  rL  rM  r  r  r  r  r  rS   r4   r2   r  r  (  s           III!#G####INE
 "#'	    <3 3 3  ( ( ( ( (r4   r  c                      e Zd ZddZddZdS )_IntFlagMeta	classnamer+   r   Tuple[Type[Any], ...]dict_r   r  r   r*   r8   c                   g x| _         }|                                D ]\  }}t          j        d|          rt	          |t
                    rt          ||          }n%|                    d          st          d          gt          | ||           |
                    |           t          j        d |D                       | _        d S )Nz^__.*__$)r  r  z#Expected integer values for IntFlagc                    i | ]
}|j         |S rS   r  )rl   r   s     r2   
<dictcomp>z)_IntFlagMeta.__init__.<locals>.<dictcomp>{  s    ,,,sSXs,,,r4   )_itemsrp  rp   matchrb   r   r  r  r  r  r   r   immutabledict__members__)	rT   r  r   r  r  rp  r?  vr   s	            r2   r   z_IntFlagMeta.__init__e  s      
UKKMM 
	 
	DAqxQ'' !S!! Q!,,,\\#&&  EFFFCC   LL&4,,e,,,
 
r4   Iterator[symbol]c                     t          d          )Nziter not implemented to ensure compatibility with Python 3.11 IntFlag.  Please use __members__.  See https://github.com/python/cpython/issues/99304r  r=   s    r2   __iter__z_IntFlagMeta.__iter__~  s    !=
 
 	
r4   N)
r  r+   r   r  r  r   r  r   r*   r8   )r*   r  )rM   rN   rO   r   r  rS   r4   r2   r  r  d  s<        
 
 
 
2
 
 
 
 
 
r4   r  c                      e Zd ZdZdS )_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  rS   r4   r2   r  r    s           r4   r  )	metaclass)IntFlag_EchoicesDict[_E, List[Any]]resolve_symbol_namesOptional[_E]c                    |                                 D ]&\  }}| |u r|c S |r| |j        k    r|c S | |v r|c S '| dS t          j        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': )rp  rr   r   rZ  )r`  r  rr   r  
enum_valuechoices         r2   parse_user_argument_for_enumr    s    ( &mmoo  
F*! 	cZ_&<&<F]]  {t

B$BB3BB
C
CCr4   r  c                2    t           | _         t           dz  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  s    r2   set_creation_orderr    s      /HqOOOr4   rR  c                    	  | |i |S # t           $ r/ t          dt          j                    dd         z             Y dS w xY w)zXexecutes the given function, catches all exceptions and converts to
    a warning.

    z%s('%s') ignoredr   r   N)rc   warnr;   r<   )r  r$  rR  s      r2   warn_exceptionr    sc    
7tT$V$$$ 7 7 7#,..1"556666667s   
 5AA   c                l    	 t          |           |k    rd| d|         z  S | S # t          $ r | cY S w xY w)Nz%s...r   )r   r  )rB   len_s     r2   ellipses_stringr    sT    u::U1T6]**L   s   $ $ 33c                  @     e Zd ZU dZded<   d fd
ZddZddZ x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   _hashrB   r+   numr$  Sequence[Any]r*   c                    ||z  d|z  z   }t                                          | |          }t          d|t          |          |z  fz            |_        |S )Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)ri  r  r  r  )rT   rB   r  r$  interpolatedr>   r{   s         r2   r  z_hash_limit_string.__new__  s_     DsJ
 wwsL11'UD,>,>,D$EEFF
r4   c                    | j         S r:   )r  r=   s    r2   __hash__z_hash_limit_string.__hash__  s
    zr4   otherr   rx   c                B    t          |           t          |          k    S r:   )r  )r>   r  s     r2   __eq__z_hash_limit_string.__eq__  s    DzzT%[[((r4   )rB   r+   r  r   r$  r  r*   r  )r*   r   )r  r   r*   rx   )	rM   rN   rO   rP   rR   r  r  r  rl  rm  s   @r2   r  r    s|           JJJ        ) ) ) ) ) ) ) )r4   r  msgc                    |r%t          t          j        | |                     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   s     r2   r  r     sG      +s}St44455555sCM*****r4   r  c                `    |rt          | d|          } t          | t          j                   dS )z\Issue a warning with a parameterized string, limiting the number
    of registrations.

    
   N)r  r  r   r  )r  r$  s     r2   warn_limitedr    s5    
  0 b$//3&&&&&r4   z)Dict[CodeType, Tuple[str, Type[Warning]]]_warning_tagsmessagecategoryType[Warning]Callable[[_F], _F]c                      fd}|S )Nc                *    ft           | j        <   | S r:   )r  r   )r   r  r  s    r2   goz#tag_method_for_warnings.<locals>.go  s    &-x%8bk"	r4   rS   )r  r  r  s   `` r2   tag_method_for_warningsr    s)          Ir4   z&^(?:sqlalchemy\.(?!testing)|alembic\.)Union[str, Warning]Optional[Type[Warning]]
stacklevelc                   	 t          j        |          }dx}}|~|s5t          j        t          |j                            dd                    sd}|j        t          v r#d}t          |j                 \  }}|p|}|  d| d} |j	        }|s|dz  }n|r|rn|~n# t          $ r d}Y n d}Y nxY w|t          j        | ||dz   	           d S t          j        | |dz   	           d S )
NFrM   r   Tz (rk  r   r   )r  )r;   	_getframerp   r  _not_sa_pattern	f_globalsr  f_coder  f_backr*  warningsr  )r  r  r  framestacklevel_foundwarning_tag_found_suffix	_categorys           r2   r  r  '  s]   %j)) 054, $ (BH!4!4Z!D!D- - (
 $( 
 |},,$(!'4U\'B$)#0y$22222LE# a

! &7 3      


 


< gxJNCCCCCCg*q.999999s   B B.)B.r  retry_on_exceptionCallable[..., Optional[_T]]c                "      gd fd}|S )zNDecorate the given function to be a no-op after it is called exactly
    once.r`  r   r  r*   Optional[_T]c                     }r;                                 }	  || i |S #  r                    d|            xY wd S )Nr   )rY   insert)r`  r  	strong_fnonce_fnr   oncer  s       r2   r  zonly_once.<locals>.gob  sf     	 	hhjjGw*r***% ,KK7+++ts   # >)r`  r   r  r   r*   r  rS   )r   r  r  r  s   `` @r2   	only_oncer  Z  s=     4D        Ir4   z%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)tbexclude_prefixre.Pattern[str]exclude_suffixc                `   d}t          |           dz
  }||k    rA|                    | |                   r&|dz  }||k    r|                    | |                   &||k    rA|                    | |                   r&|dz  }||k    r|                    | |                   &| ||dz            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   ends        r2   chop_tracebackr  x  s    " E
b''A+C
3,,>00E;;,
 3,,>00E;;,
3,,>00C99,q 3,,>00C99,ecAgor4   c                |    d| z  }t                                                      }t          ||           |d         S )Nz&def set(obj, value):    obj.%s = valuerX   )r  copyr   )attrnamer   r   s      r2   
attrsetterr    s4    3h>D
((--//CsOOOu:r4   z^__.+__$c                  (     e Zd ZdZdZd fdZ xZS )
TypingOnlyzA mixin class that marks a class as 'typing only', meaning it has
    absolutely no methods, attributes, or runtime functionality whatsoever.

    rS   r*   r8   c                    t           | j        v r)d | j        D             }|rt          d|  d| d          t	                                                       d S )Nc                F    h | ]}t                               |          |S rS   )_dundersr  rl   rr   s     r2   	<setcomp>z/TypingOnly.__init_subclass__.<locals>.<setcomp>  s9       X^^D5I5I  r4   zClass z< directly inherits TypingOnly but has additional attributes r   )r	  r  r  AssertionErrorri  __init_subclass__)rT   	remainingr{   s     r2   r  zTypingOnly.__init_subclass__  s    && !$  I  $:S : :-6: : :   	!!#####r4   rL   )rM   rN   rO   rP   rQ   r  rl  rm  s   @r2   r	  r	    sN         
 I
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$r4   r	  c                  J     e Zd ZU dZded<   	 d
 fdZedd	            Z xZS )EnsureKWArga6  Apply translation of functions to accept \**kw arguments if they
    don't already.

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

    r+   ensure_kwargr*   r8   c                2   | j         }| j        }|re|D ]b}t          j        ||          }|rI||         }t	          j        |          }|j        s&|                     |          }t          | ||           ct                      
                                 d S r:   )r  r  rp   r  r   r   r&  
_wrap_w_kwr  ri  r  )	rT   fn_regclsdictr  r1   r   r   wrappedr{   s	           r2   r  zEnsureKWArg.__init_subclass__  s    !, 	3 3 3HVS)) 3 B!8<<D: 3"%.."4"4S'222!!#####r4   r   rw   c                0    dfd}t          |          S )Nr`  r   r  r*   c                      |  S r:   rS   )r`  r  r   s     r2   wrapz$EnsureKWArg._wrap_w_kw.<locals>.wrap  s    2s8Or4   )r`  r   r  r   r*   r   r   )rT   r   r  s    ` r2   r  zEnsureKWArg._wrap_w_kw  s3    	 	 	 	 	 	 dB'''r4   rL   )r   rw   r*   rw   )	rM   rN   rO   rP   rR   r  r  r  rl  rm  s   @r2   r  r    s|           $ $ $ $ $ $ ( ( ( [( ( ( ( (r4   r  c                0   t          |d          rt          | |          S | }|j        j        |_        t          |d          r|j        |_        t          |j        d          r|j        j        r|j        j        |_        n|j        r|j        |_        |S )zAugment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    rM   rN   rP   )r   r   r{   rM   rN   r!  rP   )wrapperr   _fs      r2   wrap_callabler     s     r: gr***l+2|$$ 	*MBM2;	** 	$r{/B 	$,BJJZ 	$BJ	r4   c                   d| vr|                      d          S d}g g}d}t          |           }||k     r| |         }|dk    rE|dk    r9||dz
  k     r0| |dz            dk    r!|d                             d           |dz  }nC|dz  }n=|dk    r|dk    r|                    g            n|d                             |           |dz  }||k     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                8    g | ]}d                      |          S )r   )ro   )rl   r   s     r2   rb  z'quoted_token_parser.<locals>.<listcomp>  s"    ///uBGGENN///r4   )r   r   r   )rB   r  r  idxlvchars         r2   quoted_token_parserr'    s   $ %{{3 E!dF
C	UB
((Sz3;;zzcBFlluS1W~/D/Dr
!!#&&&q
S[[UaZZMM"2Jd###q (( 0/////r4   paramsc                >     t          j                     fd}|S )Nc                v    | j         d ur| j         pd}|rt          |fdD                       }|| _         | S )Nr   c                    i | ]}|S rS   rS   )rl   paramr,  s     r2   r  z8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>'  s    )J)J)J%%)J)J)Jr4   )rP   inject_param_text)r   r  r(  r,  s     r2   r   z$add_parameter_text.<locals>.decorate$  sT    j$39r 	L#C)J)J)J)J6)J)J)JKKC
	r4   )r   rl  )r(  r,  r   s   `` r2   add_parameter_textr.  !  s9    !&))F      Or4   c                    |                      dd          }t          |          dk    r| S |\  }}|                    d          s|dz   t          j        |          z   S t          j        |           S )N
r   ri   )r   r   r  textwrapdedent)r,  
split_text	firstliner  s       r2   _dedent_docstringr5  .  su    D!$$J
:!)	9$$ %4(/)"<"<<<t$$$r4   given_doctext
injecttextposc                ,   t          | pd          }|                    d          }t          |          dk    r|                    d           t	          j        |                              d          }|d         r|                    dd           d t          |          D             }|                    dd           |t          |t          |          dz
                     }|d|         |z   ||d          z   }d	                    |          S )Nr   r0  r   r   c                @    g | ]\  }}|                                 |S rS   )r)  )rl   r  lines      r2   rb  z)inject_docstring_text.<locals>.<listcomp>E  s)    HHHic44::<<HcHHHr4   )
r5  r   r   r   r1  r2  r  rn  minro   )r6  r7  r8  doctextlinesinjectlinesblanks
inject_poss           r2   inject_docstring_textrB  :  s    %]%8b99GMM$E
5zzQR/*--33D99K1~ "1b!!!HH9U#3#3HHHF
MM!QCVq112J!J,+-jkk0BBE99Ur4   z(\s+):param (.+?):r=  inject_paramsDict[str, str]c                z   t          j        |                                           }g }d }|rz|                                }t                              |          }||r|                    d                              d          }||v rwdt          |                    d                    z  dz   }|rBt          j        d|d                   }	|	r%dt          |	                    d                    z  }|||         z   }n|r|
                    d|dg           d }no|                                s|
                    ||dg           d }n@|                    d          r+|
                    ||                                g           e|                    |           |zd                    |          S )	Nr   *ri   r   z(\s+)\Sr   r0  z::)collectionsdeque
splitlinespopleft
_param_regr  r   lstripr   rp   r[   rstripr  r   ro   )
r=  rC  doclinesr>  	to_injectr;  r1   r,  indentm2s
             r2   r-  r-  Q  s    !3!3!5!566HE I
 !!T"" >

))#..M)) 3qwwqzz??2S8F   <Xj(1+>> <%(3rxx{{+;+;%;F &u)= =I 
	LL$	40111II 	LL$	40111II]]4   	 LL$ 0 0 2 23444T?  B 99Ur4   r   c                *   t          |           dk    rdS t          |           dk    }|r
| dd         n| dd         | dd         z   } d | D             }|rd                    |          S d                    |dd                   d|d         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                R    g | ]$}t          |          d k    rd|dd          z  n|%S )   z%s..N)r   r  s     r2   rb  z$repr_tuple_names.<locals>.<listcomp>  s8    
L
L
LdTR6D"IT
L
L
Lr4   rj  z, ..., )r   ro   )r   flagress      r2   repr_tuple_namesrW  |  s     5zzQtu::?D;E!A#JJE!A#Jrss$;E
L
Le
L
L
LC >yy~~ $		#ac( 3 3 3 3SWW==r4   c                :    t           rdS | rt          d          dS )NTzDcython extensions were expected to be installed, but are not presentF)r   ImportError)raise_s    r2   has_compiled_extr[    s5     t	 "
 
 	

 ur4   c                  ,    e Zd Z ej                    ZdS )_MissingN)rM   rN   rO   enumautoMissingrS   r4   r2   r]  r]    s        dikkGGGr4   r]  )r)   r   r*   r+   )rT   rU   r*   rV   )r`   r   r*   r+   r:   )rT   re   rf   rg   r*   r+   )rt   ru   rv   rw   r*   rx   )r   r   r*   r   )r   r   r   r+   r*   r   )r   r   rm   r   r*   r   )r   rw   r*   r   )r   r   r   r   r   r+   r*   rw   )rT   rz   r  r  r  r  r*   r  )rT   rz   r  r  r  rx   r*   r  )r  rw   r*   r  )FF)r   rw   r  rx   r  rx   r*   r  )T)r   r+  r   rx   r*   r,  )rS   rS   rS   rS   )rF  re   rG  r+   rH  r+   rI  r   rJ  r   rK  r   rL  r   r*   rM  )rS   NrS   )
rX  r   rY  rZ  r[  r\  r]  r   r*   r+   )NNr  N)NNNr  )rX  r   r*   rx   )r,  r+   r*   r-  )rB   r   r*   r3  )TN)r  r   r  r+   r@   re   r6  rx   r7  r8  r*   r8   )rX  r   rT   re   r*   r   )
rX  r    rT   rU   r$  r   r  r   r*   r    )r*   rE  )rO  r   rd  rP  r*   rP  )r`  r   rU  rV  rr   r+   r*   r   )F)
r`  r   r  r  rr   r+   r  rx   r*   r  r  )r  rw   r$  r   rR  r   r*   r   )r  )r  r+   r   rg   r*   r8   )r  r+   r$  r  r*   r8   )r  r+   r  r  r*   r  )Nr   )r  r  r  r  r  r   r*   r8   )r   r  r  rx   r*   r  )r  r  r  r  r  r  r*   r  )r(  r   r,  r+   r*   r  )r,  r+   r*   r+   )r6  rg   r7  r+   r8  r   r*   r+   )r=  r+   rC  rD  r*   r+   )r   r  r*   rg   )rP   
__future__r   rG  r^  	functoolsr   r   r   r  rp   r;   r1  rL  r   r   typingr   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(   r3   r6   r_   rd   rs   r   r   r   r   r   r   r   r   r   r   r  r  r  r*  r   rE  rP  rS  rW  rx  rz  r  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+  r2  r5  r:  r@  rD  rI  rT  r[  r  rf  ro  r  r  r   r  rz   r  r  r  FastIntFlagEnumr  r  r  r  r  r  r+   r  r  r  r  rR   r  compiler  r  r  _SQLA_RE_UNITTEST_REr  NoneTyper  r  r	  r  r   r'  r.  r5  rB  rK  r-  rW  r[  r]  r`  	MissingOrrS   r4   r2   <module>rq     s     # " " " " "      $ $ $ $ $ $       				 



                                                                                                                                            $ $ $ $ $ $            WT]]4(((WT#s(+,,,ge3444ge@AAAge0111ge.///$ $ $ $82 82 82 82 82 82 82 82v   6 6 6 6 /3O O O O O, , , ,$   M M M M     ge/000
Y, Y, Y, Y,x    genngenn( ( ( ( ( ( ( (V
 
 
( 
  $!	     
 
-1E     
 .2E2 2 2 2 2 2j2 2 2 2 EJ5; 5; 5; 5; 5;r HLr
 r
 r
 r
 r
j   J #% "/1    26 6 6(	 	 	 028< "	KB KB KB KB KB\; ; ; ; ; ; ; ;<# # #L  & 
		@/ @/ @/ @/F  S S S Sl wv9:::($ ($ ($ ($ ($GEN ($ ($ ($V" " " " "259 " " ""% % % % %.u5 % % %<  N .1
 $' 0BA,7MM4' ' ' '.J+ J+ J+ J+ J+ J+ J+ J+Z  G(0%%(3(F%-/ -/ -/ -/ -/ -/ -/ -/b	 	 	 	       %)' ' ' ' '4          37         F   $C C C0    H   *    WR[   "       4    72;   $9( 9( 9( 9( 9(S 9( 9( 9(x
 
 
 
 
4 
 
 
D    \      KKK WT### "'	D D D D DD 
 
 
 
7 7 7 7   ) ) ) ) ) ) ) )<
+ 
+ 
+ 
+ 
+' ' ' ' <> = = = =    "*FGG
 )-0: 0: 0: 0: 0:f   4 2:>??rz.//
 '3&.    4 4::   2:j!!$ $ $ $ $ $ $ $*&( &( &( &( &( &( &( &(R  0)0 )0 )0X
 
 
 
	% 	% 	% 	%   ( RZ-..
( ( ( (V> > > >	 	 	 	    ty    
"gh.//0			r4   