
    gt                    l	   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"#      Z- e"d$ed%ef   &      Z. e"d'd(&      Z/ e"d)d*&      Z0 e"d+d,&      Z1 e"d-d.&      Z2e'jf                  rdd/Z4ndd0Z4dd1Z5 G d2 d3      Z6dd4Z7dd5Z8	 d	 	 	 	 	 dd6Z9	 	 	 	 	 	 dd8Z:dd9Z;dd:Z<dd;Z= e"d<d7&      Z>dd=Z?d> Z@	 	 	 	 	 	 	 	 dd?ZA e"d@      ZB e"dA      ZC G dB dC      ZDdD ZEedd%dE	 	 	 	 	 	 	 ddF       ZFeddGdE	 	 	 	 	 	 	 ddH       ZFddGdE	 	 	 	 	 	 	 ddIZFddJZG	 d	 	 	 	 	 	 	 ddKZH	 d	 	 	 	 	 ddLZIddMZJ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddNZKdO ZLdP ZM	 	 	 d	 	 	 	 	 	 	 	 	 ddQZN G dR dS      ZOdT ZPdU ZQ	 	 	 	 ddVZRdW ZSddXZT e"dYdZ&      ZU G d[ d\ee-         ZV G d] d^eVe-         ZW G d_ d`eVe-         ZXe!r	eVZYeVZZe[Z\e[Z]neXxZYZ\eWxZZZ]ddaZ^ G db dc      Z_e!re[Z`ne_j                  Z` G dd de      ZbddfZcddgZdddhZe	 	 d	 	 	 	 	 	 	 	 	 	 	 ddiZfddjZgddkZhddlZi	 d	 	 	 	 	 ddmZj	 	 	 	 	 	 	 	 ddnZkdo Zl G dp dqe[      Zm G dr dsee,         Zn G dt duee,         Zo G dv dwee,         Zp G dx dyeq      Zr G dz d{es      Zt G d| d}et~      Zue!r	ddlmvZv evZwneuZw e"dej                  &      Zy	 d	 	 	 	 	 	 	 	 	 ddZzda{ddZ|ddZ}ddZ~ G d de      ZdddZddZi Zded<   	 	 	 	 	 	 ddZ e
j                  d      Z	 	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ e
j                  d      Z e
j                  d      Zeef	 	 	 	 	 	 	 ddZ esd      Zd Z e
j                  d      Z G d d      Z G d d      Zd Zd ZddZddZ	 	 	 	 	 	 	 	 ddZ e
j                  d      ZddZddZddZ G d dej                        Zej8                  Ze#e,e*ej8                     f   Zy)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]c                ,    t        j                  |       S N)inspectget_annotationsobjs    Z/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.pyr-   r-   A   s    &&s++    c                    t        | t              r| j                  j                  dd       }nt	        | dd       }|t
        j                  S t        d|      S )N__annotations__Mapping[str, Any])
isinstancetype__dict__getgetattrr   
EMPTY_DICTr	   )r/   anns     r0   r-   r-   F   sS     c4 ,,""#4d;C#0$7C;***+S11r1   c                    | j                  d      } t        j                         }|j                  |        t	        t
        |j                               S )Nzutf-8)encoder   md5_not_for_securityupdater	   str	hexdigest)xms     r0   md5_hexrD   W   s<    	A##%AHHQKQ[[]##r1   c                  @    e Zd ZU dZdZded<   ddZ	 	 	 	 	 	 	 	 d	dZy)
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]]rG   c                6    t        j                         | _        y r+   )sysexc_inforG   selfs    r0   	__enter__zsafe_reraise.__enter__   s    r1   c                    | j                   J |,| j                   \  }}}|J d | _         |j                  |      d | _         |J |j                  |      r+   )rG   with_traceback)rL   type_value	tracebackexc_type	exc_valueexc_tbs          r0   __exit__zsafe_reraise.__exit__   sq     ~~)))=*...'Hi(((!DN**622!DN$$$&&y11r1   NreturnNone)rP   zOptional[Type[BaseException]]rQ   zOptional[BaseException]rR   zOptional[types.TracebackType]rX   r   )__name__
__module____qualname____doc__	__slots__r3   rM   rV    r1   r0   rF   rF   ^   sH    0 I (2,2 '2 1	2
 
2r1   rF   c              #     K   t               }| g}|rM|j                         } | |v r|j                  |        |j                  | j	                                |  |rLy y wr+   )setpopaddextend__subclasses__)clsseenstacks      r0   walk_subclassesri      sV     UDEE
iik$;HHSMS'')*	 s   AA A c                f    t        | t              r| S 	 t        |       S # t        $ r d| z  cY S w xY w)Nzunprintable element %r)r5   r@   	Exception)elements    r0   string_or_unprintablerm      s:    '3	6w< 	6+g55	6s   
 00c                z    |xs | j                   }dj                  d t        j                  d|      D              S )N c              3  <   K   | ]  }|j                           y wr+   )lower).0ns     r0   	<genexpr>z(clsname_as_plain_name.<locals>.<genexpr>   s     N!AGGINs   z([A-Z][a-z]+|SQL))rZ   joinrefindall)rf   use_namenames      r0   clsname_as_plain_namerz      s3     #s||D88Nrzz2F'MNNNr1   Callable[..., Any]c                z    t        | t              s| j                  }n| }|j                  }t	        ||      }||k7  S )z1Return True if the two class methods don't match.)r5   r6   	__class__rZ   r9   )instance_or_clsagainst_methodcurrent_clsmethod_namecurrent_methods        r0   method_is_overriddenr      s@     ot,%//% ))K'.{K'HN^++r1   c                    g }| j                   | j                  | j                  fD ]/  }t        |d      r|j	                         }|j                  |       1 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)slcretrB   s      r0   decode_slicer      sW     CYY#((* 1k"A

1 :r1   c           
   '     K   t        |       }|D ]^  t        j                  ft        fdt	        d                  }|D ]  }||vs|j                  |       |  Q t        dz         y w)Nc                     t        |       z   S r+   r@   )ibases    r0   <lambda>z!_unique_symbols.<locals>.<lambda>   s    $Q- r1   i  z&exhausted namespace for symbol base %s)ra   	itertoolschainmaprangerc   	NameError)usedbasesused_setpoolsymr   s        @r0   _unique_symbolsr      s     4yH MG't5
  	MC("S!			M DtKLLMs   AA3(A3c              #  H   K   |r|| dz   z  } | |       ||z  }|ryyw)z6Call the given function given each nonzero bit from n.r   Nr_   )fnrs   bs      r0   map_bitsr      s1      !aLe	Q s   ""_Fnc                (     d fd}t        |       S )z'A signature-matching decorator factory.c                   t        j                  |       s t        j                  |       st        d      t	        j
                  |       }i }t        ||      }t        t        d|d               t        d|dd       z   | j                  fz   }t        |dd      \  }}t        ||      }|j                  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  }t         j"                  | j$                     }|j                  t'        |             |j                  |
