U
    ÌZjàÛ  ã                   @   sd  d 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ZddlmZ ddlmZ ddlmZ d	d
„ ZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd™d!d"„ZG d#d$„ d$eƒZd%d&„ Z dšd'd(„Z!d)d*„ Z"d›d,d-„Z#dœd/d0„Z$d�d1d2„Z%džd4d5„Z&d6d7„ Z'd8d9„ Z(dŸd:d;„Z)G d<d=„ d=eƒZ*d>d?„ Z+d@dA„ Z,d dCdD„Z-dEdF„ Z.d¡dGdH„Z/G dIdJ„ dJeƒZ0dKdL„ Z1G dMdN„ dNeƒZ2G dOdP„ dPeƒZ3dQdR„ Z4dSdT„ Z5dUdV„ Z6d¢dWdX„Z7dYdZ„ Z8d[d\„ Z9d]d^„ Z:d£d_d`„Z;dadb„ Z<dcdd„ Z=G dedf„ dfe>ƒZ?G dgdh„ dheƒZ@G didj„ djeƒZAG dkdl„ dleBƒZCdmeC_DG dndm„ dmeƒZEdaFdodp„ ZGdqdr„ ZHd¤dtdu„ZIG dvdw„ dwejJƒZKd¥dxdy„ZLdzd{„ ZMd¦d|d}„ZNd~d„ ZOe Pd€¡ZQe Pd�¡ZReReQfd‚dƒ„ZSeTdƒZUd„d…„ ZVG d†d‡„ d‡eTƒZWdˆd‰„ ZXdŠd‹„ ZYdŒd�„ ZZdŽd�„ Z[d�d‘„ Z\e Pd’¡Z]d“d”„ Z^d•d–„ Z_d—d˜„ Z`dS )§z…Routines to help with the creation, loading and introspection of
modules, classes, hierarchies, attributes, functions, and methods.

é    N©Úupdate_wrapperé   )Ú_collections)Úcompaté   )Úexcc                 C   s*   t jr|  d¡} t ¡ }| | ¡ | ¡ S )Nzutf-8)r   Úpy3kÚencodeÚhashlibÚmd5ÚupdateÚ	hexdigest)ÚxÚm© r   ú^/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.pyÚmd5_hex   s
    

r   c                   @   s.   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
S )Úsafe_reraiseaK  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()

    )Ú	warn_onlyÚ	_exc_infoFc                 C   s
   || _ d S ©N)r   )Úselfr   r   r   r   Ú__init__:   s    zsafe_reraise.__init__c                 C   s   t  ¡ | _d S r   )ÚsysÚexc_infor   ©r   r   r   r   Ú	__enter__=   s    zsafe_reraise.__enter__c                 C   sz   |d kr0| j \}}}d | _ | jsvtj||d� nFtjsb| j rb| j d rbtd| j d | j d f ƒ d | _ tj||d� d S )N)Úwith_tracebackr   zfAn exception has occurred during handling of a previous exception.  The previous exception is:
 %s %s
r   )r   r   r   Zraise_r	   Úwarn)r   Útype_ÚvalueÚ	tracebackÚexc_typeÚ	exc_valueÚexc_tbr   r   r   Ú__exit__@   s     þþÿzsafe_reraise.__exit__N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r&   r   r   r   r   r   &   s
   
r   c                 c   sH   t ƒ }| g}|rD| ¡ } | |kr$qn
| | ¡ | |  ¡ ¡ | V  qd S r   )ÚsetÚpopÚaddÚextendÚ__subclasses__)ÚclsÚseenÚstackr   r   r   Úwalk_subclassesW   s    
r4   c                 C   s<   t | tjƒr| S z
t| ƒW S  tk
r6   d|   Y S X d S )Nzunprintable element %r)Ú
isinstancer   Ústring_typesÚstrÚ	Exception)Úelementr   r   r   Ústring_or_unprintablee   s    
r:   c                 C   s   d  dd„ t d| j¡D ƒ¡S )Nú c                 s   s   | ]}|  ¡ V  qd S r   )Úlower)Ú.0Únr   r   r   Ú	<genexpr>p   s    z(clsname_as_plain_name.<locals>.<genexpr>z([A-Z][a-z]+))ÚjoinÚreÚfindallr'   )r1   r   r   r   Úclsname_as_plain_nameo   s    
ÿrC   c                 C   s.   t | tƒs| j}n| }|j}t||ƒ}||kS )z1Return True if the two class methods don't match.)r5   ÚtypeÚ	__class__r'   Úgetattr)Zinstance_or_clsZagainst_methodZcurrent_clsÚmethod_nameZcurrent_methodr   r   r   Úmethod_is_overriddenu   s    

rH   c                 C   s>   g }| j | j| jfD ] }t|dƒr*| ¡ }| |¡ qt|ƒS )zrdecode a slice object as sent to __getitem__.

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

    Ú	__index__)ÚstartÚstopÚstepÚhasattrrI   ÚappendÚtuple)ZslcÚretr   r   r   r   Údecode_slice„   s    
rQ   c              	   '   sj   t | ƒ} |D ]X‰ t ˆ ft ‡ fdd„tdƒ¡¡}|D ] }|| kr6|  |¡ |V   qq6tdˆ  ƒ‚qd S )Nc                    s   ˆ t | ƒ S r   )r7   )Úi©Úbaser   r   Ú<lambda>—   ó    z!_unique_symbols.<locals>.<lambda>iè  z&exhausted namespace for symbol base %s)r,   Ú	itertoolsÚchainr   Zitertools_imapÚranger.   Ú	NameError)ÚusedÚbasesÚpoolÚsymr   rS   r   Ú_unique_symbols’   s    þ
r_   c                 c   s*   |r&|| d @ }| |ƒV  ||N }q dS )z6Call the given function given each nonzero bit from n.r   Nr   )Úfnr>   Úbr   r   r   Úmap_bits¢   s    
rb   c                    s   ‡ fdd„}t |ˆ ƒS )z'A signature-matching decorator factory.c           	         sÚ   t  | ¡st  | ¡stdƒ‚t | ¡}i }t||ƒ}t|d ƒ|dd…  | jf }t	|ddƒ\}}t
||d�}| t|dd	�¡ | j|d
< d| }| |ˆ || d| ji¡ t||| jƒ}t| d| ƒj|_| |_t|| ƒS )Nznot a decoratable functionr   r   é   Útargetr`   )rd   r`   F©ÚgroupedÚnamezDdef %(name)s(%(args)s):
    return %(target)s(%(fn)s, %(apply_kw)s)
