
    pXHh                   	   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:dd/l4m5Z5 dd0l4m6Z6 d1 Z7e8jr                  d2   jt                  Z;d3 Z<	 	 	 	 	 	 dd4Z=dd5Z>ne'j~                  rdd6Z>ndd7Z>dd8Z@ G d9 d:      ZAdd;ZBdd<ZC	 d	 	 	 	 	 dd=ZD	 	 	 	 	 	 dd?ZEdd@ZFddAZGddBZH e"dCd>&      ZIddDZJ	 	 	 	 	 	 	 	 ddEZK e"dF      ZL e"dG      ZM G dH dI      ZNdJ ZOedd%dK	 	 	 	 	 	 	 ddL       ZPeddMdK	 	 	 	 	 	 	 ddN       ZPddMdK	 	 	 	 	 	 	 ddOZPddPZQ	 d	 	 	 	 	 	 	 ddQZR	 d	 	 	 	 	 ddRZSddSZT	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddTZUdU ZVdV ZW	 	 	 d	 	 	 	 	 	 	 	 	 ddWZX G dX dY      ZYdZ ZZd[ Z[	 	 	 	 dd\Z\d] Z]dd^Z^ e"d_d`&      Z_ G da dbee-         Z` G dc dde`e-         Za G de dfe`e-         Zbe!r	e`Zce`ZdeeZfeeZgnebxZcZfeaxZdZgddgZh G dh di      Zie!reeZjneij                  Zj G dj dk      ZlddlZmddmZnddnZo	 	 d	 	 	 	 	 	 	 	 	 	 	 ddoZpddpZqddqZrddrZs	 d	 	 	 	 	 ddsZt	 	 	 	 	 	 	 	 ddtZudu Zv G dv dwee      Zw G dx dyee,         Zx G dz d{ee,         Zy G d| d}ee,         Zz G d~ de{      Z| G d de8      Z} G d de}      Z~e!r	ddlmZ eZne~Z e"dej                  &      Z	 d	 	 	 	 	 	 	 	 	 ddZdaddZddZdd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 e8d      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jJ                  Ze#e,e*ejJ                     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])call_annotate_function)Formatc                ~    t        | dd       }|.t        |||       }t        |t              st	        | d      |S y )N__annotate__)ownerz!.__annotate__ returned a non-dict)getattrr*   
isinstancedict
ValueError)objformatannotateanns       T/var/www/html/planif/env/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py_get_and_call_annotater8   F   sI    35(6ECc4( C7*K!LMMJ    __annotations__c                    t        | t              r	 t        |       }nt	        | dd       }|i S t        |t
              st        | d      t        |      S # t        $ r i cY S w xY w)Nr:   z+.__annotations__ is neither a dict nor None)r0   type_BASE_GET_ANNOTATIONSAttributeErrorr/   r1   r2   r3   r6   s     r7   _get_dunder_annotationsr@   R   sz    c4 +C0
 #0$7C{	#t$'DE  Cy " 	s   A A&%A&c                   	 t        |       }|t        |      S t        | |      }|t        |       }|+t	        | t
              st        |       ri S t        | d      |si S t        |      S # t        $ r Y `w xY w)z:A sparse implementation of annotationlib.get_annotations()z does not have annotations)r@   r1   	Exceptionr8   r0   r<   callable	TypeError)r3   r4   r6   s      r7   _vendored_get_annotationsrE   d   s    
	!)#.C Cy  %S&1; *#.C;#t$	sg%?@AAICy1  		s   A/ /	A;:A;c                8    t        | t        j                        S )N)r4   )rE   r+   
FORWARDREFr3   s    r7   get_annotationsrI      s     )V5F5FGGr9   c                ,    t        j                  |       S N)inspectrI   rH   s    r7   rI   rI      s    &&s++r9   c                    t        | t              r| j                  j                  dd       }nt	        | dd       }|t
        j                  S t        d|      S )Nr:   Mapping[str, Any])r0   r<   __dict__getr/   r   
EMPTY_DICTr	   r?   s     r7   rI   rI      sS     c4 ,,""#4d;C#0$7C;***+S11r9   c                    | j                  d      } t        j                         }|j                  |        t	        t
        |j                               S )Nzutf-8)encoder   md5_not_for_securityupdater	   str	hexdigest)xms     r7   md5_hexrZ      s<    	A##%AHHQKQ[[]##r9   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]]r]   c                6    t        j                         | _        y rK   )sysexc_infor]   selfs    r7   	__enter__zsafe_reraise.__enter__   s    r9   c                    | j                   J |,| j                   \  }}}|J d | _         |j                  |      d | _         |J |j                  |      rK   )r]   with_traceback)rb   type_value	tracebackexc_type	exc_valueexc_tbs          r7   __exit__zsafe_reraise.__exit__   sq     ~~)))=*...'Hi(((!DN**622!DN$$$&&y11r9   NreturnNone)rf   zOptional[Type[BaseException]]rg   zOptional[BaseException]rh   zOptional[types.TracebackType]rn   r   )__name__
