a [dg@sddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZz ddlZWneydZYn0ddlZddlZddlZddlZddlZz ddlZWneyddlZYn0ddlZddlmZddlmZmZmZmZm 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 1e2Z3e 4dZ5e 4dZ6e 4d Z7e 4d Z8e 4d Z9e 4d Z:e 4d Z;e 4dZddZ?ddZ@ddZAdddZBddZCddZDdd ZEejFd!d"ZGejFd#d$ZHejFdd&d'ZIGd(d)d)eJZKd*d+ZLGd,d-d-eJZMd.d/ZNGd0d1d1eJZOe 4d2e jPZQd3d4ZRdd5d6ZSd7d8ZTd9d:ZUd;d<ZVd=d>ZWd?d@ZXe 4dAe jYZZe 4dBZ[ddCdDZ\e 4dEZ]dFdGZ^dHdIZ_dJdKZ`dLZadMdNZbdOdPZcGdQdRdReJZdGdSdTdTeJZeGdUdVdVeJZfdWZgddYdZZhd[d\Zid]ZjGd^d_d_eJZke 4d`Zle 4daZme 4dbZndcddZdedfZoerddglmpZqmrZrmsZsGdhdidie$jtZtGdjdkdkeqZpGdldmdmepe'ZuejvddnZwewdokrGdpdqdqe$jxZxerGdrdsdse$jyZyGdtdudue%jzZzer>Gdvdwdwe%j{Z{Gdxdydye%j|Z|dzd{Z}Gd|d}d}eJZ~Gd~dde~ZGddde~ZGddde(ZGdddeJZddZdS)N)deque)iglob)DistlibException) string_types text_typeshutil raw_inputStringIOcache_from_sourceurlopenurljoinhttplib xmlrpclib splittype HTTPHandlerBaseConfigurator valid_ident Container configparserURLErrorZipFilefsdecodeunquoteurlparsez^([\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\.{}()*+#:;,/?!~`@$%^&=|<>\[\]-]+)cs6ddfddfddfdd|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:tdn|d}|dvrVtd|d|d}|dd}|g}|r|d|krqqt|d|kr|||dd}qtt|}|std|||d||d}qtd|}td|||d|}|dd }||fS) Nrzunexpected end of inputz'"zinvalid expression: %srzerror in string literal: %szunterminated string: %s) IDENTIFIERmatchgroupsend SyntaxErrorreplaceappend STRING_CHUNKjoinlstrip) remainingmresultqZoqpartssr,B/usr/local/lib/python3.9/site-packages/pip/_vendor/distlib/util.py marker_varAs:               z parse_marker..marker_varcs|rR|ddkrR|dd\}}|ddkr@td||dd}nZ|\}}|rt|}|srq|d}||d}|\}}|||d}q^|}||fS)Nr(r)unterminated parenthesis: %soplhsrhs)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)Nandr2)ANDrrr&r4r'r5)r8r,r- marker_andxs   z parse_marker..marker_andcsR|\}}|rJt|}|s qJ||d}|\}}d||d}q ||fS)Norr2)ORrrr;)r<r,r-r7s   zparse_marker..markerr,)Z marker_stringr,)r7r<r8r.r- parse_marker8s $ r?cCs0|}|r|drdSt|}|s4td||d}||d}d}}}}|r:|ddkr:|dd}|dkrtd||d|} ||dd}g}| r0t| }|std | | |d| |d} | sq0| dd krtd | | dd} q|s:d}|r|dd kr|dd}t |}|sztd ||d}t |} | j r| j std|||d}ndd} |ddkr| |\}}n|dd}|dkrtd||d|} ||dd}t| r@| | \}} nXt| }|s\td| |d} | |d} | rtd| d| fg}|r|ddkrtd||dd}t|\}}|r|ddkrtd||s|}nd|ddd|Df}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: %scSst|}d}|rg}|d}||d}t|}|sLtd||d}|||f||d}|r|ddkrq|dd}t|}|std|q|sd}||fS)z| Return a list of operator, version tuples if any are specified, else None. Nrzinvalid version: %srCrinvalid constraint: %s) COMPARE_OPrrrVERSION_IDENTIFIERr r"r%)Z ver_remainingr'versionsr3vr,r,r- get_versionss*      z'parse_requirement..get_versionsr/r0r1rEz~=;zinvalid requirement: %szunexpected trailing data: %s%s %s, cSsg|] }d|qS)rLr,).0Zconr,r,r- z%parse_requirement..)nameextras constraintsr7urlZ requirement)strip startswithrrr rrfindr%r" NON_SPACErschemenetlocrFrGr?r$r)reqr&r'ZdistnamerRZ mark_exprrHuriir+trJ_rIZrsr,r,r-parse_requirements                          r`cCsdd}i}|D]\}}}tj||}t|D]p}tj||} t| D]T} ||| } |durn|| dqJ||| } |tjjdd} | d| || <qJq0q|S)z%Find destinations for resources filescSs6|tjjd}|tjjd}|t|ddSN/)r!ospathseplenr%)rootrdr,r,r- get_rel_path sz)get_resources_dests..get_rel_pathNrb)rcrdr$rpopr!rerstrip)Zresources_rootZrulesrhZ destinationsbasesuffixdestprefixZabs_baseZabs_globZabs_pathZ resource_fileZrel_pathZrel_destr,r,r-get_resources_dests s    rocCs(ttdrd}ntjttdtjk}|S)NZ real_prefixT base_prefix)hasattrsysrngetattrr(r,r,r-in_venv$s rucCs$tjtj}t|ts t|}|SN)rcrdnormcaserr executable isinstancerrrtr,r,r-get_executable.s  rzcCsN|}t|}|}|s|r|}|r|d}||vr6qJ|rd|||f}q|S)Nrz %c: %s %s)r lower)promptZ allowed_charsZ error_promptdefaultpr+cr,r,r-proceed>s rcCs8t|tr|}i}|D]}||vr||||<q|Srv)ryrsplit)dkeysr(keyr,r,r-extract_by_keyNs rcCs\tjddkrtd|}|}t|}z`t|}|ddd}|D]6\}}|D]$\}}d||f}t |} | ||<q`qP|WSt y| ddYn0dd } t } z| | |Wn:t jy|t|}t|}| | |Yn0i}| D]D} i|| <}| | D]&\} }d| |f}t |} | || <q,q|S) Nrutf-8 extensionszpython.exportsexportsz%s = %scSs$t|dr||n ||dS)N read_file)rqrZreadfp)cpstreamr,r,r- read_streamks  z!read_exports..read_stream)rr version_infocodecs getreaderreadr jsonloaditemsget_export_entry Exceptionseekr ConfigParserZMissingSectionHeaderErrorclosetextwrapdedentZsections)rdataZjdatar(groupentrieskrIr+entryrrrrQvaluer,r,r- read_exportsWs@        rcCstjddkrtd|}t}|D]l\}}|||D]P}|j dur\|j }nd|j |j f}|j rd|d |j f}| ||j|qFq,||dS)Nrrrz%s:%sz%s [%s]rM)rrrr getwriterrrrZ add_sectionvaluesrlrnflagsr$setrQwrite)rrrrrIrr+r,r,r- write_exportss   rc cs.t}z|VWt|n t|0dSrv)tempfilemkdtemprrmtree)Ztdr,r,r-tempdirsrc cs8t}zt|dVWt|n t|0dSrv)rcgetcwdchdir)rcwdr,r,r-rs  rc cs8t}zt|dVWt|n t|0dSrv)socketgetdefaulttimeoutsetdefaulttimeout)ZsecondsZctor,r,r-socket_timeouts  rc@seZdZddZdddZdS)cached_propertycCs ||_dSrv)func)selfrr,r,r-__init__szcached_property.__init__NcCs,|dur |S||}t||jj||Srv)robject __setattr____name__)robjclsrr,r,r-__get__s  zcached_property.__get__)N)r __module__ __qualname__rrr,r,r,r-rsrcCs~tjdkr|S|s|S|ddkr.td||ddkrFtd||d}tj|vrh|tjqP|srtjStjj|S)aReturn '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. rbrzpath '%s' cannot be absolutezpath '%s' cannot end with '/')rcre ValueErrorrcurdirremoverdr$)pathnamepathsr,r,r- convert_paths       rc@seZdZd$ddZddZddZdd Zd%d d Zd&ddZddZ ddZ ddZ ddZ ddZ d'ddZddZddZd d!Zd"d#Zd S)( FileOperatorFcCs||_t|_|dSrv)dry_runrensured _init_record)rrr,r,r-rszFileOperator.__init__cCsd|_t|_t|_dSNF)recordr files_written dirs_createdrr,r,r-rszFileOperator._init_recordcCs|jr|j|dSrv)rradd)rrdr,r,r-record_as_writtenszFileOperator.record_as_writtencCsHtj|s tdtj|tj|s0dSt|jt|jkS)aTell 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)rcrdexistsrabspathstatst_mtime)rsourcetargetr,r,r-newers   zFileOperator.newerTcCs|tj|td|||jsd}|rdtj|rDd|}n tj|rdtj |sdd|}|rtt |dt ||| |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_dirrcrddirnameloggerinforislinkrisfilerrcopyfiler)rZinfileoutfilecheckmsgr,r,r- copy_files    zFileOperator.copy_fileNcCs||tj|td|||jsn|dur:t|d}ntj|d|d}zt ||W| n | 0| |dS)NzCopying stream %s to %swbwencoding) rrcrdrrrropenrr copyfileobjrr)rZinstreamrrZ outstreamr,r,r- copy_streams zFileOperator.copy_streamcCsp|tj||jsbtj|r.t|t|d}||Wdn1sX0Y| |dS)Nr) rrcrdrrrrrrr)rrdrfr,r,r-write_binary_file!s   (zFileOperator.write_binary_filecCs||||dSrv)rencode)rrdrrr,r,r-write_text_file*szFileOperator.write_text_filecCsntjdkstjdkrjtjdkrj|D]F}|jr:td|q"t|j|B|@}td||t||q"dS)Nposixjavazchanging mode of %szchanging mode of %s to %o) rcrQ_namerrrrst_modechmod)rbitsmaskfilesrmoder,r,r-set_mode-szFileOperator.set_modecCs|dd|S)Nimi)r)r+rr,r,r-9rPzFileOperator.cCs|tj|}||jvrxtj|sx|j|tj|\}}||t d||j sft ||j rx|j |dS)Nz Creating %s)rcrdrrrrrrrrrmkdirrr)rrdrrr,r,r-r;s    zFileOperator.ensure_dirc Cst|| }td|||js|s0|||rJ|s:d}n|t|d}i}|rhttdrhtjj |d<tj |||dfi|| ||S)NzByte-compiling %s to %sPycInvalidationModeinvalidation_modeT) r rrrrrfrq py_compiler CHECKED_HASHcompiler) rrdoptimizeforcernZhashed_invalidationZdpathZdiagpathZcompile_kwargsr,r,r- byte_compileGs   zFileOperator.byte_compilecCstj|rtj|r^tj|s^td||js@t ||j r||j vr|j |nPtj|rpd}nd}td|||jst ||j r||j vr|j |dS)NzRemoving directory tree at %slinkfilezRemoving %s %s)rcrdrisdirrrdebugrrrrrrr)rrdr+r,r,r-ensure_removedXs"       zFileOperator.ensure_removedcCsDd}|s@tj|r$t|tj}q@tj|}||kr:q@|}q|Sr)rcrdraccessW_OKr)rrdr(parentr,r,r- is_writablems  zFileOperator.is_writablecCs|j|jf}||S)zV Commit recorded changes, turn off recording, return changes. )rrr)rr(r,r,r-commitys zFileOperator.commitcCs|jsxt|jD]}tj|rt|qt|jdd}|D]8}t |}|rltj ||d}t |t |q>| dS)NT)reverser) rlistrrcrdrrsortedrlistdirr$rmdirr)rrdirsrflistsdr,r,r-rollbacks     zFileOperator.rollback)F)T)N)FFNF)rrrrrrrrrrrrZset_executable_moderrrr r rr,r,r,r-rs         rcCs^|tjvrtj|}nt|}|dur,|}n.|d}t||d}|D]}t||}qJ|S)N.r)rrmodules __import__rrsri) module_nameZ dotted_pathmodr(r*r~r,r,r-resolves    rc@s6eZdZddZeddZddZddZej Z d S) ExportEntrycCs||_||_||_||_dSrvrQrnrlr)rrQrnrlrr,r,r-rszExportEntry.__init__cCst|j|jSrv)rrnrlrr,r,r-rszExportEntry.valuecCsd|j|j|j|jfS)Nzrrr,r,r-__repr__s zExportEntry.__repr__cCsDt|tsd}n0|j|jko>|j|jko>|j|jko>|j|jk}|Sr)ryrrQrnrlr)rotherr(r,r,r-__eq__s     zExportEntry.__eq__N) rrrrrrrr!r__hash__r,r,r,r-rs   rz(?P(\w|[-.+])+) \s*=\s*(?P(\w+)([:\.]\w+)*) \s*(\[\s*(?P[\w-]+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])? c Cst|}|s0d}d|vs"d|vrtd|n|}|d}|d}|d}|dkrf|d}}n"|dkrztd||d\}}|d } | durd|vsd|vrtd|g} nd d | d D} t|||| }|S) NrArBzInvalid specification '%s'rQcallable:rrrcSsg|] }|qSr,)rU)rNrr,r,r-rOrPz$get_export_entry..rC)ENTRY_REsearchr groupdictcountrr) Z specificationr'r(rrQrdZcolonsrnrlrr,r,r-rs8   rcCs|dur d}tjdkr.dtjvr.tjd}n tjd}tj|rft|tj}|st d|n:zt |d}Wn&t yt j d |dd d }Yn0|st }t d |tj||S) a Return the default base location for distlib caches. If the directory does not exist, it is created. Use the suffix provided for the base directory, and default to '.distlib' if it isn't provided. On Windows, if LOCALAPPDATA is defined in the environment, then it is assumed to be a directory, and will be the parent directory of the result. On POSIX, and on Windows if LOCALAPPDATA is not defined, the user's home directory - using os.expanduser('~') - will be the parent directory of the result. The result is just the directory '.distlib' in the parent directory as determined above, or with the name specified with ``suffix``. Nz.distlibntZ LOCALAPPDATAz $localappdata~z(Directory exists but is not writable: %sTzUnable to create %s)exc_infoFz#Default location unusable, using %s)rcrQenvironrd expandvars expanduserrr r rwarningmakedirsOSErrorrrr$)rlr(Zusabler,r,r-get_cache_bases&      r2cCsBtjtj|\}}|r(|dd}|tjd}||dS)a Convert an absolute path to a directory name for use in a cache. The algorithm used is: #. On Windows, any ``':'`` in the drive is replaced with ``'---'``. #. Any occurrence of ``os.sep`` is replaced with ``'--'``. #. ``'.cache'`` is appended. r$z---z--z.cache)rcrd splitdriverr!re)rdrr~r,r,r-path_to_cache_dir s  r4cCs|ds|dS|Sra)endswith)r+r,r,r- ensure_slashs r6cCs`d}}d|vr>|dd\}}d|vr.|}n|dd\}}|rJt|}|rVt|}|||fS)NrDrr$)rsplitrr)rZusernamepasswordrnr,r,r-parse_credentials$sr:cCstd}t||S)N)rcumaskrtr,r,r-get_process_umask3s  r=cCs0d}d}t|D]\}}t|tsd}q,q|S)NTF) enumerateryr)seqr(r]r+r,r,r-is_string_sequence8s r@z3([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)z -py(\d\.?\d?)cCsd}d}t|dd}t|}|r@|d}|d|}|rt|t|dkrtt |d|}|r| }|d|||dd|f}|durt |}|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_VERSIONr&rstartrfrerescaperPROJECT_NAME_AND_VERSION)filenameZ project_namer(Zpyverr'nr,r,r-split_filenameGs"   rJz-(?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'rQver)NAME_VERSION_RErrr'rUr{)r~r'rr,r,r-parse_name_and_versioncs  rMcCst}t|pg}t|pg}d|vr8|d||O}|D]x}|dkrT||q<|dr|dd}||vrtd|||vr||q<||vrtd|||q<|S)N*rBrzundeclared extra: %s)rrrrVrr/)Z requestedZ availabler(rZunwantedr,r,r- get_extrasrs&        rPc Csi}zNt|}|}|d}|ds8td|ntd|}t |}Wn2t y}zt d||WYd}~n d}~00|S)Nz Content-Typezapplication/jsonz(Unexpected response for JSON request: %srz&Failed to get external data for %s: %s) r rgetrVrrrrrrr exception)rTr(ZrespZheadersctreaderer,r,r-_get_external_datas  $rVz'https://www.red-dove.com/pypi/projects/cCs*d|d|f}tt|}t|}|S)Nz%s/%s/project.jsonrupperr _external_data_base_urlrV)rQrTr(r,r,r-get_project_datas rZcCs(d|d||f}tt|}t|S)Nz%s/%s/package-%s.jsonrrW)rQversionrTr,r,r-get_package_datas r\c@s(eZdZdZddZddZddZdS) 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@dkr6td|tjtj ||_ dS)zu Initialise an instance. :param base: The base directory where the cache should be located. ?rzDirectory '%s' is not privateN) rcrdrr0rrrr/rnormpathrk)rrkr,r,r-rs    zCache.__init__cCst|S)zN Converts a resource prefix to a directory name in the cache. )r4)rrnr,r,r- prefix_to_dirszCache.prefix_to_dirc Csg}t|jD]p}tj|j|}z>tj|s>tj|rJt|ntj|r`t |Wqt y~| |Yq0q|S)z" Clear the cache. ) rcrrkrdr$rrrrrrrr")rZ not_removedfnr,r,r-clears   z Cache.clearN)rrr__doc__rr`rbr,r,r,r-r]sr]c@s:eZdZdZddZdddZddZd d Zd d Zd S) EventMixinz1 A very simple publish/subscribe system. cCs i|_dSrv) _subscribersrr,r,r-rszEventMixin.__init__TcCsD|j}||vrt|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)rerr" appendleft)revent subscriberr"subssqr,r,r-rs  zEventMixin.addcCs,|j}||vrtd||||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)rerr)rrgrhrir,r,r-rs zEventMixin.removecCst|j|dS)z Return an iterator for the subscribers for an event. :param event: The event to return subscribers for. r,)iterrerQ)rrgr,r,r-get_subscribersszEventMixin.get_subscribersc Ospg}||D]J}z||g|Ri|}Wn tyLtdd}Yn0||qtd|||||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)rlrrrRr"r)rrgargskwargsr(rhrr,r,r-publishs     zEventMixin.publishN)T) rrrrcrrrrlror,r,r,r-rds   rdc@s^eZdZddZddZdddZdd Zd d Zd d ZddZ e ddZ e ddZ dS) SequencercCsi|_i|_t|_dSrv)_preds_succsr_nodesrr,r,r-r"szSequencer.__init__cCs|j|dSrv)rsrrnoder,r,r-add_node'szSequencer.add_nodeFcCs||jvr|j||rt|j|dD]}|||q,t|j|dD]}|||qPt|jD]\}}|sp|j|=qpt|jD]\}}|s|j|=qdS)Nr,)rsrrrqrQrrrr)rruZedgesr~r+rrIr,r,r- remove_node*s   zSequencer.remove_nodecCs0|j|t||j|t|dSrv)rq setdefaultrrrr)rpredsuccr,r,r-r:sz Sequencer.addcCsxz|j|}|j|}Wnty6td|Yn0z||||Wn"tyrtd||fYn0dS)Nz%r not a successor of anythingz%r not a successor of %r)rqrrKeyErrorrr)rryrzpredsZsuccsr,r,r-r?s    zSequencer.removecCs||jvp||jvp||jvSrv)rqrrrs)rstepr,r,r-is_stepLszSequencer.is_stepcCs||std|g}g}t}|||r|d}||vrb||kr||||q.|||||j|d}| |q.t |S)Nz Unknown: %rrr,) r~rrr"rirrrqrQextendreversed)rfinalr(Ztodoseenr}r|r,r,r- get_stepsPs"         zSequencer.get_stepscsRdggiig|jfddD]}|vr8|q8S)Nrcsd|<d|<dd7<|z |}WntyTg}Yn0|D]J}|vr|t|||<qZ|vrZt|||<qZ||krg}}||||krqqt|}|dS)Nrr)r"rminrituple)ruZ successors successorZconnected_componentZ componentZgraphindexZ index_counterZlowlinksr(stack strongconnectr,r-rts*        z3Sequencer.strong_connections..strongconnect)rrrtr,rr-strong_connectionsis" zSequencer.strong_connectionscCsfdg}|jD]*}|j|}|D]}|d||fqq |jD]}|d|q>|dd|S)Nz digraph G {z %s -> %s;z %s;} )rqr"rsr$)rr(rzr|ryrur,r,r-dots    z Sequencer.dotN)F) rrrrrvrwrrr~rpropertyrrr,r,r,r-rp!s   2rp).tar.gz.tar.bz2.tar.zip.tgz.tbz.whlTc sZfdd}tjtd}|dur|dr>d}nH|drRd}d}n4|drfd }d }n |d rzd }d }n td|z|dkrt|d }|r|}|D] }||qn*t ||}|r| }|D] }||q|dkr*t j ddkr*| D]"} t| jts| jd| _q|W|rV|n|rT|0dS)NcsRt|ts|d}tjtj|}|rB|tjkrNt d|dS)Nrzpath outside destination: %r) ryrdecodercrdrr$rVrer)rdr~dest_dirZplenr,r- check_paths   zunarchive..check_path)rrzip)rrZtgzzr:gz)rrZtbzzr:bz2rtarrOzUnknown format for %rrrr)rcrdrrfr5rrZnamelisttarfilerZgetnamesrrrZ getmembersryrQrr extractallr) Zarchive_filenamerformatrrarchivernamesrQtarinfor,rr- unarchivesL             rc Cst}t|}t|dd}t|D]H\}}}|D]8}tj||}||d} tj| |} ||| q4q&Wdn1s0Y|S)z*zip a directory tree into a BytesIO objectrN) ioBytesIOrfrrcwalkrdr$r) Z directoryr(ZdlenzfrgrrrQfullrelrmr,r,r-zip_dirs  .r)rKMGTPc@sreZdZdZdddZddZdd Zd d Zd d Ze ddZ e ddZ ddZ e ddZ e ddZdS)ProgressZUNKNOWNrdcCs(||_|_||_d|_d|_d|_dS)NrF)rcurmaxstartedelapseddone)rZminvalZmaxvalr,r,r-rs  zProgress.__init__cCs0||_t}|jdur ||_n ||j|_dSrv)rtimerr)rZcurvalZnowr,r,r-updates  zProgress.updatecCs||j|dSrv)rr)rZincrr,r,r- incrementszProgress.incrementcCs||j|Srv)rrrr,r,r-rDs zProgress.startcCs |jdur||jd|_dS)NT)rrrrr,r,r-stops  z Progress.stopcCs|jdur|jS|jSrv)runknownrr,r,r-maximumszProgress.maximumcCsD|jr d}n4|jdurd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)rrrr)rr(rIr,r,r- percentages zProgress.percentagecCs:|dkr|jdus|j|jkr$d}ntdt|}|S)Nrz??:??:??z%H:%M:%S)rrrrstrftimegmtime)rZdurationr(r,r,r-format_duration*szProgress.format_durationcCs|jrd}|j}n^d}|jdur&d}nJ|jdks<|j|jkrBd}n.t|j|j}||j|j}|d|j}d|||fS)NZDonezETA rrrz%s: %s)rrrrrfloatr)rrnr^r,r,r-ETA3s z Progress.ETAcCsL|jdkrd}n|j|j|j}tD]}|dkr6q@|d}q&d||fS)Nrgig@@z%d %sB/s)rrrUNITS)rr(Zunitr,r,r-speedFs  zProgress.speedN)rr)rrrrrrrrDrrrrrrrr,r,r,r-rs      rz \{([^}]*)\}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_GLOBr&r_CHECK_MISMATCH_SET_iglob) path_globrr,r,r-r[s    rc cst|d}t|dkrT|\}}}|dD]$}td|||fD] }|VqDq,nd|vrrt|D] }|Vqdn~|dd\}}|dkrd}|dkrd}n|d}|d}t|D]4\}}} tj |}ttj ||D] } | VqqdS) NrrCrz**rrNrb\) RICH_GLOBrrfrr$ std_iglobr%rcrrdr_) rZrich_path_globrnrrlitemrdZradicaldirrrar,r,r-rfs(         r) HTTPSHandlermatch_hostnameCertificateErrorc@seZdZdZdZddZdS)HTTPSConnectionNTcCs^t|j|jf|j}t|ddr0||_|tt dsp|j rHt j }nt j }t j ||j|j|t j|j d|_nt t j}tt dr|jt jO_|jr||j|ji}|j rt j |_|j|j dtt ddr|j|d<|j |fi||_|j rZ|jrZz$t|j|jtd |jWn.tyX|jtj|jYn0dS) NZ _tunnel_hostF SSLContext) cert_reqsZ ssl_versionca_certs OP_NO_SSLv2)ZcafileZHAS_SNIZserver_hostnamezHost verified: %s) rcreate_connectionhostporttimeoutrssockZ_tunnelrqsslrZ CERT_REQUIREDZ CERT_NONEZ wrap_socketZkey_fileZ cert_fileZPROTOCOL_SSLv23roptionsrZload_cert_chainZ verify_modeZload_verify_locations check_domainrZ getpeercertrrrshutdown SHUT_RDWRr)rrrcontextrnr,r,r-connectsB        zHTTPSConnection.connect)rrrrrrr,r,r,r-rsrc@s&eZdZd ddZddZddZdS) rTcCst|||_||_dSrv)BaseHTTPSHandlerrrr)rrrr,r,r-rs zHTTPSHandler.__init__cOs(t|i|}|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. )rrr)rrmrnr(r,r,r- _conn_makers zHTTPSHandler._conn_makerc CsZz||j|WStyT}z,dt|jvr>td|jnWYd}~n d}~00dS)Nzcertificate verify failedz*Unable to verify server certificate for %s)Zdo_openrrstrreasonrr)rr[rUr,r,r- https_openszHTTPSHandler.https_openN)T)rrrrrrr,r,r,r-rs rc@seZdZddZdS)HTTPSOnlyHandlercCstd|dS)NzAUnexpected HTTP request on what should be a secure connection: %s)r)rr[r,r,r- http_openszHTTPSOnlyHandler.http_openN)rrrrr,r,r,r-rsrrc@seZdZdddZdS)HTTPrNcKs*|dkr d}||j||fi|dSNr_setupZ_connection_classrrrrnr,r,r-rsz HTTP.__init__)rNrrrrr,r,r,r-rsrc@seZdZdddZdS)HTTPSrNcKs*|dkr d}||j||fi|dSrrrr,r,r-rszHTTPS.__init__)rNrr,r,r,r-rsrc@seZdZdddZddZdS) TransportrcCs||_tj||dSrv)rrrrrr use_datetimer,r,r-rszTransport.__init__cCs`||\}}}tdkr(t||jd}n4|jr<||jdkrR||_|t|f|_|jd}|S)Nr)rrr) get_host_info _ver_inforr _connection_extra_headersrZHTTPConnection)rrhehZx509r(r,r,r-make_connections zTransport.make_connectionN)rrrrrrr,r,r,r-rs rc@seZdZdddZddZdS) SafeTransportrcCs||_tj||dSrv)rrrrrr,r,r-r szSafeTransport.__init__cCs||\}}}|si}|j|d<tdkr>t|dfi|}n>|jrR||jdkrr||_|tj|dfi|f|_|jd}|S)Nrrrr)rrrrrrrr)rrrrrnr(r,r,r-rs   zSafeTransport.make_connectionN)rrr,r,r,r-r s rc@seZdZddZdS) ServerProxyc Ksx|dd|_}|dur^t|\}}|dd}|dkr@t}nt}|||d|d<}||_tjj ||fi|dS)Nrrrhttps)r transport) rirrrQrrrrrr) rr\rnrrYr_rZtclsr^r,r,r-r s  zServerProxy.__init__Nrr,r,r,r-rsrcKs:tjddkr|d7}nd|d<d|d<t||fi|S)Nrrbrnewlinerr)rrrr)rarrnr,r,r- _csv_open4s  rc@s4eZdZedededdZddZddZd S) CSVBaserC"r) delimiterZ quotecharZlineterminatorcCs|Srvr,rr,r,r- __enter__FszCSVBase.__enter__cGs|jdSrv)rr)rr+r,r,r-__exit__IszCSVBase.__exit__N)rrrrdefaultsrr r,r,r,r-r?s rc@s(eZdZddZddZddZeZdS) CSVReadercKs`d|vr4|d}tjddkr,td|}||_nt|dd|_tj|jfi|j|_dS)NrrrrrdrO) rrrrrrrcsvrTr )rrnrr,r,r-rNszCSVReader.__init__cCs|Srvr,rr,r,r-__iter__YszCSVReader.__iter__cCsFt|j}tjddkrBt|D] \}}t|ts |d||<q |SNrrr)nextrTrrrr>ryrr)rr(r]rr,r,r-r\s   zCSVReader.nextN)rrrrr r__next__r,r,r,r-r Ms r c@seZdZddZddZdS) CSVWritercKs(t|d|_tj|jfi|j|_dS)Nr)rrr writerr )rrarnr,r,r-rgs zCSVWriter.__init__cCsNtjddkr>g}|D]"}t|tr.|d}||q|}|j|dSr)rrrryrrr"rwriterow)rrowrOrr,r,r-rks   zCSVWriter.writerowN)rrrrrr,r,r,r-rfsrcsHeZdZeejZded<d fdd ZddZdd Zd d Z Z S) Configurator inc_convertZincNcs"tt|||pt|_dSrv)superrrrcrrk)rconfigrk __class__r,r-r~szConfigurator.__init__c sfddd}t|s*|}dd}dd}|r\tfdd|D}fd dD}t|}||i|}|r|D]\}} t||| q|S) Ncsvt|ttfr*t|fdd|D}nHt|trhd|vrH|}qri}|D]}||||<qPn |}|S)Ncsg|] }|qSr,r,)rNr]convertr,r-rOrPzBConfigurator.configure_custom..convert..())ryrrtypedictconfigure_customr)or(r)rrr,r-rs   z.Configurator.configure_custom..convertrrz[]r,csg|] }|qSr,r,)rNr!rr,r-rOrPz1Configurator.configure_custom..cs$g|]}t|r||fqSr,)r)rNr)rrr,r-rOrP)rir#rrrrsetattr) rrrZpropsrmrrnr(rIrIr,)rrrr-r s    zConfigurator.configure_customcCs4|j|}t|tr0d|vr0|||j|<}|S)Nr)rryrr )rrr(r,r,r- __getitem__s zConfigurator.__getitem__cCsZtj|stj|j|}tj|ddd}t|}Wdn1sL0Y|S)z*Default converter for the inc:// protocol.rOrrN) rcrdisabsr$rkrrrr)rrrr(r,r,r-rs  (zConfigurator.inc_convert)N) rrrrrZvalue_convertersrr r#r __classcell__r,r,rr-rys  rc@s*eZdZdZd ddZddZdd ZdS) SubprocessMixinzC Mixin for running subprocesses and capturing their output FNcCs||_||_dSrv)verboseprogress)rr'r(r,r,r-rszSubprocessMixin.__init__cCsj|j}|j}|}|sq^|dur.|||q |s@tjdntj|dtjq |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) r(r'readlinerrstderrrrflushr)rrrr(r'r+r,r,r-rTs  zSubprocessMixin.readercKstj|ftjtjd|}tj|j|jdfd}|tj|j|jdfd}|| | | |j dur| ddn|j rt jd|S)N)stdoutr*r,)rrmr*zdone.mainzdone. ) subprocessPopenPIPE threadingThreadrTr,rDr*waitr$r(r'rrr)rcmdrnr~t1t2r,r,r- run_commands"   zSubprocessMixin.run_command)FN)rrrrcrrTr7r,r,r,r-r&s r&cCstdd|S)z,Normalize a python package name a la PEP 503z[-_.]+rB)rEsubr{)rQr,r,r-normalize_namesr9)NN)r)N)N)NT)r collectionsr contextlibr globrrrrloggingrcrrErr ImportErrorr.rrrrrr1Zdummy_threadingrrrcompatrrrr r r r r rrrrrrrrrrrrr getLoggerrrrrrGrFr6r>r:rXr#r?r`rorurzrrrrcontextmanagerrrrrrrrrrVERBOSEr%rr2r4r6r:r=r@IrGrCrJrLrMrPrVrYrZr\r]rdrpZARCHIVE_EXTENSIONSrrrrrrrrrrrrrrrrrrrrrrrr rrr&r9r,r,r,r-s        \         Yy   /   8 )    ,H  6]    +)   7.