r'   Ú__func__)ÚinspectÚ
isfunctionÚismethodr8   r   Úinspect_getfullargspecÚ!_update_argspec_defaults_into_envrO   r'   r_   Údictr   Úformat_argspec_plusr(   Ú_exec_code_in_envrF   Ú__defaults__Ú__wrapped__r   )	r`   ÚspecÚenvÚnamesZ	targ_nameÚfn_nameÚmetadataÚcodeÚ	decorated©rd   r   r   Údecorate®   s&    

 
üÿzdecorator.<locals>.decorater   )rd   r{   r   rz   r   Ú	decorator«   s    r|   c                 C   s|   | j rtg }d}| j D ]@}t|ƒjdkrJd| }|||< | |¡ |d7 }q| |¡ qt| ƒ}t|ƒ|d< tj|Ž S | S dS )zCgiven a FullArgSpec, convert defaults to be symbol names in an env.r   )ÚbuiltinsÚ__builtin__zx%dr   rc   N)ÚdefaultsrD   r(   rN   ÚlistrO   r   ÚFullArgSpec)rs   rt   Znew_defaultsrR   Úargrg   Úelemr   r   r   rm   Î   s    



rm   c                 C   s   t | |ƒ || S r   )Úexec)rx   rt   rv   r   r   r   rp   ã   s    
rp   c                 C   s‚  t | tƒr0| j}| }d|r|nd| j |f }n|  }}d| }| d¡d }t |¡}|d d= t|dd�}||d	< d
| }	|t|j	dœ}
t
|	|
ƒ |
| }t|dƒrî|j\}}|j}|dkrÐd| j	| jf }t|d|||f dƒ}||_n|j|_d| dd¡d  |_	|j	tjk�r*td|j	f ƒ‚tj�s>t|dƒ�rb||j_t|jdƒ�s~||f|j_n||_t|dƒ�s~||f|_|S )z´Produce a wrapping function for the given cls or classmethod.

    Rationale here is so that the __init__ method of the
    class can serve as documentation for the function.

    z Construct a new :class:`%s` object. 

This constructor is mirrored as a public API function; see :func:`sqlalchemy%s` for a full usage and argument description.z.%szSThis function is mirrored; see :func:`sqlalchemy%s` for a description of arguments.Ú.éÿÿÿÿr   Fre   rg   z5def %(name)s(%(args)s):
    return cls(%(apply_kw)s)
)r1   Úsymbolr'   Ú
_linked_toNz%s.%szò.. container:: inherited_member

    This documentation is inherited from :func:`sqlalchemy%s`; this constructor, :func:`sqlalchemy%s`,   creates a :class:`sqlalchemy%s` object.  See that class for additional details describing this subclass.r   Ú
sqlalchemyz0public_factory location %s is not in sys.modulesrh   )r5   rD   r   r'   Úsplitr   rl   ro   r‡   r(   r„   rM   rˆ   r*   Úinject_docstring_textÚrsplitr   ÚmodulesÚImportErrorÚpy2krh   )rd   ÚlocationZclass_locationr`   Z	callable_ÚdocZlocation_namers   rw   rx   rt   ry   Z	linked_toZlinked_to_locationZlinked_to_docr   r   r   Úpublic_factoryè   st    
þüÿÿÿ

üÿý


ûø
ÿÿ
r’   c                   @   s.   e Zd Zd
dd„Zdd„ Zdd„ Zdd	„ ZdS )ÚPluginLoaderNc                 C   s   || _ i | _|| _d S r   )ÚgroupÚimplsÚauto_fn)r   r”   r–   r   r   r   r   @  s    zPluginLoader.__init__c                 C   s   | j  ¡  d S r   )r•   Úclearr   r   r   r   r—   E  s    zPluginLoader.clearc                 C   s†   || j kr| j | ƒ S | jr:|  |¡}|r:|| j |< |ƒ S t | j¡D ]&}|j|krF|j| j |< | ¡   S qFt d| j|f ¡‚d S )NzCan't load plugin: %s:%s)	r•   r–   r   Zimportlib_metadata_getr”   rg   Úloadr   ZNoSuchModuleError)r   rg   ÚloaderÚimplr   r   r   r˜   H  s    



ÿzPluginLoader.loadc                    s   ‡ ‡fdd„}|| j |< d S )Nc                     s6   t  ˆ ¡} ˆ  d¡dd … D ]}t| |ƒ} qt| ˆƒS )Nr…   r   )r   Úimport_rŠ   rF   )ÚmodÚtoken©Ú
modulepathÚobjnamer   r   r˜   \  s    
z#PluginLoader.register.<locals>.load)r•   )r   rg   rŸ   r    r˜   r   rž   r   Úregister[  s    zPluginLoader.register)N)r'   r(   r)   r   r—   r˜   r¡   r   r   r   r   r“   ?  s   
r“   c                 C   sn   z
t j}W n2 tk
r<   t | ¡}|d t|d ƒf Y S X | j}|j}t|j	d |… ƒt|j
|@ ƒfS d S )Nr   r   )ri   ÚCO_VARKEYWORDSÚAttributeErrorr   rl   ÚboolÚ__code__Úco_argcountr€   Úco_varnamesÚco_flags)r`   Zco_varkeywordsrs   ÚcoÚnargsr   r   r   Ú_inspect_func_argse  s    

þr«   c                 C   s˜   |dk}|rt ƒ }| j dd¡}|o<t|tjƒo<t|jtjƒ}|rdt|ƒ\}}| 	|¡ |sd|sddS |rl|rŠ| j
D ]}t||ƒdkrr qŠqr| 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   Fr   )r,   Ú__dict__Úgetr5   ÚtypesÚFunctionTyper¥   ÚCodeTyper«   r   Ú	__bases__Úget_cls_kwargsÚdiscard)r1   Z_setÚtoplevelZctrZhas_initru   Zhas_kwÚcr   r   r   r²   y  s(    
ÿý


r²   c                 C   s   t  | ¡d S )zƒReturn the set of legal kwargs for the given `func`.

    Uses getargspec so is safe to call for methods, functions,
    etc.

    r   )r   rl   )Úfuncr   r   r   Úget_func_kwargs¤  s    r·   Fc              	   C   sD  t  | ¡rtd|  ƒ‚�n&t  | ¡rn|rb|rbt | ¡}t |jdd… |j|j	|j
|j|j|j¡S t | ¡S nÒt  | ¡rÌ|r¾|s†| jr¾t | j¡}t |jdd… |j|j	|j
|j|j|j¡S t | j¡S ntt  | ¡ræt| j|dd�S t| dƒ� rþt | j¡S t| dƒ�r4t  | j¡�r&t| j|d�S td	|  ƒ‚ntd	|  ƒ‚dS )
zþReturn 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_initrh   Ú__call__)r¸   zCan't inspect callable: %s)ri   Ú	isbuiltinÚ	TypeErrorrj   r   rl   r�   ÚargsÚvarargsÚvarkwr   Ú
kwonlyargsÚkwonlydefaultsÚannotationsrk   Ú__self__rh   ÚisclassÚget_callable_argspecr   rM   rº   )r`   r¸   r¹   rs   r   r   r   rÅ   ¯  sR    	