|| d| j$                  i       t        t(        j*                  t-        ||| j                              }	t/        | d|       j0                  |	_        | |	_        t5        |	|       S )Nznot a decoratable functionzTuple[str, ...]r   r      targetr   )r   r   Fgroupedry   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)
rZ   __func__)r,   
isfunctionismethodrk   r   inspect_getfullargspec!_update_argspec_defaults_into_envr   r	   rZ   r   dictr?   format_argspec_plusiscoroutinefunctionreprrI   modulesr[   varstypesFunctionType_exec_code_in_envr9   __defaults____wrapped__r   )r   specenvnames	targ_namefn_namemetadatacodemod	decoratedr   s             r0   decoratezdecorator.<locals>.decorate   s   !!"%g.>.>r.B899,,R0 0s; $($q'23$d1Qi01{{n 	
 -UHdC	7-1w-O+D%@A;;&&r*!)HX(0H_%!#HX(*H_% 4Q=  	  	  kk"--(

49

IvwJNOdC5
	 ")Z!<!I!I	 "	i,,r1   )r   r   rX   r   r   )r   r   s   ` r0   	decoratorr      s    ?-B (F++r1   c                0   | j                   rg }d}| j                   D ]K  }t        |      j                  dvr!d|z  }|||<   |j                  |       |dz  };|j                  |       M t	        |       }t        |      |d<   t        j                  | S | S )zCgiven a FullArgSpec, convert defaults to be symbol names in an env.r   )builtins__builtin__zx%dr   r   )defaultsr6   r[   r   listr   r   FullArgSpec)r   r   new_defaultsr   argry   elems          r0   r   r   =  s     }}== 	)CCy##+FFqyD	##D)Q##C(	) Dz%Q!!4((r1   c                $    t        | |       ||   S r+   )exec)r   r   r   s      r0   r   r   R  s     	sOw<r1   _PF_TEc                  4    e Zd Z	 d	 	 	 ddZd ZddZd	dZy)
PluginLoaderNc                .    || _         i | _        || _        y r+   )groupimplsauto_fn)rL   r   r   s      r0   __init__zPluginLoader.__init__^  s     
%'
r1   c                8    | j                   j                          y r+   )r   clearrK   s    r0   r   zPluginLoader.cleare  s    

r1   c                   || j                   v r | j                   |          S | j                  r)| j                  |      }|r|| j                   |<    |       S t        j                  | j                        D ]<  }|j
                  |k(  s|j                  | j                   |<   |j                         c S  t        j                  d| j                  d|      )NzCan't load plugin: :)	r   r   r   importlib_metadata_getr   ry   loadr    NoSuchModuleError)rL   ry   loaderimpls       r0   r   zPluginLoader.loadh  s    4::#4::d#%%<<\\$'F#)

4 x11$**= 	#DyyD #'99

4 yy{"	#
 ##*.**d;
 	
r1   c                2    fd}|| j                   |<   y )Nc                 |    t              } j                  d      dd  D ]  }t        | |      }  t        |       S )N.r   )
__import__splitr9   )r   token
modulepathobjnames     r0   r   z#PluginLoader.register.<locals>.load|  sG    Z(C#))#.qr2 *c5)*3((r1   )r   )rL   ry   r   r   r   s     `` r0   registerzPluginLoader.register{  s    	)  

4r1   r+   )r   r@   r   zOptional[Callable[..., Any]])ry   r@   rX   r   )ry   r@   r   r@   r   r@   rX   rY   )rZ   r[   r\   r   r   r   r   r_   r1   r0   r   r   ]  s)    BF#?
& r1   r   c                "   	 t         j                  }| j                  }|j                  }t	        |j
                  d |       t        |j                  |z        fS # t        $ r+ t        j                  |       }|d   t        |d         fcY S w xY w)Nr   r   )r,   CO_VARKEYWORDS__code__co_argcountr   co_varnamesboolco_flagsAttributeErrorr   r   )r   co_varkeywordsconargsr   s        r0   _inspect_func_argsr     s    
 // [['(~-.
 	
  &
 ,,R0AwT!W%%&s   A 1BB)_setraiseerrc                    y r+   r_   rf   r   r   s      r0   get_cls_kwargsr     s     r1   Fc                    y r+   r_   r   s      r0   r   r     s     r1   c                  |du }|r
t               }|J | j                  j                  dd      }|xr@ t        |t        j
                        xr$ t        |j                  t        j                        }|r5t        |      \  }}|j                  |       |s|s|rt        d|  d      yd}|r|r | j                  D ]  }t        ||       n |j                  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   rL   )ra   r7   r8   r5   r   r   r   r   r   r?   	TypeError	__bases__r   discard)	rf   r   r   toplevelctrhas_initr   has_kwcs	            r0   r   r     s    " t|Hu
,,

:u
-C 	 	5sE../	5s||U^^4  *3/vEh %EF  v 	Aad+3	 	LLKr1   c                2    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   )funcs    r0   get_func_kwargsr    s     ((.q11r1   c           	        t        j                  |       rt        d| z        t        j                  |       r|r{|ryt	        j
                  |       }t	        j                  |j                  dd |j                  |j                  |j                  |j                  |j                  |j                        S t	        j
                  |       S t        j                  |       r|r|s| j                  rt	        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      rDt        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)no_self_is_initr   __call__)r  zCan't inspect callable: %s)r,   	isbuiltinr  r   r   r   r   argsvarargsvarkwr   
kwonlyargskwonlydefaultsr   r   __self__r   isclassget_callable_argspecr   r   r  )r   r  r  r   s       r0   r  r    s    3b899			B	004D%%		!"

##    0044			"	BKK00=D%%		!"

##    00==		#KK4
 	
 
Z	 ,,R[[99	Z	 BKK('WEE82=>>4r9::r1   c           
        t        |       rt        j                  |       }n| }t        j                  | }t        j                  |d   |d   |d   d|d         }|d   r1|d   d   }t        j                  |d   dd |d   |d   d|d         }n|d   rd|d   z  }|}nd}|}d}|d   r&|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   r_   c                    dt        |       z   S N=r   rB   s    r0   r   z%format_argspec_plus.<locals>.<lambda>s  s    cCFl r1   )formatvaluec                    dt        |       z   S r  r   r   s    r0   r   z%format_argspec_plus.<locals>.<lambda>|  s    #A, r1   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	callabler   r   inspect_formatargspeclenr	   r   r   r   )r   r   r   r  r%  r$  r'  num_defaults	name_argsdefaulted_valsr&  r(  s               r0   r   r      s    H |,,R0''.D,,Qa$q'4aI Aw71:"88GABKa$q'4a
 
aT!W$%%LAwDsT!W566AwDG$Q$q'!I "1|#3#56++QQ*H Aw!77abMGG.
 $/-
 	
 "oa^/"5-a3
 	
r1   c                    | t         j                  u rd}|rdnd}|rdnd}n	 t        | |      S t	        d|||||
      S # t        $ r d}|r|nd}|rdnd	}Y *w xY w)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)rL   z()r   r   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r$  r#  r%  r&  r'  r(  )objectr   r   r  r   )methodr   r#  r  proxieds        r0   format_argspec_initr4    s      "x!$r	L&vw??
 !!  	  	L4L#*<0GD-4):KG	Ls   A AA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+   r_   )rf   s    r0   r   z&create_proxy_methods.<locals>.decorate  s    
r1   r_   )
target_clstarget_cls_sphinx_nameproxy_cls_sphinx_nameclassmethodsmethods
attributesuse_intermediate_variabler   s           r0   create_proxy_methodsr>    s    & Or1   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)

    rL   Nr  kwargs)r   r   r  r1  r   )r2  s    r0   getargspec_initrA    sU    6,,V44 6V__$HdD$//Hfh55	6s    "AAAc                j    t        | t        j                        r| j                  s| j                  S | S )zSAdjust the incoming callable such that a 'self' argument is not
    required.

    )r5   r   
MethodTyper  r   )func_or_clss    r0   unbound_method_to_callablerE    s.     +u//09M9M###r1   c           	         | g}nt        j                  |      }t               }g }t        j                         }d}t	        |      D ]/  \  }}		 t        j                  |	j                        }
|
j                  rt        |
j                        nd}|dk(  rY|
j                  r|
j                  }|r |j                  |
j                  d|         nN|j                  |
j                  dd        n/|j                  |
j                  d|  D cg c]  }||f c}       |s|
j                  sJ |j                  t        |
j                  | d |
j                        D cg c]	  \  }}||f c}}       2 g }|j                   fd|D               |>t!         |      r2|j                  t#         |      D cg c]  }t%        |       c}       |j'                         D ]7  \  }}||v r	 t#         ||      }||ur||k7  r|j)                  |d|       9 |r7|D ]2  \  }}	 t#         ||      }||ur||k7  r|j)                  |d|       4  j,                  j.                  ddj1                  |      dS c c}w c c}}w # t        $ r Y Tw xY wc c}w # t*        $ r Y w xY w# t*        $ r Y w xY w)	z}Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    Nr   r   c              3  J   K   | ]  }t        t        |d               y wr+   )r   r9   )rr   r   r/   s     r0   rt   zgeneric_repr.<locals>.<genexpr>"  s     DC$wsC./Ds    #r  (, ))r   to_listr1  OrderedDict	enumerater   r   r   r   r,  r  rd   r  r?   zipr  r   r9   r   itemsr   rk   r}   rZ   ru   )r/   additional_kw
to_inspect
omit_kwargmissingpos_argskw_argsvargsr   inspr   default_lenr   defaultoutputvaldefvals   `                r0   generic_reprr]    s    U
!))*5
hGH2>2J2J2LGEZ( 4	00?D 15#dmm,1KAv<< LLEOODIIa$=>OODIIabM2/3yyK</HIc7^I }}$} -0 II{lm4dmm-(C g+: F
MMD8DDWS%0GC,?@StCy@A}} V*	#sG,C'!cVmc23 ( 	KCc30g%#-MMS#"67		 }}--tyy/@AAO J'  		> A  		  sH   JJ
$J J"5,J'.,J6	JJ'	J32J36	KKc                  .    e Zd ZdZdZd Zd ZddZd Zy)	portable_instancemethodz_Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    )r   ry   r@  __weakref__c                J    | j                   | j                  | j                  dS )Nr   ry   r@  rb  rK   s    r0   __getstate__z$portable_instancemethod.__getstate__E  s!    kkIIkk
 	
