3
ûâde¢  ã            �   @   s*  d dl mZ d dlZd dlZd dlZyd dlZW n ek
rH   dZY nX ejd  dk �rrd 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 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l0Z0d dl1Z2d dl3m3Z3 d dl4Z4e5Z5d dl6m7Z8 d dl6m9Z: �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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lAjBZ/d dl?jCZ$d dlDjBZ0d dl2Z2d dlEm3Z3 d dlFjGZ4eHZ5d dl6m:Z: e8Z8yd dlmIZImJZJ W n8 ek
�rÆ   G dd„ deKƒZJdbdd„ZLdd„ ZIY nX yd dlmMZN W n& ek
�rþ   G dd„ deOƒZNY nX yd d lmPZP W n, ek
�r<   ejQejRB dfd!d"„ZPY nX d d#lSmTZU eVeUd$ƒ�r\eUZTn,d d%lSmWZX G d&d'„ d'eXƒZWG d(d)„ d)eUƒZTyd d*lYmZZZ W n ek
�r¶   d+d,„ ZZY nX yd dl[Z[W n" ek
�ræ   dd-lm[Z[ Y nX ye\Z\W n* e]k
�r   d d.l^m_Z_ d/d0„ Z\Y nX yej`Z`ejaZaW nH ebk
�rt   ejcƒ �pJd1Zdedd2k�r\d3Zend4Zed5d6„ Z`d7d8„ ZaY nX yd d9lfmgZg W nH ek
�rÎ   d d:lhmiZimjZj d dlZejkd;ƒZld<d=„ Zmd>d?„ ZgY nX yd d@lnmoZo W n" ek
�r   d d@lpmoZo Y nX ejddA… dck �r"e3ƒ jqZqnd dClnmqZq yd dDlrmsZs W nd ek
�r¢   d dElrmtZt yd dFlumvZw W n  ek
�rŒ   dddHdI„ZwY nX G dJdK„ dKetƒZsY nX yd dLlxmyZy W nH ek
�rü   yd dLlzmyZy W n  ek
�rö   dedMdN„ZyY nX Y nX yd dOlrm{Z{ W nŠ ek
�r˜   yd dPl|m}Z~ W n" ek
�rR   d dPlm}Z~ Y nX yd dQl€m�Z�m‚Z‚mƒZƒ W n ek
�r‚   Y nX G dRdS„ dSe„ƒZ{Y nX yd dTl…m†Z†m‡Z‡ W nv ek
�r$   ejkdUejˆƒZ‰dVdW„ Z‡G dXdY„ dYe„ƒZŠdfdZd[„Z‹G d\d]„ d]eŒƒZ�G d^d_„ d_eŽƒZ�G d`da„ daeOƒZ†Y nX dS )gé    )Úabsolute_importNé   )ÚStringIO)ÚFileTypeé   )Úshutil)ÚurlparseÚ
urlunparseÚurljoinÚurlsplitÚ
urlunsplit)ÚurlretrieveÚquoteÚunquoteÚurl2pathnameÚpathname2urlÚContentTooShortErrorÚ	splittypec             C   s   t | tƒr| jdƒ} t| ƒS )Nzutf-8)Ú
isinstanceÚunicodeÚencodeÚ_quote)Ús© r   ú9/tmp/pip-build-red6nood/pip/pip/_vendor/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 | j dƒ}|d |dd…  }}|jdƒ}||krNtdt| ƒ ƒ‚|sb| jƒ |jƒ kS |dkrv|jdƒ n>|jd	ƒsŠ|jd	ƒrœ|jtj|ƒƒ n|jtj|ƒj	d
dƒƒ x|D ]}|jtj|ƒƒ qºW tj
ddj|ƒ d tjƒ}	|	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_matchd   s(    


rH   c             C   sò   | st dƒ‚g }| jdf ƒ}x0|D ](\}}|dkr"t||ƒr@dS |j|ƒ q"W |sšxF| jdf ƒD ]6}x0|D ](\}}|dkrjt||ƒrˆdS |j|ƒ qjW q`W t|ƒdkrÄtd|d	jtt|ƒƒf ƒ‚n*t|ƒdkræt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ÚsubjectAltNameÚDNSNÚsubjectÚ
commonNamer   z&hostname %r doesn't match either of %sz, 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*   –   s.    

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 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   rX   Ä   s   rX   )Úwhichc                s"  dd„ }t jjˆ ƒr&|ˆ |ƒr"ˆ S dS |dkr>t jjdt jƒ}|sFdS |jt jƒ}tj	dkr¼t j
|krt|jdt j
ƒ t jjddƒjt jƒ}t‡ fd	d
„|D ƒƒr¨ˆ g}qÂ‡ fdd„|D ƒ}nˆ g}tƒ }xT|D ]L}t jj|ƒ}||krÎ|j|ƒ x(|D ] }	t jj||	ƒ}
||
|ƒrö|
S qöW qÎW d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j| ƒo$t j| |ƒo$t jj| ƒ S )N)ÚosÚpathÚexistsÚaccessÚisdir)ÚfnÚmoder   r   r   Ú_access_checkÝ   s    zwhich.<locals>._access_checkNÚPATHÚwin32r   ÚPATHEXTÚ c             3   s    | ]}ˆ j ƒ j|j ƒ ƒV  qd S )N)r4   Úendswith)Ú.0Úext)Úcmdr   r   ú	<genexpr>ú   s    zwhich.<locals>.<genexpr>c                s   g | ]}ˆ | ‘qS r   r   )rm   rn   )ro   r   r   ú
<listcomp>ý   s    zwhich.<locals>.<listcomp>)r`   ra   ÚdirnameÚenvironrN   Údefpathr1   ÚpathsepÚsysÚplatformÚcurdirÚinsertÚanyÚsetÚnormcaseÚaddr;   )ro   rf   ra   rg   ÚpathextÚfilesÚseenÚdirÚnormdirÚthefileÚnamer   )ro   r   r_   Ð   s8    