ù

ù

  ÿrÅ   Tc              	   C   sº  t  | ¡rt  | ¡}n| }t j|Ž }t  |d |d |d d|d ¡}|d r†|d d }t  |d dd… |d |d d|d ¡}n"|d r d|d  }|}nd}|}d}|d rÄ|t|d ƒ7 }|d rÜ|t|d ƒ7 }|d |d  }|�r|d| d… }	nd}	t j||d |d |	d	d
„ d�}
|d �r\t j|dd… |d |d |	dd
„ d�}n|
}|�rzt||||
||d�S t|dd… ||dd… |
dd… |dd… |dd… d�S 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)
      {'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]rc   r   c                 S   s   d|  S ©Nú=r   ©r   r   r   r   rU   3  rV   z%format_argspec_plus.<locals>.<lambda>)Úformatvaluec                 S   s   d|  S rÇ   r   rÉ   r   r   r   rU   <  rV   )r½   Úself_argÚ	apply_posÚapply_kwÚapply_pos_proxiedÚapply_kw_proxiedr†   )r   Úcallablerl   Úinspect_formatargspecÚlenrn   )r`   rf   rs   r½   rÌ   rË   rÎ   Únum_defaultsZ	name_argsZdefaulted_valsrÍ   rÏ   r   r   r   ro   å  s†    "

    ÿ    ÿû

ûú	




úro   c                 C   st   | t jkr$|rdnd}|rdnd}n<zt| |d�W S  tk
r^   |rJdnd}|rVdnd	}Y nX td|||||d
�S )a  format_argspec_plus with considerations for typical __init__ methods

    Wraps format_argspec_plus with error handling strategies for typical
    __init__ cases::

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    z(self)r   z()Ú re   z(self, *args, **kwargs)zself, *args, **kwargsz(*args, **kwargs)z*args, **kwargs)rË   r½   rÌ   rÍ   rÎ   rÏ   )Úobjectr   ro   r¼   rn   )Úmethodrf   r½   Zproxiedr   r   r   Úformat_argspec_initU  s&    

ÿýúr×   r   c                    s   ‡ ‡‡‡‡‡fdd„}|S )z�A class decorator that will copy attributes to a proxy class.

    The class to be instrumented must define a single accessor "_proxied".

    c                    sÆ   d	‡‡‡fdd„	}‡‡‡fdd„}ˆD ].}t | |ƒrDtd| |f ƒ‚t| |||ƒƒ q&ˆ D ].}t | |ƒrxtd| |f ƒ‚t| |||ƒƒ qZˆD ]2}t | |ƒr¬td| |f ƒ‚t| |||dd�ƒ qŽ| S )
NFc           	         sº   t ˆ| ƒ}t |¡}d|ji}t||ƒ}t|dd�}|j|d |d |d |d dœ}|rld	| }ˆ|d
< nd| }t|||jƒ}t |d|ƒj|_t	|j
dˆˆ f dƒ|_
|r¶t|ƒ}|S )Nr'   Fre   rÎ   rÏ   r½   rË   )rg   rÎ   rÏ   r½   rË   zLdef %(name)s(%(args)s):
    return target_cls.%(name)s(%(apply_kw_proxied)s)Ú
target_clszWdef %(name)s(%(args)s):
    return %(self_arg)s._proxied.%(name)s(%(apply_kw_proxied)s)rh   úS.. container:: class_bases

    Proxied for the %s class on behalf of the %s class.r   )rF   r   rl   r(   rm   ro   r'   rp   rq   r‹   r*   Úclassmethod)	rg   Úclslevelr`   rs   rt   Zcaller_argspecrw   rx   Zproxy_fn©Úproxy_cls_sphinx_namerØ   Útarget_cls_sphinx_namer   r   Ú
instrument…  sB    



ûþÿ
þÿþûz:create_proxy_methods.<locals>.decorate.<locals>.instrumentc                    sR   ˆj  | d ¡}|d k	r.t|jdˆˆ f dƒ}nd }dd| i }t|d|idƒ}|S )NrÙ   r   z—def set_(self, attr):
    self._proxied.%(name)s = attr
def get(self):
    return self._proxied.%(name)s
get.__doc__ = doc
getset = property(get, set_)rg   r‘   Úgetset)r¬   r­   r‹   r*   rp   )rg   Úattrr‘   rx   rà   rÜ   r   r   Úmakeprop²  s"    þþøù	z8create_proxy_methods.<locals>.decorate.<locals>.makepropz class %s already has a method %sT©rÛ   )F)rM   r¼   Úsetattr)r1   rß   râ   ÚmethÚprop©Ú
attributesÚclassmethodsÚmethodsrÝ   rØ   rÞ   r   r   r{   „  s*    -

ÿ

ÿ

ÿz&create_proxy_methods.<locals>.decorater   )rØ   rÞ   rÝ   ré   rê   rè   r{   r   rç   r   Úcreate_proxy_methodsv  s    crë   c                 C   sT   zt  | ¡W S  tk
rN   | tjkr8dgdddf Y S dgdddf Y S Y nX dS )zúinspect.getargspec with considerations for typical __init__ methods

    Wraps inspect.getargspec with error handling for typical __init__ cases::

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    r   Nr½   Úkwargs)r   rl   r¼   rÕ   r   )rÖ   r   r   r   Úgetargspec_initê  s    	
rí   c                 C   s    t | tjƒr| js| jS | S dS )zSAdjust the incoming callable such that a 'self' argument is not
    required.

    N)r5   r®   Ú
MethodTyperÃ   rh   )Zfunc_or_clsr   r   r   Úunbound_method_to_callableü  s    rï   c              	      sL  |dkrˆg}n
t  |¡}tƒ ‰ g }t  ¡ }d}t|ƒD ]Ü\}}zt |j¡}	W n tk
rh   Y q8Y q8X |	j	rzt
|	j	ƒp|d}
|dkrÄ|	jr’|	j}|
r®| |	jd|
 … ¡ qè| |	jdd… ¡ n$| ‡ fdd„|	jd|
 … D ƒ¡ |
r8| dd„ t|	j|
 d… |	j	ƒD ƒ¡ q8g }| ‡fdd„|D ƒ¡ |dk	�rbtˆ|ƒ�rb| d	d„ tˆ|ƒD ƒ¡ | ¡ D ]f\}}||k�r€�qjz6tˆ|ˆ ƒ}|ˆ k	�r´||k�r´| d
