U
    x^v:                     @   st  d 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jdkZejd	Zeed
ZejdZe oe ZejZejZejZeZeddddddddgZzddlZW n ek
r   ddlZY nX er
dd ZneZdd Z er4d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.m/Z/m0Z0m1Z1m2Z2 efZ3e4fZ5e4Z6eZ7e8fZ9e:Z;e$j<Z=e>Z?e@ZAeBe"dZCeBe"dZDeBe"dZEd d! ZFd"d# ZGd$d% ZHd&d' ZId(d) ZJd]d*d+ZKd,d- ZLd.d/ ZMe
r(eNZNnd0d1 ZNn<ddl!Z!ddlOZ#ddl$Z$ddl+m+Z+ ddlPm+Z* dd2l$mQZ, dd3lRm1Z1 dd4lRm.Z. dd5lRm2Z2 dd6lRm/Z/ dd7lSm0Z0 zddlTZ%W n ek
r   ddl%Z%Y nX eUfZ3e4fZ5eZ6eVZ7e8eWfZ9eNZNeJZJe'Z'e!jHZHe!jGZGe$jXZ=e$jYZ?e$jZZAd8d! ZFd^d9d:ZCd;d< Z;d=d> ZDd?d@ ZEdAd- ZLdBd/ ZMdCd' ZIdDdE Z[e\dF e	rddGlm]Z] ddddHi i edId dJd dKd dLd e]fdMdNZ^n(erddOlm_Z` dPdN Z^nddOlm_Z^ erddlambZc nddlZcejdQdR Zdd_dSdTZedUdV Zfer.ddWlgmhZh nBddXlgmgZg ddYlgmiZi ddZlgmjZj G d[d\ d\ejZheheideh_kdS )`z1Handle Python version/platform incompatibilities.    N)      )r   r   )r      )r      )r   r   )r   r   r   javapypy_version_infowinFullArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotationsc                 C   s   | S N )argr   r   >/tmp/pip-install-dq5v43_d/SQLAlchemy/sqlalchemy/util/compat.py<lambda>7       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   )inspectismethod__func__
isfunction	TypeErrorformat__code__iscodeco_argcountco_varnamespy3kco_kwonlyargcountlistco_flags
CO_VARARGSCO_VARKEYWORDSr	   __defaults____kwdefaults____annotations__)	funcconargsnamesnkwargsr
   r   r   r   r   r   r   inspect_getfullargspec<   s:    




r0   )reduce)BytesIO)StringIO)zip_longest)
quote_plusunquote_plus	parse_qslquoteunquoteexec
__import__printc                 C   s
   |  dS )Nzlatin-1)encodesr   r   r   b   s    r@   c                 C   s   t | dS Nascii)base64	b64decoder=   xr   r   r   rD      s    rD   c                 C   s   t | dS rA   )rC   	b64encodedecoderE   r   r   r   rG      s    rG   c                 C   s   | j |ddS )Nbackslashreplaceerrors)rH   textencodingr   r   r   decode_backslashreplace   s    rO   c                 C   s   | |k| |k  S r   r   )ar@   r   r   r   cmp   s    rQ   c                 C   s:   |d k	r||k	st d||_|j|k	r2|||d S )NzSame cause emitted)AssertionError	__cause____traceback__with_traceback)tpvaluetbcauser   r   r   reraise   s    