r1   c                Z    |d   | _         |d   | _        |j                  dd      | _        y )Nr   ry   r@  r_   )r   ry   r8   r@  )rL   states     r0   __setstate__z$portable_instancemethod.__setstate__L  s*    Ho&M	ii"-r1   c                V    |j                   | _        |j                  | _        || _        y r+   )r  r   rZ   ry   r@  )rL   methr@  s      r0   r   z portable_instancemethod.__init__Q  s    mmMM	r1   c                    |j                  | j                          t        | j                  | j                        |i |S r+   )r?   r@  r9   r   ry   )rL   r   kws      r0   r  z portable_instancemethod.__call__V  s3    
		$++.wt{{DII.:r::r1   N)r_   )	rZ   r[   r\   r]   r^   rc  rf  r   r  r_   r1   r0   r_  r_  =  s"    
 :I
.

;r1   r_  c                   | ht        | j                        }|r|j                         }fd|j                  D        }|D ]$  }|j	                  |       j                  |       & |j                  dk(  st        |d      slt        |t              s|j                         n|j                  |      D cg c]  }|vr|
 c}D ]$  }|j	                  |       j                  |       & |rt              S c c}w )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s|  y wr+   r_   )rr   _hiers     r0   rt   z"class_hierarchy.<locals>.<genexpr>j  s     9q1D=9s   	r   re   )r   __mro__rb   r  r   rc   r[   r   
issubclassr6   re   )rf   processr
  r   r   rm  srn  s          @r0   class_hierarchyrs  [  s     5D3;;G
KKM9AKK9 	ANN1HHQK	 <<:%WQ8H-I "!T*   "%%a(

 } 
 
	A NN1HHQK
	 , :
s   9C>c              #     K   t        |       }|D ]6  }| j                  D ]%  }||j                  v s||j                  |   f  6 8 yw)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)dirro  r7   )rf   keyskeyr
  s       r0   iterate_attributesrx    sU      s8D  	Aajj AJJsO,,	s
   .A
A
c                   |r|}nN|d}t        |      D cg c]6  }|j                  d      r#|j                  d      rt        | |      s||vr|8 }}|D ]  }	 t	        ||      }	t        |	d      st	        |	d|	      }	t        t        j                  |	      }
	 t        j                  |
      }t        j                  |d         }t        j                  |d   dd       }d