||f ¡ W n tk
�rÌ   Y nX �qj|�r6|D ]X\}}z6tˆ|ˆ ƒ}|ˆ k	�r||k�r| d
||f ¡ W n tk
�r0   Y nX �qÜdˆjjd |¡f S )z}Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    Nr   r   c                    s   g | ]}|ˆ f‘qS r   r   ©r=   r‚   )Úmissingr   r   Ú
<listcomp>'  s     z generic_repr.<locals>.<listcomp>c                 S   s   g | ]\}}||f‘qS r   r   )r=   r‚   Údefaultr   r   r   rò   ,  s   ÿc                 3   s   | ]}t tˆ |d ƒƒV  qd S r   )ÚreprrF   rð   ©Úobjr   r   r?   5  s     zgeneric_repr.<locals>.<genexpr>c                 S   s   g | ]}t |ƒ‘qS r   ©rô   )r=   Úvalr   r   r   rò   8  s     z%s=%rz%s(%s)ú, )r   Úto_listrÕ   ÚOrderedDictÚ	enumerater   rl   r   r¼   r   rÒ   r¾   r/   r½   r   ÚziprM   rF   ÚitemsrN   r8   rE   r'   r@   )rö   Zadditional_kwZ
to_inspectZ
omit_kwargZpos_argsZkw_argsZvargsrR   Zinsprs   Zdefault_lenÚoutputr‚   Zdefvalrø   r   )rñ   rö   r   Úgeneric_repr  sj    

ÿ ÿþÿ


r   c                   @   s6   e Zd ZdZdZdd„ Zdd„ Zddd	„Zd
d„ ZdS )Úportable_instancemethodz_Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    )rd   rg   rì   Ú__weakref__c                 C   s   | j | j| jdœS )N©rd   rg   rì   r  r   r   r   r   Ú__getstate__X  s    ýz$portable_instancemethod.__getstate__c                 C   s&   |d | _ |d | _| dd¡| _d S )Nrd   rg   rì   r   )rd   rg   r­   rì   )r   Ústater   r   r   Ú__setstate___  s    

z$portable_instancemethod.__setstate__r   c                 C   s   |j | _|j| _|| _d S r   )rÃ   rd   r'   rg   rì   )r   rå   rì   r   r   r   r   d  s    z portable_instancemethod.__init__c                 O   s    |  | j¡ t| j| jƒ||ŽS r   )r   rì   rF   rd   rg   )r   r‚   Úkwr   r   r   rº   i  s    z portable_instancemethod.__call__N)r   )	r'   r(   r)   r*   r+   r  r  r   rº   r   r   r   r   r  P  s   
r  c                    sþ   t jrt| tjƒrtƒ S | h‰ t| jƒ}|rö| ¡ }t jr^t|tjƒrHq(‡ fdd„|jD ƒ}n‡ fdd„|jD ƒ}|D ]}| 	|¡ ˆ  
|¡ qvt jr®|jdks(t|dƒsÄq(n|jdks(t|dƒsÄq(‡ fdd„| ¡ D ƒD ]}| 	|¡ ˆ  
|¡ qÚq(tˆ ƒS )	a†  Return an unordered sequence of all classes related to cls.

    Traverses diamond hierarchies.

    Fibs slightly: subclasses of builtin types are not returned.  Thus
    class_hierarchy(class A(object)) returns (A, object), not A plus every
    class systemwide that derives from object.

    Old-style classes are discarded and hierarchies rooted on them
    will not be descended.

    c                 3   s&   | ]}|ˆ krt |tjƒs|V  qd S r   )r5   r®   Ú	ClassType©r=   Ú_©Zhierr   r   r?   †  s    þz"class_hierarchy.<locals>.<genexpr>c                 3   s   | ]}|ˆ kr|V  qd S r   r   r	  r  r   r   r?   Œ  s      r}   r0   r~   c                    s   g | ]}|ˆ kr|‘qS r   r   r	  r  r   r   rò   ›  s      z#class_hierarchy.<locals>.<listcomp>)r   r�   r5   r®   r  r€   Ú__mro__r-   r±   rN   r.   r	   r(   rM   r0   )r1   Úprocessrµ   r\   ra   Úsr   r  r   Úclass_hierarchyn  s:    

þ
 ÿ
r  c                 c   s@   t | ƒ}|D ].}| jD ]"}||jkr||j| fV   qqqdS )zÍiterate all the keys and attributes associated
    with a class, without using getattr().

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

    N)Údirr  r¬   )r1   ÚkeysÚkeyrµ   r   r   r   Úiterate_attributes¡  s    

r  ú
self.proxyc              	      s0  |r
|}n$ˆdkrd‰‡ ‡fdd„t |ƒD ƒ}|D ]ø}z(t||ƒ}t|dƒsPW q2t|d|ƒ}W n tk
rv   Y q2Y nX z2t |¡}	t |	d ¡}
t |	d dd… ¡}W n tk
rÆ   d	}
d
}Y nX dtƒ  }|dk	râ||ipäi }t 	||¡ z|j
|| _
W n tk
�r   Y nX tˆ ||| ƒ q2dS )z9Automates delegation of __specials__ for a proxying type.N)r+   Ú__del__Ú__getattribute__Z__metaclass__r  r  c                    s6   g | ].}|  d ¡r| d ¡rtˆ |ƒs|ˆkr|‘qS )Ú__)Ú
startswithÚendswithrM   ©r=   r   ©Úinto_clsÚskipr   r   rò   Ç  s   