__module____qualname____doc__	__slots__r:   rc   rl    r9   r7   r\   r\      sH    0 I (2,2 '2 1	2
 
2r9   r\   c              #     K   t               }| g}|rM|j                         } | |v r|j                  |        |j                  | j	                                |  |rLy y wrK   )setpopaddextend__subclasses__)clsseenstacks      r7   walk_subclassesr      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)r0   rV   rB   )elements    r7   string_or_unprintabler      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rK   )lower).0ns     r7   	<genexpr>z(clsname_as_plain_name.<locals>.<genexpr>  s     N!AGGINs   z([A-Z][a-z]+|SQL))rp   joinrefindall)r|   use_namenames      r7   clsname_as_plain_namer      s3     #s||D88Nrzz2F'MNNNr9   Callable[..., Any]c                z    t        | t              s| j                  }n| }|j                  }t	        ||      }||k7  S )z1Return True if the two class methods don't match.)r0   r<   	__class__rp   r/   )instance_or_clsagainst_methodcurrent_clsmethod_namecurrent_methods        r7   method_is_overriddenr     s@     ot,%//% ))K'.{K'HN^++r9   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retrX   s      r7   decode_slicer     sW     CYY#((* 1k"A

1 :r9   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 rK   rV   )ibases    r7   <lambda>z!_unique_symbols.<locals>.<lambda>+  s    $Q- r9   i  z&exhausted namespace for symbol base %s)rw   	itertoolschainmaprangery   	NameError)usedbasesused_setpoolsymr   s        @r7   _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   Nru   )fnr   bs      r7   map_bitsr   6  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	        | dd       }|%d | _        	 t        j                  |       }|| _        nt        j                  |       }dt        |j                  xs d      z  }t        j                  |j                  xs d      }|j                  i ||      }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  }	||| d| j,                  i}
t        t.        j0                  t3        |	|
| j                               }| j4                  |_        | j6                  |_        t9        ||       S # || _        w xY w)Nznot a decoratable functionr-   rK   ru   )r   defaultskwonlydefaultszTuple[str, ...]r   r      targetr   )r   r   Fgroupedr   zasync prefixzawait target_prefix __zf%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_pos)s)
ze%(prefix)sdef %(name)s%(grouped_args)s:
    return %(target_prefix)s%(target)s(%(fn)s, %(apply_kw)s)
rp   )rL   
isfunctionismethodrB   r/   r-   r   inspect_getfullargspeclenr   r1   fromkeysr   _replacer   r	   rp   r   rU   format_argspec_plusiscoroutinefunctionreprrq   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               r7   decoratezdecorator.<locals>.decorateG  s+   !!"%g.>.>r.B899 2~t4"BO+44R8"*004D !3t}}':#;;==)<)<)BC}}#+  
 $($q'23$d1Qi01{{n 	
 -UHdC	7-1w-O+D%@A;;&&r*!)HX(0H_%!#HX(*H_% 4Q=  	  	  vR
 dC5
	 "$	#%#4#4	 i,,Q #+s   H 	H)r   r   rn   r   r   )r   r   s   ` r7   	decoratorr   D  s    T-l (F++r9   c                $    t        | |       ||   S rK   )exec)r   r   r   s      r7   r   r     s     	sOw<r9   _PF_TEc                  <    e Zd Z	 d	 	 	 ddZd Zd	dZd
dZddZy)PluginLoaderNc                .    || _         i | _        || _        y rK   )groupimplsauto_fn)rb   r   r   s      r7   __init__zPluginLoader.__init__  s     
%'
r9   c                8    | j                   j                          y rK   )r   clearra   s    r7   r   zPluginLoader.clear  s    

r9   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   r   loadr    NoSuchModuleError)rb   r   loaderimpls       r7   r   zPluginLoader.load  s    4::#4::d#%%<<\\$'F#)

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

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

