B
    KLciG                 @   s  d 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ejdkZejdkZ	ejdkZ
ejdkZejdkZejdk Ze dkZe d	kZejd
ZejdZde  kZeeZejZejZejZeZeddddddddgZG dd deZ yddl!Z!W n e"k
r"   ddl#Z!Y nX dd Z$e
r@ddl%m&Z' nddl'Z'dd Z(erd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l0m1Z2 ddl0m3Z3 ddl,m4Z4 dd l5m6Z6 dd!l7m8Z8m9Z9m:Z:m;Z;m<Z< e=fZ>e?fZ@e?ZAe=ZBeCfZDeEZFeCZGe,jHZIeJZKeLZMeNe*d"ZOeNe*d#ZPeNe*d$ZQd%d& ZRd'd( ZSd)d* ZTd+d, ZUd-d. ZVdrd0d1ZWd2d3 ZXd4d5 ZYdd6lZm[Z[ e\Z\dd7l]m^Z^ d8d9 Z_ntddl)Z)ddl`Z+ddl,Z,ddl3m3Z3 ddlam3Z2 dd:l,mbZ4 dd;l5mcZ6 dd<ldm;Z; dd=ldm8Z8 dd>ldm<Z< dd?ldm9Z9 dd@lem:Z: ddAl]mfZf G dBdC dCeZ^yddlgZ-W n e"k
rX   ddl-Z-Y nX ehfZ>e?fZ@e=ZAeiZBeCejfZDejZGe\Z\eVZVe/Z/e)jTZTe)jSZSe,jkZIe,jlZKe,jmZMdDd& ZRdsdEdFZOdGdH ZFdIdJ ZPdKdL ZQdMd3 ZXdNd5 ZYdOd, ZUdPdQ ZneodR d/Z[dSd9 Z_erFdtdTdUZpddddVi i e=dWdX dYdX dZdX d[dX epfd\d]Zqndd^lmrZs d_d] Zqernddltm]Zu nddlZuerddlvZvd`da Zwdbdc Zxnddda Zwdedc ZxdudfdgZydvdhdiZzdjdk Z{erddll|m}Z} nBddml|m|Z| ddnl|m~Z~ ddol|mZ G dpdq dqeZ}e}e~de}_dS )wz1Handle Python version/platform incompatibilities.    N)      )r   	   )r      )r      )r   r   ZPyPyZCPythonwindarwinZaarchFullArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotationsc               @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
nullcontextzXContext manager that does no additional processing.

    Vendored from Python 3.7.

    Nc             C   s
   || _ d S )N)enter_result)selfr    r   5lib/python3.7/site-packages/sqlalchemy/util/compat.py__init__;   s    znullcontext.__init__c             C   s   | j S )N)r   )r   r   r   r   	__enter__>   s    znullcontext.__enter__c             G   s   d S )Nr   )r   excinfor   r   r   __exit__A   s    znullcontext.__exit__)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   4   s   
r   c       	      C   s   t | r| j} t | s(td| | j}t |sFtd||j}|j	}t
r\|jnd}t|d| }t||||  }||7 }d}|jt j@ r|j	| }|d }d}|jt j@ r|j	| }t|||| j|t
r| jndt
r| jni S )z9Fully vendored version of getfullargspec from Python 3.3.z{!r} is not a Python functionz{!r} is not a code objectr   N   )inspectZismethod__func__Z
isfunction	TypeErrorformat__code__Ziscodeco_argcountco_varnamespy3kco_kwonlyargcountlistco_flagsZ
CO_VARARGSZCO_VARKEYWORDSr	   __defaults____kwdefaults____annotations__)	funcconargsnamesZnkwargsr
   r   r   r   r   r   r   inspect_getfullargspecK   s8    




