
^VԞ                 @   s  d  d l  m Z d  d l Z d  d l Z d  d l Z e j d  d k  r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 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+ m, Z, d  d l- Z- d  d l. Z. d  d l/ Z0 d  d l1 m1 Z1 d  d l2 Z2 e3 Z3 d  d l4 m5 Z6 d  d l4 m7 Z8 d a9 d d   Z: no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 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+ m, Z, d  d l@ m& Z& m% Z% m  Z  d  d lA jB Z- d  d l? jC Z" d  d lD jB Z. d  d l0 Z0 d  d lE m1 Z1 d  d lF jG Z2 eH Z3 d  d l4 m8 Z8 e6 Z6 y d  d lI mJ ZJ mK ZK WnC eL k
 rGd d   d eM  ZK d d d  ZN d d   ZJ Yn Xy d  d l mO ZP Wn( eL k
 rGd d    d  eQ  ZP Yn Xy d  d! l mR ZR Wn. eL k
 r%e jS e jT Bd d" d#  ZR Yn Xd  d$ lU mV ZW eX eW d%  rNeW ZV n< d  d& lU mY ZZ Gd' d(   d( eZ  ZY Gd) d*   d* eW  ZV y d  d+ l[ m\ Z\ Wn eL k
 rd, d-   Z\ Yn Xy d  d l] Z] Wn" eL k
 rd d. l m] Z] Yn Xy
 e^ Z^ Wn. e_ k
 r.d  d/ l` ma Za d0 d1   Z^ Yn Xy e jb Zb e jc Zc WnQ ed k
 re je   Zf ef d2 k rvd3 Zg n d4 Zg d5 d6   Zb d7 d8   Zc Yn Xy d  d9 lh mi Zi Wn[ eL k
 r
d  d: lj mk Zk ml Zl d  d l Z e jm d;  Zn d< d=   Zo d> d?   Zi Yn Xy d  d@ lp mq Zq Wn" eL k
 rCd  d@ lr mq Zq Yn Xe j d dA  db k  rle1   js Zs n d  dC lp ms Zs y d  dD l` mt Zt Wnp eL k
 rd  dE l` mu Zu y d  dF lv mw Zx Wn! eL k
 rdG dH dI  Zx Yn XGdJ dK   dK eu  Zt Yn Xy d  dL ly mz Zz Wn! eL k
 r:d dM dN  Zz Yn Xy d  dO l` m{ Z{ Wn eL k
 ry d  dP l| m} Z~ Wn" eL k
 rd  dP l m} Z~ Yn Xy  d  dQ l m Z m Z m Z Wn eL k
 rYn XGdR dS   dS e  Z{ Yn Xy d  dT l m Z m Z Wn eL k
 re jm dU e j  Z dV dW   Z GdX dY   dY e  Z d dZ d[  Z Gd\ d]   d] e  Z Gd^ d_   d_ e  Z Gd` da   da eQ  Z Yn Xd S)c    )absolute_importN   )StringIO)FileType   )shutil)urlparse
urlunparseurljoinurlsplit
urlunsplit)urlretrievequoteunquoteurl2pathnamepathname2urlContentTooShortError	splittypec             C   s+   t  |  t  r! |  j d  }  n  t |   S)Nzutf-8)
isinstanceunicodeencode_quote)s r   9/tmp/pip-build-9m6vxulb/pip/pip/_vendor/distlib/compat.pyr      s    r   )
RequesturlopenURLError	HTTPErrorHTTPBasicAuthHandlerHTTPPasswordMgrHTTPSHandlerHTTPHandlerHTTPRedirectHandlerbuild_opener)
HTMLParser)ifilter)ifilterfalsec             C   sY   t  d k r* d d l } | j d  a  n  t  j |   } | rO | j d d  Sd |  f S)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.Nr   z^(.*)@(.*)$r      )	_userprogrecompilematchgroup)hostr*   r,   r   r   r   	splituser-   s     r/   )TextIOWrapper)	r   r	   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)r3   N)__name__
__module____qualname__r   r   r   r   r3   U   s   r3   c       
      C   sY  g  } |  s d S|  j  d  } | d | d d  } } | j d  } | | k rn t d t |     n  | s |  j   | j   k S| d k r | j d  nY | j d	  s | j d	  r | j t j |   n" | j t j |  j	 d
 d   x$ | D] } | j t j |   qWt 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countr3   reprlowerappend
startswithr*   escapereplacer+   join
IGNORECASEr,   )
dnhostnamemax_wildcardspatspartsleftmost	remainder	wildcardsfragpatr   r   r   _dnsname_matchY   s(    "&rM   c             C   s[  |  s t  d   n  g  } |  j d f   } xC | D]; \ } } | d k r4 t | |  r_ d S| j |  q4 q4 W| s xc |  j d f   D]L } xC | D]; \ } } | d k r t | |  r d S| j |  q q Wq Wn  t |  d k rt d | d	 j t t |   f   n; t |  d k rK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getrM   r=   lenr3   rA   mapr;   )certrD   dnsnamessankeyvaluesubr   r   r   r2      s.    %r2   )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)r4   r5   r6   __doc__rb   r   r   r   r   r]      s   r]   )whichc                s  d d   } t  j j    r5 |   |  r1   Sd S| d k r\ t  j j d t  j  } n  | sf d S| j t  j  } t j	 d k rt  j
 | k r | j d t  j
  n  t  j j d d  j t  j  } t   f d	 d
   | D  r   g } q  f d d   | D } n	   g } t   } xu | D]m } t  j j |  } | | k r-| j |  x9 | D]. }	 t  j j | |	  }
 | |
 |  re|
 SqeWq-q-Wd 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   s5   t  j j |   o4 t  j |  |  o4 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)r<   endswith).0ext)cmdr   r   	<genexpr>   s    zwhich.<locals>.<genexpr>c                s   g  |  ] }   |  q Sr   r   )rr   rs   )rt   r   r   
<listcomp>   s   	 zwhich.<locals>.<listcomp>)re   rf   dirnameenvironrS   defpathr9   pathsepsysplatformcurdirinsertanysetnormcaseaddrA   )rt   rk   rf   rl   pathextfilesseendirnormdirthefilenamer   )rt   r   rd      s8    !		rd   )ZipFile	__enter__)
ZipExtFilec               @   s4   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)r^   r_   )r`   baser   r   r   rb     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)r4   r5   r6   rb   r   r   r   r   r   r   r     s   r   c               @   s4   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 |  | |  } t |  S)N)BaseZipFileopenr   )r`   argsra   r   r   r   r   r      s    zZipFile.openN)r4   r5   r6   r   r   r   r   r   r   r   r     s   r   )python_implementationc               C   s@   d t  j k r d St j d k r& d St  j j d  r< d Sd S)z6Return a string identifying the Python implementation.PyPyjavaJython
IronPythonCPython)r{   versionre   r   r>   r   r   r   r   r   '  s    r   )	sysconfig)Callablec             C   s   t  |  t  S)N)r   r   )objr   r   r   callable;  s    r   mbcsstrictsurrogateescapec             C   sO   t  |  t  r |  St  |  t  r2 |  j t t  St d t |   j   d  S)Nzexpect bytes or str, not %s)	r   bytes	text_typer   _fsencoding	_fserrors	TypeErrortyper4   )filenamer   r   r   fsencodeI  s    r   c             C   sO   t  |  t  r |  St  |  t  r2 |  j t t  St d t |   j   d  S)Nzexpect bytes or str, not %s)	r   r   r   decoder   r   r   r   r4   )r   r   r   r   fsdecodeR  s    r   )detect_encoding)BOM_UTF8lookupzcoding[:=]\s*([-\w.]+)c             C   sd   |  d d  j    j d d  } | d k s= | j d  rA d S| d k s\ | j d  r` d 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   )r<   r@   r>   )orig_encencr   r   r   _get_normal_namec  s    "r   c                s  y  j  j  Wn t k
 r* d  Yn Xd   d } d }  f d d   }    f d d   } |   } | j t  r d   | d	 d  } d
 } n  | 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 argment, 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     SWn t  k
 r# d SYn Xd  S)N    )StopIterationr   )readliner   r   read_or_stop  s    z%detect_encoding.<locals>.read_or_stopc                s9  y |  j  d  } WnE t k
 rZ d }  d  k	 rJ d j |   } n  t |   Yn Xt j |  } | st d  St | d  } y t |  } WnI t k
 r  d  k r d | } n d j  |  } t |   Yn X  r5| j	 d k r( d  k r
d } n d j   } t |   n  | d	 7} n  | 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   AttributeErrorr>   r   )r   r   defaultr   r   firstsecondr   )r   r   r   r   r   n  s4    &		
	r   )r?   r(      )unescape)ChainMap)MutableMapping)recursive_reprz...c                s     f d d   } | S)zm
            Decorator to make a repr function return fillvalue for a recursive
            call
            c                sp   t          f d d   } t  d  | _ t  d  | _ t  d  | _ t  d i   | _ | S)Nc                sW   t  |   t   f } |  k r%   S j |  z  |   } Wd   j |  X| S)N)id	get_identr   discard)r`   rY   result)	fillvaluerepr_runninguser_functionr   r   wrapper  s    z=_recursive_repr.<locals>.decorating_function.<locals>.wrapperr5   rc   r4   __annotations__)r   getattrr5   rc   r4   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   rb     s    zChainMap.__init__c             C   s   t  |   d  S)N)KeyError)r`   rY   r   r   r   __missing__  s    zChainMap.__missing__c             C   sB   x2 |  j  D]' } y | | SWq
 t k
 r0 Yq
 Xq
 W|  j |  S)N)r   r   r   )r`   rY   mappingr   r   r   __getitem__  s    	zChainMap.__getitem__Nc             C   s   | |  k r |  | S| S)Nr   )r`   rY   r   r   r   r   rS     s    zChainMap.getc             C   s   t  t   j |  j    S)N)rT   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   )rr   m)rY   r   r   ru      s    z(ChainMap.__contains__.<locals>.<genexpr>)r   r   )r`   rY   r   )rY   r   __contains__  s    zChainMap.__contains__c             C   s   t  |  j  S)N)r   r   )r`   r   r   r   __bool__"  s    zChainMap.__bool__c             C   s%   d j  |  d j t t |  j    S)Nz{0.__class__.__name__}({1})z, )r   rA   rU   r;   r   )r`   r   r   r   __repr__%  s    zChainMap.__repr__c             G   s   |  t  j | |   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   |  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  |  j  S)z;New ChainMap with a new dict followed by all previous maps.)r   r   )r`   r   r   r   	new_child5  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   parents9  s    zChainMap.parentsc             C   s   | |  j  d | <d  S)Nr   )r   )r`   rY   rZ   r   r   r   __setitem__>  s    zChainMap.__setitem__c             C   s@   y |  j  d | =Wn' t k
 r; t d j |    Yn Xd  S)Nr   z(Key not found in the first mapping: {!r})r   r   r   )r`   rY   r   r   r   __delitem__A  s    zChainMap.__delitem__c             C   s:   y |  j  d j   SWn t k
 r5 t d   Yn Xd 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   G  s    zChainMap.popitemc             G   sI   y |  j  d j | |  SWn' t k
 rD t d j |    Yn Xd 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`   rY   r   r   r   r   r   N  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   U  s    zChainMap.clear)r4   r5   r6   rc   rb   r   r   rS   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   sG   |  j  d  s t  | d  k r* t } n  | r9 d } n d } |  | S)Nz.pyco)rq   AssertionError	__debug__)rf   debug_overridesuffixr   r   r   r  \  s    		r  )OrderedDict)r   )KeysView