4r9   c                    | j                   |= y rK   r   )rb   r   s     r7   
deregisterzPluginLoader.deregister  s    JJtr9   rK   )r   rV   r   zOptional[Callable[..., Any]])r   rV   rn   r   )r   rV   r   rV   r   rV   rn   ro   )r   rV   rn   ro   )rp   rq   rr   r   r   r   r   r  ru   r9   r7   r   r     s.    BF#?
& r9   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   )rL   CO_VARKEYWORDS__code__co_argcountlistco_varnamesboolco_flagsr>   r   r   )r   co_varkeywordsconargsr   s        r7   _inspect_func_argsr    s    
 // [['(~-.
 	
  &
 ,,R0AwT!W%%&s   A 1BB)_setraiseerrc                    y rK   ru   r|   r  r  s      r7   get_cls_kwargsr    s     r9   Fc                    y rK   ru   r  s      r7   r  r    s     r9   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  rb   )rw   rO   rP   r0   r   r   r  r   r  rU   rD   	__bases__r  discard)	r|   r  r  toplevelctrhas_initr   has_kwcs	            r7   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Kr9   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    r7   get_func_kwargsr  .  s     ((.q11r9   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_init__func____call__)r   zCan't inspect callable: %s)rL   	isbuiltinrD   r   r   r   FullArgSpecargsvarargsvarkwr   
kwonlyargsr   r   r   __self__r"  isclassget_callable_argspecr   r   r#  )r   r   r!  r   s       r7   r,  r,  9  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::r9   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   ru   c                    dt        |       z   S N=r   rX   s    r7   r   z%format_argspec_plus.<locals>.<lambda>  s    cCFl r9   )formatvaluec                    dt        |       z   S r0  r   r2  s    r7   r   z%format_argspec_plus.<locals>.<lambda>  s    #A, r9   )grouped_argsself_arg	apply_posapply_kwapply_pos_proxiedapply_kw_proxied)	rC   r   r   inspect_formatargspecr   r	   r   r   r1   )r   r   r   r&  r7  r6  r9  num_defaults	name_argsdefaulted_valsr8  r:  s               r7   r   r   q  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
 	
r9   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)rb   z()r   r   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)r6  r5  r7  r8  r9  r:  )objectr   r   rD   r1   )methodr   r5  r&  proxieds        r7   format_argspec_initrD    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 rK   ru   )r|   s    r7   r   z&create_proxy_methods.<locals>.decorate  s    
r9   ru   )
target_clstarget_cls_sphinx_nameproxy_cls_sphinx_nameclassmethodsmethods
attributesuse_intermediate_variabler   s           r7   create_proxy_methodsrN    s    & Or9   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)

    rb   Nr&  kwargs)r   r   rD   rA  r   )rB  s    r7   getargspec_initrQ     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.

    )r0   r   