t               z  }|duxr ||ixs i }t        ||       	 |
j                  ||   _        t!        | |||           yc c}w # t        $ r Y w xY w# t        $ r d}d	}Y rw xY w# t        $ r Y Ew xY w)z9Automates delegation of __specials__ for a proxying type.N)r^   __del____getattribute____metaclass__rc  rf  r   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)ru  
startswithendswithr   r9   r	   r   r   r   r   r   r+  r  localsr   r   setattr)into_clsfrom_clsskiponlyry   from_instancedundersrC   r2  maybe_fnr   r   fn_argsd_argspyr   s                   r0   monkeypatch_proxied_specialsr    s    <D ]	
T"JJt$!,TM 	
 	
  /	x0H8Z0xX>He(((3B	%004D2247;G11$q'!"+>F35;X> 	 %?4*?E2 	 	R	')CK$ 	&#f+.?/	
&  		  	%+G$F	%  		sB   ;D2D73'D7AEE7	EEEE	E%$E%c                6    t        | d|       t        |d|      u S )z;Return True if the two methods are the same implementation.r   )r9   )meth1meth2s     r0   methods_equivalentr    s(     5*e,z51  r1   c           	        |s|st        d      t        |t              rt        | |      r| S t        |xs+ t	        |      D cg c]  }|j                  d      r| c}      }t        t	        |             }t        j                  }t        |t              r|}n(|st               }t        j                  }nt        |      } ||j                  |      |      r| S t        | t              s<|t        j                  u xr dxs d}t        | d|ddj                  |             G d d	      }	|rd
|j                  z   |	_        t               }
t        |       D ]Z  \  }}||vrt        d|z        t        |      st        |d|d      t        |	|t!        |             |
j#                  |       \  ||
|      r|	S t        ddj                  ||
z
        z        c c}w )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 requiredrm  zany ofzall ofz does not implement z: rI  c                      e Zd ZdZy)(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.NrZ   r[   r\   r]   r_   r1   r0   AnonymousInterfacer    s    'r1   r  	Anonymousz%r: unknown in this interfacer  z is not callablez,dictionary does not contain required keys %s)r  r5   r6   ra   ru  r}  operatorgegtintersectionr   ru   rZ   dictlike_iteritemsr*  r  staticmethodrc   )r/   rf   r;  requiredrC   	interfaceimplementedcomplies	qualifierr  foundr2  r   s                r0   as_interfacer    s   B wLMM#tC!5
GM3s8Ma1<<;LMNIc#h-K{{H(D!5;;x=((3X>
 c4 +8DH	Ityy35
 	

( ( &1CLL&@#EE*3/ ";fDEE~vtDEE"FL,>?		& x !!
6
))Hu$
%	& S  Ns   G(G(_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y)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]fgetOptional[str]r]   r@   rZ   Nc                ^    || _         |xs |j                  | _        |j                  | _        y r+   r  r]   rZ   rL   r  docs      r0   r   zgeneric_fn_descriptor.__init__D  s$    	*dllr1   c                     y r+   r_   rL   r/   rf   s      r0   __get__zgeneric_fn_descriptor.__get__I  s    :=r1   c                     y r+   r_   r  s      r0   r  zgeneric_fn_descriptor.__get__L  s    7:r1   c                    t               r+   NotImplementedErrorr  s      r0   r  zgeneric_fn_descriptor.__get__O      !##r1   c                     y r+   r_   rL   instancerQ   s      r0   __set__zgeneric_fn_descriptor.__set__T      r1   c                     y r+   r_   )rL   r  s     r0   
__delete__z generic_fn_descriptor.__delete__V  r  r1   c                    t               r+   r  rL   r/   s     r0   _resetzgeneric_fn_descriptor._resetX  r  r1   c                    t               r+   r  rf   r/   ry   s      r0   resetzgeneric_fn_descriptor.reset[  s    !##r1   r+   )r  r  r  r  )rL   r  r/   rY   rf   r   rX   r  )r/   r1  rf   r   rX   r"   )rL   r  r/   r   rf   r   rX   zUnion[_GFD, _T_co]r  r   rQ   r   rX   rY   r  r   rX   rY   )r/   r   rX   rY   )r/   r   ry   r@   rX   rY   )rZ   r[   r\   r]   r3   r   r   r  r   r  r  r  classmethodr  r_   r1   r0   r  r  5  sf     M&
 = =: :$ A8$ $ $r1   r  c                      e Zd ZdZesd Zyy)_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                ,    || S | j                  |      S r+   r  r  s      r0   r  z_non_memoized_property.__get__k  s    {99S>!r1   N)rZ   r[   r\   r]   r   r  r_   r1   r0   r  r  `  s     	" r1   r  c                  0    e Zd ZdZesd Zd Zed        Zy)_memoized_propertyz2A read-only @property that is only evaluated once.c                b    || S | j                  |      x|j                  | j                  <   }|S r+   )r  r7   rZ   rL   r/   rf   results       r0   r  z_memoized_property.__get__v  s0    {3799S>ACLL'&Mr1   c                D    t         j                  || j                         y r+   )r  r  rZ   r  s     r0   r  z_memoized_property._reset|  s      dmm4r1   c                <    |j                   j                  |d        y r+   )r7   rb   r  s      r0   r  z_memoized_property.reset  s    t$r1   N)	rZ   r[   r\   r]   r   r  r  r  r  r_   r1   r0   r  r  q  s&    <	5 % %r1   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                     | g|i |fd}j                   |_         j                  |_        || j                  j                   <   S )Nc                     S r+   r_   arj  r  s     r0   memoz6memoized_instancemethod.<locals>.oneshot.<locals>.memo  s    Mr1   )rZ   r]   r7   rL   r  rj  r  r  r   s       @r0   oneshotz(memoized_instancemethod.<locals>.oneshot  sK    D&4&2&	 zz%)bkk"r1   r   )r   r  s   ` r0   memoized_instancemethodr    s    	 '2&&r1   c                  x    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y)HasMemoizedzA mixin class that maintains the names of memoized elements in a
    collection for easy cache clearing, generative, etc.

    r_   zFrozenSet[str]_memoized_keysc                ^    | j                   D ]  }| j                  j                  |d          y r+   )r  r7   rb   rL   r   s     r0   _reset_memoizationszHasMemoized._reset_memoizations  s+    '' 	*DMMdD)	*r1   c                F    | j                   D ]  }|| j                  vrJ  y r+   )r  r7   r  s     r0   _assert_no_memoizationsz#HasMemoized._assert_no_memoizations  s)    '' 	-Dt}},,,	-r1   c                N    || j                   |<   | xj                  |hz  c_        y r+   )r7   r  )rL   rw  rQ   s      r0   _set_memoized_attributez#HasMemoized._set_memoized_attribute  s#    "cu$r1   c                  d    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y)HasMemoized.memoized_attributezTA read-only @property that is only evaluated once.

        :meta private:

        Callable[..., _T]r  r  r]   r@   rZ   Nc                ^    || _         |xs |j                  | _        |j                  | _        y r+   r  r  s      r0   r   z'HasMemoized.memoized_attribute.__init__  s$    DI.$,,DL MMDMr1   c                     y r+   r_   r  s      r0   r  z&HasMemoized.memoized_attribute.__get__  s    <?r1   c                     y r+   r_   r  s      r0   r  z&HasMemoized.memoized_attribute.__get__  s    58r1   c                    || S | j                  |      x|j                  | j                  <   }|xj                  | j                  hz  c_        |S r+   )r  r7   rZ   r  r  s       r0   r  z&HasMemoized.memoized_attribute.__get__  sG    {3799S>ACLL'&4==/1Mr1   r+   )r  r  r  r  )rL   r'   r/   rY   rf   r   rX   r'   )r/   r   rf   r   rX   r!   )rZ   r[   r\   r]   r3   r   r   r  r_   r1   r0   memoized_attributer    sB    	  	*
 