r_   )Ú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|j ƒ d S )N)rY   rZ   )r[   Úbaser   r   r   r]     s    zZipExtFile.__init__c             C   s   | S )Nr   )r[   r   r   r   r†     s    zZipExtFile.__enter__c             G   s   | j ƒ  d S )N)Ú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 )Nr   )r[   r   r   r   r†   $  s    zZipFile.__enter__c             G   s   | j ƒ  d S )N)r‰   )r[   rŠ   r   r   r   r‹   '  s    zZipFile.__exit__c             O   s   t j| f|ž|Ž}t|ƒS )N)Ú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jdƒr,dS dS )z6Return a string identifying the Python implementation.ÚPyPyÚjavaÚJythonÚ
IronPythonÚCPython)rv   Úversionr`   r„   r6   r   r   r   r   r�   2  s    

r�   )Ú	sysconfig)ÚCallablec             C   s
   t | tƒS )N)r   r—   )Úobjr   r   r   ÚcallableF  s    r™   zutf-8ÚmbcsÚstrictÚsurrogateescapec             C   s:   t | tƒr| S t | tƒr$| j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$| jttƒS tdt| ƒj ƒ‚d S )Nzexpect bytes or str, not %s)	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… j ƒ jddƒ}|dks*|jdƒr.dS |dks@|jdƒrDdS | S )z(Imitates get_normal_name in tokenizer.c.Né   Ú_ú-zutf-8zutf-8-úlatin-1ú
iso-8859-1úiso-latin-1úlatin-1-úiso-8859-1-úiso-latin-1-)r­   r®   r¯   )r°   r±   r²   )r4   r9   r6   )Úorig_encÚencr   r   r   Ú_get_normal_namet  s    
rµ   c                sÊ   yˆj j‰W n tk
r$   d‰Y nX d‰ d}d}‡fdd„}‡ ‡fdd„}|ƒ }|j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.
        NFzutf-8c                  s    yˆ ƒ S  t k
r   dS X d S )Nó    )ÚStopIterationr   )Úreadliner   r   Úread_or_stop—  s    z%detect_encoding.<locals>.read_or_stopc                sä   y| j dƒ}W n4 tk
rB   d}ˆd k	r6dj|ˆƒ}t|ƒ‚Y nX tj|ƒ}|sVd S t|d ƒ}yt|ƒ}W n: tk
r¨   ˆd kr�d| }ndjˆ|ƒ}t|ƒ‚Y nX ˆ rà|j	dkrØˆd krÆd}n
djˆƒ}t|ƒ‚|d	7 }|S )
Nzutf-8z'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�  s6    



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   é   é   )Ú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 ˆj|ƒ zˆ| ƒ}W d ˆj|ƒ X |S )N)ÚidÚ	get_identr}   Údiscard)r[   rT   Úresult)Ú	fillvalueÚrepr_runningÚuser_functionr   r   Úwrapperô  s    
z=_recursive_repr.<locals>.decorating_function.<locals>.wrapperr-   r^   r,   Ú__annotations__)r{   Úgetattrr-   r^   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 )z˜Initialize 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 )N)ÚKeyError)r[   rT   r   r   r   Ú__missing__  s    zChainMap.__missing__c             C   s8   x,| j D ]"}y|| S  tk
r(   Y qX qW | j|ƒS )N)rá   râ   rã   )r[   rT   Úmappingr   r   r   Ú__getitem__  s    
zChainMap.__getitem__Nc             C   s   || kr| | S |S )Nr   )r[   rT   rÊ   r   r   r   rN   '  s    zChainMap.getc             C   s   t tƒ j| jŽ ƒS )N)rO   r{   Úunionrá   )r[   r   r   r   Ú__len__*  s    zChainMap.__len__c             C   s   t tƒ j| jŽ ƒS )N)Úiterr{   ræ   rá   )r[   r   r   r   Ú__iter__-  s    zChainMap.__iter__c                s   t ‡ fdd„| jD ƒƒS )Nc             3   s   | ]}ˆ |kV  qd S )Nr   )rm   Úm)rT   r   r   rp   1  s    z(ChainMap.__contains__.<locals>.<genexpr>)rz   rá   )r[   rT   r   )rT   r   Ú__contains__0  s    zChainMap.__contains__c             C   s
   t | jƒS )N)rz   rá   )r[   r   r   r   Ú__bool__3  s    zChainMap.__bool__c             C   s   dj | djtt| jƒƒƒS )Nz{0.__class__.__name__}({1})z, )r»   r;   rP   r3   rá   )r[   r   r   r   Ú__repr__6  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ï   ;  s    zChainMap.fromkeysc             C   s$   | j | jd jƒ 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á   Úcopy)r[   r   r   r   ró   @  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_childF  s    zChainMap.new_childc             C   s   | j | jdd… Ž S )zNew ChainMap from maps[1:].r   N)rò   rá   )r[   r   r   r   ÚparentsJ  s    zChainMap.parentsc             C   s   || j d |< d S )Nr   )rá   )r[   rT   rU   r   r   r   Ú__setitem__O  s    zChainMap.__setitem__c             C   s8   y| j d |= W n" tk
r2   tdj|ƒƒ‚Y nX d S )Nr   z(Key not found in the first mapping: {!r})rá   râ   r»   )r[   rT   r   r   r   Ú__delitem__R  s    zChainMap.__delitem__c             C   s0   y| j d jƒ 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ø   X  s    zChainMap.popitemc             G   s>   y| j d j|f|žŽ S  tk
r8   tdj|ƒƒ‚Y nX dS )zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r   z(Key not found in the first mapping: {!r}N)rá   Úpoprâ   r»   )r[   rT   rŽ   r   r   r   rù   _  s    zChainMap.popc             C   s   | j d jƒ  dS )z'Clear maps[0], leaving maps[1:] intact.r   N)rá   Úclear)r[   r   r   r   rú   f  s    zChainMap.clear)N)r,   r-   r.   r^   r]   rã   rå   rN   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   | j dƒst‚|d krd}|r$d}nd}| | S )Nz.pyTÚcÚo)rl   ÚAssertionError)ra   Údebug_overrideÚsuffixr   r   r   rþ   p  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 |ƒ ƒ‚y
| j W n6 tk
r\   g  | _}||dg|dd…< i | _Y nX | j||Ž dS )zÑInitialize 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)rO   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[   rT   rU   Zdict_setitemr  Úlastr   r   r   rö   §  s
     zOrderedDict.__setitem__c             C   s0   || |ƒ | j j|ƒ\}}}||d< ||d< dS )z od.__delitem__(y) <==> del od[y]r   r   N)r	  rù   )r[   rT   Zdict_delitemÚ	link_prevÚ	link_nextr   r   r   r÷   ±  s    
zOrderedDict.__delitem__c             c   s2   | j }|d }x||k	r,|d V  |d }qW dS )zod.__iter__() <==> iter(od)r   rÍ   N)r  )r[   r  Úcurrr   r   r   ré   º  s
    

zOrderedDict.__iter__c             c   s2   | j }|d }x||k	r,|d V  |d }qW dS )z#od.__reversed__() <==> reversed(od)r   rÍ   N)r  )r[   r  r  r   r   r   Ú__reversed__Â  s
    

zOrderedDict.__reversed__c             C   sh   yDx| j jƒ D ]}|dd…= qW | j}||dg|dd…< | j jƒ  W n tk
rX   Y nX tj| ƒ 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j| |ƒ}||fS )z¡od.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  rT   rU   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   )rm   rT   )r[   r   r   rq   õ  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   )rm   rT   )r[   r   r   rq   ù  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   x| D ]}| | V  qW dS )z2od.itervalues -> an iterator over the values in odNr   )r[   Úkr   r   r   r  ÿ  s    
zOrderedDict.itervaluesc             c   s    x| D ]}|| | fV  qW dS )z=od.iteritems -> an iterator over the (key, value) items in odNr   )r[   r  r   r   r   Ú	iteritems  s    
zOrderedDict.iteritemsc              O   sØ   t | ƒdkr tdt | ƒf ƒ‚n| s,tdƒ‚| d }f }t | ƒdkrL| d }t|tƒrrx^|D ]}|| ||< q\W nDt|dƒrœx8|jƒ D ]}|| ||< q†W nx|D ]\}}|||< q¢W x|jƒ D ]\}}|||< qÀW d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  N)rO   r¡   r   rî   Úhasattrr  r  )rŽ   r  r[   ÚotherrT   rU   r   r   r   rZ   	  s&    	


zOrderedDict.updatec             C   s0   || kr| | }| |= |S || j kr,t|ƒ‚|S )z±od.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[   rT   rÊ   r×   r   r   r   rù   ,  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[   rT   rÊ   r   r   r   Ú
setdefault9  s    zOrderedDict.setdefaultc             C   s^   |si }t | ƒtƒ f}||kr"dS d||< z&| s>d| jjf S d| jj| jƒ f S ||= X dS )zod.__repr__() <==> repr(od)z...r   z%s()z%s(%r)N)rÔ   Ú
_get_identrò   r,   r  )r[   Z_repr_runningZcall_keyr   r   r   rí   @  s     zOrderedDict.__repr__c                s\   ‡ fdd„ˆ D ƒ}t ˆ ƒjƒ }xt tƒ ƒD ]}|j|dƒ q*W |rPˆ j|f|fS ˆ j|ffS )z%Return state information for picklingc                s   g | ]}|ˆ | g‘qS r   r   )rm   r  )r[   r   r   rq   P  s    z*OrderedDict.__reduce__.<locals>.<listcomp>N)Úvarsró   r  rù   rò   )r[   r  Ú	inst_dictr  r   )r[   r   Ú
__reduce__N  s    zOrderedDict.__reduce__c             C   s
   | j | ƒS )z!od.copy() -> a shallow copy of od)rò   )r[   r   r   r   ró   X  s    zOrderedDict.copyc             C   s    | ƒ }x|D ]}|||< qW |S )zˆOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
            and values equal to v (which defaults to None).

            r   )rð   rñ   rU   ÚdrT   r   r   r   rï   \  s    
zOrderedDict.fromkeysc             C   s6   t |tƒr*t| ƒt|ƒko(| jƒ |jƒ kS tj| |ƒS )z›od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
            while comparison to a regular mapping is order-insensitive.

            )r   r  rO   r  rî   Ú__eq__)r[   r  r   r   r   r$  g  s    
 zOrderedDict.__eq__c             C   s
   | |k S )Nr   )r[   r  r   r   r   Ú__ne__p  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   Úviewkeysu  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   Ú
viewvaluesy  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.   r^   r]   rî   rö   r÷   ré   r  rú   rø   r  r  r  r  r  r  rZ   r
  Úobjectr  rù   r  rí   r"  ró   rû   rï   r$  r%  r&  r'  r(  r   r   r   r   r  ‹  s:   
	




	r  )ÚBaseConfiguratorÚvalid_identz^[a-z_][a-z0-9_]*$c             C   s   t j| ƒ}|std|  ƒ‚dS )Nz!Not a valid Python identifier: %rT)Ú
IDENTIFIERr=   rM   )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| |ƒ}| jj|ƒ}||k	rF|| |< t|ƒtttfkrF| |_||_	|S )N)
rî   rå   ÚconfiguratorÚconvertr¢   r-  ÚConvertingListÚConvertingTupleÚparentrT   )r[   rT   rU   r×   r   r   r   rå   š  s    
zConvertingDict.__getitem__Nc             C   sL   t j| ||ƒ}| jj|ƒ}||k	rH|| |< t|ƒtttfkrH| |_||_	|S )N)
rî   rN   r.  r/  r¢   r-  r0  r1  r2  rT   )r[   rT   rÊ   rU   r×   r   r   r   rN   ¦  s    
zConvertingDict.get)N)r,   r-   r.   r^   rå   rN   r   r   r   r   r-  —  s   r-  c             C   sD   t j| ||ƒ}| jj|ƒ}||k	r@t|ƒtttfkr@| |_||_	|S )N)
rî   rù   r.  r/  r¢   r-  r0  r1  r2  rT   )r[   rT   rÊ   rU   r×   r   r   r   rù   ²  s    
rù   c               @   s"   e Zd ZdZdd„ Zd	dd„ZdS )
r0  zA converting list wrapper.c             C   sJ   t j| |ƒ}| jj|ƒ}||k	rF|| |< t|ƒtttfkrF| |_||_	|S )N)
rà   rå   r.  r/  r¢   r-  r0  r1  r2  rT   )r[   rT   rU   r×   r   r   r   rå   ¾  s    
zConvertingList.__getitem__r   c             C   s<   t j| |ƒ}| jj|ƒ}||k	r8t|ƒtttfkr8| |_|S )N)	rà   rù   r.  r/  r¢   r-  r0  r1  r2  )r[   ÚidxrU   r×   r   r   r   rù   Ê  s    
zConvertingList.popNéÿÿÿÿ)r4  )r,   r-   r.   r^   rå   rù   r   r   r   r   r0  ¼  s   r0  c               @   s   e Zd ZdZdd„ ZdS )r1  zA converting tuple wrapper.c             C   sB   t j| |ƒ}| jj|ƒ}||k	r>t|ƒtttfkr>| |_||_	|S )N)
Útuplerå   r.  r/  r¢   r-  r0  r1  r2  rT   )r[   rT   rU   r×   r   r   r   rå   Õ  s    
zConvertingTuple.__getitem__N)r,   r-   r.   r^   rå   r   r   r   r   r1  Ó  s   r1  c               @   sŒ   e Zd ZdZejdƒZejdƒZejdƒZejdƒZ	ej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)rn   Úcfgc             C   s   t |ƒ| _| | j_d S )N)r-  Úconfigr.  )r[   r9  r   r   r   r]   ó  s    
zBaseConfigurator.__init__c       	      C   sÄ   |j dƒ}|jdƒ}y`| j|ƒ}xP|D ]H}|d| 7 }yt||ƒ}W q& tk
rl   | j|ƒ t||ƒ}Y q&X q&W |S  tk
r¾   tjƒ 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É   ÚImportErrorrv   rŠ   rM   Ú	__cause__Ú__traceback__)	r[   r   r„   ÚusedÚfoundrF   ÚeÚtbÚvr   r   r   Úresolve÷  s"    




zBaseConfigurator.resolvec             C   s
   | j |ƒS )z*Default converter for the ext:// protocol.)rC  )r[   rU   r   r   r   r6    s    zBaseConfigurator.ext_convertc             C   s  |}| j j|ƒ}|dkr&td| ƒ‚nØ||jƒ d… }| j|jƒ d  }x´|rü| jj|ƒ}|rp||jƒ d  }nd| jj|ƒ}|rÔ|jƒ d }| jj|ƒs¢|| }n2yt	|ƒ}|| }W n t
