U
    ڲg                     @   s  d dl mZ d dlZd dlZd dlZd dlZzd dlZW n ek
rP   dZY nX ejd  dk rnd dl	m	Z	 e
fZeZd dlmZ d dlZd dlZd dlmZmZmZmZmZ d dlmZmZmZmZm Z m!Z!m"Z" dd	 Zd dl#Z#d d
l#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, er"d dl#m-Z- d dl.Z.d dl/Z/d dl0Z1d dl2m2Z2 d dl3Z3e4Z4d dl5m6Z7 d dl5m8Z9 nd dl:m	Z	 e;fZe;Zd dl:m<Z d dlZd dlZd dl=mZmZmZmZmZmZmZm"Z" d dl>m%Z%mZm$Z$mZm Z m(Z(m)Z)m*Z*m+Z+m,Z, er
d dl>m-Z- d dl?m'Z'm&Z&m!Z! d dl@mAZ. d dl>mBZ# d dlCmAZ/ d dl1Z1d dlDm2Z2 d dlEmFZ3 eGZ4d dl5m9Z9 e7Z7zd dlmHZHmIZI W n8 ek
r   G dd deJZId`ddZKdd ZHY nX zd dlmLZM W n& ek
r   G dd deNZMY nX zd dlmOZO W n, ek
r8   ejPejQB dfd d!ZOY nX d d"lRmSZT eUeTd#rXeTZSn,d d$lRmVZW G d%d& d&eWZVG d'd( d(eTZSzd d)lXmYZY W n ek
r   d*d+ ZYY nX d dlZZZze[Z[W n* e\k
r   d d,l]m^Z^ d-d. Z[Y nX zej_Z_ej`Z`W nH eak
rH   eb pd/Zcecd0kr0d1Zdnd2Zdd3d4 Z_d5d6 Z`Y nX zd d7lemfZf W n@ ek
r   d d8lgmhZhmiZi ejd9Zkd:d; Zld<d= ZfY nX zd d>lmmnZn W n" ek
r   d d>lomnZn Y nX ejdd? d@k re2 jpZpnd dAlmmpZp zd dBlqmrZr W nd ek
rn   d dClqmsZs zd dDltmuZv W n  ek
rX   dadFdGZvY nX G dHdI dIesZrY nX zd dJlwmxZx W n  ek
r   dbdKdLZxY nX zd dMlqmyZy W n ek
r<   zd dNlzm{Z| W n" ek
r   d dNl}m{Z| Y nX zd dOl~mZmZmZ W n ek
r&   Y nX G dPdQ dQeZyY nX zd dRlmZmZ W nv ek
r   ejdSejZdTdU ZG dVdW dWeZdcdXdYZG dZd[ d[eZG d\d] d]eZG d^d_ d_eNZY nX dS )d    )absolute_importN   )StringIO)FileType)urlparse
urlunparseurljoinurlsplit
urlunsplit)urlretrievequoteunquoteurl2pathnamepathname2urlContentTooShortError	splittypec                 C   s   t | tr| d} t| S )Nutf-8)
isinstanceunicodeencode_quote)s r   2/tmp/pip-unpacked-wheel-mq592sfu/distlib/compat.pyr      s    

r   )	RequesturlopenURLError	HTTPErrorHTTPBasicAuthHandlerHTTPPasswordMgrHTTPHandlerHTTPRedirectHandlerbuild_opener)HTTPSHandler)
HTMLParser)ifilter)ifilterfalse)TextIOWrapper)r   r   r   r   r   r	   r
   r   )
r   r   r   r   r   r   r   r    r!   r"   )r   r   r   )filterfalse)match_hostnameCertificateErrorc                   @   s   e Zd ZdS )r*   N)__name__
__module____qualname__r   r   r   r   r*   ]   s   r*      c           
      C   s   g }| sdS |  d}|d |dd  }}|d}||krNtdt|  |sb|  | kS |dkrv|d n>|d	s|d	r|t| n|t|	d