? 
?	8 
8	r1   r  c                (    dfd}t        |      S )zMDecorate a method memoize its return value.

        :meta private:

        c                     | g|i |fd}j                   |_         j                  |_        || j                  j                   <   | xj                  j                   hz  c_        S )Nc                     S r+   r_   r  s     r0   r  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo  s    r1   )rZ   r]   r7   r  r  s       @r0   r  z4HasMemoized.memoized_instancemethod.<locals>.oneshot  sb    *t*r*F KKDM::DL)-DMM"++&BKK=0Mr1   )rL   r   r  r   rj  r   rX   r   r   )rf   r   r  s    ` r0   r  z#HasMemoized.memoized_instancemethod  s    
	 gr**r1   NrW   )rw  r@   rQ   r   rX   rY   r   r$   rX   r$   )rZ   r[   r\   r]   r   r^   	frozensetr  r3   r  r  r  memoized_propertyr!   r  r  r  r_   r1   r0   r  r    sT    
  	%.[NN0*-%.r2 : + +r1   r  c                  "    e Zd ZdZdZd ZddZy)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__.

    r_   c                    t        |      r+   )r   )rL   rw  s     r0   _fallback_getattrzMemoizedSlots._fallback_getattr  s    S!!r1   c                    j                  d      sj                  d      rt              t         j                  d       r# t	         d              }t         |       |S t         j                  d       r)t	         d        fd}j                  |_        |S  j                        S )N_memoized_attr__memoized_method_c                      | i |fd}j                   |_         j                  |_        t        |       S )Nc                     S r+   r_   r  s     r0   r  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)  s    !Mr1   )rZ   r]   r  )r  rj  r  r  r   rw  rL   s      @r0   r  z*MemoizedSlots.__getattr__.<locals>.oneshot&  s>    TR" !#!zzc4(r1   )r}  r   r   r}   r9   r  r]   r  )rL   rw  rQ   r  r   s   ``  @r0   __getattr__zMemoizedSlots.__getattr__  s    >>+,1
 !%% T^^se%<=:GDOC5"9:<ED#u%LT^^'8%>?!23%89B	 !jjGON))#..r1   N)rw  r@   rX   r   )rZ   r[   r\   r]   r^   r  r  r_   r1   r0   r  r  
  s     I"/r1   r  c                    t        | t              r6| j                         j                         } | dv ry| dv ryt	        d| z        t        |       S )N)trueyesonyt1T)falsenooffrs   f0FzString is not true/false: %r)r5   r@   striprq   
ValueErrorr   r.   s    r0   asboolr	  8  sS    #siik!6699;cABB9r1   c                      d fd}|S )zqReturn a callable that will evaluate a string as
    boolean, or one of a set of "alternate" string values.

    c                &    | v r| S t        |       S r+   )r	  )r/   texts    r0   bool_or_valuez"bool_or_str.<locals>.bool_or_valueJ  s    $;J#;r1   )r/   r@   rX   zUnion[str, bool]r_   )r  r  s   ` r0   bool_or_strr  D  s     r1   c                     | | S t        |       S )zCoerce to integer.)int)rQ   s    r0   asintr  S  s     }u:r1   c                    || }|| v rQt        |t              rt        | |   |      s1| |   +|t        u r|rt        | |         ||<   y || |         ||<   yyyy)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)r5   r6   r   r	  )rj  rw  rP   
flexi_booldests        r0   coerce_kw_typer  [  ss     | 	r	E4(
2c7E0JsGD=Zr#wDIbgDI   1K 	r1   c                J     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  ^   K   | ]$  }|j                   v s|j                   |   f & y wr+   r7   rr   kr/   s     r0   rt   z"constructor_key.<locals>.<genexpr>{  s.      !"qCLL/@CLLO   --)r   r   )r/   rf   r   s   `  r0   constructor_keyr  u  s2    
 3E6E &+   r1   c                |     t        |      }|j                   fd|j                  |      D                ||i |S )zInstantiate cls using the __dict__ of obj as constructor arguments.

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

    c              3  ^   K   | ]$  }|j                   v s|j                   |   f & y wr+   r  r  s     r0   rt   z#constructor_copy.<locals>.<genexpr>  s.      !"a3<<>OCLLOr  )r   r?   
difference)r/   rf   r  rj  r   s   `    r0   constructor_copyr     sE     3EII &+&6&6r&:  r1   c                 h    t        j                         t        j                  d      fd} | S )z%Return a threadsafe counter function.r   c                 J    5  t               cd d d        S # 1 sw Y   y xY wr+   )next)counterlocks   r0   _nextzcounter.<locals>._next  s"     	!=	! 	! 	!s   ")	threadingLockr   count)r&  r$  r%  s    @@r0   r$  r$    s+     >>Dooa G! Lr1   c                   t        | d      r8| 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__r   rc   ra   )r   r+  rp  ra   r5   r6   r   r   )specimenrY  isas      r0   duck_type_collectionr.    s     x(  ,!!32
 J((("8T2*
C
8T	Xs	
	Xt	x"	5	!
	5	!r1   c           
     
   t        | |      r| S t        |t              r>t        j                  d|ddj	                  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    yw)z'%s'Nr_   )rr   r  s     r0   rt   z"assert_arg_type.<locals>.<genexpr>  s     $AAVaZ$As   z, got ''z' is expected to be of type 'z', got ')r5   r   r    ArgumentErrorru   r6   )r   argtypery   s      r0   assert_arg_typer4    su     #w
gu%##$A$AA49N 
 ##$s)- r1   c           	     J    t         d      rt         j                               S t         dt         dd            t	        d z        t         d      r fd} |       S t         d      r"t        fd	 j                         D              S t	        d z        )
z?Return a (key, value) iterator for almost any dict-like object.rO  __getitem__r8   NzObject '%r' is not dict-likeiterkeysc               3  X   K   j                         D ]  } J |  |       f  y wr+   )r7  )rw  dictlikegetters    r0   iteratorz$dictlike_iteritems.<locals>.iterator  s:     ((* ')))6#;&&'s   '*rv  c              3  2   K   | ]  }| |      f  y wr+   r_   )rr   rw  r:  s     r0   rt   z%dictlike_iteritems.<locals>.<genexpr>  s     B3S&+&Bs   )r   r   rO  r9   r  iterrv  )r9  r;  r:  s   ` @r0   r  r    s     x!HNN$%%X}ght.LMF~6ABBx$	'
 z	6	"B(--/BBB6ABBr1   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  c                N    t        |   |g|i | |j                  | _        y r+   )superr   r]   )rL   r  r   rj  r}   s       r0   r   zclassproperty.__init__  s%    **r*||r1   c                $    | j                  |      S r+   r  r  s      r0   r  zclassproperty.__get__  s    yy~r1   )r  r@  r   r   rj  r   r+   )r/   r   rf   zOptional[type]rX   r   )rZ   r[   r\   r]   r3   r   r  __classcell__r}   s   @r0   r?  r?    s     $ r1   r?  c                  $    e Zd ZddZddZddZy)hybridpropertyc                     || _         || _        y r+   )r  clslevelrL   r  s     r0   r   zhybridproperty.__init__  s    	r1   c                N    || j                  |      }|S | j                  |      S r+   rI  r  rL   r  ownerclsvals       r0   r  zhybridproperty.__get__  *    ]]5)FM99X&&r1   c                    || _         | S r+   rI  rJ  s     r0   
