U ÀÒ.eøëã@s¸ddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZz ddlZWnek rŒdZYnXddlZddlZddlZddlZddlZz ddlZWnek rÞddlZYnXddlZddlmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e  1e2¡Z3e  4d¡Z5e  4d¡Z6e  4d ¡Z7e  4d ¡Z8e  4d ¡Z9e  4d ¡Z:e  4d ¡Z;e  4d¡Zdd„Z?dd„Z@dd„ZAdˆdd„ZBdd„ZCdd„ZDdd „ZEejFd!d"„ƒZGejFd#d$„ƒZHejFd‰d&d'„ƒZIGd(d)„d)eJƒZKd*d+„ZLGd,d-„d-eJƒZMd.d/„ZNGd0d1„d1eJƒZOe  4d2e jP¡ZQd3d4„ZRdŠd5d6„ZSd7d8„ZTd9d:„ZUd;d<„ZVd=d>„ZWd?d@„ZXe  4dAe jY¡ZZe  4dB¡Z[d‹dCdD„Z\e  4dE¡Z]dFdG„Z^dHdI„Z_dJdK„Z`dLZadMdN„ZbdOdP„ZcGdQdR„dReJƒZdGdSdT„dTeJƒZeGdUdV„dVeJƒZfdWZgdŒdYdZ„Zhd[d\„Zid]ZjGd^d_„d_eJƒZke  4d`¡Zle  4da¡Zme  4db¡Zndcdd„Zdedf„ZoerÖddglmpZqmrZrmsZsGdhdi„die$jtƒZtGdjdk„dkeqƒZpGdldm„dmepe'ƒZuejvddn…ZwewdokrGdpdq„dqe$jxƒZxerGdrds„dse$jyƒZyGdtdu„due%jzƒZzerBGdvdw„dwe%j{ƒZ{Gdxdy„dye%j|ƒZ|dzd{„Z}Gd|d}„d}eJƒZ~Gd~d„de~ƒZGd€d„de~ƒZ€Gd‚dƒ„dƒe(ƒZGd„d…„d…eJƒZ‚d†d‡„ZƒdS)éN)Údeque)Úiglobé)ÚDistlibException)Ú string_typesÚ text_typeÚshutilÚ raw_inputÚStringIOÚcache_from_sourceÚurlopenÚurljoinÚhttplibÚ xmlrpclibÚ splittypeÚ HTTPHandlerÚBaseConfiguratorÚ valid_identÚ ContainerÚ configparserÚURLErrorÚZipFileÚfsdecodeÚunquoteÚurlparsez^([\w\.-]+)\s*z^([\w\.*+-]+)\s*z^(<=?|>=?|={2,3}|[~!]=)\s*z*^((<=?)|(>=?)|={2,3}|[~!]=|in|not\s+in)\s*z^or\b\s*z ^and\b\s*z(\S+)\s*z(([\s\w\.{}()*+#:;,/?!~`@$%^&=|<>\[\]-]+)cs6dd„‰‡‡fdd„‰‡fdd„‰‡fdd„‰ˆ|ƒS) ae Parse a marker string and return a dictionary containing a marker expression. The dictionary will contain keys "op", "lhs" and "rhs" for non-terminals in the expression grammar, or strings. A string contained in quotes is to be interpreted as a literal string, and a string not contained in quotes is a variable (such as os_name). cSs.t |¡}|r,| ¡d}|| ¡d…}nú|s:tdƒ‚nì|d}|dkrVtd|ƒ‚d |d¡}|dd…}|g}|rì|d|krŠqqt|d|kr®| |¡|dd…}qtt |¡}|sÈtd|ƒ‚| | ¡d¡|| ¡d…}qtd |¡}td|ƒ‚| |¡d |¡}|dd…  ¡}||fS) Nrzunexpected end of inputz'"zinvalid expression: %sÚrzerror in string literal: %szunterminated string: %s) Ú IDENTIFIERÚmatchÚgroupsÚendÚ SyntaxErrorÚreplaceÚappendÚ STRING_CHUNKÚjoinÚlstrip)Ú remainingÚmÚresultÚqZoqÚpartsÚs©r,ú.marker_varcs´|rR|ddkrRˆ|dd… ¡ƒ\}}|ddkr@td|ƒ‚|dd… ¡}nZˆ|ƒ\}}|r¨t |¡}|srq¨| ¡d}|| ¡d…}ˆ|ƒ\}}|||dœ}q^|}||fS)Nrú(rú)úunterminated parenthesis: %s©ÚopÚlhsÚrhs)r%r Ú MARKER_OPrrr)r&r(r4r'r3r5)Úmarkerr.r,r-Ú marker_expres       z!parse_marker..marker_exprcsRˆ|ƒ\}}|rJt |¡}|s qJ|| ¡d…}ˆ|ƒ\}}d||dœ}q ||fS)NÚandr2)ÚANDrr©r&r4r'r5)r8r,r-Ú marker_andxs   z parse_marker..marker_andcsRˆ|ƒ\}}|rJt |¡}|s qJ|| ¡d…}ˆ|ƒ\}}d||dœ}q ||fS)NÚorr2)ÚORrrr;)r<r,r-r7ƒs   zparse_marker..markerr,)Z marker_stringr,)r7r<r8r.r-Ú parse_marker8s $ r?cCs0| ¡}|r| d¡rdSt |¡}|s4td|ƒ‚| ¡d}|| ¡d…}d}}}}|r:|ddkr:| dd¡}|dkr”td|ƒ‚|d|…} ||dd… ¡}g}| r0t | ¡}|sØtd | ƒ‚|  | ¡d¡| | ¡d…} | sq0| dd krtd | ƒ‚| dd… ¡} q¸|s:d}|r˜|dd krÀ|dd… ¡}t  |¡}|sztd |ƒ‚| ¡d}t |ƒ} | j rž| j sªtd|ƒ‚|| ¡d… ¡}nØdd„} |ddkrä| |ƒ\}}n´| dd¡}|dkrtd|ƒ‚|d|…} ||dd… ¡}t | ¡r@| | ƒ\}} nXt | ¡}|s\td| ƒ‚| ¡d} | | ¡d… ¡} | rŽtd| ƒ‚d| fg}|rÔ|ddkr¸td|ƒ‚|dd… ¡}t|ƒ\}}|rô|ddkrôtd|ƒ‚|s|}nd|d dd„|Dƒ¡f}t||||||dS)zŠ Parse a requirement passed in as a string. Return a Container whose attributes contain the various parts of the requirement. ú#Nzname expected: %srú[ú]rzunterminated extra: %szmalformed extra: %sú,zcomma expected in extras: %sú@zinvalid URI: %szInvalid URL: %scSsÄt |¡}d}|r¼g}| ¡d}|| ¡d…}t |¡}|sLtd|ƒ‚| ¡d}| ||f¡|| ¡d…}|r´|ddkrˆq´|dd… ¡}t |¡}|std|ƒ‚q|s¼d}||fS)z| Return a list of operator, version tuples if any are specified, else None. Nrzinvalid version: %srCrúinvalid constraint: %s)Ú COMPARE_OPrrrÚVERSION_IDENTIFIERr r"r%)Z ver_remainingr'Úversionsr3Úvr,r,r-Ú get_versionsÅs*      z'parse_requirement..get_versionsr/r0r1rEz~=ú;zinvalid requirement: %szunexpected trailing data: %sú%s %sú, cSsg|] }d|‘qS)rLr,)Ú.0Zconr,r,r-Ú sz%parse_requirement..)ÚnameÚextrasZ constraintsr7ÚurlZ requirement)ÚstripÚ startswithrrr rrÚfindr%r"Ú NON_SPACErÚschemeÚnetlocrFrGr?r$r)Úreqr&r'ZdistnamerQZ mark_exprrHÚuriÚir+ÚtrJÚ_rIZrsr,r,r-Úparse_requirement‘s’                          ÿr^cCs¨dd„}i}|D]’\}}}tj ||¡}t|ƒD]p}tj ||¡} t| ƒD]T} ||| ƒ} |dkrn| | d¡qJ||| ƒ} | tjjd¡ d¡} | d| || <qJq0q|S)z%Find destinations for resources filescSs6| tjjd¡}| tjjd¡}|t|ƒd… d¡S©Nú/)r!ÚosÚpathÚsepÚlenr%)Úrootrbr,r,r-Ú get_rel_path sz)get_resources_dests..get_rel_pathNr`)rarbr$rÚpopr!rcÚrstrip)Zresources_rootZrulesrfZ destinationsÚbaseÚsuffixÚdestÚprefixZabs_baseZabs_globZabs_pathZ resource_fileZrel_pathZrel_destr,r,r-Úget_resources_dests s    rmcCs(ttdƒrd}ntjttdtjƒk}|S)NZ real_prefixTÚ base_prefix)ÚhasattrÚsysrlÚgetattr©r(r,r,r-Úin_venv$s rscCs$tj tj¡}t|tƒs t|ƒ}|S©N)rarbÚnormcaserpÚ executableÚ isinstancerrrrr,r,r-Úget_executable.s  rxcCsN|}t|ƒ}|}|s|r|}|r|d ¡}||kr6qJ|rd|||f}q|S)Nrz %c: %s %s)r Úlower)ÚpromptZ allowed_charsZ error_promptÚdefaultÚpr+Úcr,r,r-Úproceed>s r~cCs8t|tƒr| ¡}i}|D]}||kr||||<q|Srt)rwrÚsplit)ÚdÚkeysr(Úkeyr,r,r-Úextract_by_keyNs rƒcCs`tjddkrt d¡|ƒ}| ¡}t|ƒ}z`t |¡}|ddd}| ¡D]6\}}| ¡D]$\}}d||f}t |ƒ} | ||<q`qP|WSt k r¬|  dd¡YnXdd „} t   ¡} z| | |ƒWn<t jk r| ¡t |¡}t|ƒ}| | |ƒYnXi}|  ¡D]D} i|| <}|  | ¡D]&\} }d| |f}t |ƒ} | || <q0q|S) Nréúutf-8Ú extensionszpython.exportsÚexportsz%s = %scSs$t|dƒr| |¡n | |¡dS)NÚ read_file)rorˆZreadfp)ÚcpÚstreamr,r,r-Ú read_streamks  z!read_exports..read_stream)rpÚ version_infoÚcodecsÚ getreaderÚreadr ÚjsonÚloadÚitemsÚget_export_entryÚ ExceptionÚseekrÚ ConfigParserZMissingSectionHeaderErrorÚcloseÚtextwrapÚdedentZsections)rŠÚdataZjdatar(ÚgroupÚentriesÚkrIr+Úentryr‹r‰r‚rPÚvaluer,r,r-Ú read_exportsWs@       r cCs¨tjddkrt d¡|ƒ}t ¡}| ¡D]l\}}| |¡| ¡D]P}|j dkr\|j }nd|j |j f}|j r†d|d  |j ¡f}|  ||j|¡qFq,| |¡dS)Nrr„r…z%s:%sz%s [%s]rM)rprŒrÚ getwriterrr–r’Z add_sectionÚvaluesrjrlÚflagsr$ÚsetrPÚwrite)r‡rŠr‰rrIržr+r,r,r-Ú write_exports†s   r¦c cs$t ¡}z |VW5t |¡XdSrt)ÚtempfileÚmkdtemprÚrmtree)Ztdr,r,r-Útempdir™s rªc cs.t ¡}zt |¡dVW5t |¡XdSrt)raÚgetcwdÚchdir)r€Úcwdr,r,r-r¬¡s   r¬éc cs.t ¡}zt |¡dVW5t |¡XdSrt)ÚsocketZgetdefaulttimeoutZsetdefaulttimeout)ZsecondsZctor,r,r-Úsocket_timeout«s   r°c@seZdZdd„Zddd„ZdS)Úcached_propertycCs ||_dSrt)Úfunc)Úselfr²r,r,r-Ú__init__¶szcached_property.__init__NcCs,|dkr |S| |¡}t ||jj|¡|Srt)r²ÚobjectÚ __setattr__Ú__name__)r³ÚobjÚclsrŸr,r,r-Ú__get__»s  zcached_property.__get__)N)r·Ú __module__Ú __qualname__r´rºr,r,r,r-r±µsr±cCs~tjdkr|S|s|S|ddkr.td|ƒ‚|ddkrFtd|ƒ‚| d¡}tj|krh| tj¡qP|srtjStjj|ŽS)aÐReturn 'pathname' as a name that will work on the native filesystem. The path is split on '/' and put back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. r`rzpath '%s' cannot be absoluteéÿÿÿÿzpath '%s' cannot end with '/')rarcÚ ValueErrorrÚcurdirÚremoverbr$)ÚpathnameÚpathsr,r,r-Ú convert_pathÃs       rÃc@s”eZdZd$dd„Zdd„Zdd„Zdd „Zd%d d „Zd&dd„Zdd„Z dd„Z dd„Z dd„Z dd„Z d'dd„Zdd„Zdd„Zd d!„Zd"d#„Zd S)(Ú FileOperatorFcCs||_tƒ|_| ¡dSrt)Údry_runr¤ÚensuredÚ _init_record)r³rÅr,r,r-r´ßszFileOperator.__init__cCsd|_tƒ|_tƒ|_dS©NF)Úrecordr¤Ú files_writtenÚ dirs_created©r³r,r,r-rÇäszFileOperator._init_recordcCs|jr|j |¡dSrt)rÉrÊÚadd)r³rbr,r,r-Úrecord_as_writtenészFileOperator.record_as_writtencCsHtj |¡s tdtj |¡ƒ‚tj |¡s0dSt |¡jt |¡jkS)aÎTell if the target is newer than the source. Returns true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Returns false if both exist and 'target' is the same age or younger than 'source'. Raise PackagingFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". zfile '%r' does not existT)rarbÚexistsrÚabspathÚstatÚst_mtime)r³ÚsourceÚtargetr,r,r-Únewerís  ÿ zFileOperator.newerTcCsŽ| tj |¡¡t d||¡|js€d}|rdtj |¡rDd|}n tj |¡rdtj  |¡sdd|}|rtt |dƒ‚t   ||¡|  |¡dS)z8Copy a file respecting dry-run and force flags. zCopying %s to %sNz%s is a symlinkz%s is a non-regular filez which would be overwritten)Ú ensure_dirrarbÚdirnameÚloggerÚinforÅÚislinkrÏÚisfiler¾rZcopyfilerÎ)r³ZinfileÚoutfileÚcheckÚmsgr,r,r-Ú copy_files    zFileOperator.copy_fileNcCst| tj |¡¡t d||¡|jsf|dkr:t|dƒ}ntj|d|d}zt   ||¡W5|  ¡X|  |¡dS)NzCopying stream %s to %sÚwbÚw©Úencoding) rÖrarbr×rØrÙrÅÚopenrr—rZ copyfileobjrÎ)r³ZinstreamrÜrãZ outstreamr,r,r-Ú copy_streams  zFileOperator.copy_streamc Cs\| tj |¡¡|jsNtj |¡r.t |¡t|dƒ}| |¡W5QRX|  |¡dS)Nrà) rÖrarbr×rÅrÏrÀrär¥rÎ)r³rbršÚfr,r,r-Úwrite_binary_file!s   zFileOperator.write_binary_filecCs| || |¡¡dSrt)rçÚencode)r³rbršrãr,r,r-Úwrite_text_file*szFileOperator.write_text_filecCsntjdkstjdkrjtjdkrj|D]F}|jr:t d|¡q"t |¡j|B|@}t d||¡t ||¡q"dS)NÚposixÚjavazchanging mode of %szchanging mode of %s to %o) rarPÚ_namerÅrØrÙrÑÚst_modeÚchmod)r³ÚbitsÚmaskÚfilesræÚmoder,r,r-Úset_mode-szFileOperator.set_modecCs| dd|¡S)Nimiÿ)ró)r+rær,r,r-Ú9ózFileOperator.cCs|tj |¡}||jkrxtj |¡sx|j |¡tj |¡\}}| |¡t  d|¡|j sft  |¡|j rx|j  |¡dS)Nz Creating %s)rarbrÐrÆrÏrÍrrÖrØrÙrÅÚmkdirrÉrË)r³rbr€rær,r,r-rÖ;s    zFileOperator.ensure_dirc CsŠt|| ƒ}t d||¡|js||s0| ||¡rJ|s:d}n|t|ƒd…}i}|rhttdƒrhtjj |d<tj |||df|Ž|  |¡|S)NzByte-compiling %s to %sÚPycInvalidationModeÚinvalidation_modeT) r rØrÙrÅrÕrdroÚ py_compiler÷Ú CHECKED_HASHÚcompilerÎ) r³rbÚoptimizeÚforcerlZhashed_invalidationZdpathZdiagpathZcompile_kwargsr,r,r-Ú byte_compileGs   zFileOperator.byte_compilecCs²tj |¡r®tj |¡r^tj |¡s^t d|¡|js@t  |¡|j r®||j kr®|j   |¡nPtj |¡rpd}nd}t d||¡|js’t  |¡|j r®||j kr®|j   |¡dS)NzRemoving directory tree at %sÚlinkÚfilezRemoving %s %s)rarbrÏÚisdirrÚrØÚdebugrÅrr©rÉrËrÀrÊ)r³rbr+r,r,r-Úensure_removedXs"       zFileOperator.ensure_removedcCsDd}|s@tj |¡r$t |tj¡}q@tj |¡}||kr:q@|}q|SrÈ)rarbrÏÚaccessÚW_OKr×)r³rbr(Úparentr,r,r-Ú is_writablems  zFileOperator.is_writablecCs|j|jf}| ¡|S)zV Commit recorded changes, turn off recording, return changes. )rÊrËrÇ)r³r(r,r,r-Úcommitys zFileOperator.commitcCs„|jsxt|jƒD]}tj |¡rt |¡qt|jdd}|D]8}t  |¡}|rltj  ||d¡}t  |¡t  |¡q>|  ¡dS)NT)Úreverser) rÅÚlistrÊrarbrÏrÀÚsortedrËÚlistdirr$ÚrmdirrÇ)r³ræÚdirsr€ÚflistZsdr,r,r-Úrollbackƒs     zFileOperator.rollback)F)T)N)FFNF)r·r»r¼r´rÇrÎrÕrßrårçréróZset_executable_moderÖrþrrrrr,r,r,r-rÄÞs         rÄcCs^|tjkrtj|}nt|ƒ}|dkr,|}n.| d¡}t|| d¡ƒ}|D]}t||ƒ}qJ|S)NÚ.r)rpÚmodulesÚ __import__rrqrg)Z module_nameZ dotted_pathÚmodr(r*r|r,r,r-Úresolve•s    rc@s6eZdZdd„Zedd„ƒZdd„Zdd„Zej Z d S) Ú ExportEntrycCs||_||_||_||_dSrt©rPrlrjr£)r³rPrlrjr£r,r,r-r´¥szExportEntry.__init__cCst|j|jƒSrt)rrlrjrÌr,r,r-rŸ«szExportEntry.valuecCsd|j|j|j|jfS)NzrrÌr,r,r-Ú__repr__¯s ÿzExportEntry.__repr__cCsDt|tƒsd}n0|j|jko>|j|jko>|j|jko>|j|jk}|SrÈ)rwrrPrlrjr£)r³Úotherr(r,r,r-Ú__eq__³s   ÿ þ ýzExportEntry.__eq__N) r·r»r¼r´r±rŸrrrµÚ__hash__r,r,r,r-r¤s   rzµ(?P(\w|[-.+])+) \s*=\s*(?P(\w+)([:\.]\w+)*) \s*(\[\s*(?P\w+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])? c Csàt |¡}|s0d}d|ks"d|krÜtd|ƒ‚n¬| ¡}|d}|d}| d¡}|dkrf|d}}n"|dkrztd|ƒ‚| d¡\}}|d } | dkrºd|ks¨d|kr´td|ƒ‚g} nd d „|  d ¡Dƒ} t|||| ƒ}|S) NrArBzInvalid specification '%s'rPÚcallableú:rrr£cSsg|] }| ¡‘qSr,)rS)rNrær,r,r-rOßsz$get_export_entry..rC)ÚENTRY_REÚsearchrÚ groupdictÚcountrr) Z specificationr'r(r€rPrbZcolonsrlrjr£r,r,r-r“Ås8 ÿ  ÿÿr“cCsÈ|dkr d}tjdkr.dtjkr.tj d¡}n tj d¡}tj |¡rft |tj¡}|s¢t   d|¡n| dd¡\}}d|kr.|}n| dd¡\}}|rJt|ƒ}|rVt|ƒ}|||fS)NrDrr)Úrsplitrr)rXZusernameZpasswordrlr,r,r-Úparse_credentials$sr1cCst d¡}t |¡|S)Né)raÚumaskrrr,r,r-Úget_process_umask3s  r4cCs0d}d}t|ƒD]\}}t|tƒsd}q,q|S)NTF)Ú enumeraterwr)Úseqr(r[r+r,r,r-Úis_string_sequence8s r7z3([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)z -py(\d\.?\d?)cCsÈd}d}t|ƒ dd¡}t |¡}|r@| d¡}|d| ¡…}|r˜t|ƒt|ƒdkr˜t t  |¡d|¡}|r˜|  ¡}|d|…||dd…|f}|dkrÄt  |¡}|rÄ| d¡| d¡|f}|S)zw Extract name, version, python version from a filename (no extension) Return name, version, pyver or None Nú ú-rz\br„) rr!ÚPYTHON_VERSIONrr›ÚstartrdÚrerÚescaperÚPROJECT_NAME_AND_VERSION)ÚfilenameZ project_namer(Zpyverr'Únr,r,r-Úsplit_filenameGs"   rAz-(?P[\w .-]+)\s*\(\s*(?P[^\s)]+)\)$cCs:t |¡}|std|ƒ‚| ¡}|d ¡ ¡|dfS)zÇ A utility method used to get name and version from a string. From e.g. a Provides-Dist value. :param p: A value in a form 'foo (1.0)' :return: The name and version as a tuple. z$Ill-formed name/version string: '%s'rPZver)ÚNAME_VERSION_RErrr rSry)r|r'r€r,r,r-Úparse_name_and_versioncs  rCcCsºtƒ}t|pgƒ}t|pgƒ}d|kr8| d¡||O}|D]x}|dkrT| |¡q<| d¡r”|dd…}||kr€t d|¡||kr´| |¡q<||krªt d|¡| |¡q<|S)NÚ*r9rzundeclared extra: %s)r¤rÀrÍrTrØr()Z requestedZ availabler(ÚrZunwantedr,r,r-Ú get_extrasrs&        rFc Csˆi}zNt|ƒ}| ¡}| d¡}| d¡s8t d|¡nt d¡|ƒ}t  |¡}Wn0t k r‚}zt  d||¡W5d}~XYnX|S)Nz Content-Typezapplication/jsonz(Unexpected response for JSON request: %sr…z&Failed to get external data for %s: %s) r rÙÚgetrTrØrrrŽrr‘r”Ú exception)rRr(ZrespZheadersZctÚreaderÚer,r,r-Ú_get_external_data‹s   rKz'https://www.red-dove.com/pypi/projects/cCs*d|d ¡|f}tt|ƒ}t|ƒ}|S)Nz%s/%s/project.jsonr©Úupperr Ú_external_data_base_urlrK)rPrRr(r,r,r-Úget_project_data¡s rOcCs(d|d ¡||f}tt|ƒ}t|ƒS)Nz%s/%s/package-%s.jsonrrL)rPÚversionrRr,r,r-Úget_package_data§s rQc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚCachezæ A class implementing a cache for resources that need to live in the file system e.g. shared libraries. This class was moved from resources to here because it could be used by other modules, e.g. the wheel module. cCsPtj |¡st |¡t |¡jd@dkr6t d|¡tj tj  |¡¡|_ dS)zu Initialise an instance. :param base: The base directory where the cache should be located. é?rzDirectory '%s' is not privateN) rarbrr)rÑrírØr(rÐÚnormpathri)r³rir,r,r-r´´s    zCache.__init__cCst|ƒS)zN Converts a resource prefix to a directory name in the cache. )r-)r³rlr,r,r-Ú prefix_to_dirÂszCache.prefix_to_dirc Csˆg}t |j¡D]r}tj |j|¡}z>tj |¡s>tj |¡rJt |¡ntj |¡r`t   |¡Wqt k r€|  |¡YqXq|S)z" Clear the cache. ) rar rirbr$rÚrÛrÀrrr©r”r")r³Z not_removedÚfnr,r,r-ÚclearÈs  z Cache.clearN)r·r»r¼Ú__doc__r´rUrWr,r,r,r-rR­srRc@s:eZdZdZdd„Zddd„Zdd„Zd d „Zd d „Zd S)Ú EventMixinz1 A very simple publish/subscribe system. cCs i|_dSrt)Ú _subscribersrÌr,r,r-r´ÝszEventMixin.__init__TcCsD|j}||krt|gƒ||<n"||}|r6| |¡n | |¡dS)a` Add a subscriber for an event. :param event: The name of an event. :param subscriber: The subscriber to be added (and called when the event is published). :param append: Whether to append or prepend the subscriber to an existing subscriber list for the event. N)rZrr"Ú appendleft)r³ÚeventÚ subscriberr"ÚsubsZsqr,r,r-rÍàs  zEventMixin.addcCs,|j}||krtd|ƒ‚|| |¡dS)z™ Remove a subscriber for an event. :param event: The name of an event. :param subscriber: The subscriber to be removed. zNo subscribers: %rN)rZr¾rÀ)r³r\r]r^r,r,r-rÀôs zEventMixin.removecCst|j |d¡ƒS)z Return an iterator for the subscribers for an event. :param event: The event to return subscribers for. r,)ÚiterrZrG)r³r\r,r,r-Úget_subscribersszEventMixin.get_subscribersc Oslg}| |¡D]F}z||f|ž|Ž}Wn"tk rHt d¡d}YnX| |¡qt d||||¡|S)a^ Publish a event and return a list of values returned by its subscribers. :param event: The event to publish. :param args: The positional arguments to pass to the event's subscribers. :param kwargs: The keyword arguments to pass to the event's subscribers. z"Exception during event publicationNz/publish %s: args = %s, kwargs = %s, result = %s)r`r”rØrHr"r)r³r\ÚargsÚkwargsr(r]rŸr,r,r-Úpublishs    ÿzEventMixin.publishN)T) r·r»r¼rXr´rÍrÀr`rcr,r,r,r-rYÙs   rYc@s^eZdZdd„Zdd„Zddd„Zdd „Zd d „Zd d „Zdd„Z e dd„ƒZ e dd„ƒZ dS)Ú SequencercCsi|_i|_tƒ|_dSrt)Ú_predsÚ_succsr¤Ú_nodesrÌr,r,r-r´"szSequencer.__init__cCs|j |¡dSrt)rgrÍ©r³Únoder,r,r-Úadd_node'szSequencer.add_nodeFcCs®||jkr|j |¡|rªt|j |d¡ƒD]}| ||¡q,t|j |d¡ƒD]}| ||¡qPt|j ¡ƒD]\}}|sp|j|=qpt|j ¡ƒD]\}}|s”|j|=q”dS)Nr,)rgrÀr¤rerGrfr r’)r³riZedgesr|r+rrIr,r,r-Ú remove_node*s   zSequencer.remove_nodecCs0|j |tƒ¡ |¡|j |tƒ¡ |¡dSrt)reÚ setdefaultr¤rÍrf)r³ÚpredÚsuccr,r,r-rÍ:sz Sequencer.addcCs|z|j|}|j|}Wn tk r8td|ƒ‚YnXz| |¡| |¡Wn$tk rvtd||fƒ‚YnXdS)Nz%r not a successor of anythingz%r not a successor of %r)rerfÚKeyErrorr¾rÀ)r³rmrnÚpredsZsuccsr,r,r-rÀ?s  zSequencer.removecCs||jkp||jkp||jkSrt)rerfrg)r³Ústepr,r,r-Úis_stepLsÿzSequencer.is_stepcCs˜| |¡std|ƒ‚g}g}tƒ}| |¡|r| d¡}||krb||krŽ| |¡| |¡q.| |¡| |¡|j |d¡}|  |¡q.t |ƒS)Nz Unknown: %rrr,) rrr¾r¤r"rgrÀrÍrerGÚextendÚreversed)r³Úfinalr(ZtodoÚseenrqrpr,r,r-Ú get_stepsPs"         zSequencer.get_stepscsRdg‰g‰i‰i‰g‰|j‰‡‡‡‡‡‡‡fdd„‰ˆD]}|ˆkr8ˆ|ƒq8ˆS)Nrcsðˆdˆ|<ˆdˆ|<ˆdd7<ˆ |¡z ˆ|}Wntk rVg}YnX|D]J}|ˆkrˆˆ|ƒtˆ|ˆ|ƒˆ|<q\|ˆkr\tˆ|ˆ|ƒˆ|<q\ˆ|ˆ|krìg}ˆ ¡}| |¡||kr¼qÚq¼t|ƒ}ˆ |¡dS)Nrr)r"r”ÚminrgÚtuple)riZ successorsZ successorZconnected_componentZ component©ZgraphÚindexZ index_counterZlowlinksr(ÚstackÚ strongconnectr,r-r}ts,      z3Sequencer.strong_connections..strongconnect)rfrhr,rzr-Ústrong_connectionsis" zSequencer.strong_connectionscCsfdg}|jD]*}|j|}|D]}| d||f¡qq |jD]}| d|¡q>| d¡d |¡S)Nz digraph G {z %s -> %s;z %s;Ú}Ú )rer"rgr$)r³r(rnrprmrir,r,r-Údotœs    z Sequencer.dotN)F) r·r»r¼r´rjrkrÍrÀrrrwÚpropertyr~rr,r,r,r-rd!s   2rd)ú.tar.gzú.tar.bz2ú.tarú.zipú.tgzú.tbzú.whlTc sZ‡‡fdd„}tj ˆ¡‰tˆƒ‰d}|dkr†| d¡r>d}nH| d¡rRd}d}n4| d¡rfd }d }n | d ¡rzd }d }n td|ƒ‚z¾|dkrºt|d ƒ}|rä| ¡}|D] }||ƒqªn*t   ||¡}|rä|  ¡}|D] }||ƒqÖ|dkr*t j ddkr*| ¡D]"} t| jtƒs| j d¡| _qdd„} | |_| ˆ¡W5|rT| ¡XdS)NcsRt|tƒs| d¡}tj tj ˆ|¡¡}| ˆ¡rB|ˆtjkrNt d|ƒ‚dS)Nr…zpath outside destination: %r) rwrÚdecoderarbrÐr$rTrcr¾)rbr|©Údest_dirZplenr,r-Ú check_path±s   zunarchive..check_path)r†r‰Úzip)rƒr‡Ztgzzr:gz)r„rˆZtbzzr:bz2r…ZtarrEzUnknown format for %rrr„r…c SsDzt ||¡WStjk r>}ztt|ƒƒ‚W5d}~XYnXdS)z:Run tarfile.tar_fillter, but raise the expected ValueErrorN)ÚtarfileZ tar_filterZ FilterErrorr¾Ústr)ÚmemberrbÚexcr,r,r-Úextraction_filterâsz$unarchive..extraction_filter)rarbrÐrdr.r¾r—rZnamelistrräZgetnamesrprŒZ getmembersrwrPrrŠr“Z extractall) Zarchive_filenamerŒÚformatrÝrÚarchiveròÚnamesrPZtarinfor“r,r‹r-Ú unarchive¯sL           r—c Cs~t ¡}t|ƒ}t|dƒZ}t |¡D]H\}}}|D]8}tj ||¡}||d…} tj | |¡} | || ¡q4q&W5QRX|S)z*zip a directory tree into a BytesIO objectráN) ÚioÚBytesIOrdrraÚwalkrbr$r¥) Z directoryr(ZdlenZzfrerrñrPZfullZrelrkr,r,r-Úzip_diròs  r›)rÚKÚMÚGÚTÚPc@sreZdZdZddd„Zdd„Zdd „Zd d „Zd d „Ze dd„ƒZ e dd„ƒZ dd„Z e dd„ƒZ e dd„ƒZdS)ÚProgressZUNKNOWNrédcCs(||_|_||_d|_d|_d|_dS)NrF)rxÚcurÚmaxÚstartedÚelapsedÚdone)r³ZminvalZmaxvalr,r,r-r´ s  zProgress.__init__cCs0||_t ¡}|jdkr ||_n ||j|_dSrt)r£Útimer¥r¦)r³ZcurvalZnowr,r,r-Úupdates  zProgress.updatecCs| |j|¡dSrt)r©r£)r³Zincrr,r,r-Ú incrementszProgress.incrementcCs| |j¡|Srt)r©rxrÌr,r,r-r;s zProgress.startcCs |jdk r| |j¡d|_dS)NT)r¤r©r§rÌr,r,r-Ústop#s  z Progress.stopcCs|jdkr|jS|jSrt)r¤ÚunknownrÌr,r,r-Úmaximum(szProgress.maximumcCsD|jr d}n4|jdkrd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)r§r¤r£rx)r³r(rIr,r,r-Ú percentage,s zProgress.percentagecCs:|dkr|jdks|j|jkr$d}nt dt |¡¡}|S)Nrz??:??:??z%H:%M:%S)r¤r£rxr¨ÚstrftimeÚgmtime)r³Zdurationr(r,r,r-Úformat_duration7szProgress.format_durationcCs‚|jrd}|j}n^d}|jdkr&d}nJ|jdks<|j|jkrBd}n.t|j|jƒ}||j|j}|d|j}d|| |¡fS)NZDonezETA r½rrz%s: %s)r§r¦r¤r£rxÚfloatr±)r³rlr\r,r,r-ÚETA@s z Progress.ETAcCsL|jdkrd}n|j|j|j}tD]}|dkr6q@|d}q&d||fS)Nrgièg@@z%d %sB/s)r¦r£rxÚUNITS)r³r(Zunitr,r,r-ÚspeedSs  zProgress.speedN)rr¢)r·r»r¼r¬r´r©rªr;r«r‚r­r®r±r³rµr,r,r,r-r¡s      r¡z \{([^}]*)\}z[^/\\,{]\*\*|\*\*[^/\\,}]z^[^{]*\}|\{[^}]*$cCs<t |¡rd}t||ƒ‚t |¡r4d}t||ƒ‚t|ƒS)zAExtended globbing function that supports ** and {opt1,opt2,opt3}.z7invalid glob %r: recursive glob "**" must be used alonez2invalid glob %r: mismatching set marker '{' or '}')Ú_CHECK_RECURSIVE_GLOBrr¾Ú_CHECK_MISMATCH_SETÚ_iglob)Ú path_globrÞr,r,r-rhs    rc csôt |d¡}t|ƒdkrT|\}}}| d¡D]$}td |||f¡ƒD] }|VqDq,nœd|krrt|ƒD] }|Vqdn~| dd¡\}}|dkrŽd}|dkrœd}n| d¡}| d¡}t |¡D]4\}}} tj   |¡}ttj  ||¡ƒD] } | VqâqºdS) NrrCrz**rrDr`ú\) Ú RICH_GLOBrrdr¸r$Ú std_iglobr%raršrbrT) r¹Zrich_path_globrlr¤rjÚitemrbZradicalÚdirrñrVr,r,r-r¸ss(         r¸)Ú HTTPSHandlerÚmatch_hostnameÚCertificateErrorc@seZdZdZdZdd„ZdS)ÚHTTPSConnectionNTcCsRt |j|jf|j¡}t|ddƒr0||_| ¡tt dƒsp|j rHt j }nt j }t j ||j|j|t j|j d|_nxt  t j¡}|jt jO_|jr¢| |j|j¡i}|j rØt j |_|j|j dtt ddƒrØ|j|d<|j |f|Ž|_|j rN|jrNz$t|j ¡|jƒt d|j¡Wn0tk rL|j tj¡|j ¡‚YnXdS) NZ _tunnel_hostFÚ SSLContext)Ú cert_reqsZ ssl_versionÚca_certs)ZcafileZHAS_SNIZserver_hostnamezHost verified: %s) r¯Zcreate_connectionÚhostÚportÚtimeoutrqÚsockZ_tunnelroÚsslrÅZ CERT_REQUIREDZ CERT_NONEZ wrap_socketZkey_fileZ cert_fileZPROTOCOL_SSLv23rÃZoptionsZ OP_NO_SSLv2Zload_cert_chainZ verify_modeZload_verify_locationsÚ check_domainrÀZ getpeercertrØrrÁZshutdownZ SHUT_RDWRr—)r³rÉrÄÚcontextrbr,r,r-Úconnectœs@  ý     zHTTPSConnection.connect)r·r»r¼rÅrËrÍr,r,r,r-r—srÂc@s&eZdZd dd„Zdd„Zdd„ZdS) r¿TcCst |¡||_||_dSrt)ÚBaseHTTPSHandlerr´rÅrË)r³rÅrËr,r,r-r´Âs zHTTPSHandler.__init__cOs$t||Ž}|jr |j|_|j|_|S)a This is called to create a connection instance. Normally you'd pass a connection class to do_open, but it doesn't actually check for a class, and just expects a callable. As long as we behave just as a constructor would have, we should be OK. If it ever changes so that we *must* pass a class, we'll create an UnsafeHTTPSConnection class which just sets check_domain to False in the class definition, and choose which one to pass to do_open. )rÂrÅrË)r³rarbr(r,r,r-Ú _conn_makerÇs zHTTPSHandler._conn_makerc CsXz| |j|¡WStk rR}z$dt|jƒkr@td|jƒ‚n‚W5d}~XYnXdS)Nzcertificate verify failedz*Unable to verify server certificate for %s)Zdo_openrÏrrÚreasonrÁrÆ)r³rYrJr,r,r-Ú https_open×sÿzHTTPSHandler.https_openN)T)r·r»r¼r´rÏrÑr,r,r,r-r¿Ás r¿c@seZdZdd„ZdS)ÚHTTPSOnlyHandlercCstd|ƒ‚dS)NzAUnexpected HTTP request on what should be a secure connection: %s)r)r³rYr,r,r-Ú http_openësÿzHTTPSOnlyHandler.http_openN)r·r»r¼rÓr,r,r,r-rÒêsrÒé©rÔéc@seZdZddd„ZdS)ÚHTTPrNcKs&|dkr d}| |j||f|Ž¡dS©Nr©Ú_setupZ_connection_class©r³rÆrÇrbr,r,r-r´÷sz HTTP.__init__)rN©r·r»r¼r´r,r,r,r-r×ösr×c@seZdZddd„ZdS)ÚHTTPSrNcKs&|dkr d}| |j||f|Ž¡dSrØrÙrÛr,r,r-r´ÿszHTTPS.__init__)rNrÜr,r,r,r-rÝþsrÝc@seZdZddd„Zdd„ZdS)Ú TransportrcCs||_tj ||¡dSrt)rÈrrÞr´©r³rÈÚ use_datetimer,r,r-r´szTransport.__init__cCs`| |¡\}}}tdkr(t||jd}n4|jr<||jdkrR||_|t |¡f|_|jd}|S)NrÕ)rÈrr)Ú get_host_infoÚ _ver_infor×rÈÚ _connectionÚ_extra_headersrZHTTPConnection)r³rÆÚhÚehZx509r(r,r,r-Úmake_connection s zTransport.make_connectionN)r©r·r»r¼r´rçr,r,r,r-rÞs rÞc@seZdZddd„Zdd„ZdS)Ú SafeTransportrcCs||_tj ||¡dSrt)rÈrrér´rßr,r,r-r´szSafeTransport.__init__cCsx| |¡\}}}|si}|j|d<tdkr:t|df|Ž}n:|jrN||jdkrj||_|tj|df|Žf|_|jd}|S)NrÈrÕrr)rárÈrârÝrãrärrÂ)r³rÆrårærbr(r,r,r-rçs  ÿ zSafeTransport.make_connectionN)rrèr,r,r,r-rés réc@seZdZdd„ZdS)Ú ServerProxyc Kst| dd¡|_}|dk r^t|ƒ\}}| dd¡}|dkr@t}nt}|||d|d<}||_tjj ||f|ŽdS)NrÈràrZhttps)ràÚ transport) rgrÈrrGrérÞrërrêr´) r³rZrbrÈrWr]ràZtclsr\r,r,r-r´,s  zServerProxy.__init__NrÜr,r,r,r-rê+srêcKs6tjddkr|d7}nd|d<d|d<t||f|ŽS)Nrr„ÚbrÚnewliner…rã)rprŒrä)rVròrbr,r,r-Ú _csv_open@s  rîc@s4eZdZedƒedƒedƒdœZdd„Zdd„Zd S) ÚCSVBaserCú"r€)Z delimiterZ quotecharZlineterminatorcCs|Srtr,rÌr,r,r-Ú __enter__RszCSVBase.__enter__cGs|j ¡dSrt)rŠr—)r³r$r,r,r-Ú__exit__UszCSVBase.__exit__N)r·r»r¼rÚdefaultsrñròr,r,r,r-rïKs ýrïc@s(eZdZdd„Zdd„Zdd„ZeZdS)Ú CSVReadercKs\d|kr4|d}tjddkr,t d¡|ƒ}||_nt|ddƒ|_tj|jf|jŽ|_dS)NrŠrr„r…rbrE) rprŒrrŽrŠrîÚcsvrIró)r³rbrŠr,r,r-r´ZszCSVReader.__init__cCs|Srtr,rÌr,r,r-Ú__iter__eszCSVReader.__iter__cCsFt|jƒ}tjddkrBt|ƒD] \}}t|tƒs | d¡||<q |S©Nrr„r…)ÚnextrIrprŒr5rwrrŠ)r³r(r[r½r,r,r-røhs   zCSVReader.nextN)r·r»r¼r´rörøÚ__next__r,r,r,r-rôYs rôc@seZdZdd„Zdd„ZdS)Ú CSVWritercKs$t|dƒ|_tj|jf|jŽ|_dS)Nrá)rîrŠrõÚwriterró)r³rVrbr,r,r-r´ss zCSVWriter.__init__cCsNtjddkr>g}|D]"}t|tƒr.| d¡}| |¡q|}|j |¡dSr÷)rprŒrwrrèr"rûÚwriterow)r³ÚrowrEr½r,r,r-rüws   zCSVWriter.writerowN)r·r»r¼r´rür,r,r,r-rúrsrúcsHeZdZeejƒZded<d ‡fdd„ Zdd„Zdd „Zd d „Z ‡Z S) Ú ConfiguratorÚ inc_convertZincNcs"tt|ƒ |¡|pt ¡|_dSrt)Úsuperrþr´rar«ri)r³Úconfigri©Ú __class__r,r-r´ŠszConfigurator.__init__c s¬‡‡fdd„‰ˆ d¡}t|ƒs*ˆ |¡}ˆ dd¡}ˆ dd¡}|r\t‡fdd„|Dƒƒ}‡‡fd d„ˆDƒ}t|ƒ}|||Ž}|r¨| ¡D]\}} t||ˆ| ƒƒqŽ|S) Ncsvt|ttfƒr*t|ƒ‡fdd„|Dƒƒ}nHt|tƒrhd|krHˆ |¡}qri}|D]}ˆ||ƒ||<qPn ˆ |¡}|S)Ncsg|] }ˆ|ƒ‘qSr,r,)rNr[©Úconvertr,r-rO‘szBConfigurator.configure_custom..convert..ú())rwr ryÚtypeÚdictÚconfigure_customr)Úor(r)rr³r,r-rs   z.Configurator.configure_custom..convertrrz[]r,csg|] }ˆ|ƒ‘qSr,r,)rNr rr,r-rO¤sz1Configurator.configure_custom..cs$g|]}t|ƒr|ˆˆ|ƒf‘qSr,)r)rNr)rrr,r-rO¥s)rgrrryrr’Úsetattr) r³rr}Zpropsrar’rbr(r@rIr,)rrr³r-r Žs     zConfigurator.configure_customcCs4|j|}t|tƒr0d|kr0| |¡|j|<}|S)Nr)rrwrr )r³r‚r(r,r,r-Ú __getitem__­s zConfigurator.__getitem__c CsFtj |¡stj |j|¡}tj|ddd}t |¡}W5QRX|S)z*Default converter for the inc:// protocol.rEr…râ) rarbÚisabsr$rirrärr‘)r³rŸrær(r,r,r-rÿ³s  zConfigurator.inc_convert)N) r·r»r¼rrZvalue_convertersr´r r rÿÚ __classcell__r,r,rr-rþ…s  rþc@s*eZdZdZd dd„Zdd„Zdd „ZdS) ÚSubprocessMixinzC Mixin for running subprocesses and capturing their output FNcCs||_||_dSrt)ÚverboseÚprogress)r³rrr,r,r-r´ÀszSubprocessMixin.__init__cCsj|j}|j}| ¡}|sq^|dk r.|||ƒq |s@tj d¡ntj | d¡¡tj ¡q | ¡dS)z¨ Read lines from a subprocess' output stream and either pass to a progress callable (if specified) or write progress information to sys.stderr. Nrr…) rrÚreadlinerpÚstderrr¥rŠÚflushr—)r³rŠrÌrrr+r,r,r-rIÄs  zSubprocessMixin.readercKsžtj|ftjtjdœ|—Ž}tj|j|jdfd}| ¡tj|j|jdfd}| ¡|  ¡|  ¡|  ¡|j dk rˆ|  dd¡n|j ršt j d¡|S)N)Ústdoutrr)rÔrarzdone.Úmainzdone. )Ú subprocessÚPopenÚPIPEÚ threadingZThreadrIrr;rÚwaitr$rrrpr¥)r³Úcmdrbr|Út1Út2r,r,r-Ú run_commandÙs" ÿÿ  zSubprocessMixin.run_command)FN)r·r»r¼rXr´rIrr,r,r,r-r¼s rcCst dd|¡ ¡S)z,Normalize a python package name a la PEP 503z[-_.]+r9)r<Úsubry)rPr,r,r-Únormalize_nameêsr!)NN)r®)N)N)NT)„rÚ collectionsrÚ contextlibrõZglobrr¼r˜rZloggingrarùr<r¯rÊÚ ImportErrorrrprr§r˜rZdummy_threadingr¨rrÚcompatrrrr r r r r rrrrrrrrrrrrrZ getLoggerr·rØrûrrGrFr6r>r:rVr#r?r^rmrsrxr~rƒr r¦Úcontextmanagerrªr¬r°rµr±rÃrÄrrÚVERBOSErr“r+r-r/r1r4r7ÚIr>r:rArBrCrFrKrNrOrQrRrYrdZARCHIVE_EXTENSIONSr—r›r´r¡r»r¶r·r¸r¿rÎrÀrÁrÂrÒrŒrâr×rÝrÞrérêrîrïrôrúrþrr!r,r,r,r-Úsä      \         Yy   /   8ý ) ÿ   ,H  C]    *)   7.