d |D ]}|t| qt
dd| d tj}	|	|S )zpMatching according to RFC 6125, section 6.4.3

        http://tools.ietf.org/html/rfc6125#section-6.4.3
        F.r   r.   N*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountr*   reprlowerappend
startswithreescapereplacecompilejoin
IGNORECASEmatch)
dnhostnamemax_wildcardspatspartsleftmost	remainder	wildcardsfragpatr   r   r   _dnsname_match`   s*    


rH   c                 C   s   | st dg }| dd}|D ]*\}}|dkr t||r@ dS || q |s| ddD ]6}|D ],\}}|dkrdt||r  dS || qdq\t|dkrtd	|d
tt|f n*t|dkrtd||d f ntddS )a=  Verify that *cert* (in decoded format as returned by
        SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
        rules are followed, but IP addresses are not accepted for *hostname*.

        CertificateError is raised on failure. On success, the function
        returns nothing.
        ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDsubjectAltNamer   DNSNsubject
commonNamer.   z&hostname %r doesn't match either of %s, zhostname %r doesn't match %rr   z=no appropriate commonName or subjectAltName fields were found)	
ValueErrorgetrH   r5   lenr*   r;   mapr3   )certr?   dnsnamessankeyvaluesubr   r   r   r)      s2    


r)   )SimpleNamespacec                   @   s   e Zd ZdZdd ZdS )	ContainerzR
        A generic container for when multiple values need to be returned
        c                 K   s   | j | d S N__dict__update)selfkwargsr   r   r   __init__   s    zContainer.__init__N)r+   r,   r-   __doc__r`   r   r   r   r   rY      s   rY   )whichc                    s"  dd }t j r&| |r" S dS |dkr>t jdt j}|sFdS |t j}tj	dkrt j
|krt|dt j
 t jddt j}t fd	d
|D r g}q fdd|D }n g}t }|D ]P}t j|}||kr|| |D ](}	t j||	}
||
|r|
    S qqdS )aK  Given a command, mode, and a PATH string, return the path which
        conforms to the given mode on the PATH, or None if there is no such
        file.

        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
        of os.environ.get("PATH"), or can be overridden with a custom search
        path.

        c                 S   s&   t j| o$t | |o$t j|  S rZ   )ospathexistsaccessisdir)fnmoder   r   r   _access_check   s    zwhich.<locals>._access_checkNPATHwin32r   PATHEXT c                 3   s    | ]}   |  V  qd S rZ   )r4   endswith.0extcmdr   r   	<genexpr>   s     zwhich.<locals>.<genexpr>c                    s   g | ]} | qS r   r   rp   rs   r   r   
<listcomp>   s     zwhich.<locals>.<listcomp>)rc   rd   dirnameenvironrO   defpathr1   pathsepsysplatformcurdirinsertanysetnormcaseaddr;   )rt   ri   rd   rj   pathextfilesseendirnormdirthefilenamer   rs   r   rb      s8    




rb   )ZipFile	__enter__)
ZipExtFilec                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 C   s   | j |j  d S rZ   r[   )r^   baser   r   r   r`     s    zZipExtFile.__init__c                 C   s   | S rZ   r   r^   r   r   r   r     s    zZipExtFile.__enter__c                 G   s   |    d S rZ   closer^   exc_infor   r   r   __exit__  s    zZipExtFile.__exit__N)r+   r,   r-   r`   r   r   r   r   r   r   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 C   s   | S rZ   r   r   r   r   r   r   $  s    zZipFile.__enter__c                 G   s   |    d S rZ   r   r   r   r   r   r   '  s    zZipFile.__exit__c                 O   s   t j| f||}t|S rZ   )BaseZipFileopenr   )r^   argsr_   r   r   r   r   r   +  s    zZipFile.openN)r+   r,   r-   r   r   r   r   r   r   r   r   "  s   r   )python_implementationc                   C   s0   dt jkrdS tjdkrdS t jdr,dS dS )z6Return a string identifying the Python implementation.PyPyjavaJython
IronPythonCPython)r{   versionrc   r   r6   r   r   r   r   r   4  s    

r   )Callablec                 C   s
   t | tS rZ   )r   r   )objr   r   r   callableF  s    r   r   mbcsstrictsurrogateescapec                 C   s:   t | tr| S t | tr$| ttS tdt| j d S Nzexpect bytes or str, not %s)	r   bytes	text_typer   _fsencoding	_fserrors	TypeErrortyper+   filenamer   r   r   fsencodeZ  s    