ValuesView	ItemsViewc               @   sr  e  Z d  Z d Z d d   Z e j d d  Z e j d 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 d d   Z d d   Z d d   Z e Z e   Z e d d   Z d! d" d#  Z d! d$ d%  Z d& d'   Z d( d)   Z e d! d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z  d4 d5   Z! d! S)6r  z)Dictionary that remembers insertion orderc             O   s   t  |  d k r+ t d t  |    n  y |  j WnA t k
 ry g  |  _ } | | d g | d d  <i  |  _ Yn 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)rT   r   _OrderedDict__rootr   _OrderedDict__map_OrderedDict__update)r`   r   kwdsrootr   r   r   rb     s    zOrderedDict.__init__c             C   s\   | |  k rH |  j  } | d } | | | g | d <| d <|  j | <n  | |  | |  d S)z!od.__setitem__(i, y) <==> od[i]=yr   r   N)r  r  )r`   rY   rZ   dict_setitemr  lastr   r   r   r     s
    	
)zOrderedDict.__setitem__c             C   s@   | |  |  |  j  j |  \ } } } | | d <| | d <d S)z od.__delitem__(y) <==> del od[y]r   r   N)r  r   )r`   rY   dict_delitem	link_prev	link_nextr   r   r   r     s    
zOrderedDict.__delitem__c             c   s=   |  j  } | d } x# | | k	 r8 | d V| d } q Wd 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 } x# | | k	 r8 | d V| d } q Wd S)z#od.__reversed__() <==> reversed(od)r   r(   N)r  )r`   r  r  r   r   r   __reversed__  s
    	
	zOrderedDict.__reversed__c             C   s   yZ x$ |  j  j   D] } | d d  =q W|  j } | | d g | d d  <|  j  j   Wn t k
 rn Yn Xt 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   n  |  j } | rO | d } | d } | | d <| | d <n( | d } | d } | | d <| | d <| d } |  j | =t j |  |  } | | 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  rY   rZ   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 Sr   r   )rr   rY   )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 Sr   r   )rr   rY   )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   x |  D] } |  | Vq Wd 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 Wd 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 |  sC t d   n  |  d } f  } t  |   d k rr |  d } n  t | t  r xw | D] } | | | | <q WnX t | d  r xF | j   D] } | | | | <q Wn! x | D] \ } } | | | <q Wx$ | j   D] \ } } | | | <qWd 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)rT   r   r   r   hasattrr  r  )r   r  r`   otherrY   rZ   r   r   r   r_     s&    	
zOrderedDict.updatec             C   sC   | |  k r! |  | } |  | =| S| |  j  k r? t |   n  | 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`   rY   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`   rY   r   r   r   r   
setdefault%  s    
zOrderedDict.setdefaultc             C   s   | s i  } n  t  |   t   f } | | k r4 d Sd | | <z5 |  sX d |  j j f Sd |  j j |  j   f SWd | | =Xd S)zod.__repr__() <==> repr(od)z...r   z%s()z%s(%r)N)r   
_get_identr   r4   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| rn   j | f | f S  j | f f S)z%Return state information for picklingc                s    g  |  ] } |   | g  q Sr   r   )rr   r  )r`   r   r   rv   <  s   	 z*OrderedDict.__reduce__.<locals>.<listcomp>N)varsr   r  r   r   )r`   r  	inst_dictr  r   )r`   r   
__reduce__:  s    zOrderedDict.__reduce__c             C   s   |  j  |   S)z!od.copy() -> a shallow copy of od)r   )r`   r   r   r   r   D  s    zOrderedDict.copyc             C   s(   |    } x | D] } | | | <q W| S)zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
            and values equal to v (which defaults to None).

            r   )r   r   rZ   drY   r   r   r   r   H  s    	zOrderedDict.fromkeysc             C   sM   t  | t  r= t |   t |  k o< |  j   | j   k St j |  |  S)zod.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
            while comparison to a regular mapping is order-insensitive.

            )r   r  rT   r  r   __eq__)r`   r"  r   r   r   r*  S  s    .zOrderedDict.__eq__c             C   s   |  | k S)Nr   )r`   r"  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   viewkeysa  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   