classlevelzhybridproperty.classlevel
      r1   Nr  r  r  r   rN  r   rX   r!   )r  r{   rX   zhybridproperty[_T])rZ   r[   r\   r   r  rS  r_   r1   r0   rG  rG    s    'r1   rG  c                  4    e Zd ZddZddZd	dZd
dZd
dZy)rw_hybridpropertyc                .    || _         || _        d | _        y r+   )r  rI  setfnrJ  s     r0   r   zrw_hybridproperty.__init__  s    	37
r1   c                N    || j                  |      }|S | j                  |      S r+   rL  rM  s       r0   r  zrw_hybridproperty.__get__  rP  r1   c                D    | j                   J | j                  ||       y r+   rZ  r  s      r0   r  zrw_hybridproperty.__set__  s     zz%%%

8U#r1   c                    || _         | S r+   r]  rJ  s     r0   setterzrw_hybridproperty.setter   s    
r1   c                    || _         | S r+   rR  rJ  s     r0   rS  zrw_hybridproperty.classlevel$  rT  r1   NrU  rV  r  )r  r{   rX   zrw_hybridproperty[_T])rZ   r[   r\   r   r  r  r_  rS  r_   r1   r0   rX  rX    s    8
'$r1   rX  c                  (    e Zd ZdZddZddZddZy)	hybridmethodz/Decorate a function as cls- or instance- level.c                .    |x| _         | _        || _        y r+   )r  r   rI  rJ  s     r0   r   zhybridmethod.__init__,  s    $((	DMr1   c                    |&| j                   j                  ||j                        S | j                  j                  ||      S r+   )rI  r  r}   r  )rL   r  rN  s      r0   r  zhybridmethod.__get__0  s:    ==((@@99$$Xu55r1   c                    || _         | S r+   rR  rJ  s     r0   rS  zhybridmethod.classlevel6  rT  r1   NrU  )r  r   rN  r   rX   r  )r  r{   rX   zhybridmethod[_T])rZ   r[   r\   r]   r   r  rS  r_   r1   r0   rb  rb  )  s    96r1   rb  c                  z    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y)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@   ry   zDict[str, symbol]symbolsNc                f   | j                   5  | j                  j                  |      }|Yt        |t              sJ |t        |      }t        j                  t        |      }||_	        |r||_
        || j                  |<   n|r||k7  rt        d|d|       |cd d d        S # 1 sw Y   y xY w)Nz#Can't replace canonical symbol for z with new int value )_lockrh  r8   r5   r@   hashr  __new__rg  ry   r]   r  )rf   ry   r  	canonicalr   s        r0   rl  zsymbol.__new__O  s     YY 	++//$'C{!$,,,$ $T
Ikk&)4"%CK %(D!c!1#=dX F..7[:  -	 	 	s   BB''B0c                >    t         | j                  dt        |       ffS )NrB   )rg  ry   r  rK   s    r0   
__reduce__zsymbol.__reduce__m  s    		3D	222r1   c                    t        |       S r+   )r   rK   s    r0   __str__zsymbol.__str__p  s    Dzr1   c                "    d| j                   dS )Nzsymbol(rJ  )ry   rK   s    r0   __repr__zsymbol.__repr__s  s    Q''r1   )NN)ry   r@   r  r  rm  Optional[int]rX   rg  )rZ   r[   r\   r]   r3   rh  r'  r(  rj  rl  ro  rq  rs  r_   r1   r0   rg  rg  ;  si     I!#G#INNE
 "#'	  !	
 
<3(r1   rg  c                  0    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZddZy)_IntFlagMetac                   g x| _         }|j                         D ]u  \  }}t        j                  d|      rt	        |t
              rt        ||      }n|j                  d      st        d      Xt        | ||       |j                  |       w t        j                  |D ci c]  }|j                  | c}      | _        y c c}w )Nz^__.*__$)rm  rm  z#Expected integer values for IntFlag)_itemsrO  rv   matchr5   r  rg  r}  r  r  r   r   immutabledictry   __members__)	rf   	classnamer   dict_rj  rO  r  vr   s	            r0   r   z_IntFlagMeta.__init__x  s      
UKKM 
	DAqxxQ'!S!Q!,\\#& EFFCC LL
	 '44&+,sSXXs],
,s   %C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  rK   s    r0   __iter__z_IntFlagMeta.__iter__  s    !=
 	
r1   N)
r|  r@   r   zTuple[Type[Any], ...]r}  Dict[str, Any]rj  r   rX   rY   )rX   zIterator[symbol])rZ   r[   r\   r   r  r_   r1   r0   rv  rv  w  s<    

 %
 	

 
 

2
r1   rv  c                      e Zd ZdZy)_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  r_   r1   r0   r  r    s    r1   r  )	metaclass)IntFlag_Ec                    |j                         D ]*  \  }}| |u r|c S |r| |j                  k(  r|c S | |v s(|c S  | y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': )rO  ry   r    r2  )r   choicesry   resolve_symbol_names
enum_valuechoices         r0   parse_user_argument_for_enumr    sv    ( &mmo 
F*!cZ__&<F] {


1$s3'B
CCr1   c                ,    t         | _         t         dz  a y)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    r0   set_creation_orderr    s      /HqOr1   c                x    	  | |i |S # t         $ r& t        dt        j                         dd z         Y yw xY w)zXexecutes the given function, catches all exceptions and converts to
    a warning.

    z%s('%s') ignoredr   r   N)rk   warnrI   rJ   )r  r  r@  s      r0   warn_exceptionr    sA    
7T$V$$ 7#,,.1"5567s   
 ,99c                V    	 t        |       |kD  rd| d| z  S | S # t        $ r | cY S w xY w)Nz%s...r   )r,  r  )rQ   len_s     r0   ellipses_stringr    s=    u:U1T]**L s     ((c                  P     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  _hashc                    ||z  d|z  z   }t         |   | |      }t        d|t        |      |z  fz        |_        |S )Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)rB  rl  rk  r  )rf   rQ   numr  interpolatedrL   r}   s         r0   rl  z_hash_limit_string.__new__  sR     DsJ
 wsL1'UD,>,D$EEF