r   c                 C   s:   t | tr| S t | tr$| ttS tdt| j d S r   )	r   r   r   decoder   r   r   r   r+   r   r   r   r   fsdecodec  s    

r   )detect_encoding)BOM_UTF8lookupzcoding[:=]\s*([-\w.]+)c                 C   sH   | dd   dd}|dks*|dr.dS |dks@|drDd	S | S )
z(Imitates get_normal_name in tokenizer.c.N   _-r   zutf-8-)zlatin-1
iso-8859-1ziso-latin-1)zlatin-1-ziso-8859-1-ziso-latin-1-r   )r4   r9   r6   )orig_encencr   r   r   _get_normal_namet  s    r   c                    s   zj jW n tk
r$   dY nX d d}d}fdd} fdd}| }|trpd |d	d }d
}|s||g fS ||}|r||gfS | }|s||gfS ||}|r|||gfS |||gfS )a?  
        The detect_encoding() function is used to detect the encoding that should
        be used to decode a Python source file.  It requires one argument, readline,
        in the same way as the tokenize() generator.

        It will call readline a maximum of twice, and return the encoding used
        (as a string) and a list of any lines (left as bytes) it has read in.

        It detects the encoding from the presence of a utf-8 bom or an encoding
        cookie as specified in pep-0263.  If both a bom and a cookie are present,
        but disagree, a SyntaxError will be raised.  If the encoding cookie is an
        invalid charset, raise a SyntaxError.  Note that if a utf-8 bom is found,
        'utf-8-sig' is returned.

        If no encoding is specified, then the default of 'utf-8' will be returned.
        NFr   c                      s$   z  W S  t k
r   Y dS X d S )N    )StopIterationr   )readliner   r   read_or_stop  s    z%detect_encoding.<locals>.read_or_stopc                    s   z|  d}W n4 tk
rB   d}d k	r6d|}t|Y nX t|}|sVd S t|d }zt|}W n: tk
r   d krd| }nd|}t|Y nX  r|j	dkr؈d krd}n
d}t||d	7 }|S )
Nr   z'invalid or missing encoding declarationz{} for {!r}r   zunknown encoding: zunknown encoding for {!r}: {}zencoding problem: utf-8z encoding problem for {!r}: utf-8z-sig)
r   UnicodeDecodeErrorformatSyntaxError	cookie_refindallr   r   LookupErrorr   )lineline_stringmsgmatchesencodingcodec)	bom_foundr   r   r   find_cookie  s>    

 
z$detect_encoding.<locals>.find_cookieTr   z	utf-8-sig)__self__r   AttributeErrorr6   r   )r   r   defaultr   r   firstsecondr   )r   r   r   r   r     s4    
'


r   )r8      )r      )unescape)ChainMap)MutableMapping)recursive_repr...c                    s    fdd}|S )zm
            Decorator to make a repr function return fillvalue for a recursive
            call
            c                    sL   t    fdd}td|_td|_td|_tdi |_|S )Nc              	      sB   t | t f}|kr S | z| }W 5 | X |S rZ   )id	get_identr   discard)r^   rU   result)	fillvaluerepr_runninguser_functionr   r   wrapper  s    