úz0monkeypatch_proxied_specials.<locals>.<listcomp>rº   rh   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  rF   rM   r£   r   rl   rÑ   r¼   ÚlocalsÚexec_rq   rä   )r  Zfrom_clsr  Úonlyrg   Zfrom_instanceZdundersrÖ   r`   rs   Zfn_argsZd_argsÚpyrt   r   r  r   Úmonkeypatch_proxied_specials±  sB    
þ




ÿÿr"  c                 C   s   t | d| ƒt |d|ƒkS )z;Return True if the two methods are the same implementation.rh   )rF   )Zmeth1Zmeth2r   r   r   Úmethods_equivalentð  s
      ÿr#  c                 C   st  |s|st dƒ‚t|tƒr(t| |ƒr(| S t|p>dd„ t|ƒD ƒƒ}tt| ƒƒ}tj}t|tƒrd|}n|svtƒ }tj}nt|ƒ}|| |¡|ƒr’| S t| t	ƒsÆ|tjkrªdp¬d}t d| |d 
|¡f ƒ‚G dd	„ d	tƒ}|ræd
|j |_tƒ }	t| ƒD ]T\}
}|
|k�rt d|
 ƒ‚t |¡�s.t d|
|f ƒ‚t||
t|ƒƒ |	 |
¡ qô||	|ƒ�rZ|S t dd 
||	 ¡ ƒ‚dS )aŽ  Ensure basic interface compliance for an instance or dict of callables.

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

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

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

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

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

    z2a class or collection of method names are requiredc                 S   s   g | ]}|  d ¡s|‘qS )r
  )r  r  r   r   r   rò     s     
 z as_interface.<locals>.<listcomp>zany ofzall ofz%r does not implement %s: %srù   c                   @   s   e Zd ZdZdS )z(as_interface.<locals>.AnonymousInterfacezA callable-holding shell.N)r'   r(   r)   r*   r   r   r   r   ÚAnonymousInterface6  s   r$  Z	Anonymousz%r: unknown in this interfacez%r=%r is not callablez,dictionary does not contain required keys %sN)r¼   r5   rD   r,   r  ÚoperatorÚgeÚgtÚintersectionrn   r@   rÕ   r'   Údictlike_iteritemsr   rÐ   rä   Ústaticmethodr.   )rö   r1   rê   ÚrequiredZ	interfaceZimplementedZcompliesZ	qualifierr$  ÚfoundrÖ   rš   r   r   r   Úas_interfaceø  sP    !

ÿÿ
ÿÿr-  c                   @   s6   e Zd ZdZddd„Zdd„ Zdd„ Zed	d
„ ƒZdS )Úmemoized_propertyz2A read-only @property that is only evaluated once.Nc                 C   s   || _ |p|j| _|j| _d S r   ©Úfgetr*   r'   ©r   r0  r‘   r   r   r   r   Q  s    zmemoized_property.__init__c                 C   s&   |d kr| S |   |¡ |j| j< }|S r   )r0  r¬   r'   ©r   rö   r1   Úresultr   r   r   Ú__get__V  s    zmemoized_property.__get__c                 C   s   t  || j¡ d S r   )r.  Úresetr'   )r   rö   r   r   r   Ú_reset\  s    zmemoized_property._resetc                 C   s   |j  |d ¡ d S r   )r¬   r-   )r1   rö   rg   r   r   r   r5  _  s    zmemoized_property.reset)N)	r'   r(   r)   r*   r   r4  r6  rÚ   r5  r   r   r   r   r.  N  s   
r.  c                    s   ‡ fdd„}t |ˆ ƒS )zàDecorate 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                    s<   ˆ| f|ž|Ž‰ ‡ fdd„}ˆj |_ ˆj|_|| jˆj < ˆ S )Nc                     s   ˆ S r   r   ©Úar  ©r3  r   r   Úmemop  s    z6memoized_instancemethod.<locals>.oneshot.<locals>.memo)r'   r*   r¬   ©r   r½   r  r:  ©r`   r9  r   Úoneshotm  s    z(memoized_instancemethod.<locals>.oneshotr   )r`   r=  r   r<  r   Úmemoized_instancemethodd  s    	r>  c                   @   sN   e Zd ZdZdZeƒ Zdd„ Zdd„ Zdd„ Z	G d	d
„ d
e
ƒZedd„ ƒZdS )ÚHasMemoizedzyA class that maintains the names of memoized elements in a
    collection for easy cache clearing, generative, etc.

    r   c                 C   s   | j D ]}| j |d ¡ qd S r   )Ú_memoized_keysr¬   r-   ©r   rƒ   r   r   r   Ú_reset_memoizations…  s    
zHasMemoized._reset_memoizationsc                 C   s   | j D ]}|| jkst‚qd S r   )r@  r¬   ÚAssertionErrorrA  r   r   r   Ú_assert_no_memoizations‰  s    
z#HasMemoized._assert_no_memoizationsc                 C   s   || j |< |  j|hO  _d S r   )r¬   r@  )r   r  r!   r   r   r   Ú_set_memoized_attribute�  s    
z#HasMemoized._set_memoized_attributec                   @   s"   e Zd ZdZddd„Zdd„ ZdS )zHasMemoized.memoized_attributezTA read-only @property that is only evaluated once.

        :meta private:

        Nc                 C   s   || _ |p|j| _|j| _d S r   r/  r1  r   r   r   r   ˜  s    z'HasMemoized.memoized_attribute.__init__c                 C   s8   |d kr| S |   |¡ |j| j< }| j| jhO  _|S r   )r0  r¬   r'   r@  r2  r   r   r   r4  �  s
    z&HasMemoized.memoized_attribute.__get__)N)r'   r(   r)   r*   r   r4  r   r   r   r   Úmemoized_attribute‘  s   
rF  c                    s   ‡ fdd„}t |ˆ ƒS )z+Decorate a method memoize its return value.c                    sN   ˆ| f|ž|Ž‰ ‡ fdd„}ˆj |_ ˆj|_|| jˆj < |  jˆj hO  _ˆ S )Nc                     s   ˆ S r   r   r7  r9  r   r   r:  «  s    zBHasMemoized.memoized_instancemethod.<locals>.oneshot.<locals>.memo)r'   r*   r¬   r@  r;  r<  r9  r   r=  ¨  s    z4HasMemoized.memoized_instancemethod.<locals>.oneshotr   )r1   r`   r=  r   r<  r   r>  ¤  s    z#HasMemoized.memoized_instancemethodN)r'   r(   r)   r*   r+   Ú	frozensetr@  rB  rD  rE  rÕ   rF  rÚ   r>  r   r   r   r   r?  {  s   r?  c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚMemoizedSlotszÇApply memoized items to an object using a __getattr__ scheme.

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

    r   c                 C   s   t |ƒ‚d S r   )r£   )r   r  r   r   r   Ú_fallback_getattrÁ  s    zMemoizedSlots._fallback_getattrc                    sˆ   ˆ  d¡rtˆƒ‚nptˆdˆ ƒrBtˆdˆ ƒƒ }tˆˆ|ƒ |S tˆdˆ ƒrztˆdˆ ƒ‰ ‡ ‡‡fdd„}ˆ j|_|S ˆ ˆ¡S d S )NZ	_memoizedz_memoized_attr_%sz_memoized_method_%sc                     s6   ˆ| |Ž‰ ‡ fdd„}ˆj |_ ˆj|_tˆˆ|ƒ ˆ S )Nc                     s   ˆ S r   r   r7  r9  r   r   r:  Ñ  s    z8MemoizedSlots.__getattr__.<locals>.oneshot.<locals>.memo)r'   r*   rä   )r½   r  r:  ©r`   r  r   r9  r   r=  Î  s    
z*MemoizedSlots.__getattr__.<locals>.oneshot)r  r£   rM   rF   rä   r*   rI  )r   r  r!   r=  r   rJ  r   Ú__getattr__Ä  s    

zMemoizedSlots.__getattr__N)r'   r(   r)   r*   r+   rI  rK  r   r   r   r   rH  ·  s   rH  c                 C   sD   t | tjƒr<|  ¡  ¡ } | dkr$dS | dkr0dS td|  ƒ‚t| ƒS )N)ÚtrueÚyesÚonÚyÚtÚ1T)ÚfalseÚnoÚoffr>   ÚfÚ0FzString is not true/false: %r)r5   r   r6   Ústripr<   Ú
ValueErrorr¤   rõ   r   r   r   Úasboolà  s    rY  c                     s   ‡ fdd„}|S )zqReturn a callable that will evaluate a string as
    boolean, or one of a set of "alternate" string values.

    c                    s   | ˆ kr| S t | ƒS d S r   )rY  rõ   ©Útextr   r   Úbool_or_valueò  s    z"bool_or_str.<locals>.bool_or_valuer   )r[  r\  r   rZ  r   Úbool_or_strì  s    r]  c                 C   s   | dkr| S t | ƒS )zCoerce to integer.N)Úint)r!   r   r   r   Úasintû  s    r_  c                 C   sj   |dkr| }|| krft |tƒr,t | | |ƒsf| | dk	rf|tkrV|rVt| | ƒ||< n|| | ƒ||< dS )zµIf '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   rD   r¤   rY  )r  r  r    Z