r1   c                    | j                   S r+   )r  rK   s    r0   __hash__z_hash_limit_string.__hash__  s    zzr1   c                0    t        |       t        |      k(  S r+   )rk  )rL   others     r0   __eq__z_hash_limit_string.__eq__  s    DzT%[((r1   )rQ   r@   r  r  r  Sequence[Any]rX   r  )rX   r  )r  r   rX   r   )	rZ   r[   r\   r]   r3   rl  r  r  rD  rE  s   @r0   r  r    s>     J!)6	)r1   r  c                ~    |r!t        t        j                  | |             yt        | t        j                         y)zdIssue a warning.

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

    )r   N)_warnings_warnr    	SAWarning)msgr   s     r0   r  r    s(     s}}St45sCMM*r1   c                V    |rt        | d|      } t        | t        j                         y)z\Issue a warning with a parameterized string, limiting the number
    of registrations.

    
   N)r  r  r    r  )r  r  s     r0   warn_limitedr     s#    
  b$/3&r1   z)Dict[CodeType, Tuple[str, Type[Warning]]]_warning_tagsc                      fd}|S )Nc                2    ft         | j                  <   | S r+   )r  r   )r   categorymessages    r0   goz#tag_method_for_warnings.<locals>.go0  s    &-x%8bkk"	r1   r_   )r  r  r  s   `` r0   tag_method_for_warningsr  -  s     Ir1   z&^(?:sqlalchemy\.(?!testing)|alembic\.)c                   	 t        j                  |      }dx}}||s6t        j                  t        |j
                  j                  dd            sd}|j                  t        v r&d}t        |j                     \  }}|xs |}|  d| d} |j                  }|s|dz  }n|r|rn|	 |t        j                  | ||dz   	       y t        j                  | |dz   	       y # t        $ r d}Y F d}Y KxY w)
NFrZ   r   Tz (rJ  r   r   )
stacklevel)rI   	_getframerv   ry  _not_sa_pattern	f_globalsr8   f_coder  f_backr  warningsr  )r  r  r  framestacklevel_foundwarning_tag_found_suffix	_categorys           r0   r  r  :  s   %j) 054, $BHH!4!4Z!D-
 $( 
 ||},$(!'4U\\'B$)#0y$IRy2LLE#a
!&73 6 gxJNCg*q.9Q   
 
s   C# #C50C5c                "      gd fd}|S )zNDecorate the given function to be a no-op after it is called exactly
    once.c                 t    }rj                         }	  || i |S y #  rj                  d|        xY w)Nr   )rb   insert)r   rj  	strong_fnonce_fnr   onceretry_on_exceptions       r0   r  zonly_once.<locals>.gou  sM     	hhjG*r** %KK7+s     7)r   r   rj  r   rX   zOptional[_T]r_   )r   r  r  r  s   `` @r0   	only_oncer  m  s     4D Ir1   z%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)c                   d}t        |       dz
  }||k  r3|j                  | |         r|dz  }||k  r|j                  | |         r||k  r3|j                  | |         r|dz  }||k  r|j                  | |         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)tbexclude_prefixexclude_suffixr   ends        r0   chop_tracebackr    s    " E
b'A+C
3,>00E;
 3,>00E;
3,>00C9q 3,>00C9ecAgr1   c                ^    d| z  }t               j                         }t        ||       |d   S )Nz&def set(obj, value):    obj.%s = valuera   )r  copyr   )attrnamer   r   s      r0   
attrsetterr    s,    3h>D
(--/CsOu:r1   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.

    r_   c                    t         | j                  v rC| j                  D ch c]  }t        j	                  |      r| }}|rt        d|  d| d      t        |           y c c}w )NzClass z< directly inherits TypingOnly but has additional attributes r   )r  r  r7   _dundersry  AssertionErrorrB  __init_subclass__)rf   ry   	remainingr}   s      r0   r  zTypingOnly.__init_subclass__  st    &!$X^^D5II  $SE "--6Kq:  	!#s
   A&A&rW   )rZ   r[   r\   r]   r^   r  rD  rE  s   @r0   r  r    s    
 I
$ 
$r1   r  c                  D     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_kwargc                    | j                   }| j                  }|re|D ]`  }t        j                  ||      }|s||   }t	        j
                  |      }|j                  rC| j                  |      }t        | ||       b t        | )          y r+   )r  r7   rv   ry  r   r   r  
_wrap_w_kwr  rB  r  )	rf   fn_regclsdictrw  rC   r   r   wrappedr}   s	           r0   r  zEnsureKWArg.__init_subclass__  s    !!,, 3HHVS) B!88<D::"%.."4S'23 	!#r1   c                (    dfd}t        |      S )Nc                      |  S r+   r_   )r   rj  r   s     r0   wrapz$EnsureKWArg._wrap_w_kw.<locals>.wrap  s    s8Or1   )r   r   rj  r   rX   r   r   )rf   r   r  s    ` r0   r  zEnsureKWArg._wrap_w_kw  s    	 dB''r1   rW   )r   r{   rX   r{   )	rZ   r[   r\   r]   r3   r  r  r  rD  rE  s   @r0   r  r    s.     $ ( (r1   r  c                v   t        |d      rt        | |      S | }|j                  j                  |_        t        |d      r|j                  |_        t        |j
                  d      r3|j
                  j                  r|j
                  j                  |_        |S |j                  r|j                  |_        |S )zAugment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    rZ   r[   r]   )r   r   r}   rZ   r[   r  r]   )wrapperr   _fs      r0   wrap_callabler    s     r:gr**ll++2|$MMBM2;;	*r{{/B/B,,BJ 	 ZZBJ	r1   c                   d| vr| j                  d      S d}g g}d}t        |       }||k  r}| |   }|dk(  r8|dk(  r-||dz
  k  r%| |dz      dk(  r|d   j                  d       |dz  }n6|dz  }n0|dk(  r|dk(  r|j                  g        n|d   j                  |       |dz  }||k  r}|D cg c]  }dj                  |       c}S c c}w )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)  r   )r   r,  r   ru   )rQ   re  r  idxlvcharr   s          r0   quoted_token_parserr    s    $ %{{3 E!dF
C	UB
(Sz3;zcBFluS1W~/Dr
!!#&q
S[UaZMM"2Jd#q ( )//uBGGEN///s   .C	c                @     t        j                           fd}|S )Nc                    | j                   d uxr | j                   xs d}|rt        |D ci c]  }| c}      }|| _         | S c c}w )Nr   )r]   inject_param_text)r   r  paramparamsr  s      r0   r   z$add_parameter_text.<locals>.decorate7  sO    jj$39r#C6)J%%+)JKC
	 *Ks   
A
)r   rK  )r  r  r   s   `` r0   add_parameter_textr  4  s    !!&)F Or1   c                    | j                  dd      }t        |      dk(  r| S |\  }}|j                  d      s|dz   t        j                  |      z   S t        j                  |       S )N
r   ro   )r   r,  r}  textwrapdedent)r  
split_text	firstliner  s       r0   _dedent_docstringr  A  sc    D!$J
:!)	9$4(//)"<<<t$$r1   c                   t        | xs d      }|j                  d      }t        |      dk(  r|j                  d       t	        j
                  |      j                  d      }|d   r|j                  dd       t        |      D cg c]  \  }}|j                         r| }}}|j                  dd       |t        |t        |      dz
           }	|d|	 |z   ||	d  z   }dj                  |      S c c}}w )Nr   r  r   r   )r  r   r,  r   r  r  r  rM  r  minru   )