z=_recursive_repr.<locals>.decorating_function.<locals>.wrapperr,   ra   r+   __annotations__)r   getattrr,   ra   r+   r   )r   r   r   )r   r   r   decorating_function  s     z,_recursive_repr.<locals>.decorating_functionr   )r   r   r   r   r   _recursive_repr  s    r   c                   @   s   e Zd ZdZdd Zdd Zdd Zd'd	d
Zdd Zdd Z	dd Z
dd Ze dd Zedd Zdd ZeZdd Zedd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZdS )(r   a  
        A ChainMap groups multiple dicts (or other mappings) together
        to create a single, updateable view.

        The underlying mappings are stored in a list.  That list is public and can
        accessed or updated using the *maps* attribute.  There is no other state.

        Lookups search the underlying mappings successively until a key is found.
        In contrast, writes, updates, and deletions only operate on the first
        mapping.
        c                 G   s   t |pi g| _dS )zInitialize a ChainMap by setting *maps* to the given mappings.
            If no mappings are provided, a single empty dictionary is used.

            N)listmaps)r^   r   r   r   r   r`     s    zChainMap.__init__c                 C   s   t |d S rZ   )KeyErrorr^   rU   r   r   r   __missing__!  s    zChainMap.__missing__c              	   C   s:   | j D ](}z|| W   S  tk
r,   Y qX q| |S rZ   )r   r   r   )r^   rU   mappingr   r   r   __getitem__$  s    

zChainMap.__getitem__Nc                 C   s   || kr| | S |S rZ   r   r^   rU   r   r   r   r   rO   .  s    zChainMap.getc                 C   s   t t j| j S rZ   )rP   r   unionr   r   r   r   r   __len__1  s    zChainMap.__len__c                 C   s   t t j| j S rZ   )iterr   r   r   r   r   r   r   __iter__5  s    zChainMap.__iter__c                    s   t  fdd| jD S )Nc                 3   s   | ]} |kV  qd S rZ   r   )rq   mrU   r   r   ru   9  s     z(ChainMap.__contains__.<locals>.<genexpr>r   r   r   r   r   r   __contains__8  s    zChainMap.__contains__c                 C   s
   t | jS rZ   r   r   r   r   r   __bool__;  s    zChainMap.__bool__c                 C   s   d | dtt| jS )Nz{0.__class__.__name__}({1})rM   )r   r;   rQ   r3   r   r   r   r   r   __repr__>  s     zChainMap.__repr__c                 G   s   | t j|f| S )z?Create a ChainMap with a single dict created from the iterable.)dictfromkeys)clsiterabler   r   r   r   r   C  s    zChainMap.fromkeysc                 C   s$   | j | jd  f| jdd  S )zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r   r.   N)	__class__r   copyr   r   r   r   r   H  s    zChainMap.copyc                 C   s   | j i f| j S )z;New ChainMap with a new dict followed by all previous maps.r   r   r   r   r   r   	new_childN  s    zChainMap.new_childc                 C   s   | j | jdd  S )zNew ChainMap from maps[1:].r.   Nr   r   r   r   r   parentsR  s    zChainMap.parentsc                 C   s   || j d |< d S )Nr   )r   )r^   rU   rV   r   r   r   __setitem__W  s    zChainMap.__setitem__c                 C   s8   z| j d |= W n" tk
r2   td|Y nX d S )Nr   (Key not found in the first mapping: {!r})r   r   r   r   r   r   r   __delitem__Z  s    zChainMap.__delitem__c                 C   s2   z| j d  W S  tk
r,   tdY nX dS )zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.r   z#No keys found in the first mapping.N)r   popitemr   r   r   r   r   r  a  s    zChainMap.popitemc                 G   s@   z| j d j|f| W S  tk
r:   td|Y nX dS )zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r   r  N)r   popr   r   )r^   rU   r   r   r   r   r  h  s    zChainMap.popc                 C   s   | j d   dS )z'Clear maps[0], leaving maps[1:] intact.r   N)r   clearr   r   r   r   r  p  s    zChainMap.clear)N)r+   r,   r-   ra   r`   r   r   rO   r   r   r   r   r   r   classmethodr   r   __copy__r   propertyr   r   r  r  r  r  r   r   r   r   r     s.   