MethodTyper*  r"  )func_or_clss    r7   unbound_method_to_callablerU  4  s.     +u//09M9M###r9   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rK   )r   r/   )r   argr3   s     r7   r   zgeneric_repr.<locals>.<genexpr>s  s     DC$wsC./Ds    #r1  (, ))r   to_listrA  OrderedDict	enumerater   r   r   r   r   r'  rz   r&  rU   ziprD   r   r/   r   itemsr   rB   r   rp   r   )r3   additional_kw
to_inspect
omit_kwargmissingpos_argskw_argsvargsr   inspr   default_lenrX  defaultoutputvaldefvals   `                r7   generic_reprrn  @  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   r   rP  __weakref__c                J    | j                   | j                  | j                  dS )Nr   r   rP  rs  ra   s    r7   __getstate__z$portable_instancemethod.__getstate__  s!    kkIIkk
 	
r9   c                Z    |d   | _         |d   | _        |j                  dd      | _        y )Nr   r   rP  ru   )r   r   rP   rP  )rb   states     r7   __setstate__z$portable_instancemethod.__setstate__  s*    Ho&M	ii"-r9   c                V    |j                   | _        |j                  | _        || _        y rK   )r*  r   rp   r   rP  )rb   methrP  s      r7   r   z portable_instancemethod.__init__  s    mmMM	r9   c                    |j                  | j                          t        | j                  | j                        |i |S rK   )rU   rP  r/   r   r   )rb   rX  kws      r7   r#  z portable_instancemethod.__call__  s3    
		$++.wt{{DII.:r::r9   N)ru   )	rp   rq   rr   rs   rt   rt  rw  r   r#  ru   r9   r7   rp  rp    s"    
 :I
.

;r9   rp  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rK   ru   )r   _hiers     r7   r   z"class_hierarchy.<locals>.<genexpr>  s     9q1D=9s   	builtinsr{   )r  __mro__rx   r  r   ry   rq   r   
issubclassr<   r{   )r|   processr  r   r   r~  sr  s          @r7   class_hierarchyr    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)dirr  rO   )r|   keyskeyr  s       r7   iterate_attributesr    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)rt   __del____getattribute____metaclass__rt  rw  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)r  
startswithendswithr   r/   r	   r   r   r>   r   r   r<  rD   localsr   r   setattr)into_clsfrom_clsskiponlyr   from_instancedundersrY   rB  maybe_fnr   r   fn_argsd_argspyr   s                   r7   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"  )r/   )meth1meth2s     r7   methods_equivalentr  %  s(     5*e,z51  r9   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 requiredr~  zany ofzall ofz does not implement z: rZ  c                      e Zd ZdZy)(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.Nrp   rq   rr   rs   ru   r9   r7   AnonymousInterfacer  k  s    'r9   r  	Anonymousz%r: unknown in this interfacer1  z is not callablez,dictionary does not contain required keys %s)rD   r0   r<   rw   r  r  operatorgegtintersectionr1   r   rp   dictlike_iteritemsrC   r  staticmethodry   )r3   r|   rK  requiredrY   	interfaceimplementedcomplies	qualifierr  foundrB  r   s                r7   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]rs   rV   rp   Nc                ^    || _         |xs |j                  | _        |j                  | _        y rK   r  rs   rp   rb   r  docs      r7   r   zgeneric_fn_descriptor.__init__  s$    	*dllr9   c                     y rK   ru   rb   r3   r|   s      r7   __get__zgeneric_fn_descriptor.__get__  s    :=r9   c                     y rK   ru   r  s      r7   r  zgeneric_fn_descriptor.__get__  s    7:r9   c                    t               rK   NotImplementedErrorr  s      r7   r  zgeneric_fn_descriptor.__get__      !##r9   c                     y rK   ru   rb   instancerg   s      r7   __set__zgeneric_fn_descriptor.__set__      r9   c                     y rK   ru   )rb   r  s     r7   
__delete__z generic_fn_descriptor.__delete__  r  r9   c                    t               rK   r  rb   r3   s     r7   _resetzgeneric_fn_descriptor._reset  r  r9   c                    t               rK   r  r|   r3   r   s      r7   resetzgeneric_fn_descriptor.reset  s    !##r9   rK   )r  r  r  r  )rb   r  r3   ro   r|   r   rn   r  )r3   rA  r|   r   rn   r"   )rb   r  r3   r   r|   r   rn   zUnion[_GFD, _T_co]r  r   rg   r   rn   ro   r  r   rn   ro   )r3   r   rn   ro   )r3   r   r   rV   rn   ro   )rp   rq   rr   rs   r:   r   r   r  r   r  r  r  classmethodr  ru   r9   r7   r  r    sf     M&
 = =: :$ A8$ $ $r9   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 rK   r  r  s      r7   r  z_non_memoized_property.__get__  s    {99S>!r9   N)rp   rq   rr   rs   r   r  ru   r9   r7   r  r    s     	" r9   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 rK   )r  rO   rp   rb   r3   r|   results       r7   r  z_memoized_property.__get__  s0    {3799S>ACLL'&Mr9   c                D    t         j                  || j                         y rK   )r  r  rp   r  s     r7   r  z_memoized_property._reset  s      dmm4r9   c                <    |j                   j                  |d        y rK   )rO   rx   r  s      r7   r  z_memoized_property.reset  s    t$r9   N)	rp   rq   rr   rs   r   r  r  r  r  ru   r9   r7   r  r    s&    <	5 % %r9   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 rK   ru   ar{  r  s     r7   memoz6memoized_instancemethod.<locals>.oneshot.<locals>.memo  s    Mr9   )rp   rs   rO   rb   r&  r{  r  r  r   s       @r7   oneshotz(memoized_instancemethod.<locals>.oneshot  sK    D&4&2&	 zz%)bkk"r9   r   )r   r  s   ` r7   memoized_instancemethodr    s    	 '2&&r9   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.

    ru   zFrozenSet[str]_memoized_keysc                ^    | j                   D ]  }| j                  j                  |d          y rK   )r  rO   rx   rb   elems     r7   _reset_memoizationszHasMemoized._reset_memoizations  s+    '' 	*DMMdD)	*r9   c                F    | j                   D ]  }|| j                  vrJ  y rK   )r  rO   r  s     r7   _assert_no_memoizationsz#HasMemoized._assert_no_memoizations  s)    '' 	-Dt}},,,	-r9   c                N    || j                   |<   | xj                  |hz  c_        y rK   )rO   r  )rb   r  rg   s      r7   _set_memoized_attributez#HasMemoized._set_memoized_attribute  s#    "cu$r9   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  rs   rV   rp   Nc                ^    || _         |xs |j                  | _        |j                  | _        y rK   r  r  s      r7   r   z'HasMemoized.memoized_attribute.__init__,  s$    DI.$,,DL MMDMr9   c                     y rK   ru   r  s      r7   r  z&HasMemoized.memoized_attribute.__get__1  s    <?r9   c                     y rK   ru   r  s      r7   r  z&HasMemoized.memoized_attribute.__get__4  s    58r9   c                    || S | j                  |      x|j                  | j                  <   }|xj                  | j                  hz  c_        |S rK   )r  rO   rp   r  r  s       r7   r  z&HasMemoized.memoized_attribute.__get__7  sG    {3799S>ACLL'&4==/1Mr9   rK   )r  r  r  r  )rb   r'   r3   ro   r|   r   rn   r'   )r3   r   r|   r   rn   r!   )rp   rq   rr   rs   r:   r   r   r  ru   r9   r7   memoized_attributer  !  sB    	  	*
 