rZ   c                 C   s   | S r   r   r>   r   r   r   u   s    r[   c                 C   s   | S r   r   r>   r   r   r   ue   s    r\   c                 C   s
   t | dS )N__call__)hasattr)fnr   r   r   callable   s    r`   )izip_longest)r8   )r5   )r9   )r6   )r7   c                 C   s   | S r   r   r>   r   r   r   r@      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)r:   )Z	func_textglobals_Zlclr   r   r   exec_   s    
rc   c                 C   s   dd | D S )Nc                 s   s   | ]}t |V  qd S r   )ord).0byter   r   r   	<genexpr>   s     ziterbytes.<locals>.<genexpr>r   )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)re   r   r   r   r   
<listcomp>   s     zimport_.<locals>.<listcomp>)lenr;   )r
   r   r   r   import_   s     rn   c                  O   sH   | dtj}|d krd S t| D ] }t|ts8t|}|| q"d S )Nfile)popsysstdout	enumerate
isinstance
basestringrk   write)r
   kwargsfpr   r   r   r   print_   s    
ry   c                 C   s
   t | dS )Nzutf-8unicoder>   r   r   r   r[      s    c                 C   s
   t | dS )NZunicode_escaperz   r>   r   r   r   r\      s    c                 C   s:   z|  |W S  tk
r4   t| dd    Y S X d S )Nr   )rH   UnicodeDecodeErrorreprrL   r   r   r   rO      s    c                 C   s<   t | tst| jdddS t | tr4| jdddS | S d S )NrB   rI   rJ   )rt   string_typesr{   r=   rM   r   r   r   safe_bytestring   s
    

r   zdef reraise(tp, value, tb=None, cause=None):
    if cause is not None:
        assert cause is not value, 'Same cause emitted'
    raise tp, value, tb
)formatannotationr   c                 C   s   d|  S )N*r   namer   r   r   r     r   c                 C   s   d|  S )Nz**r   r   r   r   r   r     r   c                 C   s   dt |  S )N=)r~   )rW   r   r   r   r     r   c                 C   s   d|  S )Nz -> r   r   r   r   r   r     r   c                    s    fdd}g }|r(t | t | }t| D ]:\}}||}|r`||kr`||
|||   }|| q0|dk	r|||| n|r|d |r|D ]2}||}|r||kr||
|| 7 }|| q|dk	r||	|| dd| d }d kr|| d 7 }|S )	aa  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.

        Utimately 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   )r   resultr   r   	formatargr   r   formatargandannotation-  s    z5inspect_formatargspec.<locals>.formatargandannotationNr   (z, )return)rm   rs   appendjoin)r
   r   r   r   r   r   r   r   formatvarargsformatvarkwformatvalueformatreturnsr   r   specsfirstdefaultir   spec	kwonlyargr   r   r   r   inspect_formatargspec  s2    

r   )formatargspecc                  O   s   t | dd |S )Nr   rj   )_inspect_formatargspec)r   kwr   r   r   r   U  s    c                  g   s   g }g }d}zPz6| D ]&}|j}|j}||  || q|V  W n   t }Y nX W 5 |r|  }z|| rxd}W q^   t }Y q^X q^|dkrt|d |d |d  X dS )zImplement contextlib.nested, mostly for unit tests.

    As tests still need to run on py2.6 we can't use multiple-with yet.

    Function is removed in py3k but also emits deprecation warning in 2.7
    so just roll it here for everyone.

    )NNNr   r   r   N)rp   rq   exc_inforZ   __exit__	__enter__r   )ZmanagersZexitsZvars_excZexit_ZmgrZenterr   r   r   nestedf  s*    
r   c                 C   sB   |d krt  }|\}}}|| k	r&|nd }tt| | ||d d S )N)rX   rY   )rq   r   rZ   type)	exceptionr   exc_type	exc_valueexc_tbrY   r   r   r   raise_from_cause  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: http://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                    s$   |d krt | |d|S | |S )Nr   )r   __new__)clsr   
this_basesdbasesmetar   r   r     s    z)with_metaclass.<locals>.metaclass.__new__N)__name__
__module____qualname__r   r]   __init__r   r   r   r   r   	metaclass  s   r   temporary_classNr   )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).)rt   r   r   
_minoffset
_maxoffset
ValueErrorr   )self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 r   )hashr   r   r   r   r   __hash__  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__  s    ztimezone.__repr__c                 C   s
   |  d S r   )tznamer   r   r   r   __str__  s    ztimezone.__str__c                 C   s   | j S r   )r   r   dtr   r   r   	utcoffset  s    ztimezone.utcoffsetc                 C   s   |  | jS r   )_name_from_offsetr   r   r   r   r   r     s    ztimezone.tznamec                 C   s   d S r   r   r   r   r   r   dst  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)rt   r   r   r   r   r   r   r   r   r   fromutc  s    


ztimezone.fromutcc                 C   s   | j d | j d | j S )z(backport of timedelta._to_microseconds()iQ i@B )dayssecondsmicrosecondsr   r   r   r   _timedelta_to_microseconds  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   )rP   r@   qrr   r   r   _divmod_timedeltas  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 )NUTCr   -+r   )hours)minuteszUTC%s%02d:%02dz:%02dz.%06d)r   r   r   r   r   )deltasignr   restr   r   r   r   r   r     s(      ztimezone._name_from_offset   ;   )r   r   N)r   r   r   __doc__	__slots__r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r     s&   	

	
r   )NN)N)N)lr   collections
contextlibr   operatorrq   version_infoZpy36Zpy33Zpy35Zpy32r"   Zpy2kZpy265platform
startswithZjythonr^   Zpypywin32Zcpythoncontextmanager
attrgetterZdottedgetter
namedtuplenextr	   	threadingImportErrorZdummy_threadingZ
safe_kwargrk   r0   rC   builtinsconfigparser	itertoolspickle	functoolsr1   ior2   Zbyte_bufferr3   r4   urllib.parser5   r6   r7   r8   r9   r   bytesZbinary_typesbinary_type	text_typeint	int_typesiterri   filterfalseZitertools_filterfalsefilterZitertools_filtermapZitertools_imapgetattrrc   rn   ry   r@   rD   rG   rO   rQ   rZ   r[   r\   r`   ConfigParser	cStringIOra   urlliburlparsecPickleru   r{   longifilterfalseifilterimapr   r:   r   r   r   r   collections.abcabcZcollections_abcr   r   r   r   r   r   r   utcr   r   r   r   <module>   s$  








&




		B

"
]