r1   )metadatac             C   s.   t  }t|dr|j| dS || dS d S )Nselect)groupr   )importlib_metadataZentry_pointshasattrr3   get)r4   Zepr   r   r   importlib_metadata_getw   s    
r8   )reduce)BytesIO)StringIO)zip_longest)perf_counter)
quote_plusunquote_plus	parse_qslquoteunquoteexec
__import__printc             C   s
   |  dS )Nzlatin-1)encode)sr   r   r   b   s    rH   c             C   s   t | dS )Nascii)base64	b64decoderF   )xr   r   r   rK      s    rK   c             C   s   t | dS )NrI   )rJ   	b64encodedecode)rL   r   r   r   rM      s    rM   c             C   s   | j |ddS )Nbackslashreplace)errors)rN   )textencodingr   r   r   decode_backslashreplace   s    rS   c             C   s   | |k| |k  S )Nr   )arH   r   r   r   cmp   s    rU   Fc             C   sH   |dk	r|  |} |dk	r"|| _n|dk	r0|| _z| W d~ ~~~X dS )a{  implement "raise" with cause support.

        :param exception: exception to raise
        :param with_traceback: will call exception.with_traceback()
        :param replace_context: an as-yet-unsupported feature.  This is
         an exception object which we are "replacing", e.g., it's our
         "cause" but we don't want it printed.    Basically just what
         ``__suppress_context__`` does but we don't want to suppress
         the enclosing context, if any.  So for now we make it the
         cause.
        :param from\_: the cause.  this actually sets the cause and doesn't
         hope to hide it someday.

        NF)with_traceback	__cause__)	exceptionrV   Zreplace_contextfrom_r   r   r   raise_   s    
rZ   c             C   s   | S )Nr   )rG   r   r   r   u   s    r[   c             C   s   | S )Nr   )rG   r   r   r   ue   s    r\   )TYPE_CHECKING)ABCc             C   s   | j S )N)r   )fnr   r   r   	_qualname   s    r`   )izip_longest)clock)rA   )r>   )rB   )r?   )r@   )ABCMetac               @   s   e Zd ZeZdS )r^   N)r   r   r   rc   Z__metaclass__r   r   r   r   r^      s   r^   c             C   s   | S )Nr   )rG   r   r   r   rH     s    c             C   s   |d krt d nt d d S )Nzexec func_text in globals_zexec func_text in globals_, lcl)rC   )Z	func_textglobals_Zlclr   r   r   exec_  s    
re   c             C   s   dd | D S )Nc             s   s   | ]}t |V  qd S )N)ord).0Zbyter   r   r   	<genexpr>  s    ziterbytes.<locals>.<genexpr>r   )Zbufr   r   r   	iterbytes  s    ri   c              G   s4   t | dkr,| dd dd | d D f } t|  S )N   r   r   c             S   s   g | ]}t |qS r   )str)rg   argr   r   r   
<listcomp>!  s    zimport_.<locals>.<listcomp>)lenrD   )r
   r   r   r   import_  s     ro   c              O   sL   | dtj}|d krd S x,t| D ] }t|ts:t|}|| q$W d S )Nfile)popsysstdout	enumerate
isinstance
basestringrk   write)r
   kwargsfprl   r   r   r   print_$  s    
rz   c             C   s
   t | dS )Nzutf-8)unicode)rG   r   r   r   r[   -  s    c             C   s
   t | dS )NZunicode_escape)r{   )rG   r   r   r   r\   4  s    c             C   s4   y
|  |S  tk
r.   t| dd   S X d S )Nr   )rN   UnicodeDecodeErrorrepr)rQ   rR   r   r   r   rS   7  s    
c             C   s<   t | tst| jdddS t | tr4| jdddS | S d S )NrI   rO   )rP   )ru   string_typesr{   rF   )rQ   r   r   r   safe_bytestring@  s    


r   zdef raise_(exception, with_traceback=None, replace_context=None, from_=False):
    if with_traceback:
        raise type(exception), exception, with_traceback
    else:
        raise exception
c             C   s6   x$| j jD ]}| j|jkr
P q
W | jS d|j| jf S )z6return __qualname__ equivalent for a method on a classz%s.%s)Zim_class__mro__r   __dict__)methclsr   r   r   r`   V  s
    c             C   sV   t | dddkr t| ddS t| trN| jd|fkr>| jS | jd | j S t| S )zvendored from python 3.7r   Ntypingztyping. builtins.)getattrr~   replaceru   typer   r   )Z