r   )cache_from_sourcec                 C   s0   |  dst|d krd}|r$d}nd}| | S )Nz.pyTco)ro   AssertionError)rd   debug_overridesuffixr   r   r   r	  y  s    r	  )OrderedDict)r   )KeysView
ValuesView	ItemsViewc                   @   s   e Zd ZdZdd ZejfddZejfddZdd	 Zd
d Z	dd Z
d6ddZdd Zdd Zdd Zdd Zdd Zdd Zdd ZeZe Zefdd Zd7d"d#Zd8d$d%Zd&d' Zd(d) Zed9d*d+Zd,d- Zd.d/ Zd0d1 Zd2d3 Z d4d5 Z!d!S ):r  z)Dictionary that remembers insertion orderc                 O   sn   t |dkrtdt | z
| j W n6 tk
r\   g  | _}||dg|dd< i | _Y nX | j|| dS )zInitialize an ordered dictionary.  Signature is the same as for
            regular dictionaries, but keyword arguments are not recommended
            because their insertion order is arbitrary.

            r.   z$expected at most 1 arguments, got %dN)rP   r   _OrderedDict__rootr   _OrderedDict__map_OrderedDict__update)r^   r   kwdsrootr   r   r   r`     s    

zOrderedDict.__init__c                 C   sF   || kr6| j }|d }|||g |d<  |d< | j|< || || dS )z!od.__setitem__(i, y) <==> od[i]=yr   r.   N)r  r  )r^   rU   rV   Zdict_setitemr  lastr   r   r   r     s
     zOrderedDict.__setitem__c                 C   s0   || | | j |\}}}||d< ||d< dS )z od.__delitem__(y) <==> del od[y]r.   r   N)r  r  )r^   rU   Zdict_delitem	link_prev	link_nextr   r   r   r    s    
zOrderedDict.__delitem__c                 c   s.   | j }|d }||k	r*|d V  |d }qdS )zod.__iter__() <==> iter(od)r.   r   Nr  r^   r  currr   r   r   r     s
    
zOrderedDict.__iter__c                 c   s.   | j }|d }||k	r*|d V  |d }qdS )z#od.__reversed__() <==> reversed(od)r   r   Nr  r  r   r   r   __reversed__  s
    
zOrderedDict.__reversed__c                 C   sd   z@| j  D ]}|dd= q| j}||dg|dd< | j   W n tk
rT   Y nX t|  dS )z.od.clear() -> None.  Remove all items from od.N)r  
itervaluesr  r  r   r   )r^   noder  r   r   r   r    s    zOrderedDict.clearTc                 C   s|   | st d| j}|r8|d }|d }||d< ||d< n |d }|d }||d< ||d< |d }| j|= t| |}||fS )zod.popitem() -> (k, v), return and remove a (key, value) pair.
            Pairs are returned in LIFO order if last is true or FIFO order if false.

            zdictionary is emptyr   r.   r   )r   r  r  r   r  )r^   r  r  linkr  r  rU   rV   r   r   r   r    s     
zOrderedDict.popitemc                 C   s   t | S )zod.keys() -> list of keys in od)r   r   r   r   r   keys  s    zOrderedDict.keysc                    s    fdd D S )z#od.values() -> list of values in odc                    s   g | ]} | qS r   r   rq   rU   r   r   r   rv      s     z&OrderedDict.values.<locals>.<listcomp>r   r   r   r   r   values  s    zOrderedDict.valuesc                    s    fdd D S )z.od.items() -> list of (key, value) pairs in odc                    s   g | ]}| | fqS r   r   r#  r   r   r   rv     s     z%OrderedDict.items.<locals>.<listcomp>r   r   r   r   r   items  s    zOrderedDict.itemsc                 C   s   t | S )z0od.iterkeys() -> an iterator over the keys in od)r   r   r   r   r   iterkeys  s    zOrderedDict.iterkeysc                 c   s   | D ]}| | V  qdS )z2od.itervalues -> an iterator over the values in odNr   r^   kr   r   r   r  
  s    zOrderedDict.itervaluesc                 c   s   | D ]}|| | fV  qdS )z=od.iteritems -> an iterator over the (key, value) items in odNr   r'  r   r   r   	iteritems  s    zOrderedDict.iteritemsc                  O   s   t | dkr tdt | f n| s,td| d }d}t | dkrL| d }t|trn|D ]}|| ||< qZn<t|dr| D ]}|| ||< qn|D ]\}}|||< q| D ]\}}|||< qdS )	a  od.update(E, **F) -> None.  Update od from dict/iterable E and F.

            If E is a dict instance, does:           for k in E: od[k] = E[k]
            If E has a .keys() method, does:         for k in E.keys(): od[k] = E[k]
            Or if E is an iterable of items, does:   for k, v in E: od[k] = v
            In either case, this is followed by:     for k, v in F.items(): od[k] = v

            r   z8update() takes at most 2 positional arguments (%d given)z,update() takes at least 1 argument (0 given)r   r   r.   r"  N)rP   r   r   r   hasattrr"  r%  )r   r  r^   otherrU   rV   r   r   r   r]     s(    	


zOrderedDict.updatec                 C   s0   || kr| | }| |= |S || j kr,t||S )zod.pop(k[,d]) -> v, remove specified key and return the corresponding value.
            If key is not found, d is returned if given, otherwise KeyError is raised.

            )_OrderedDict__markerr   )r^   rU   r   r   r   r   r   r  7  s    
zOrderedDict.popNc                 C   s   || kr| | S || |< |S )zDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in odr   r   r   r   r   
setdefaultD  s    zOrderedDict.setdefaultc                 C   sf   |si }t | t f}||kr"dS d||< z.| sBd| jjf W S d| jj|  f W S ||= X dS )zod.__repr__() <==> repr(od)r   r.   z%s()z%s(%r)N)r   
_get_identr   r+   r%  )r^   Z_repr_runningZcall_keyr   r   r   r   K  s    zOrderedDict.__repr__c                    sX    fdd D }t   }t t D ]}||d q(|rL j|f|fS  j|ffS )z%Return state information for picklingc                    s   g | ]}| | gqS r   r   rq   r(  r   r   r   rv   \  s     z*OrderedDict.__reduce__.<locals>.<listcomp>N)varsr   r  r  r   )r^   r%  	inst_dictr(  r   r   r   
__reduce__Z  s    zOrderedDict.__reduce__c                 C   s
   |  | S )z!od.copy() -> a shallow copy of od)r   r   r   r   r   r   d  s    zOrderedDict.copyc                 C   s   |  }|D ]}|||< q
|S )zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
            and values equal to v (which defaults to None).

            r   )r   r   rV   drU   r   r   r   r   h  s    
zOrderedDict.fromkeysc                 C   s6   t |tr*t| t|ko(|  | kS t| |S )zod.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
            while comparison to a regular mapping is order-insensitive.

            )r   r  rP   r%  r   __eq__r^   r+  r   r   r   r4  s  s    
zOrderedDict.__eq__c                 C   s
   | |k S rZ   r   r5  r   r   r   __ne__}  s    zOrderedDict.__ne__c                 C   s   t | S )z@od.viewkeys() -> a set-like object providing a view on od's keys)r  r   r   r   r   viewkeys  s    zOrderedDict.viewkeysc                 C   s   t | S )z<od.viewvalues() -> an object providing a view on od's values)r  r   r   r   r   
viewvalues  s    zOrderedDict.viewvaluesc                 C   s   t | S )zBod.viewitems() -> a set-like object providing a view on od's items)r  r   r   r   r   	viewitems  s    zOrderedDict.viewitems)T)N)N)N)"r+   r,   r-   ra   r`   r   r   r  r   r  r  r  r"  r$  r%  r&  r  r)  r]   r  objectr,  r  r-  r   r2  r   r  r   r4  r6  r7  r8  r9  r   r   r   r   r    s:   
	