? 
?	8 
8	r9   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 rK   ru   r  s     r7   r  zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memoI  s    r9   )rp   rs   rO   r  r  s       @r7   r  z4HasMemoized.memoized_instancemethod.<locals>.oneshotF  sb    *t*r*F KKDM::DL)-DMM"++&BKK=0Mr9   )rb   r   r&  r   r{  r   rn   r   r   )r|   r   r  s    ` r7   r  z#HasMemoized.memoized_instancemethod>  s    
	 gr**r9   Nrm   )r  rV   rg   r   rn   ro   r   r$   rn   r$   )rp   rq   rr   rs   r   rt   	frozensetr  r:   r  r  r  memoized_propertyr!   r  r  r  ru   r9   r7   r  r    sT    
  	%.[NN0*-%.r2 : + +r9   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__.

    ru   c                    t        |      rK   )r>   )rb   r  s     r7   _fallback_getattrzMemoizedSlots._fallback_getattre  s    S!!r9   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 rK   ru   r  s     r7   r  z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memoz  s    !Mr9   )rp   rs   r  )r&  r{  r  r  r   r  rb   s      @r7   r  z*MemoizedSlots.__getattr__.<locals>.oneshotw  s>    TR" !#!zzc4(r9   )r  r>   r   r   r/   r  rs   r  )rb   r  rg   r  r   s   ``  @r7   __getattr__zMemoizedSlots.__getattr__h  s    >>+,1
 !%% T^^se%<=:GDOC5"9:<ED#u%LT^^'8%>?!23%89B	 !jjGON))#..r9   N)r  rV   rn   r   )rp   rq   rr   rs   rt   r  r  ru   r9   r7   r  r  [  s     I"/r9   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offr   f0FzString is not true/false: %r)r0   rV   stripr   r2   r  rH   s    r7   asboolr    sS    #siik!6699;cABB9r9   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 rK   )r  )r3   texts    r7   bool_or_valuez"bool_or_str.<locals>.bool_or_value  s    $;J#;r9   )r3   rV   rn   zUnion[str, bool]ru   )r  r  s   ` r7   bool_or_strr     s     r9   c                     | | S t        |       S )zCoerce to integer.)int)rg   s    r7   asintr#    s     }u:r9   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)r0   r<   r  r  )r{  r  rf   
flexi_booldests        r7   coerce_kw_typer'    ss     | 	r	E4(
2c7E0JsGD=Zr#wDIbgDI   1K 	r9   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rK   rO   r   kr3   s     r7   r   z"constructor_key.<locals>.<genexpr>  s.      !"qCLL/@CLLO   --)r  r   )r3   r|   r   s   `  r7   constructor_keyr.    s2    
 3E6E &+   r9   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rK   r*  r+  s     r7   r   z#constructor_copy.<locals>.<genexpr>  s.      !"a3<<>OCLLOr-  )r  rU   