given_doctext
injecttextposdoctextlinesinjectlinesr  lineblanks
inject_poss
             r0   inject_docstring_textr  M  s     %]%8b9GMM$E
5zQR//*-33D9K1~1b!#,U#3Hic44::<cHFH
MM!QCVq12J!J+-jk0BBE99U Is   	C5"C5z(\s+):param (.+?):c                   t        j                  | j                               }g }d }|r9|j                         }t        j                  |      }||r|j                  d      j                  d      }||v rdt        |j                  d            z  dz   }|r8t        j
                  d|d         }	|	rdt        |	j                  d            z  }|||   z   }nt|r|j                  d|dg       d }n[|j                         s|j                  ||dg       d }n4|j                  d      r#|j                  ||j                         g       '|j                  |       |r9dj                  |      S )	Nr   *ro   r   z(\s+)\Sr   r  z::)collectionsdeque
splitlinespopleft
_param_regry  r   lstripr,  rv   rd   rstripr~  r   ru   )
r  inject_paramsdoclinesr  	to_injectr  rC   r  indentm2s
             r0   r  r  d  sX     !3!3!56HE I
!T"
))#.M) 3qwwqz?2S8F  XXj(1+>%(3rxx{+;%;F &u)= =ILL$	401ILL$	401I]]4  LL$ 0 0 234T? B 99Ur1   c                   t        |       dk(  ryt        |       dk  }|r| dd n
| dd | dd z   } | D cg c]  }t        |      dkD  rd|dd z  n| }}|rdj                  |      S dj                  |dd       d	|d   S c c}w )
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)     z%s..rI  z, ..., )r,  ru   )r   flagry   ress       r0   repr_tuple_namesr    s     5zQu:?DE!AJE!AJrs$;EFK
LdTR6D"IT9
LC
Lyy~ $		#a( 3SW==	 Ms   Bc                ,    t         ry| rt        d      y)NTzDcython extensions were expected to be installed, but are not presentF)r   ImportError)raise_s    r0   has_compiled_extr    s"    	"
 	

 r1   c                  .    e Zd Z ej                         Zy)_MissingN)rZ   r[   r\   enumautoMissingr_   r1   r0   r  r    s    diikGr1   r  )r/   r   rX   r4   )rB   r   rX   r@   )rf   Type[_T]rX   zIterator[Type[_T]])rl   r   rX   r@   r+   )rf   	Type[Any]rx   r  rX   r@   )r~   zUnion[Type[Any], object]r   r{   rX   r   )r   slicerX   Tuple[Any, ...])r   Sequence[str]r   r@   rX   zIterator[str])r   zCallable[[int], Any]rs   r  rX   zIterator[Any])r   r{   rX   zCallable[[_Fn], _Fn])r   zUnion[str, types.CodeType]r   r  r   r@   rX   r{   )rf   r6   r   Optional[Set[str]]r   zLiteral[True]rX   zSet[str])rf   r6   r   r&  r   r   rX   r&  )r  r{   rX   	List[str])FF)r   r{   r  r   r  r   rX   zcompat.FullArgSpec)T)r   z-Union[Callable[..., Any], compat.FullArgSpec]r   r   rX   zDict[str, Optional[str]])r_   r_   r_   r_   )r7  r"  r8  r@   r9  r@   r:  r%  r;  r%  r<  r%  r=  r%  rX   zCallable[[_T], _T])r_   Nr_   )
r/   r   rP  zSequence[Tuple[str, Any]]rQ  z%Optional[Union[object, List[object]]]rR  r%  rX   r@   )NNz
self.proxyN)NNNr  )r/   r   rX   r   )r  r@   rX   z!Callable[[str], Union[str, bool]])rQ   r   rX   rt  )TN)rj  r  rw  r@   rP   r"  r  r   r  zOptional[Dict[str, Any]]rX   rY   )r/   r   rf   r"  rX   r$  )
r/   r!   rf   r!  r  r   rj  r   rX   r!   )rX   zCallable[[], int])r,  r   rY  Optional[Type[Any]]rX   r(  )r   r   r3  z'Union[Tuple[Type[Any], ...], Type[Any]]ry   r@   rX   r   )F)
r   r   r  zDict[_E, List[Any]]ry   r@   r  r   rX   zOptional[_E]r  )r  r{   r  r   r@  r   rX   r   )   )r  r@   r   r  rX   rY   )r  r@   r  r  rX   rY   )r  r@   r  zType[Warning]rX   Callable[[_F], _F])Nr   )r  zUnion[str, Warning]r  zOptional[Type[Warning]]r  r  rX   rY   )r   r  r  r   rX   zCallable[..., Optional[_T]])r  r'  r  re.Pattern[str]r  r+  rX   r'  )r  r   r  r@   rX   r*  )r  r@   rX   r@   )r  r  r  r@   r  r  rX   r@   )r  r@   r  zDict[str, str]rX   r@   )r   r'  rX   r  )r]   
__future__r   r  r  	functoolsr   r,   r   r  rv   rI   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)   py310r-   rD   rF   ri   rm   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r4  r>  rA  rE  r]  r_  rs  rx  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.  r4  r  r?  rG  rX  rb  r  rg  r6   rv  r  r  FastIntFlagEnumr  r  r  r  r  r  r@   r  r  r  r  r3   r  compiler  r  r  _SQLA_RE_UNITTEST_REr  NoneTyper  r  r  r  r  r  r  r  r  r  r  r  r  r  r   	MissingOrr_   r1   r0   <module>r=     s   #   $    	 
                            $  T]4(T#s(+,e34e@Ae01e./ 
<<,
2"$82 82v6 /3O	O+OO,-,&, 
,$M  e/0
D,N*
$+9DG enen%  % P
( 
  $!		  	
  
 
-1E	*=A 
 .2E2	2*2=A22j2 EJ5;5;%)5;=A5;5;r HLr
5r
@Dr
r
jJ #% "/1   	
    - 26(	 028< "	KB	KB,KB 6KB 	KB
 	KB\; ;<#L& 
		@/FSl v9:($GEN ($V"259 ""%.u5 %<  .1
 $' 0BA,7MM4'.J+ J+Z (0%(3(F(F%*/ */\	 %)''	' ' 	'
 #' 
'4 37  /  F	>FI$C0H *WR[ " 472; $9(S 9(x
4 
D\  KK T# "'	D	D D D 	D
 DD 
7) )<
+' <>8 =) "**FG
 )-0: 0:%0: 0: 
	0:f/3 4 2::>?rzz./
 '3&.# $ 	4 : 2::j!$ $*&( &(R0)0X
	% .18;( RZZ-.
(V>	tyy  

"gh..//0	r1   