k
rÒ   || }Y nX |rê||jƒ d… }qJtd||f ƒ‚qJW |S )z*Default converter for the cfg:// protocol.NzUnable to convert %rr   zUnable to convert %r at %r)ÚWORD_PATTERNr=   rM   Úendr9  ÚgroupsÚDOT_PATTERNÚINDEX_PATTERNÚDIGIT_PATTERNÚintr¡   )r[   rU   Úrestrê   r#  r3  Únr   r   r   r7    s2    
zBaseConfigurator.cfg_convertc             C   sÌ   t |tƒ r&t |tƒr&t|ƒ}| |_n¢t |tƒ rLt |tƒrLt|ƒ}| |_n|t |tƒ rrt |tƒrrt|ƒ}| |_nVt |tƒrÈ| j	j
|ƒ}|rÈ|jƒ }|d }| j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.  r0  rà   r1  r5  Ústring_typesÚCONVERT_PATTERNr=   Ú	groupdictÚvalue_convertersrN   rÝ   )r[   rU   rê   r#  rM  Ú	converterr  r   r   r   r/  4  s*    


zBaseConfigurator.convertc                sr   ˆ j dƒ}t|ƒs| j|ƒ}ˆ j ddƒ}t‡ fdd„ˆ D ƒƒ}|f |Ž}|rnx |jƒ D ]\}}t|||ƒ qVW |S )z1Configure an object with a user-supplied factory.z()r/   Nc                s    g | ]}t |ƒr|ˆ | f‘qS r   )r+  )rm   r  )r9  r   r   rq   W  s    z5BaseConfigurator.configure_custom.<locals>.<listcomp>)rù   r™   rC  rî   r  Úsetattr)r[   r9  rÿ   Úpropsr\   r×   r„   rU   r   )r9  r   Úconfigure_customP  s    