difference)r3   r|   r&  r{  r   s   `    r7   constructor_copyr2    sE     3EII &+&6&6r&:  r9   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rK   )next)counterlocks   r7   _nextzcounter.<locals>._next  s"     	!=	! 	! 	!s   ")	threadingLockr   count)r8  r6  r7  s    @@r7   r6  r6    s+     >>Dooa G! Lr9   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   ry   rw   )r   r=  r  rw   r0   r<   r  r1   )specimenrj  isas      r7   duck_type_collectionr@    s     x(  ,!!32
 J((("8T2*
C
8T	Xs	
	Xt	x"	5	!
	5	!r9   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'Nru   )r   r  s     r7   r   z"assert_arg_type.<locals>.<genexpr>  s     $AAVaZ$As   z, got ''z' is expected to be of type 'z', got ')r0   r   r    ArgumentErrorr   r<   )rX  argtyper   s      r7   assert_arg_typerF    su     #w
gu%##$A$AA49N 
 ##$s)- r9   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.r`  __getitem__rP   NzObject '%r' is not dict-likeiterkeysc               3  X   K   j                         D ]  } J |  |       f  y wrK   )rI  )r  dictlikegetters    r7   iteratorz$dictlike_iteritems.<locals>.iterator.  s:     ((* ')))6#;&&'s   '*r  c              3  2   K   | ]  }| |      f  y wrK   ru   )r   r  rL  s     r7   r   z%dictlike_iteritems.<locals>.<genexpr>5  s     B3S&+&Bs   )r   r  r`  r/   rD   iterr  )rK  rM  rL  s   ` @r7   r  r  "  s     x!HNN$%%X}ght.LMF~6ABBx$	'
 z	6	"B(--/BBB6ABBr9   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 rK   )superr   rs   )rb   r  rX  r{  r   s       r7   r   zclassproperty.__init__G  s%    **r*||r9   c                $    | j                  |      S rK   r  r  s      r7   r  zclassproperty.__get__K  s    yy~r9   )r  rR  rX  r   r{  r   rK   )r3   r   r|   zOptional[type]rn   r   )rp   rq   rr   rs   r:   r   r  __classcell__r   s   @r7   rQ  rQ  :  s     $ r9   rQ  c                  $    e Zd ZddZddZddZy)hybridpropertyc                     || _         || _        y rK   )r  clslevelrb   r  s     r7   r   zhybridproperty.__init__P  s    	r9   c                N    || j                  |      }|S | j                  |      S rK   r[  r  rb   r  r.   clsvals       r7   r  zhybridproperty.__get__T  *    ]]5)FM99X&&r9   c                    || _         | S rK   r[  r\  s     r7   
classlevelzhybridproperty.classlevel[      r9   Nr  r  r  r   r.   r   rn   r!   )r  r   rn   zhybridproperty[_T])rp   rq   rr   r   r  rd  ru   r9   r7   rY  rY  O  s    'r9   rY  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 rK   )r  r[  setfnr\  s     r7   r   zrw_hybridproperty.__init__a  s    	37
r9   c                N    || j                  |      }|S | j                  |      S rK   r^  r_  s       r7   r  zrw_hybridproperty.__get__f  ra  r9   c                D    | j                   J | j                  ||       y rK   rk  r  s      r7   r  zrw_hybridproperty.__set__m  s     zz%%%

8U#r9   c                    || _         | S rK   rn  r\  s     r7   setterzrw_hybridproperty.setterq  s    
r9   c                    || _         | S rK   rc  r\  s     r7   rd  zrw_hybridproperty.classlevelu  re  r9   Nrf  rg  r  )r  r   rn   zrw_hybridproperty[_T])rp   rq   rr   r   r  r  rp  rd  ru   r9   r7   ri  ri  `  s    8
'$r9   ri  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 rK   )r  r"  r[  r\  s     r7   r   zhybridmethod.__init__}  s    $((	DMr9   c                    |&| j                   j                  ||j                        S | j                  j                  ||      S rK   )r[  r  r   r  )rb   r  r.   s      r7   r  zhybridmethod.__get__  s:    ==((@@99$$Xu55r9   c                    || _         | S rK   rc  r\  s     r7   rd  zhybridmethod.classlevel  re  r9   Nrf  )r  r   r.   r   rn   r  )r  r   rn   zhybridmethod[_T])rp   rq   rr   rs   r   r  rd  ru   r9   r7   rs  rs  z  s    96r9   rs  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.

    rV   r   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 )_lockry  rP   r0   rV   hashr"  __new__rx  r   rs   rD   )r|   r   r  	canonicalr   s        r7   r}  zsymbol.__new__  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 )NrX   )rx  r   r"  ra   s    r7   
__reduce__zsymbol.__reduce__  s    		3D	222r9   c                    t        |       S rK   )r   ra   s    r7   __str__zsymbol.__str__  s    Dzr9   c                "    d| j                   dS )Nzsymbol(r[  )r   ra   s    r7   __repr__zsymbol.__repr__  s    Q''r9   )NN)r   rV   r  r  r~  Optional[int]rn   rx  )rp   rq   rr   rs   r:   ry  r9  r:  r{  r}  r  r  r  ru   r9   r7   rx  rx    si     I!#G#INNE
 "#'	  !	
 
<3(r9   rx  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^__.*__$)r~  r~  z#Expected integer values for IntFlag)_itemsr`  r   matchr0   r"  rx  r  rD   r  r   r   immutabledictr   __members__)	r|   	classnamer   dict_r{  r`  r,  vr   s	            r7   r   z_IntFlagMeta.__init__  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  ra   s    r7   __iter__z_IntFlagMeta.__iter__  s    !=
 	
r9   N)
r  rV   r   zTuple[Type[Any], ...]r  Dict[str, Any]r{  r   rn   ro   )rn   zIterator[symbol])rp   rq   rr   r   r  ru   r9   r7   r  r    s<    

 %
 	

 
 