annotationZbase_moduler   r   r   _formatannotationd  s    
r   r   c             C   s   d|  S )N*r   )namer   r   r   <lambda>x      r   c             C   s   d|  S )Nz**r   )r   r   r   r   r   y  r   c             C   s   dt |  S )N=)r~   )valuer   r   r   r   z  r   c             C   s   d|  S )Nz -> r   )rQ   r   r   r   r   {  r   c                s:  |pi } pi   fdd}g }|r8t | t | }xFt| D ]:\}}||}|rr||krr||
|||   }|| qBW |dk	r|||| n|r|d |rx:|D ]2}||}|r||kr||
|| 7 }|| qW |dk	r||	|| dd| d }d kr6|| d 7 }|S )	ab  Copy formatargspec from python 3.7 standard library.

        Python 3 has deprecated formatargspec and requested that Signature
        be used instead, however this requires a full reimplementation
        of formatargspec() in terms of creating Parameter objects and such.
        Instead of introducing all the object-creation overhead and having
        to reinvent from scratch, just copy their compatibility routine.

        Ultimately we would need to rewrite our "decorator" routine completely
        which is not really worth it right now, until all Python 2.x support
        is dropped.

        c                s(   | }|  kr$|d |   7 }|S )Nz: r   )rl   result)r   formatannotation	formatargr   r   formatargandannotation  s    z5inspect_formatargspec.<locals>.formatargandannotationNr   (z, )return)rn   rt   appendjoin)r
   r   r   r   r   r   r   r   ZformatvarargsZformatvarkwZformatvalueZformatreturnsr   r   ZspecsZfirstdefaultirl   specZ	kwonlyargr   r   )r   r   r   r   inspect_formatargspeco  s6    



r   )formatargspecc              O   s   t | dd |S )Nr   rj   )_inspect_formatargspec)r   kwr   r   r   r     s    c             C   s   t | rt | S g S dS )zSReturn a sequence of all dataclasses.Field objects associated
        with a class.N)dataclassesis_dataclassfields)r   r   r   r   dataclass_fields  s    

r   c                sN   t | rFt  x| jD ]} t| qW  fddt | D S g S dS )zReturn a sequence of all dataclasses.Field objects associated with
        a class, excluding those that originate from a superclass.c                s   g | ]}| kr|qS r   r   )rg   f)super_fieldsr   r   rm     s    z*local_dataclass_fields.<locals>.<listcomp>N)r   r   set	__bases__updater   r   )r   Zsupr   )r   r   local_dataclass_fields  s    
r   c             C   s   g S )Nr   )r   r   r   r   r     s    c             C   s   g S )Nr   )r   r   r   r   r     s    c             C   sB   |dkrt  }|\}}}|| k	r&|nd}tt| | ||d dS )zlegacy.  use raise\_()N)tbcause)rr   exc_inforeraiser   )rX   r   exc_type	exc_valueZexc_tbr   r   r   r   raise_from_cause  s
    
r   c             C   s   t |||d dS )zlegacy.  use raise\_())rV   rY   N)rZ   )tpr   r   r   r   r   r   r     s    r   c                s$   G  fddd}|ddi S )zCreate a base class with a metaclass.

    Drops the middle class upon creation.

    Source: https://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/

    c                   s(   e Zd ZejZejZ fddZdS )z!with_metaclass.<locals>.metaclassc                sP   |d krt | |d|} n| |} t| drLt| jdrL| jj| f | S )Nr   __init_subclass__r    )r   __new__r6   r   r    )r   r   Z