flexi_boolÚdestr   r   r   Úcoerce_kw_type  s    ÿþþ
ýra  c                    s$   t |ƒ}|ft‡ fdd„|D ƒƒ S )zbProduce a tuple structure that is cacheable using the __dict__ of
    obj to retrieve values

    c                 3   s&   | ]}|ˆ j kr|ˆ j | fV  qd S r   ©r¬   ©r=   Úkrõ   r   r   r?     s    
 z"constructor_key.<locals>.<genexpr>)r²   rO   )rö   r1   ru   r   rõ   r   Úconstructor_key  s    ÿre  c                    s0   t |ƒ}| ‡ fdd„| |¡D ƒ¡ |||ŽS )z„Instantiate cls using the __dict__ of obj as constructor arguments.

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

    c                 3   s&   | ]}|ˆ j kr|ˆ j | fV  qd S r   rb  rc  rõ   r   r   r?   *  s    
 z#constructor_copy.<locals>.<genexpr>)r²   r   Ú
difference)rö   r1   r½   r  ru   r   rõ   r   Úconstructor_copy"  s
    ÿrg  c                     s&   t j ¡ ‰t d¡‰ ‡ ‡fdd„} | S )z%Return a threadsafe counter function.r   c                
      s$   ˆ� t ˆ ƒW  5 Q R £ S Q R X d S r   )Únextr   ©ÚcounterÚlockr   r   Ú_next7  s    zcounter.<locals>._next)r   Ú	threadingÚLockrW   Úcount)rl  r   ri  r   rj  0  s    

rj  c                 C   s˜   t | dƒr*| jdk	r$t| jtƒr$tS | jS t| tƒr8tp:t}|| tƒrJtS || tƒrXtS || tƒrftS t | dƒrttS t | dƒr‚tS t | dƒr�tS |S dS )zÄGiven 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__NrN   r.   r,   )rM   rp  Ú
issubclassr,   r5   rD   r€   rn   )Zspecimenró   Zisar   r   r   Úduck_type_collection>  s*    
 ÿ





rr  c                 C   s^   t | |ƒr| S t |tƒrBt d|d dd„ |D ƒ¡t| ƒf ¡‚nt d||t| ƒf ¡‚d S )Nz8Argument '%s' is expected to be one of type %s, got '%s'z or c                 s   s   | ]}d | V  qdS )z'%s'Nr   )r=   r8  r   r   r   r?   f  s     z"assert_arg_type.<locals>.<genexpr>z6Argument '%s' is expected to be of type '%s', got '%s')r5   rO   r   ÚArgumentErrorr@   rD   )r‚   Zargtyperg   r   r   r   Úassert_arg_type_  s    

ÿÿÿÿrt  c                    sÀ   t jrtˆ dƒrFtˆ  ¡ ƒS n(tˆ dƒr0ˆ  ¡ S tˆ dƒrFtˆ  ¡ ƒS tˆ dtˆ ddƒƒ‰ˆdkrntdˆ  ƒ‚tˆ dƒrŒ‡ ‡fdd	„}|ƒ S tˆ d
ƒr°t‡fdd„ˆ  	¡ D ƒƒS tdˆ  ƒ‚dS )z?Return a (key, value) iterator for almost any dict-like object.rþ   Ú	iteritemsÚ__getitem__r­   NzObject '%r' is not dict-likeÚiterkeysc                  3   s    ˆ   ¡ D ]} | ˆ| ƒfV  qd S r   )rw  )r  ©ÚdictlikeÚgetterr   r   Úiterator�  s    z$dictlike_iteritems.<locals>.iteratorr  c                 3   s   | ]}|ˆ |ƒfV  qd S r   r   )r=   r  )rz  r   r   r?   ‡  s     z%dictlike_iteritems.<locals>.<genexpr>)
r   r	   rM   r€   rþ   ru  ÚiterrF   r¼   r  )ry  r{  r   rx  r   r)  o  s     




r)  c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚclasspropertyaA  A decorator that behaves like @property except that operates
    on classes rather than instances.

    The decorator is currently special when using the declarative
    module, but note that the
    :class:`~.sqlalchemy.ext.declarative.declared_attr`
    decorator should be used for this purpose with declarative.

    c                    s$   t t| ƒj|f|ž|Ž |j| _d S r   )Úsuperr}  r   r*   )r   r0  r‚   r  ©rE   r   r   r   —  s    zclassproperty.__init__c                 C   s
   |   |¡S r   )r0  )Údescr   r1   r   r   r   r4  ›  s    zclassproperty.__get__)r'   r(   r)   r*   r   r4  Ú__classcell__r   r   r  r   r}  Œ  s   
r}  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Úhybridpropertyc                 C   s   || _ || _d S r   )r¶   rÛ   ©r   r¶   r   r   r   r      s    zhybridproperty.__init__c                 C   s$   |d kr|   |¡}|S |  |¡S d S r   )rÛ   r¶   )r   ÚinstanceÚownerZclsvalr   r   r   r4  ¤  s    
zhybridproperty.__get__c                 C   s
   || _ | S r   rã   rƒ  r   r   r   Ú
classlevel«  s    zhybridproperty.classlevelN)r'   r(   r)   r   r4  r†  r   r   r   r   r‚  Ÿ  s   r‚  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Úhybridmethodz/Decorate a function as cls- or instance- level.c                 C   s   | | _ | _|| _d S r   )r¶   rh   rÛ   rƒ  r   r   r   r   ³  s    zhybridmethod.__init__c                 C   s*   |d kr| j  ||j¡S | j ||¡S d S r   )rÛ   r4  rE   r¶   )r   r„  r…  r   r   r   r4  ·  s    zhybridmethod.__get__c                 C   s
   || _ | S r   rã   rƒ  r   r   r   r†  ½  s    zhybridmethod.classlevelN)r'   r(   r)   r*   r   r4  r†  r   r   r   r   r‡  °  s   r‡  c                   @   s.   e Zd Zd