2
r9   r  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  ru   r9   r7   r  r    s    r9   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': )r`  r   r    rD  )rX  choicesr   resolve_symbol_names
enum_valuechoices         r7   parse_user_argument_for_enumr    sv    ( &mmo 
F*!cZ__&<F] {


1$s3'B
CCr9   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    r7   set_creation_orderr  $  s      /HqOr9   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)rB   warnr_   r`   )r  r&  rP  s      r7   warn_exceptionr  1  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   rD   )rg   len_s     r7   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)rT  r}  r|  r  )r|   rg   numr&  interpolatedrb   r   s         r7   r}  z_hash_limit_string.__new__S  sR     DsJ
 wsL1'UD,>,D$EEF
r9   c                    | j                   S rK   )r  ra   s    r7   __hash__z_hash_limit_string.__hash__]  s    zzr9   c                0    t        |       t        |      k(  S rK   )r|  )rb   others     r7   __eq__z_hash_limit_string.__eq__`  s    DzT%[((r9   )rg   rV   r  r"  r&  Sequence[Any]rn   r  )rn   r"  )r  r   rn   r  )	rp   rq   rr   rs   r:   r}  r  r  rV  rW  s   @r7   r  r  F  s>     J!)6	)r9   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     r7   r  r  d  s(     s}}St45sCMM*r9   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     r7   warn_limitedr  q  s#    
  b$/3&r9   z)Dict[CodeType, Tuple[str, Type[Warning]]]_warning_tagsc                      fd}|S )Nc                2    ft         | j                  <   | S rK   )r  r  )r   categorymessages    r7   goz#tag_method_for_warnings.<locals>.go  s    &-x%8bkk"	r9   ru   )r  r  r  s   `` r7   tag_method_for_warningsr  ~  s     Ir9   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)
NFrp   r   Tz (r[  r   r   )
stacklevel)r_   	_getframer   r  _not_sa_pattern	f_globalsrP   f_coder  f_backr2   warningsr  )r  r  r  framestacklevel_foundwarning_tag_found_suffix	_categorys           r7   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   )rx   insert)rX  r{  	strong_fnonce_fnr   onceretry_on_exceptions       r7   r  zonly_once.<locals>.go  sM     	hhjG*r** %KK7+s     7)rX  r   r{  r   rn   zOptional[_T]ru   )r   r  r  r  s   `` @r7   	only_oncer    s     4D Ir9   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        r7   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r9   c                ^    d| z  }t               j                         }t        ||       |d   S )Nz&def set(obj, value):    obj.%s = valuerw   )r  copyr   )attrnamer   r   s      r7   
attrsetterr    s,    3h>D
(--/CsOu:r9   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.

    ru   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  rO   _dundersr  AssertionErrorrT  __init_subclass__)r|   r   	remainingr   s      r7   r  zTypingOnly.__init_subclass__  st    &!$X^^D5II  $SE "--6Kq:  	!#s
   A&A&rm   )rp   rq   rr   rs   rt   r  rV  rW  s   @r7   r  r    s    
 I
$ 
$r9   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.

    rV   ensure_kwargc                    | j                   }| j                  }|re|D ]`  }t        j                  ||      }|s||   }t	        j
                  |      }|j                  rC| j                  |      }t        | ||       b t        | )          y rK   )r  rO   r   r  r   r   r(  
_wrap_w_kwr  rT  r  )	r|   fn_regclsdictr  rY   r   r   wrappedr   s	           r7   r  zEnsureKWArg.__init_subclass__+  s    !!,, 3HHVS) B!88<D::"%.."4S'23 	!#r9   c                (    dfd}t        |      S )Nc                      |  S rK   ru   )rX  r{  r   s     r7   wrapz$EnsureKWArg._wrap_w_kw.<locals>.wrap;  s    s8Or9   )rX  r   r{  r   rn   r   r   )r|   r   r  s    ` r7   r  zEnsureKWArg._wrap_w_kw9  s    	 dB''r9   rm   )r   r   rn   r   )	rp   rq   rr   rs   r:   r  r  r  rV  rW  s   @r7   r  r    s.     $ ( (r9   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

    rp   rq   rs   )r   r   r   rp   rq   r#  rs   )wrapperr   _fs      r7   wrap_callabler  A  s     r:gr**ll++2|$MMBM2;;	*r{{/B/B,,BJ 	 ZZBJ	r9   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   r   )rg   rv  r  idxlvcharr   s          r7   quoted_token_parserr  Y  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   )rs   inject_param_text)r   r  paramparamsr  s      r7   r   z$add_parameter_text.<locals>.decorate  sO    jj$39r#C6)J%%+)JKC
	 *Ks   
A
)r   r\  )r  r  r   s   `` r7   add_parameter_textr    s    !!&)F Or9   c                    | j                  dd      }t        |      dk(  r| S |\  }}|j                  d      s|dz   t        j                  |      z   S t        j                  |       S )N
r   r   )r   r   r  textwrapdedent)r  
split_text	firstliner  s       r7   _dedent_docstringr	    sc    D!$J
:!)	9$4(//)"<<<t$$r9   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  r^  r  minr   )
given_doctext
injecttextposdoctextlinesinjectlinesr  lineblanks
inject_poss
             r7   inject_docstring_textr    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   *r   r   z(\s+)\Sr   r  z::)collectionsdeque