r  )BaseConfiguratorvalid_identz^[a-z_][a-z0-9_]*$c                 C   s   t | }|std|  dS )Nz!Not a valid Python identifier: %rT)
IDENTIFIERr=   rN   )r   r   r   r   r   r<    s    
r<  c                   @   s"   e Zd ZdZdd ZdddZdS )ConvertingDictz A converting dictionary wrapper.c                 C   sJ   t | |}| j|}||k	rF|| |< t|tttfkrF| |_||_	|S rZ   )
r   r   configuratorconvertr   r>  ConvertingListConvertingTupleparentrU   r^   rU   rV   r   r   r   r   r     s    
zConvertingDict.__getitem__Nc                 C   sL   t | ||}| j|}||k	rH|| |< t|tttfkrH| |_||_	|S rZ   )
r   rO   r?  r@  r   r>  rA  rB  rC  rU   r^   rU   r   rV   r   r   r   r   rO     s    
zConvertingDict.get)N)r+   r,   r-   ra   r   rO   r   r   r   r   r>    s   r>  c                 C   sD   t | ||}| j|}||k	r@t|tttfkr@| |_||_	|S rZ   )
r   r  r?  r@  r   r>  rA  rB  rC  rU   rE  r   r   r   r    s    
r  c                   @   s"   e Zd ZdZdd ZdddZdS )	rA  zA converting list wrapper.c                 C   sJ   t | |}| j|}||k	rF|| |< t|tttfkrF| |_||_	|S rZ   )
r   r   r?  r@  r   r>  rA  rB  rC  rU   rD  r   r   r   r     s    
zConvertingList.__getitem__c                 C   s<   t | |}| j|}||k	r8t|tttfkr8| |_|S rZ   )	r   r  r?  r@  r   r>  rA  rB  rC  )r^   idxrV   r   r   r   r   r    s    
zConvertingList.popN)rF  )r+   r,   r-   ra   r   r  r   r   r   r   rA    s   rA  c                   @   s   e Zd ZdZdd ZdS )rB  zA converting tuple wrapper.c                 C   sB   t | |}| j|}||k	r>t|tttfkr>| |_||_	|S rZ   )
tupler   r?  r@  r   r>  rA  rB  rC  rU   rD  r   r   r   r     s    
zConvertingTuple.__getitem__N)r+   r,   r-   ra   r   r   r   r   r   rB    s   rB  c                   @   s   e Zd ZdZedZedZedZedZ	edZ
ddd	ZeeZd
d Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r;  zQ
        The configurator base class which defines some useful defaults.
        z%^(?P<prefix>[a-z]+)://(?P<suffix>.*)$z^\s*(\w+)\s*z^\.\s*(\w+)\s*z^\[\s*(\w+)\s*\]\s*z^\d+$ext_convertcfg_convert)rr   cfgc                 C   s   t || _| | j_d S rZ   )r>  configr?  )r^   rL  r   r   r   r`     s    