dd„Zdd„ Zdd„ Zdd	„ ZdS )Ú_symbolNc                 C   s@   t |tjƒst‚|dkr t|ƒ}t t|¡}||_|r<||_	|S )zConstruct a new named symbol.N)
r5   r   r6   rC  Úhashr^  Ú__new__rˆ  rg   r*   )r   rg   r‘   Ú	canonicalÚvr   r   r   rŠ  Ã  s    z_symbol.__new__c                 C   s   t | jdt| ƒffS )Nr   )r‡   rg   r^  r   r   r   r   Ú
__reduce__Î  s    z_symbol.__reduce__c                 C   s   t | ƒS r   r÷   r   r   r   r   Ú__str__Ñ  s    z_symbol.__str__c                 C   s
   d| j  S )Nz
symbol(%r))rg   r   r   r   r   Ú__repr__Ô  s    z_symbol.__repr__)NN)r'   r(   r)   rŠ  r�  rŽ  r�  r   r   r   r   rˆ  Â  s   
rˆ  r‡   c                   @   s6   e Zd ZdZi Zej ¡ Zddd„Z	e
d	dd„ƒZdS )
r‡   a¶  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.

    The optional ``doc`` argument assigns to ``__doc__``.  This
    is strictly so that Sphinx autoattr picks up the docstring we want
    (it doesn't appear to pick up the in-module docstring if the datamember
    is in a different module - autoattribute also blows up completely).
    If Sphinx fixes/improves this then we would no longer need
    ``doc`` here.

    Nc              
   C   sL   | j �< | j |¡}|d kr2t|||ƒ | j|< }|W  5 Q R £ S Q R X d S r   )Ú_lockÚsymbolsr­   rˆ  )r1   rg   r‘   r‹  r^   r   r   r   rŠ  ô  s
    zsymbol.__new__Fc                 C   sj   |  ¡ D ]>\}}||kr |  S |r6||jkr6|  S ||kr|  S q|dkrTdS t d||f ¡‚dS )a�  Given a user parameter, parse the parameter into a chosen symbol.

        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 symbol object to list of possible
         entries.
        :param name: name of the argument.   Used in an :class:`.ArgumentError`
         that is raised if the parameter doesn't match any available argument.
        :param resolve_symbol_names: include the name of each symbol as a valid
         entry.

        NzInvalid value for '%s': %r)rþ   rg   r   rs  )r1   r‚   Úchoicesrg   Zresolve_symbol_namesr^   Úchoicer   r   r   Úparse_user_argumentû  s    
zsymbol.parse_user_argument)NN)F)r'   r(   r)   r*   r‘  r   rm  rn  r�  rŠ  rÚ   r”  r   r   r   r   r‡   Û  s   

 ÿc                 C   s   t | _ t d7 a dS )zÞAssign 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„  r   r   r   Úset_creation_order"  s    	r–  c                 O   s>   z| ||ŽW S  t k
r8   tdt ¡ dd…  ƒ Y nX dS )zXexecutes the given function, catches all exceptions and converts to
    a warning.

    z%s('%s') ignoredr   r   N)r8   r   r   r   )r¶   r½   rì   r   r   r   Úwarn_exception/  s    r—  é   c                 C   sF   z(t | ƒ|kr d| d|…  W S | W S W n tk
r@   |  Y S X d S )Nz%s...r   )rÒ   r¼   )r!   Zlen_r   r   r   Úellipses_string:  s    
r™  c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_hash_limit_stringa/  A string subclass that can only be hashed on a maximum amount
    of unique values.

    This is used for warnings so that we can send out parameterized warnings
    without the __warningregistry__ of the module,  or the non-overridable
    "once" registry within warnings.py, overloading memory,


    c                    s@   || d|  }t t| ƒ | |¡}td|t|ƒ| f ƒ|_|S )Nz6 (this warning may be suppressed after %d occurrences)z%s_%d)r~  rš  rŠ  r‰  Ú_hash)r1   r!   Únumr½   Zinterpolatedr   r  r   r   rŠ  O  s    ÿz_hash_limit_string.__new__c                 C   s   | j S r   )r›  r   r   r   r   Ú__hash__W  s    z_hash_limit_string.__hash__c                 C   s   t | ƒt |ƒkS r   )r‰  )r   Úotherr   r   r   Ú__eq__Z  s    z_hash_limit_string.__eq__)r'   r(   r)   r*   rŠ  r�  rŸ  r�  r   r   r  r   rš  D  s   
rš  c                 C   s(   |rt tj| |d�ƒ nt | tjƒ dS )zdIssue a warning.

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

    )rx   N)Ú_warnings_warnr   Ú	SAWarning)Úmsgrx   r   r   r   r   ^  s    r   c                 C   s    |rt | d|ƒ} t| tjƒ dS )z\Issue a warning with a parameterized string, limiting the number
    of registrations.

    é
   N)rš  r   r   r¡  )r¢  r½   r   r   r   Úwarn_limitedk  s    r¤  c                 C   s˜   zt  |¡}W n& tk
r&   d}Y n>   d}Y n0X |d k	rdt d|j dd¡¡rd|j}|d7 }q6|d k	r‚tj	| ||d d� ntj	| |d d� d S )Nr   z^(?:sqlalchemy\.|alembic\.)r'   rÔ   r   )Ú
stacklevel)
r   Ú	_getframerX  rA   ÚmatchÚ	f_globalsr­   Úf_backÚwarningsr   )ÚmessageÚcategoryr¥  Úframer   r   r   r   u  s    
 ÿ
r   c                    s   ˆ g‰‡ ‡‡fdd„}|S )zNDecorate the given function to be a no-op after it is called exactly
    once.c                     s@   ˆ }ˆr<ˆ  ¡ }z|| |ŽW S    ˆr4ˆ d|¡ ‚ Y nX d S )Nr   )r-   Úinsert)r‚   r  Z	strong_fnZonce_fn©r`   ÚonceÚretry_on_exceptionr   r   Úgo˜  s    zonly_once.<locals>.gor   )r`   r±  r²  r   r¯  r   Ú	only_once’  s    r³  z%sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pyzunit(?:2|test2?/)c                 C   s`   d}t | ƒd }||kr0| | | ¡r0|d7 }q||krP| | | ¡rP|d8 }q0| ||d … S )at  Chop extraneous lines off beginning and end of a traceback.

    :param tb:
      a list of traceback lines as returned by ``traceback.format_stack()``

    :param exclude_prefix:
      a regular expression object matching lines to skip at beginning of
      ``tb``

    :param exclude_suffix:
      a regular expression object matching lines to skip at end of ``tb``
    r   r   )rÒ   Úsearch)ÚtbZexclude_prefixZexclude_suffixrJ   Úendr   r   r   Úchop_traceback¬  s    

r·  c                 C   s$   d|  }t ƒ  ¡ }t||ƒ |d S )Nz&def set(obj, value):    obj.%s = valuer,   )r  Úcopyr„   )Úattrnamerx   rt   r   r   r   Ú
attrsetterÅ  s    

rº  c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚEnsureKWArgTypezYApply translation of functions to accept \**kw arguments if they
    don't already.

    c           
         sr   | j }|rZ|D ]J}t ||¡}|r|| }t |¡}|js|  |¡ ||< }	t| ||	ƒ qtt	| ƒ 
|||¡ d S r   )Zensure_kwargrA   r§  r   rl   r¿   Ú
_wrap_w_kwrä   r~  r»  r   )
r1   Zclsnamer\   ZclsdictZfn_regr  r   r`   rs   Úwrappedr  r   r   r   Ò  s    
zEnsureKWArgType.__init__c                    s   ‡ fdd„}t |ˆ ƒS )Nc                     s   ˆ | Ž S r   r   )r‚   r  r<  r   r   Úwrapà  s    z(EnsureKWArgType._wrap_w_kw.<locals>.wrapr   )r   r`   r¾  r   r<  r   r¼  ß  s    zEnsureKWArgType._wrap_w_kw)r'   r(   r)   r*   r   r¼  r�  r   r   r  r   r»  Ì  s   r»  c                 C   sj   t |dƒrt| |ƒS | }|jj|_t |dƒr4|j|_t |jdƒrT|jjrT|jj|_n|jrb|j|_|S dS )z‘Augment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    r'   r(   r*   N)rM   r   rE   r'   r(   rº   r*   )Úwrapperr`   Ú_fr   r   r   Úwrap_callableæ  s    