splitlinespopleft
_param_regr  r   lstripr   r   rz   rstripr  r   r   )
r  inject_paramsdoclinesr  	to_injectr  rY   r   indentm2s
             r7   r  r    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r9   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..rZ  z, ..., )r   r   )r   flagr   ress       r7   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    r7   has_compiled_extr,    s"    	"
 	

 r9   c                  .    e Zd Z ej                         Zy)_MissingN)rp   rq   rr   enumautoMissingru   r9   r7   r.  r.    s    diikGr9   r.  )r3   r   r4   r+   rn   rN   )r3   r   rn   rN   )rX   r   rn   rV   )r|   Type[_T]rn   zIterator[Type[_T]])r   r   rn   rV   rK   )r|   	Type[Any]r   r  rn   rV   )r   zUnion[Type[Any], object]r   r   rn   r  )r   slicern   Tuple[Any, ...])r   Sequence[str]r   rV   rn   zIterator[str])r   zCallable[[int], Any]r   r"  rn   zIterator[Any])r   r   rn   zCallable[[_Fn], _Fn])r   zUnion[str, types.CodeType]r   r  r   rV   rn   r   )r|   r<   r  Optional[Set[str]]r  zLiteral[True]rn   zSet[str])r|   r<   r  r7  r  r  rn   r7  )r  r   rn   	List[str])FF)r   r   r   r  r!  r  rn   zcompat.FullArgSpec)T)r   z-Union[Callable[..., Any], compat.FullArgSpec]r   r  rn   zDict[str, Optional[str]])ru   ru   ru   ru   )rG  r3  rH  rV   rI  rV   rJ  r6  rK  r6  rL  r6  rM  r6  rn   zCallable[[_T], _T])ru   Nru   )
r3   r   ra  zSequence[Tuple[str, Any]]rb  z%Optional[Union[object, List[object]]]rc  r6  rn   rV   )NNz
self.proxyN)NNNr  )r3   r   rn   r  )r  rV   rn   z!Callable[[str], Union[str, bool]])rg   r   rn   r  )TN)r{  r  r  rV   rf   r3  r%  r  r&  zOptional[Dict[str, Any]]rn   ro   )r3   r   r|   r3  rn   r5  )
r3   r!   r|   r2  r&  r   r{  r   rn   r!   )rn   zCallable[[], int])r>  r   rj  Optional[Type[Any]]rn   r9  )rX  r   rE  z'Union[Tuple[Type[Any], ...], Type[Any]]r   rV   rn   r   )F)
rX  r   r  zDict[_E, List[Any]]r   rV   r  r  rn   zOptional[_E]r  )r  r   r&  r   rP  r   rn   r   )   )r  rV   r   r  rn   ro   )r  rV   r&  r  rn   ro   )r  rV   r  zType[Warning]rn   Callable[[_F], _F])Nr   )r  zUnion[str, Warning]r  zOptional[Type[Warning]]r  r"  rn   ro   )r   r  r  r  rn   zCallable[..., Optional[_T]])r  r8  r  re.Pattern[str]r  r<  rn   r8  )r  r   r  rV   rn   r;  )r  rV   rn   rV   )r  r  r  rV   r  r"  rn   rV   )r  rV   r  zDict[str, str]rn   rV   )r   r8  rn   r  )rs   
__future__r   r  r/  	functoolsr   rL   r   r  r   r_   r  r9  r   r   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   _has_cyr   r   r    r!   r"   r$   r&   r'   r(   r)   py314annotationlibr*   r+   r8   r<   rO   r  r=   r@   rE   rI   py310rZ   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r,  r   rD  rN  rQ  rU  rn  rp  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  r   r#  r'  r.  r2  r6  r@  rF  r  rQ  rY  ri  rs  r"  rx  r  r  r  FastIntFlagEnumr  r  r  r  r  r  rV   r  r  r  r  r:   r  compiler  r  r  _SQLA_RE_UNITTEST_REr  NoneTyper  r  r  r  r  r  r  r	  r  r  r  r(  r,  r.  r1  	MissingOrru   r9   r7   <module>rP     s	   #   $    	 
                            $  T]4(T#s(+,e34e@Ae01e./ 
<< 5$ !MM*;<DD$#	BH \\,
2"$82 82v6 /3O	O+OO,-,&, 
,$M  e/0
Y,x
$+9DG enen( (V
( 
  $!		  	
  
 
-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	r9   