this_basesd)basesr   metar   r   r     s    
z)with_metaclass.<locals>.metaclass.__new__N)r   r   r   r   __call__r   r   r   )r   r   r   r   r   	metaclass  s   r   Ztemporary_classNr   )r   r   r   r   r   )r   r   r   r   with_metaclass  s    	r   )timezone)datetime)	timedelta)tzinfoc               @   s   e Zd ZdZ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edd Zedd Zedd ZedddZe ZdS )r   z(Minimal port of python 3 timezone object_offsetc             C   s>   t |tstd| j|  kr*| jks4n td|| _d S )Nzoffset must be a timedeltazYoffset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24).)ru   r   r!   
_minoffset
_maxoffset
ValueErrorr   )r   offsetr   r   r   r      s    
ztimezone.__init__c             C   s   t |tkrdS | j|jkS )NF)r   r   r   )r   otherr   r   r   __eq__+  s    ztimezone.__eq__c             C   s
   t | jS )N)hashr   )r   r   r   r   __hash__0  s    ztimezone.__hash__c             C   s   d| j j| jf S )Nzsqlalchemy.util.%s(%r))	__class__r   r   )r   r   r   r   __repr__3  s    ztimezone.__repr__c             C   s
   |  d S )N)tzname)r   r   r   r   __str__9  s    ztimezone.__str__c             C   s   | j S )N)r   )r   dtr   r   r   	utcoffset<  s    ztimezone.utcoffsetc             C   s   |  | jS )N)_name_from_offsetr   )r   r   r   r   r   r   ?  s    ztimezone.tznamec             C   s   d S )Nr   )r   r   r   r   r   dstB  s    ztimezone.dstc             C   s2   t |tr&|j| k	rtd|| j S tdd S )Nzfromutc: dt.tzinfo is not selfz6fromutc() argument must be a datetime instance or None)ru   r   r   r   r   r!   )r   r   r   r   r   fromutcE  s    


ztimezone.fromutcc             C   s   | j d | j d | j S )z(backport of timedelta._to_microseconds()iQ i@B )Zdayssecondsmicroseconds)r   r   r   r   _timedelta_to_microsecondsN  s    z#timezone._timedelta_to_microsecondsc             C   s*   t t| t|\}}|tdd|fS )z backport of timedelta.__divmod__r   )divmodr   r   r   )rT   rH   qrr   r   r   _divmod_timedeltasU  s    ztimezone._divmod_timedeltasc             C   s   | sdS | t dk r d}|  } nd}t| t dd\}}t|t dd\}}d|||f }|jrt|d	|jf 7 }|jr|d
|jf 7 }|S )NZUTCr   -+r   )hours)minuteszUTC%s%02d:%02dz:%02dz.%06d)r   r   r   r   r   )ZdeltaZsignr   restr   r   r   r   r   r   _  s     ztimezone._name_from_offset   ;   )r   r   N)r   r   r   r   	__slots__r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r     s    	
r   )NNF)N)N)N)NN)r   collections
contextlibr   operatorplatformrr   version_infoZpy311Zpy39Zpy38Zpy37r&   Zpy2kZpython_implementationZpypyZcpython
startswithZwin32ZosxmachinelowerZarmboolZhas_refcount_gccontextmanager
attrgetterZdottedgetter
namedtuplenextr	   objectr   Z	threadingImportErrorZdummy_threadingr1   	importlibr2   r5   r8   rJ   r   Zconfigparser	itertoolspickle	functoolsr9   ior:   Zbyte_bufferr;   r<   Ztimer=   Zurllib.parser>   r?   r@   rA   rB   rk   r   bytesZbinary_typesZbinary_typeZ	text_typeintZ	int_typesiterri   Z	long_typefilterfalseZitertools_filterfalsefilterZitertools_filtermapZitertools_imapr   re   ro   rz   rH   rK   rM   rS   rU   rZ   r[   r\   r   r]   callableabcr^   r`   ZConfigParserZ	cStringIOra   rb   ZurllibZurlparserc   ZcPicklerv   r{   ZlongZifilterfalseZifilterZimapr   rC   r   r   r   r   Zcollections.abcZcollections_abcr   r   r   r   r   r   r   r   r   r   Zutcr   r   r   r   <module>   s<  





&



$
		
9	



]