rÁ  c                 C   sÈ   d| kr|   d¡S d}g g}d}t| ƒ}||k rº| | }|dkr†|dkr|||d k r|| |d  dkr||d  d¡ |d7 }q°|dN }n*|dkr¢|dkr¢| g ¡ n|d  |¡ |d7 }q(dd„ |D ƒS )aÄ  Parse a dotted identifier with accommodation for quoted names.

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

    E.g.::

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

    ú"r…   r   r   r†   c                 S   s   g | ]}d   |¡‘qS )rÔ   )r@   )r=   r�   r   r   r   rò   '  s     z'quoted_token_parser.<locals>.<listcomp>)rŠ   rÒ   rN   )r!   r  r3  ÚidxÚlvÚcharr   r   r   Úquoted_token_parserþ  s$    
$


rÆ  c                    s   t  ˆ ¡‰ ‡ ‡fdd„}|S )Nc                    s:   | j d k	r| j pd}|r0t|‡fdd„ˆ D ƒƒ}|| _ | S )NrÔ   c                    s   i | ]
}|ˆ “qS r   r   )r=   ÚparamrZ  r   r   Ú
<dictcomp>0  s      z8add_parameter_text.<locals>.decorate.<locals>.<dictcomp>)r*   Úinject_param_text)r`   r‘   ©Úparamsr[  r   r   r{   -  s
    z$add_parameter_text.<locals>.decorate)r   rú   )rË  r[  r{   r   rÊ  r   Úadd_parameter_text*  s    
rÌ  c                 C   sN   |   dd¡}t|ƒdkr| S |\}}| d¡s@|d t |¡ S t | ¡S d S )NÚ
r   r;   )rŠ   rÒ   r  ÚtextwrapÚdedent)r[  Z
split_textÚ	firstlineÚ	remainingr   r   r   Ú_dedent_docstring7  s    
rÒ  c                 C   sª   t | pdƒ} |  d¡}t|ƒdkr,| d¡ t |¡ d¡}|d rP| dd¡ dd„ t|ƒD ƒ}| dd¡ |t|t|ƒd ƒ }|d|… | ||d …  }d 	|¡S )NrÔ   rÍ  r   r   c                 S   s   g | ]\}}|  ¡ s|‘qS r   )rW  )r=   rœ  Úliner   r   r   rò   L  s      z)inject_docstring_text.<locals>.<listcomp>)
rÒ  rŠ   rÒ   rN   rÎ  rÏ  r®  rü   Úminr@   )ÚdoctextZ
injecttextÚposÚlinesZinjectlinesZblanksZ
inject_posr   r   r   r‹   C  s    

r‹   z(\s+):param (.+?):c           
      C   s  t  |  ¡ ¡}g }d }|�r| ¡ }t |¡}|d kr |rö| d¡ d¡}||krödt| d¡ƒ d }|r’t	 d|d ¡}	|	r’dt|	 d¡ƒ }|||  }nV|rº| 
d|dg¡ d }n<| ¡ sØ| 
||dg¡ d }n| d¡rö| 
|| ¡ g¡ q| |¡ qd |¡S )	Nr   Ú*r;   r   z(\s+)\Sr   rÍ  z::)ÚcollectionsÚdequeÚ
splitlinesÚpopleftÚ
_param_regr§  r”   ÚlstriprÒ   rA   r/   Úrstripr  rN   r@   )
rÕ  Zinject_paramsZdoclinesr×  Z	to_injectrÓ  r   rÇ  ÚindentÚm2r   r   r   rÉ  X  s6    

rÉ  c                 C   s‚   t | ƒdkrdS t | ƒdk}|r,| dd… n| dd… | dd…  } dd„ | D ƒ}|r`d |¡S d	d |dd… ¡|d f S dS )
zŒTrims 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Æ   rc   r†   c                 S   s,   g | ]$}t |ƒd kr$d|dd …  n|‘qS )é   z%s..N)rÒ   )r=   rg   r   r   r   rò   Š  s     z$repr_tuple_names.<locals>.<listcomp>rù   z%s, ..., %s)rÒ   r@   )ru   ÚflagÚresr   r   r   Úrepr_tuple_namesƒ  s    (
rå  c                  C   sF   z*ddl m}  ddl m} ddl m} W dS  tk
r@   Y dS X d S )Nr   )Úcimmutabledict)Úcprocessors)ÚcresultproxyTF)r‰   ræ  rç  rè  rŽ   )ræ  rç  rè  r   r   r   Úhas_compiled_ext‘  s    ré  )N)N)FF)T)T)r   r   r   )r   Nr   )NNr  N)NNN)TN)N)r˜  )N)Nr   )ar*   rÙ  Ú	functoolsr   r   ri   rW   r%  rA   r   rÎ  r®   rª  rÔ   r   r   r   r   rÕ   r   r4   r:   rC   rH   rQ   r_   rb   r|   rm   rp   r’   r“   r«   r²   r·   rÅ   ro   r×   rë   rí   rï   r   r  r  r  r"  r#  r-  r.  r>  r?  rH  rY  r]  r_  ra  re  rg  rj  rr  rt  r)  Úpropertyr}  r‚  r‡  r^  rˆ  r'   r‡   r•  r–  r—  r™  Ú	text_typerš  r   r¤  r   r³  ÚcompileZ_SQLA_REZ_UNITTEST_REr·  rD   ZNoneTyperº  r»  rÁ  rÆ  rÌ  rÒ  r‹   rÝ  rÉ  rå  ré  r   r   r   r   Ú<module>   s¾   1
	#
W&
+
6
p
%   ú
t
H3    ú
?
V<)

!D






,
+