zBaseConfigurator.__init__c           	   	   C   s   | d}|d}z^| |}|D ]H}|d| 7 }zt||}W q$ tk
rj   | | t||}Y q$X q$|W S  tk
r   t dd \}}td||f }|| |_	|_
|Y nX dS )zl
            Resolve strings to objects using standard import and attribute
            syntax.
            r/   r   r.   NzCannot resolve %r: %s)r1   r  importerr   r   ImportErrorr{   r   rN   	__cause____traceback__)	r^   r   r   usedfoundrF   etbvr   r   r   resolve  s"    



zBaseConfigurator.resolvec                 C   s
   |  |S )z*Default converter for the ext:// protocol.)rV  r^   rV   r   r   r   rI    s    zBaseConfigurator.ext_convertc                 C   s   |}| j |}|dkr&td| n|| d }| j| d  }|r| j|}|rn|| d  }nd| j|}|r| d }| j|s|| }n2zt	|}|| }W n t
k
r   || }Y nX |r|| d }qHtd||f qH|S )z*Default converter for the cfg:// protocol.NzUnable to convert %rr   zUnable to convert %r at %r)WORD_PATTERNr=   rN   endrL  groupsDOT_PATTERNINDEX_PATTERNDIGIT_PATTERNintr   )r^   rV   restr   r3  rG  nr   r   r   rJ     s8    
zBaseConfigurator.cfg_convertc                 C   s   t |ts$t |tr$t|}| |_nt |tsHt |trHt|}| |_nzt |tslt |trlt|}| |_nVt |tr| j	
|}|r| }|d }| j|d}|r|d }t| |}||}|S )z
            Convert values to an appropriate type. dicts, lists and tuples are
            replaced by their converting alternatives. Strings are checked to
            see if they have a conversion format and are converted if they do.
            prefixNr  )r   r>  r   r?  rA  r   rB  rH  string_typesCONVERT_PATTERNr=   	groupdictvalue_convertersrO   r   )r^   rV   r   r3  ra  	converterr  r   r   r   r@  C  s4      