viewvaluese  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   	viewitemsi  s    zOrderedDict.viewitems)"r4   r5   r6   rc   rb   r   r   r   r   r  r   r   r  r  r  r  r  r   r_   r  objectr#  r   r$  r   r(  r   r   r   r*  r+  r,  r-  r.  r   r   r   r   r  w  s:   
		

	r  )BaseConfiguratorvalid_identz^[a-z_][a-z0-9_]*$c             C   s,   t  j |   } | s( t d |    n  d S)Nz!Not a valid Python identifier: %rT)
IDENTIFIERr,   rR   )r   r   r   r   r   r1  s  s    r1  c               @   s1   e  Z d  Z d Z d d   Z d d d  Z d S)ConvertingDictz A converting dictionary wrapper.c             C   sq   t  j |  |  } |  j j |  } | | k	 rm | |  | <t |  t t t f k rm |  | _ | | _	 qm n  | S)N)
r   r   configuratorconvertr   r3  ConvertingListConvertingTupleparentrY   )r`   rY   rZ   r   r   r   r   r     s    
	zConvertingDict.__getitem__Nc             C   st   t  j |  | |  } |  j j |  } | | k	 rp | |  | <t |  t t t f k rp |  | _ | | _	 qp n  | S)N)
r   rS   r4  r5  r   r3  r6  r7  r8  rY   )r`   rY   r   rZ   r   r   r   r   rS     s    
	zConvertingDict.get)r4   r5   r6   rc   r   rS   r   r   r   r   r3    s   r3  c             C   sj   t  j |  | |  } |  j j |  } | | k	 rf t |  t t t f k rf |  | _ | | _	 qf n  | S)N)