z!BaseConfigurator.configure_customc             C   s   t |tƒrt|ƒ}|S )z0Utility function which converts lists to tuples.)r   rà   r5  )r[   rU   r   r   r   Úas_tuple^  s    
zBaseConfigurator.as_tupleN)r,   r-   r.   r^   r7   r:   rO  rD  rG  rH  rI  rQ  ÚstaticmethodÚ
__import__r:  r]   rC  r6  r7  r/  rU  rV  r   r   r   r   r*  ß  s    




"r*  )r   )r   rÎ   )rÓ   )N)N)�Ú
__future__r   r`   r7   rv   Ússlr;  Úversion_infor   Ú
basestringrN  r   rž   Útypesr   Ú	file_typeÚ__builtin__ÚbuiltinsÚConfigParserÚconfigparserZ	_backportr   r   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ÚrequestZxmlrpc.clientÚhtml.parserÚhtml.entitiesÚentitiesÚinputr*   r+   rM   rH   rW   rX   r)  r_   ÚF_OKÚX_OKÚzipfiler…   rŒ   r  r‡   ZBaseZipExtFilerw   r�   r–   r™   Ú	NameErrorÚcollections.abcr—   r¤   r¦   rÉ   ÚgetfilesystemencodingrŸ   r    Útokenizer§   Úcodecsr¨   r©   r:   r½   rµ   Úhtmlr8   ÚcgirÏ   ÚcollectionsrÐ   rÑ   ÚreprlibrÒ   rß   Úimportlib.utilrþ   Úimpr  ÚthreadrÕ   r  Údummy_threadÚ_abcollr  r  r  rî   Úlogging.configr*  r+  ÚIr,  r-  rù   rà   r0  r5  r1  r   r   r   r   Ú<module>   s(  
$,(0




2+A


		
[
b
 w