zBaseConfigurator.convertc                    sn     d}t|s| |}  dd}t fdd D }|f |}|rj| D ]\}}t||| qT|S )z1Configure an object with a user-supplied factory.z()r/   Nc                    s    g | ]}t |r| | fqS r   )r<  r/  rL  r   r   rv   g  s      z5BaseConfigurator.configure_custom.<locals>.<listcomp>)r  r   rV  r   r%  setattr)r^   rL  r
  propsr_   r   r   rV   r   rg  r   configure_custom`  s    


z!BaseConfigurator.configure_customc                 C   s   t |trt|}|S )z0Utility function which converts lists to tuples.)r   r   rH  rW  r   r   r   as_tuplen  s    
zBaseConfigurator.as_tupleN)r+   r,   r-   ra   r7   r:   rc  rX  r[  r\  r]  re  staticmethod
__import__rM  r`   rV  rI  rJ  r@  rj  rk  r   r   r   r   r;    s"   




#r;  )r.   )r   )N)N)
__future__r   rc   r7   shutilr{   sslrN  version_infor   
basestringrb  r   r   typesr   	file_type__builtin__builtinsConfigParserconfigparserr   r   r   r	   r
   urllibr   r   r   r   r   r   r   r   urllib2r   r   r   r   r   r   r    r!   r"   r#   httplib	xmlrpclibQueuequeuer$   htmlentitydefs	raw_input	itertoolsr%   filterr&   r(   iostrr'   urllib.parseurllib.requesturllib.errorhttp.clientclientrequestxmlrpc.clienthtml.parserhtml.entitiesentitiesinputr)   r*   rN   rH   rX   rY   r:  rb   F_OKX_OKzipfiler   r   r*  r   ZBaseZipExtFiler|   r   	sysconfigr   	NameErrorcollections.abcr   r   r   r   getfilesystemencodingr   r   tokenizer   codecsr   r   r:   r   r   htmlr8   cgir   collectionsr   r   reprlibr   r   importlib.utilr	  r  threadr   r.  dummy_thread_abcollr  r  r  r   logging.configr;  r<  Ir=  r>  r  r   rA  rH  rB  r   r   r   r   <module>   s  
$,(0
1+	B

	

^
h |

