o za+ @sddlmZddlZddlZddlZzddlZWn ey#dZYnwejddkrddlmZe fZ e Z ddl mZddlZddlZddlmZmZmZmZmZddlmZmZmZmZmZm Z m!Z!dd Zddl"Z"dd l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+erdd l"m,Z,ddl-Z-ddl.Z.ddl/Z0dd l1m1Z1ddl2Z2e3Z3dd l4m5Z6ddl4m7Z8nddl9mZe:fZ e:Z ddl9m;ZddlZddlZddlm$Z$mZm#Z#mZmZm'Z'm(Z(m)Z)m*Z*m+Z+erdd l>m,Z,ddl?m&Z&m%Z%m Z ddl@mAZ-ddl>mBZ"ddlCmAZ.ddl0Z0dd lDm1Z1ddlEmFZ2eGZ3ddl4m8Z8e6Z6z ddlmHZHmIZIWney\GdddeJZId`ddZKddZHYnwzddl mLZMWneywGdddeNZMYnwzddllmmnZnWneycdd>lomnZnYnwejdd?d@krse1jpZpnddAlmmpZpzddBlqmrZrWn0eyddClqmsZszddDltmuZvWneydadFdGZvYnwGdHdIdIesZrYnwzddJlwmxZxWneydbdKdLZxYnwzddMlqmyZyWnBeyzddNlzm{Z|WneyddNl}m{Z|Ynwz ddOl~mZmZmZWn ey YnwGdPdQdQeZyYnwz ddRlmZmZWdSey[ejdSejZdTdUZGdVdWdWeZdbdXdYZGdZd[d[eZGd\d]d]eZGd^d_d_eNZYdSw)c)absolute_importN)StringIO)FileType)urlparse urlunparseurljoinurlsplit urlunsplit) urlretrievequoteunquote url2pathname pathname2urlContentTooShortError splittypecCst|tr |d}t|S)Nutf-8) isinstanceunicodeencode_quote)sr0/usr/lib/python3/dist-packages/distlib/compat.pyr s  r ) RequesturlopenURLError HTTPErrorHTTPBasicAuthHandlerHTTPPasswordMgr HTTPHandlerHTTPRedirectHandler build_opener) HTTPSHandler) HTMLParser)ifilter) ifilterfalse) TextIOWrapper)rrrr r r r r) rr rrrrrr r!r")rrr) filterfalse)match_hostnameCertificateErrorc@s eZdZdS)r*N)__name__ __module__ __qualname__rrrrr*_sr*c Csg}|sdS|d}|d|dd}}|d}||kr'tdt||s1||kS|dkr;|dn|d sE|d rN|t|n |t| d d |D] }|t|q\t d d |dtj } | |S)zpMatching according to RFC 6125, section 6.4.3 http://tools.ietf.org/html/rfc6125#section-6.4.3 F.rr.N*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountr*reprlowerappend startswithreescapereplacecompilejoin IGNORECASEmatch) dnhostname max_wildcardspatspartsleftmost remainder wildcardsfragpatrrr_dnsname_matchcs*     rHcCs|stdg}|dd}|D]\}}|dkr%t||r dS||q|sJ|ddD]}|D]\}}|dkrHt||rCdS||q2q.t|dkr^td |d tt|ft|dkrntd ||d ftd )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_REQUIREDsubjectAltNamerDNSNsubject commonNamer.z&hostname %r doesn't match either of %s, zhostname %r doesn't match %rrz=no appropriate commonName or subjectAltName fields were found) ValueErrorgetrHr5lenr*r;mapr3)certr?dnsnamessankeyvaluesubrrrr)s8          r))SimpleNamespacec@eZdZdZddZdS) ContainerzR A generic container for when multiple values need to be returned cKs|j|dSN__dict__update)selfkwargsrrr__init__szContainer.__init__N)r+r,r-__doc__rarrrrrZs rZ)whichc s"dd}tjr||rSdS|durtjdtj}|s#dS|tj}tj dkr^tj |vr:| dtj tjddtj}t fd d |DrTg}n fd d |D}ng}t }|D](}tj|}||vr|||D]} tj|| } || |r| SqyqfdS) aKGiven 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. cSs&tj|ot||otj| Sr[)ospathexistsaccessisdir)fnmoderrr _access_checks zwhich.._access_checkNPATHwin32rPATHEXTc3s"|] }|VqdSr[)r4endswith.0extcmdrr s zwhich..csg|]}|qSrrrqrtrr zwhich..)rdredirnameenvironrOdefpathr1pathsepsysplatformcurdirinsertanysetnormcaseaddr;) rurjrerkpathextfilesseendirnormdirthefilenamerrtrrcs<         rc)ZipFile __enter__) ZipExtFilec@$eZdZddZddZddZdS)rcCs|j|jdSr[r\)r_baserrrrazZipExtFile.__init__cC|Sr[rr_rrrrzZipExtFile.__enter__cG |dSr[closer_exc_inforrr__exit__ zZipExtFile.__exit__N)r+r,r-rarrrrrrrs rc@r)rcCrr[rrrrrr#rzZipFile.__enter__cGrr[rrrrrr&rzZipFile.__exit__cOs tj|g|Ri|}t|Sr[) BaseZipFileopenr)r_argsr`rrrrr*sz ZipFile.openN)r+r,r-rrrrrrrr"s r)python_implementationcCs0dtjvrdStjdkrdStjdrdSdS)z6Return a string identifying the Python implementation.PyPyjavaJython IronPythonCPython)r}versionrdrr6rrrrr1s   r)CallablecCs t|tSr[)rr)objrrrcallableC rrmbcsstrictsurrogateescapecC6t|tr|St|tr|ttStdt|jNzexpect bytes or str, not %s) rbytes text_typer _fsencoding _fserrors TypeErrortyper+filenamerrrfsencodeW   rcCrr) rrrdecoderrrrr+rrrrfsdecode`rr)detect_encoding)BOM_UTF8lookupzcoding[:=]\s*([-\w.]+)cCsH|dddd}|dks|drdS|dvs |dr"d S|S) z(Imitates get_normal_name in tokenizer.c.N _-rzutf-8-)zlatin-1 iso-8859-1z iso-latin-1)zlatin-1-z iso-8859-1-z iso-latin-1-r)r4r9r6)orig_encencrrr_get_normal_nameqsrcszjjWn tydYnwdd}d}fdd}fdd}|}|tr7d|d d}d }|s=|gfS||}|rH||gfS|}|sR||gfS||}|r^|||gfS|||gfS) 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. NFrcszWStyYdSw)N) StopIterationr)readlinerr read_or_stops  z%detect_encoding..read_or_stopcsz|d}Wntyd}durd|}t|wt|}|s(dSt|d}zt|}WntyQdurGd|}t|d|}t|wrp|j dkrldurcd}t|d}t||d 7}|S) Nrz'invalid or missing encoding declarationz {} for {!r}rzunknown encoding: zunknown encoding for {!r}: {}zencoding problem: utf-8z encoding problem for {!r}: utf-8z-sig) rUnicodeDecodeErrorformat SyntaxError cookie_refindallrr LookupErrorr)line line_stringmsgmatchesencodingcodec) bom_foundrrr find_cookies@        z$detect_encoding..find_cookieTrz utf-8-sig)__self__rAttributeErrorr6r)rrdefaultrrfirstsecondr)rrrrr|s6   &      r)r8)r)unescape)ChainMap)MutableMapping)recursive_repr...csfdd}|S)zm Decorator to make a repr function return fillvalue for a recursive call csLtfdd}td|_td|_td|_tdi|_|S)Nc sJt|tf}|vr S|z |}W||S|wr[)id get_identrdiscard)r_rUresult) fillvalue repr_running user_functionrrwrappers    z=_recursive_repr..decorating_function..wrapperr,rbr+__annotations__)rgetattrr,rbr+r)rrr)rrrdecorating_functions  z,_recursive_repr..decorating_functionr)rrrrr_recursive_reprs rc@seZdZdZddZddZddZd'd d Zd d Zd dZ ddZ ddZ e ddZ eddZddZeZddZeddZddZdd Zd!d"Zd#d$Zd%d&ZdS)(ra 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. cGst|pig|_dS)zInitialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. N)listmaps)r_rrrrraszChainMap.__init__cCst|r[)KeyErrorr_rUrrr __missing__szChainMap.__missing__c Cs6|jD]}z||WStyYqw||Sr[)rrr)r_rUmappingrrr __getitem__s   zChainMap.__getitem__NcCs||vr||S|Sr[rr_rUrrrrrO$sz ChainMap.getcCttj|jSr[)rPrunionrrrrr__len__'rzChainMap.__len__cCrr[)iterrrrrrrr__iter__*rzChainMap.__iter__cstfdd|jDS)Nc3s|]}|vVqdSr[r)rrmrUrrrv.sz(ChainMap.__contains__..rrrrrr __contains__-szChainMap.__contains__cCs t|jSr[rrrrr__bool__0rzChainMap.__bool__cCsd|dtt|jS)Nz{0.__class__.__name__}({1})rM)rr;rQr3rrrrr__repr__3szChainMap.__repr__cGs|tj|g|RS)z?Create a ChainMap with a single dict created from the iterable.)dictfromkeys)clsiterablerrrrr8szChainMap.fromkeyscCs&|j|jdg|jddRS)zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]rr.N) __class__rcopyrrrrr=s&z ChainMap.copycCs|jig|jRS)z;New ChainMap with a new dict followed by all previous maps.rrrrrr new_childCszChainMap.new_childcCs|j|jddS)zNew ChainMap from maps[1:].r.Nr rrrrparentsGszChainMap.parentscCs||jd|<dS)Nr)r)r_rUrVrrr __setitem__LrzChainMap.__setitem__cCs0z |jd|=WdStytd|w)Nr(Key not found in the first mapping: {!r})rrrrrrr __delitem__Os  zChainMap.__delitem__cCs(z|jdWStytdw)zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.rz#No keys found in the first mapping.)rpopitemrrrrrrUs  zChainMap.popitemcGs8z |jdj|g|RWStytd|w)zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].rr )rpoprr)r_rUrrrrr\s  z ChainMap.popcCs|jddS)z'Clear maps[0], leaving maps[1:] intact.rN)rclearrrrrrczChainMap.clearr[)r+r,r-rbrarrrOrrrrrr classmethodrr__copy__r propertyr r rrrrrrrrrs0      r)cache_from_sourcecCs6|dsJ|dur d}|rd}||Sd}||S)Nz.pyTco)rp)redebug_overridesuffixrrrrjsr) OrderedDict)r)KeysView ValuesView ItemsViewc@seZdZdZddZejfddZejfddZdd Zd d Z d d Z d6ddZ ddZ ddZ ddZddZddZddZddZeZeZefdd Zd7d"d#Zd7d$d%Zd&d'Zd(d)Zed7d*d+Zd,d-Zd.d/Zd0d1Zd2d3Z d4d5Z!d!S)8rz)Dictionary that remembers insertion ordercOspt|dkrtdt|z|jWnty-g|_}||dg|dd<i|_Ynw|j|i|dS)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)rPr_OrderedDict__rootr_OrderedDict__map_OrderedDict__update)r_rkwdsrootrrrras     zOrderedDict.__init__cCsF||vr|j}|d}|||g|d<|d<|j|<||||dS)z!od.__setitem__(i, y) <==> od[i]=yrr.N)rr )r_rUrV dict_setitemr#lastrrrr s  zOrderedDict.__setitem__cCs0||||j|\}}}||d<||d<dS)z od.__delitem__(y) <==> del od[y]r.rN)r r)r_rU dict_delitem link_prev link_nextrrrrs  zOrderedDict.__delitem__cc:|j}|d}||ur|dV|d}||us dSdS)zod.__iter__() <==> iter(od)r.rNrr_r#currrrrr zOrderedDict.__iter__ccr))z#od.__reversed__() <==> reversed(od)rrNr*r+rrr __reversed__r-zOrderedDict.__reversed__cCsbz |jD]}|dd=q|j}||dg|dd<|jWn ty)Ynwt|dS)z.od.clear() -> None. Remove all items from od.N)r  itervaluesrrrr)r_noder#rrrrs  zOrderedDict.clearTcCs||std|j}|r|d}|d}||d<||d<n|d}|d}||d<||d<|d}|j|=t||}||fS)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. zdictionary is emptyrr.r)rrr rr)r_r%r#linkr'r(rUrVrrrrs   zOrderedDict.popitemcCt|S)zod.keys() -> list of keys in od)rrrrrkeyszOrderedDict.keyscfddDS)z#od.values() -> list of values in odcsg|]}|qSrrrrrUrrrrwrxz&OrderedDict.values..rrrrrvaluesrzOrderedDict.valuescr5)z.od.items() -> list of (key, value) pairs in odcsg|]}||fqSrrr6rrrrwz%OrderedDict.items..rrrrritemsrzOrderedDict.itemscCr2)z0od.iterkeys() -> an iterator over the keys in od)rrrrriterkeysr4zOrderedDict.iterkeysccs|D]}||VqdS)z2od.itervalues -> an iterator over the values in odNrr_krrrr/s zOrderedDict.itervaluesccs|D] }|||fVqdS)z=od.iteritems -> an iterator over the (key, value) items in odNrr;rrr iteritemsszOrderedDict.iteritemscOst|dkrtdt|f|std|d}d}t|dkr%|d}t|tr6|D]}||||<q,nt|drI|D]}||||<q?n |D]\}}|||<qK|D]\}}|||<qXdS) aod.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 rz8update() takes at most 2 positional arguments (%d given)z,update() takes at least 1 argument (0 given)rrr.r3N)rPrrrhasattrr3r9)rr"r_otherrUrVrrrr^s.        zOrderedDict.updatecCs0||vr ||}||=|S||jurt||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_rUrrrrrr&s zOrderedDict.popNcCs||vr||S|||<|S)zDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in odrrrrr setdefault3szOrderedDict.setdefaultcCsj|si}t|tf}||vrdSd||<z|s#d|jjfW||=Sd|jj|fW||=S||=w)zod.__repr__() <==> repr(od)rr.z%s()z%s(%r))r _get_identrr+r9)r_ _repr_runningcall_keyrrrr:szOrderedDict.__repr__csXfddD}t}ttD]}||dq|r&j|f|fSj|ffS)z%Return state information for picklingcsg|]}||gqSrrrrr<rrrrwJr8z*OrderedDict.__reduce__..N)varsrrrr)r_r9 inst_dictr<rrr __reduce__Hs  zOrderedDict.__reduce__cCs ||S)z!od.copy() -> a shallow copy of od)rrrrrrR zOrderedDict.copycCs|}|D]}|||<q|S)zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S and values equal to v (which defaults to None). r)rrrVdrUrrrrVs zOrderedDict.fromkeyscCs6t|trt|t|ko||kSt||S)zod.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. )rrrPr9r__eq__r_r?rrrrKas   zOrderedDict.__eq__cCs ||k Sr[rrLrrr__ne__jrzOrderedDict.__ne__cCr2)z@od.viewkeys() -> a set-like object providing a view on od's keys)rrrrrviewkeysor4zOrderedDict.viewkeyscCr2)z an object providing a view on od's values)rrrrr viewvaluessr4zOrderedDict.viewvaluescCr2)zBod.viewitems() -> a set-like object providing a view on od's items)rrrrr viewitemswr4zOrderedDict.viewitems)Tr[)"r+r,r-rbrarr rrr.rrr3r7r9r:r/r=r^r!objectr@rrArrHrrrrKrMrNrOrPrrrrrs<           r)BaseConfigurator valid_identz^[a-z_][a-z0-9_]*$cCst|}|s td|dS)Nz!Not a valid Python identifier: %rT) IDENTIFIERr=rN)rrrrrrSs  rSc@s"eZdZdZddZdddZdS)ConvertingDictz A converting dictionary wrapper.cCJt||}|j|}||ur#|||<t|tttfvr#||_||_ |Sr[) rr configuratorconvertrrUConvertingListConvertingTupleparentrUr_rUrVrrrrr   zConvertingDict.__getitem__NcCsLt|||}|j|}||ur$|||<t|tttfvr$||_||_ |Sr[) rrOrWrXrrUrYrZr[rUr_rUrrVrrrrrOs  zConvertingDict.getr[)r+r,r-rbrrOrrrrrUs rUcCsDt|||}|j|}||ur t|tttfvr ||_||_ |Sr[) rrrWrXrrUrYrZr[rUr^rrrrs  rc@s"eZdZdZddZdddZdS) rYzA converting list wrapper.cCrVr[) rrrWrXrrUrYrZr[rUr\rrrrr]zConvertingList.__getitem__cCs<t||}|j|}||urt|tttfvr||_|Sr[) rrrWrXrrUrYrZr[)r_idxrVrrrrrs   zConvertingList.popN)r_)r+r,r-rbrrrrrrrYs rYc@rY)rZzA converting tuple wrapper.cCsBt||}|j|}||urt|tttfvr||_||_ |Sr[) tuplerrWrXrrUrYrZr[rUr\rrrrs   zConvertingTuple.__getitem__N)r+r,r-rbrrrrrrZs rZc@seZdZdZedZedZedZedZ edZ ddd Z e e Zd d Zd d ZddZddZddZddZddZdS)rRzQ The configurator base class which defines some useful defaults. z%^(?P[a-z]+)://(?P.*)$z ^\s*(\w+)\s*z^\.\s*(\w+)\s*z^\[\s*(\w+)\s*\]\s*z^\d+$ ext_convert cfg_convert)rscfgcCst||_||j_dSr[)rUconfigrW)r_rerrrras  zBaseConfigurator.__init__c Cs|d}|d}z-||}|D]"}|d|7}zt||}Wqty4||t||}Yqw|WStyYtdd\}}td||f}|||_ |_ |w)zl Resolve strings to objects using standard import and attribute syntax. r/rr.NzCannot resolve %r: %s) r1rimporterrr ImportErrorr}rrN __cause__ __traceback__) r_rrusedfoundrFetbvrrrresolves&       zBaseConfigurator.resolvecCs ||S)z*Default converter for the ext:// protocol.)ror_rVrrrrbrIzBaseConfigurator.ext_convertcCs|}|j|}|durtd|||d}|j|d}|r||j|}|r6||d}n1|j|}|rg|d}|j|sO||}nz t |}||}Wn t yf||}Ynw|rr||d}ntd||f|s%|S)z*Default converter for the cfg:// protocol.NzUnable to convert %rrzUnable to convert %r at %r) WORD_PATTERNr=rNendregroups DOT_PATTERN INDEX_PATTERN DIGIT_PATTERNintr)r_rVrestrrJr`nrrrrc s8          zBaseConfigurator.cfg_convertcCst|tst|trt|}||_|St|ts&t|tr&t|}||_|St|ts9t|tr9t|}||_|St|trd|j |}|rd| }|d}|j |d}|rd|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)rrUrrWrYrrZra string_typesCONVERT_PATTERNr= groupdictvalue_convertersrOr)r_rVrrJrz converterrrrrrX.s2   zBaseConfigurator.convertcsrd}t|s||}dd}tfddD}|di|}|r7|D] \}}t|||q,|S)z1Configure an object with a user-supplied factory.z()r/Ncs g|] }t|r||fqSr)rSrErerrrwQs z5BaseConfigurator.configure_custom..r)rrrorr9setattr)r_rerpropsr`rrrVrrrconfigure_customJs   z!BaseConfigurator.configure_customcCst|tr t|}|S)z0Utility function which converts lists to tuples.)rrrarprrras_tupleXs zBaseConfigurator.as_tupleN)r+r,r-rbr7r:r|rqrtrurvr~ staticmethod __import__rfrarorbrcrXrrrrrrrRs$     " rR)r.)rr[) __future__rrdr7r}sslrg version_infor basestringr{rrtypesr file_type __builtin__builtins ConfigParser configparserrrrr r urllibr r rr rrrrurllib2rrrrrrr r!r"r#httplib xmlrpclibQueuequeuer$htmlentitydefs raw_input itertoolsr%filterr&r(iostrr'shutil urllib.parseurllib.request urllib.error http.clientclientrequest xmlrpc.client html.parser html.entitiesentitiesinputr)r*rNrHrXrZrQrcF_OKX_OKzipfilerrr>rBaseZipExtFiler~r sysconfigr NameErrorcollections.abcrrrrgetfilesystemencodingrrtokenizercodecsrrr:rrhtmlr8cgir collectionsrrreprlibrrimportlib.utilrrthreadrrB dummy_thread_abcollrrrrlogging.configrRrSIrTrUrrrYrarZrrrrsB     $,     (0         2b  C             l