U .e@sddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZz ddlZWnek rdZYnXddlZddlZddlZddlZddlZz ddlZWnek rddlZYnXddlZddlmZddlmZmZmZmZm 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%jzZzerBGdvdwdwe%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}|dkrVtd|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,.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- sz%parse_requirement..)nameextrasZ constraintsr7urlZ requirement)strip startswithrrr rrfindr%r" NON_SPACErschemenetlocrFrGr?r$r)reqr&r'ZdistnamerQZ mark_exprrHuriir+trJ_rIZrsr,r,r-parse_requirements                          r^cCsdd}i}|D]\}}}tj||}t|D]p}tj||} t| D]T} ||| } |dkrn|| dqJ||| } |tjjdd} | d| || <qJq0q|S)z%Find destinations for resources filescSsD|tjjd}|tjjd}||s.t|t|ddSN/)r!ospathseprTAssertionErrorlenr%)rootrbr,r,r- get_rel_path sz)get_resources_dests..get_rel_pathNr`)rarbr$rpopr!rcrstrip)Zresources_rootZrulesrgZ destinationsbasesuffixdestprefixZabs_baseZabs_globZabs_pathZ resource_fileZrel_pathZrel_destr,r,r-get_resources_dests s    rncCs(ttdrd}ntjttdtjk}|S)NZ real_prefixT base_prefix)hasattrsysrmgetattrr(r,r,r-in_venv$s rtcCs$tjtj}t|ts t|}|SN)rarbnormcaserq executable isinstancerrrsr,r,r-get_executable.s  rycCsN|}t|}|}|s|r|}|r|d}||kr6qJ|rd|||f}q|S)Nrz %c: %s %s)r lower)promptZ allowed_charsZ error_promptdefaultpr+cr,r,r-proceed>s rcCs8t|tr|}i}|D]}||kr||||<q|Sru)rxrsplit)dkeysr(keyr,r,r-extract_by_keyNs rcCsztjddkrtd|}|}t|}zlt|}|ddd}|D]B\}}|D]0\}}d||f}t |} | dk st | ||<q`qP|WSt k r| ddYnXdd } t } z| | |Wn<t jk r|t|}t|}| | |YnXi}| D]R} i|| <}| | D]4\} }d| |f}t |} | dk sft | || <q<q"|S) Nrutf-8 extensionszpython.exportsexportsz%s = %scSs$t|dr||n ||dS)N read_file)rprZreadfp)cpstreamr,r,r- read_streamks  z!read_exports..read_stream)rq version_infocodecs getreaderreadr jsonloaditemsget_export_entryrd Exceptionseekr ConfigParserZMissingSectionHeaderErrorclosetextwrapdedentZsections)rdataZjdatar(groupentrieskrIr+entryrrrrPvaluer,r,r- read_exportsWsD        rcCstjddkrtd|}t}|D]l\}}|||D]P}|j dkr\|j }nd|j |j f}|j rd|d |j f}| ||j|qFq,||dS)Nrrrz%s:%sz%s [%s]rM)rqrr getwriterrrrZ add_sectionvaluesrkrmflagsr$setrPwrite)rrrrrIrr+r,r,r- write_exportss   rc cs$t}z |VW5t|XdSru)tempfilemkdtemprrmtree)Ztdr,r,r-tempdirs rc cs.t}zt|dVW5t|XdSru)ragetcwdchdir)rcwdr,r,r-rs   rc cs.t}zt|dVW5t|XdSru)socketZgetdefaulttimeoutZsetdefaulttimeout)ZsecondsZctor,r,r-socket_timeouts   rc@seZdZddZdddZdS)cached_propertycCs ||_dSru)func)selfrr,r,r-__init__szcached_property.__init__NcCs,|dkr |S||}t||jj||Sru)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|krh|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. r`rzpath '%s' cannot be absolutezpath '%s' cannot end with '/')rarc ValueErrorrcurdirremoverbr$)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|_|dSru)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|dSru)rradd)rrbr,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)rarbexistsrabspathstatst_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_dirrarbdirnameloggerinforislinkrisfilerrZcopyfiler)rZinfileoutfilecheckmsgr,r,r- copy_files    zFileOperator.copy_fileNcCstj|rt|tj|td|||jsv|dkrJt |d}nt j |d|d}zt ||W5| X||dS)NzCopying stream %s to %swbwencoding)rarbisdirrdrrrrropenrrrZ copyfileobjr)rZinstreamrrZ outstreamr,r,r- copy_streams  zFileOperator.copy_streamc Cs\|tj||jsNtj|r.t|t|d}||W5QRX| |dS)Nr) rrarbrrrrrrr)rrbrfr,r,r-write_binary_file!s   zFileOperator.write_binary_filecCs||||dSru)rencode)rrbrrr,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) rarP_namerrrrst_modechmod)rbitsmaskfilesrmoder,r,r-set_mode-szFileOperator.set_modecCs|dd|S)Nimi)r)r+rr,r,r-9zFileOperator.cCs|tj|}||jkrxtj|sx|j|tj|\}}||t d||j sft ||j rx|j |dS)Nz Creating %s)rarbrrrrrrrrrmkdirrr)rrbrrr,r,r-r;s    zFileOperator.ensure_dirc Cst|| }td|||js|s0|||rX|s:d}n||sHt|t|d}i}|rvtt drvt j j |d<t j |||df|| ||S)NzByte-compiling %s to %sPycInvalidationModeinvalidation_modeT)r rrrrrTrdrerp py_compiler CHECKED_HASHcompiler) rrboptimizeforcermZhashed_invalidationZdpathZdiagpathZcompile_kwargsr,r,r- byte_compileGs   zFileOperator.byte_compilecCstj|rtj|r^tj|s^td||js@t ||j r||j kr|j |nPtj|rpd}nd}td|||jst ||j r||j kr|j |dS)NzRemoving directory tree at %slinkfilezRemoving %s %s)rarbrrrrdebugrrrrrrr)rrbr+r,r,r-ensure_removedXs"       zFileOperator.ensure_removedcCsDd}|s@tj|r$t|tj}q@tj|}||kr:q@|}q|Sr)rarbraccessW_OKr)rrbr(parentr,r,r- is_writablems  zFileOperator.is_writablecCs"|js t|j|jf}||S)zV Commit recorded changes, turn off recording, return changes. )rrdrrr)rr(r,r,r-commitys  zFileOperator.commitcCs|jst|jD]}tj|rt|qt|jdd}|D]F}t |}|rz|dgks^t tj ||d}t |t |q>| dS)NT)reverse __pycache__r)rlistrrarbrrsortedrlistdirrdr$rmdirr)rrdirsrflistZsdr,r,r-rollbacks     zFileOperator.rollback)F)T)N)FFNF)rrrrrrrrrrrrZset_executable_moderrrrr rr,r,r,r-rs         rcCs^|tjkrtj|}nt|}|dkr,|}n.|d}t||d}|D]}t||}qJ|S)N.r)rqmodules __import__rrrrh)Z module_nameZ dotted_pathmodr(r*r}r,r,r-resolves    rc@s6eZdZddZeddZddZddZej Z d S) ExportEntrycCs||_||_||_||_dSrurPrmrkr)rrPrmrkrr,r,r-rszExportEntry.__init__cCst|j|jSru)rrmrkrr,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)rxrrPrmrkr)rotherr(r,r,r-__eq__s     zExportEntry.__eq__N) rrrrrrrrr__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|ks"d|krtd|n|}|d}|d}|d}|dkrf|d}}n"|dkrztd||d\}}|d } | dkrd|ksd|krtd|g} nd d | d D} t|||| }|S) NrArBzInvalid specification '%s'rPcallable:rrrcSsg|] }|qSr,)rS)rNrr,r,r-rOsz$get_export_entry..rC)ENTRY_REsearchr groupdictcountrr) Z specificationr'r(rrPrbZcolonsrmrkrr,r,r-rs8   rcCs|dkr d}tjdkr.dtjkr.tjd}n tjd}tj|rft|tj}|st d|n|dd\}}d|kr.|}n|dd\}}|rJt|}|rVt|}|||fS)NrDrr)rsplitrr)rXZusernameZpasswordrmr,r,r-parse_credentials$sr3cCstd}t||S)N)raumaskrsr,r,r-get_process_umask3s  r6cCs<d}d}t|D]\}}t|tsd}q,q|dk s8t|S)NTF) enumeraterxrrd)seqr(r[r+r,r,r-is_string_sequence8s  r9z3([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}|dkrt |}|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!rstartrererescaperPROJECT_NAME_AND_VERSION)filenameZ project_namer(Zpyverr'nr,r,r-split_filenameGs"   rCz-(?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"rSrz)r}r'rr,r,r-parse_name_and_versioncs  rEcCst}t|pg}t|pg}d|kr8|d||O}|D]x}|dkrT||q<|dr|dd}||krtd|||kr||q<||krtd|||q<|S)N*r;rzundeclared extra: %s)rrrrTrr*)Z requestedZ availabler(rZunwantedr,r,r- get_extrasrs&        rHc Csi}zNt|}|}|d}|ds8td|ntd|}t |}Wn0t k r}zt d||W5d}~XYnX|S)Nz Content-Typezapplication/jsonz(Unexpected response for JSON request: %srz&Failed to get external data for %s: %s) r rgetrTrrrrrrr exception)rRr(ZrespZheadersZctreaderer,r,r-_get_external_datas   rMz'https://www.red-dove.com/pypi/projects/cCs*d|d|f}tt|}t|}|S)Nz%s/%s/project.jsonrupperr _external_data_base_urlrM)rPrRr(r,r,r-get_project_datas rQcCs(d|d||f}tt|}t|S)Nz%s/%s/package-%s.jsonrrN)rPversionrRr,r,r-get_package_datas rSc@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) rarbrr+rrrr*rnormpathrj)rrjr,r,r-rs    zCache.__init__cCst|S)zN Converts a resource prefix to a directory name in the cache. )r/)rrmr,r,r- prefix_to_dirszCache.prefix_to_dirc Csg}t|jD]r}tj|j|}z>tj|s>tj|rJt|ntj|r`t |Wqt k r| |YqXq|S)z" Clear the cache. ) rarrjrbr$rrrrrrrr")rZ not_removedfnr,r,r-clears  z Cache.clearN)rrr__doc__rrWrYr,r,r,r-rTsrTc@s:eZdZdZddZdddZddZd d Zd d Zd S) EventMixinz1 A very simple publish/subscribe system. cCs i|_dSru) _subscribersrr,r,r-rszEventMixin.__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)r\rr" appendleft)revent subscriberr"subsZsqr,r,r-rs  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)r\rr)rr^r_r`r,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,)iterr\rI)rr^r,r,r-get_subscribersszEventMixin.get_subscribersc Oslg}||D]F}z||f||}Wn"tk rHtdd}YnX||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)rbrrrJr"r)rr^argskwargsr(r_rr,r,r-publishs    zEventMixin.publishN)T) rrrrZrrrrbrer,r,r,r-r[s   r[c@s^eZdZddZddZdddZdd Zd d Zd d ZddZ e ddZ e ddZ dS) SequencercCsi|_i|_t|_dSru)_preds_succsr_nodesrr,r,r-r"szSequencer.__init__cCs|j|dSru)rirrnoder,r,r-add_node'szSequencer.add_nodeFcCs||jkr|j||rt|j|dD]}|||q,t|j|dD]}|||qPt|jD]\}}|sp|j|=qpt|jD]\}}|s|j|=qdS)Nr,)rirrrgrIrhr r)rrkZedgesr}r+rrIr,r,r- remove_node*s   zSequencer.remove_nodecCs<||ks t|j|t||j|t|dSru)rdrg setdefaultrrrh)rpredsuccr,r,r-r:s z Sequencer.addcCs||ks tz|j|}|j|}Wn tk rDtd|YnXz||||Wn$tk rtd||fYnXdS)Nz%r not a successor of anythingz%r not a successor of %r)rdrgrhKeyErrorrr)rrorppredsZsuccsr,r,r-r?s   zSequencer.removecCs||jkp||jkp||jkSru)rgrhri)rstepr,r,r-is_stepLszSequencer.is_stepcCs||std|g}g}t}|||r|d}||krb||kr||||q.|||||j|d}| |q.t |S)Nz Unknown: %rrr,) rtrrr"rhrrrgrIextendreversed)rfinalr(Ztodoseenrsrrr,r,r- get_stepsPs"         zSequencer.get_stepscsRdggiig|jfddD]}|kr8|q8S)Nrcsd|<d|<dd7<|z |}Wntk rVg}YnX|D]J}|kr|t|||<q\|kr\t|||<q\||krg}}||||krqqt|}|dS)Nrr)r"rminrhtuple)rkZ successorsZ successorZconnected_componentZ componentZgraphindexZ index_counterZlowlinksr(stack strongconnectr,r-rts,      z3Sequencer.strong_connections..strongconnect)rhrjr,r|r-strong_connectionsis" zSequencer.strong_connectionscCsfdg}|jD]*}|j|}|D]}|d||fqq |jD]}|d|q>|dd|S)Nz digraph G {z %s -> %s;z %s;} )rgr"rir$)rr(rprrrorkr,r,r-dots    z Sequencer.dotN)F) rrrrrlrmrrrtrypropertyrrr,r,r,r-rf!s   2rf).tar.gz.tar.bz2.tar.zip.tgz.tbz.whlTc sZfdd}tjtd}|dkr|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| _qdd} | |_|W5|rT|XdS)NcsRt|ts|d}tjtj|}|rB|tjkrNt d|dS)Nrzpath outside destination: %r) rxrdecoderarbrr$rTrcr)rbr}dest_dirZplenr,r- check_paths   zunarchive..check_path)rrzip)rrZtgzzr:gz)rrZtbzzr:bz2rZtarrGzUnknown format for %rrrrc SsDzt||WStjk r>}ztt|W5d}~XYnXdS)z:Run tarfile.tar_fillter, but raise the expected ValueErrorN)tarfileZ tar_filterZ FilterErrorrstr)memberrbexcr,r,r-extraction_filtersz$unarchive..extraction_filter)rarbrrer0rrrZnamelistrrZgetnamesrqrZ getmembersrxrPrrrZ extractall) Zarchive_filenamerformatrrarchivernamesrPZtarinforr,rr- unarchivesL           rc Cs~t}t|}t|dZ}t|D]H\}}}|D]8}tj||}||d} tj| |} ||| q4q&W5QRX|S)z*zip a directory tree into a BytesIO objectrN) ioBytesIOrerrawalkrbr$r) Z directoryr(ZdlenZzfrfrrrPZfullZrelrlr,r,r-zip_dirs  r)rKMGTPc@sreZdZdZdddZddZdd Zd d Zd d Ze ddZ e ddZ ddZ e ddZ e ddZdS)ProgressZUNKNOWNrdcCs<|dks||kst||_|_||_d|_d|_d|_dS)NrF)rdrzcurmaxstartedelapseddone)rZminvalZmaxvalr,r,r-r s  zProgress.__init__cCsV|j|kst|jdks&||jks&t||_t}|jdkrF||_n ||j|_dSru)rzrdrrtimerr)rZcurvalZnowr,r,r-updates zProgress.updatecCs |dks t||j|dSNr)rdrr)rZincrr,r,r- increments zProgress.incrementcCs||j|Sru)rrzrr,r,r-r=s zProgress.startcCs |jdk r||jd|_dS)NT)rrrrr,r,r-stop#s  z Progress.stopcCs|jdkr|jS|jSru)runknownrr,r,r-maximum(szProgress.maximumcCsD|jr d}n4|jdkrd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)rrrrz)rr(rIr,r,r- percentage,s zProgress.percentagecCs:|dkr|jdks|j|jkr$d}ntdt|}|S)Nrz??:??:??z%H:%M:%S)rrrzrstrftimegmtime)rZdurationr(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 rrrz%s: %s)rrrrrzfloatr)rrmr\r,r,r-ETA@s z Progress.ETAcCsL|jdkrd}n|j|j|j}tD]}|dkr6q@|d}q&d||fS)Nrgig@@z%d %sB/s)rrrzUNITS)rr(Zunitr,r,r-speedSs  zProgress.speedN)rr)rrrrrrrr=rrrrrrrr,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-rhs    rc cst|d}t|dkrht|dks,t||\}}}|dD]$}td|||fD] }|VqXq@nd|krt|D] }|Vqxn~|dd\}}|dkrd}|dkrd}n|d}|d }t |D]4\}}} tj |}ttj ||D] } | VqqdS) NrrrCrz**rrFr`\) RICH_GLOBrrerdrr$ std_iglobr%rarrbrV) rZrich_path_globrmrrkitemrbZradicaldirrrXr,r,r-rss*         r) HTTPSHandlermatch_hostnameCertificateErrorc@seZdZdZdZddZdS)HTTPSConnectionNTcCsRt|j|jf|j}t|ddr0||_|tt dsp|j rHt j }nt j }t j ||j|j|t j|j d|_nxt t j}|jt jO_|jr||j|ji}|j rt j |_|j|j dtt ddr|j|d<|j |f||_|j rN|jrNz$t|j|jtd|jWn0tk rL|jtj|jYnXdS) NZ _tunnel_hostF SSLContext) cert_reqsZ ssl_versionca_certs)ZcafileZHAS_SNIZserver_hostnamezHost verified: %s) rZcreate_connectionhostporttimeoutrrsockZ_tunnelrpsslrZ CERT_REQUIREDZ CERT_NONEZ wrap_socketZkey_fileZ cert_fileZPROTOCOL_SSLv23rZoptionsZ OP_NO_SSLv2Zload_cert_chainZ verify_modeZload_verify_locations check_domainrZ getpeercertrrrZshutdownZ SHUT_RDWRr)rrrcontextrdr,r,r-connects@       zHTTPSConnection.connect)rrrrrrr,r,r,r-rsrc@s&eZdZd ddZddZddZdS) rTcCst|||_||_dSru)BaseHTTPSHandlerrrr)rrrr,r,r-rs 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. )rrr)rrcrdr(r,r,r- _conn_makers zHTTPSHandler._conn_makerc CsXz||j|WStk rR}z$dt|jkr@td|jnW5d}~XYnXdS)Nzcertificate verify failedz*Unable to verify server certificate for %s)Zdo_openrrrreasonrr)rrYrLr,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)rrYr,r,r- http_openszHTTPSOnlyHandler.http_openN)rrrrr,r,r,r-rsrrc@seZdZdddZdS)HTTPrNcKs&|dkr d}||j||f|dSr_setupZ_connection_classrrrrdr,r,r-rsz HTTP.__init__)rNrrrrr,r,r,r-rsrc@seZdZdddZdS)HTTPSrNcKs&|dkr d}||j||f|dSrrrr,r,r-rszHTTPS.__init__)rNrr,r,r,r-rsrc@seZdZdddZddZdS) TransportrcCs||_tj||dSru)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_connection s zTransport.make_connectionN)rrrrrrr,r,r,r-rs rc@seZdZdddZddZdS) SafeTransportrcCs||_tj||dSru)rrrrrr,r,r-rszSafeTransport.__init__cCsx||\}}}|si}|j|d<tdkr:t|df|}n:|jrN||jdkrj||_|tj|df|f|_|jd}|S)Nrrrr)rrrrrrrr)rrrrrdr(r,r,r-rs   zSafeTransport.make_connectionN)rrr,r,r,r-rs rc@seZdZddZdS) ServerProxyc Kst|dd|_}|dk r^t|\}}|dd}|dkr@t}nt}|||d|d<}||_tjj ||f|dS)NrrrZhttps)r transport) rhrrrIrrrrrr) rrZrdrrWr]rZtclsr\r,r,r-r,s  zServerProxy.__init__Nrr,r,r,r-r+srcKs6tjddkr|d7}nd|d<d|d<t||f|S)Nrrbrnewlinerr)rqrr)rXrrdr,r,r- _csv_open@s  rc@s4eZdZedededdZddZddZd S) CSVBaserC"r)Z delimiterZ quotecharZlineterminatorcCs|Srur,rr,r,r- __enter__RszCSVBase.__enter__cGs|jdSru)rr)rr&r,r,r-__exit__UszCSVBase.__exit__N)rrrrdefaultsrrr,r,r,r-rKs rc@s(eZdZddZddZddZeZdS) CSVReadercKs\d|kr4|d}tjddkr,td|}||_nt|dd|_tj|jf|j|_dS)NrrrrrbrG) rqrrrrrcsvrKr)rrdrr,r,r-rZszCSVReader.__init__cCs|Srur,rr,r,r-__iter__eszCSVReader.__iter__cCsFt|j}tjddkrBt|D] \}}t|ts |d||<q |SNrrr)nextrKrqrr7rxrr)rr(r[rr,r,r-rhs   zCSVReader.nextN)rrrrrr__next__r,r,r,r-rYs rc@seZdZddZddZdS) CSVWritercKs$t|d|_tj|jf|j|_dS)Nr)rrrwriterr)rrXrdr,r,r-rss zCSVWriter.__init__cCsNtjddkr>g}|D]"}t|tr.|d}||q|}|j|dSr)rqrrxrrr"rwriterow)rrowrGrr,r,r-rws   zCSVWriter.writerowN)rrrrrr,r,r,r-rrsrcsHeZdZeejZded<d fdd ZddZdd Zd d Z Z S) Configurator inc_convertZincNcs"tt|||pt|_dSru)superrrrarrj)rconfigrj __class__r,r-rszConfigurator.__init__c sfddd}t|s*|}dd}dd}|r\tfdd|D}fd dD}t|}|||}|r|D]\}} t||| q|S) Ncsvt|ttfr*t|fdd|D}nHt|trhd|krH|}qri}|D]}||||<qPn |}|S)Ncsg|] }|qSr,r,)rNr[convertr,r-rOszBConfigurator.configure_custom..convert..())rxr r{typedictconfigure_customr)or(r)rrr,r-rs   z.Configurator.configure_custom..convertrrz[]r,csg|] }|qSr,r,)rNr rr,r-rOsz1Configurator.configure_custom..cs$g|]}t|r||fqSr,)r)rNr)rrr,r-rOs)rhrrr{r rsetattr) rrr~Zpropsrcrrdr(rBrIr,)rrrr-r s     zConfigurator.configure_customcCs4|j|}t|tr0d|kr0|||j|<}|S)Nr)rrxr r )rrr(r,r,r- __getitem__s zConfigurator.__getitem__c CsFtj|stj|j|}tj|ddd}t|}W5QRX|S)z*Default converter for the inc:// protocol.rGrr) rarbisabsr$rjrrrr)rrrr(r,r,r-rs  zConfigurator.inc_convert)N) rrrr rZvalue_convertersrr rr __classcell__r,r,rr-rs  rc@s*eZdZdZd ddZddZdd ZdS) SubprocessMixinzC Mixin for running subprocesses and capturing their output FNcCs||_||_dSru)verboseprogress)rrrr,r,r-rszSubprocessMixin.__init__cCsj|j}|j}|}|sq^|dk r.|||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) rrreadlinerqstderrrrflushr)rrrrrr+r,r,r-rKs  zSubprocessMixin.readercKstj|ftjtjd|}tj|j|jdfd}|tj|j|jdfd}|| | | |j dk r| ddn|j rt jd|S)N)stdoutrr)rrcrzdone.mainzdone. ) subprocessPopenPIPE threadingZThreadrKrr=rwaitr$rrrqr)rcmdrdr}t1t2r,r,r- run_commands"   zSubprocessMixin.run_command)FN)rrrrZrrKr!r,r,r,r-rs rcCstdd|S)z,Normalize a python package name a la PEP 503z[-_.]+r;)r>subrz)rPr,r,r-normalize_namesr#)NN)r)N)N)NT)r collectionsr contextlibrZglobrrrrZloggingrarr>rr ImportErrorrrqrrrrZdummy_threadingrrrcompatrrrr r r r r rrrrrrrrrrrrrZ getLoggerrrrrrGrFr6r>r:rVr#r?r^rnrtryrrrrcontextmanagerrrrrrrrrrVERBOSEr rr-r/r1r3r6r9Ir@r<rCrDrErHrMrPrQrSrTr[rfZARCHIVE_EXTENSIONSrrrrrrrrrrrrrrrrrrrrrrrrrrrr#r,r,r,r-s      \         Yy   /   8 )    ,H  C]    *)   7.