r   r   r4  r5  r   r3  r6  r7  r8  rY   )r`   rY   r   rZ   r   r   r   r   r     s    	r   c               @   s1   e  Z d  Z d Z d d   Z d d d  Z d S)	r6  zA converting list wrapper.c             C   sq   t  j |  |  } |  j j |  } | | k	 rm | |  | <t |  t t t f k rm |  | _ | | _	 qm n  | S)N)
r   r   r4  r5  r   r3  r6  r7  r8  rY   )r`   rY   rZ   r   r   r   r   r     s    
	zConvertingList.__getitem__r   c             C   s^   t  j |  |  } |  j j |  } | | k	 rZ t |  t t t f k rZ |  | _ qZ n  | S)N)	r   r   r4  r5  r   r3  r6  r7  r8  )r`   idxrZ   r   r   r   r   r     s    zConvertingList.popN)r4   r5   r6   rc   r   r   r   r   r   r   r6    s   r6  c               @   s"   e  Z d  Z d Z d d   Z d S)r7  zA converting tuple wrapper.c             C   sg   t  j |  |  } |  j j |  } | | k	 rc t |  t t t f k rc |  | _ | | _	 qc n  | S)N)
tupler   r4  r5  r   r3  r6  r7  r8  rY   )r`   rY   rZ   r   r   r   r   r     s    	zConvertingTuple.__getitem__N)r4   r5   r6   rc   r   r   r   r   r   r7    s   r7  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
 i d d 6d	 d
 6Z 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)r0  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_convertrs   cfg_convertcfgc             C   s   t  |  |  _ |  |  j _ d  S)N)r3  configr4  )r`   r?  r   r   r   rb     s    zBaseConfigurator.__init__c       	      C   s   | j  d  } | j d  } yz |  j |  } x` | D]X } | d | 7} y t | |  } Wq7 t k
 r |  j |  t | |  } Yq7 Xq7 W| SWn] t k
 r t j   d d  \ } } t d | | f  } | | | _	 | _
 |  Yn Xd S)zl
            Resolve strings to objects using standard import and attribute
            syntax.
            r7   r   r   NzCannot resolve %r: %s)r9   r   importerr   r   ImportErrorr{   r   rR   	__cause____traceback__)	r`   r   r   usedfoundrK   etbvr   r   r   resolve  s"    zBaseConfigurator.resolvec             C   s   |  j  |  S)z*Default converter for the ext:// protocol.)rI  )r`   rZ   r   r   r   r<    s    zBaseConfigurator.ext_convertc             C   s\  | } |  j  j |  } | d k r7 t d |   n!| | j   d  } |  j | j   d } x | rW|  j j |  } | r | | j   d } n |  j j |  } | r| j   d } |  j j |  s | | } qy t	 |  } | | } Wqt
 k
 r| | } YqXn  | r>| | j   d  } qg t d | | f   qg W| S)z*Default converter for the cfg:// protocol.NzUnable to convert %rr   zUnable to convert %r at %r)WORD_PATTERNr,   rR   endr?  groupsDOT_PATTERNINDEX_PATTERNDIGIT_PATTERNintr   )r`   rZ   restr   r)  r9  nr   r   r   r=    s2    	zBaseConfigurator.cfg_convertc             C   s/  t  | t  r7 t  | t  r7 t |  } |  | _ n t  | t  rn t  | t  rn t |  } |  | _ n t  | t  r t  | t  r t |  } |  | _ n t  | t  r+|  j	 j
 |  } | r+| j   } | d } |  j j | d  } | r(| d } t |  |  } | |  } q(q+n  | 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   r3  r   r4  r6  r   r7  r;  string_typesCONVERT_PATTERNr,   	groupdictvalue_convertersrS   r   )r`   rZ   r   r)  rS  	converterr  r   r   r   r5     s*    

zBaseConfigurator.convertc                s     j  d  } t |  s- |  j |  } n    j  d d  } t   f d d     D  } | |   } | r x- | j   D] \ } } t | | |  q} Wn  | S)z1Configure an object with a user-supplied factory.z()r7   Nc                s,   g  |  ]" } t  |  r |   | f  q Sr   )r1  )rr   r  )r?  r   r   rv   C  s   	 z5BaseConfigurator.configure_custom.<locals>.<listcomp>)r   r   rI  r   r  setattr)r`   r?  r  propsra   r   r   rZ   r   )r?  r   configure_custom<  s    z!BaseConfigurator.configure_customc             C   s"   t  | t  r t |  } n  | S)z0Utility function which converts lists to tuples.)r   r   r;  )r`   rZ   r   r   r   as_tupleJ  s    zBaseConfigurator.as_tupleN)r4   r5   r6   rc   r*   r+   rU  rJ  rM  rN  rO  rW  staticmethod
__import__r@  rb   rI  r<  r=  r5  r[  r\  r   r   r   r   r0    s"   
"r0  )r   r   )
__future__r   re   r*   r{   version_infor   
basestringrT  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'   r1   r)   r/   iostrr0   urllib.parseurllib.requesturllib.errorhttp.clientclientrequestZxmlrpc.clienthtml.parserhtml.entitiesentitiesinputsslr2   r3   rA  rR   rM   r\   r]   r/  rd   F_OKX_OKzipfiler   r   r!  r   ZBaseZipExtFiler|   r   r   r   	NameErrorcollectionsr   r   r   r   getfilesystemencodingr   r   tokenizer   codecsr   r   r+   r   r   htmlr?   cgir   r   r   reprlibr   r   impr  r  threadr   r%  dummy_threadZ_abcollr	  r
  r  r   logging.configr0  r1  Ir2  r3  r   r   r6  r;  r7  r   r   r   r   <module>   s  	(4F	@L2+!A	

				[b
 
