3 ig@sddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZy ddlZWnek rdZYnXddlZddlZddlZddlZddlZy 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 j1e2Z3e j4dZ5e j4dZ6e j4d Z7e j4d Z8e j4d Z9e j4d Z:e j4d Z;e j4dZddZ?ddZ@ddZAdddZBddZCddZDdd ZEejFd!d"ZGejFd#d$ZHejFdd&d'ZIGd(d)d)eJZKd*d+ZLGd,d-d-eJZMd.d/ZNGd0d1d1eJZOe j4d2e jPZQd3d4ZRdd5d6ZSd7d8ZTd9d:ZUd;d<ZVd=d>ZWd?d@ZXe j4dAe jYZZe j4dBZ[ddCdDZ\e j4dEZ]dFdGZ^dHdIZ_dJdKZ`dLZadMdNZbdOdPZcGdQdRdReJZdGdSdTdTeJZeGdUdVdVeJZfdZgdd_d`ZhdadbZidZjGdidjdjeJZke j4dkZle j4dlZme j4dmZndndoZdpdqZoerddrlmpZqmrZrmsZsGdsdtdte$jtZtGdudvdveqZpGdwdxdxepe'ZuejvddyZwewdkrGd{d|d|e$jxZxerGd}d~d~e$jyZyGddde%jzZzerBGddde%j{Z{Gddde%j|Z|ddZ}GdddeJZ~Gddde~ZGddde~ZGddde(ZGdddeJZddZGdddeJZddZddZddZddddZddZdS)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). cSs2tj|}|r.|jd}||jd}n|s.marker_varcs|rR|ddkrR|ddj\}}|ddkr@td||ddj}n^|\}}xL|rtj|}|stP|jd}||jd}|\}}|||d}q`W|}||fS)Nr(r)zunterminated parenthesis: %s)oplhsrhs)r%r MARKER_OPrrr)r&r(r2r'r1r3)markerr.r,r- marker_expres       z!parse_marker..marker_exprcsV|\}}x@|rLtj|}|s"P||jd}|\}}d||d}qW||fS)Nand)r1r2r3)ANDrr)r&r2r'r3)r6r,r- marker_andxs   z parse_marker..marker_andcsV|\}}x@|rLtj|}|s"P||jd}|\}}d||d}qW||fS)Nor)r1r2r3)ORrr)r&r2r'r3)r9r,r-r5s   zparse_marker..markerr,)Z marker_stringr,)r5r9r6r.r- parse_marker8s $ r<cCs2|j}| s|jdrdStj|}|s6td||jd}||jd}d}}}}|op|ddkr<|jdd}|dkrtd||d|} ||ddj}g}xx| r0tj| }|std | |j |jd| |jd} | sP| dd krtd | | ddj} qW|s.get_versionsr/r0zunterminated parenthesis: %szinvalid constraint: %sz~=;zinvalid requirement: %szunexpected trailing data: %sz%s %sz, cSsg|] }d|qS)z%s %sr,).0conr,r,r- sz%parse_requirement..)nameextras constraintsr5url requirement)strip startswithrrr rrfindr%r" NON_SPACErschemenetlocrBrCr<r$r)reqr&r'distnamerLZ mark_exprrDuriir+trF_rErsr,r,r-parse_requirements                           r]cCsdd}i}x|D]\}}}tjj||}xt|D]t}tjj||} x`t| D]T} ||| } |dkrt|j| dqP||| } |jtjjdjd} | d| || <qPWq4WqW|S)z%Find destinations for resources filescSsD|jtjjd}|jtjjd}|j|s.t|t|djdS)N/)r!ospathseprQAssertionErrorlenr%)rootr`r,r,r- get_rel_pathsz)get_resources_dests..get_rel_pathNr^)r_r`r$rpopr!rarstrip)resources_rootrulesre destinationsbasesuffixdestprefixabs_baseabs_globabs_path resource_filerel_pathrel_destr,r,r-get_resources_destss  rucCs(ttdrd}ntjttdtjk}|S)N real_prefixT base_prefix)hasattrsysrngetattr)r(r,r,r-in_venv(s r{cCstj}t|tst|}|S)N)ry executable isinstancerr)r(r,r,r-get_executable2s  r~cCsT|}xJt|}|}| r |r |}|r|dj}||kr:P|rd|||f}qW|S)Nrz %c: %s %s)r lower)prompt allowed_chars error_promptdefaultpr+cr,r,r-proceedDs  rcCs<t|tr|j}i}x |D]}||kr||||<qW|S)N)r}rsplit)dkeysr(keyr,r,r-extract_by_keyTs  rcCstjddkrtjd|}|j}t|}yrtj|}|ddd}xR|jD]F\}}x<|jD]0\}}d||f}t |} | dk st | ||<qdWqRW|St k r|j ddYnXdd } t j} y| | |Wn<t jk r|jtj|}t|}| | |YnXi}xb| jD]V} i|| <}xB| j| D]4\} }d| |f}t |} | dk spt | || <qFWq*W|S) Nrzutf-8 extensionszpython.exportsexportsz%s = %scSs$t|dr|j|n |j|dS)N read_file)rxrreadfp)cpstreamr,r,r- read_streamqs  z!read_exports..read_stream)ry version_infocodecs getreaderreadr jsonloaditemsget_export_entryrb Exceptionseekr ConfigParserMissingSectionHeaderErrorclosetextwrapdedentsections)rdatajdatar(groupentrieskrEr+entryrrrrKvaluer,r,r- read_exports]sD      rcCstjddkrtjd|}tj}x||jD]p\}}|j|x\|jD]P}|j dkr`|j }nd|j |j f}|j rd|dj |j f}|j ||j|qJWq.W|j|dS)Nrrzutf-8z%s:%sz%s [%s]z, )ryrr getwriterrrr add_sectionvaluesrlrnflagsr$setrKwrite)rrrrrErr+r,r,r- write_exportss  rc cs$tj}z |VWdtj|XdS)N)tempfilemkdtemprrmtree)tdr,r,r-tempdirs rc cs.tj}ztj|dVWdtj|XdS)N)r_getcwdchdir)rcwdr,r,r-rs   rc cs.tj}ztj|dVWdtj|XdS)N)socketgetdefaulttimeoutsetdefaulttimeout)secondsctor,r,r-socket_timeouts   rc@seZdZddZdddZdS)cached_propertycCs ||_dS)N)func)selfrr,r,r-__init__szcached_property.__init__NcCs,|dkr |S|j|}tj||jj||S)N)robject __setattr____name__)robjclsrr,r,r-__get__s  zcached_property.__get__)N)r __module__ __qualname__rrr,r,r,r-rsrcCstjdkr|S|s|S|ddkr.td||ddkrFtd||jd}xtj|krj|jtjqRW|svtjStjj|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 absoluterzpath '%s' cannot end with '/')r_ra ValueErrorrcurdirremover`r$)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|_|jdS)N)dry_runrensured _init_record)rrr,r,r-rszFileOperator.__init__cCsd|_t|_t|_dS)NF)recordr files_written dirs_created)rr,r,r-rszFileOperator._init_recordcCs|jr|jj|dS)N)rradd)rr`r,r,r-record_as_writtenszFileOperator.record_as_writtencCsHtjj|s tdtjj|tjj|s0dStj|jtj|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)r_r`existsrabspathstatst_mtime)rsourcetargetr,r,r-newers  zFileOperator.newerTcCs|jtjj|tjd|||jsd}|rftjj|rDd|}n"tjj|rftjj | rfd|}|rvt |dt j |||j |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_dirr_r`dirnameloggerinforislinkrisfilerrcopyfiler)rinfileoutfilecheckmsgr,r,r- copy_files    zFileOperator.copy_fileNc Cstjj| st|jtjj|tjd|||jsx|dkrLt |d}nt j |d|d}zt j ||Wd|j X|j|dS)NzCopying stream %s to %swbw)encoding)r_r`isdirrbrrrrropenrr copyfileobjrr)rinstreamrr outstreamr,r,r- copy_streams  zFileOperator.copy_streamc Cs\|jtjj||jsNtjj|r.tj|t|d}|j|WdQRX|j |dS)Nr) rr_r`rrrrrrr)rr`rfr,r,r-write_binary_file's   zFileOperator.write_binary_filecCs|j||j|dS)N)rencode)rr`rrr,r,r-write_text_file0szFileOperator.write_text_filecCsrtjdkstjdkrntjdkrnxN|D]F}|jr?szFileOperator.cCs~tjj|}||jkrztjj| rz|jj|tjj|\}}|j|tj d||j shtj ||j rz|j j|dS)Nz Creating %s)r_r`rrrrrrrrrmkdirrr)rr`rrr,r,r-rAs    zFileOperator.ensure_dirc Cst|| }tjd|||js|s0|j||rX|s:d}n|j|sHt|t|d}i}|rvtt drvt j j |d<t j |||df||j ||S)NzByte-compiling %s to %sPycInvalidationModeZinvalidation_modeT)r rrrrrQrbrcrx py_compiler Z CHECKED_HASHcompiler) rr`optimizeforcernZhashed_invalidationdpathdiagpathZcompile_kwargsr,r,r- byte_compileMs   zFileOperator.byte_compilecCstjj|rtjj|r`tjj| r`tjd||jsBtj ||j r||j kr|j j |nPtjj|rrd}nd}tjd|||jstj ||j r||j kr|j j |dS)NzRemoving directory tree at %slinkfilezRemoving %s %s)r_r`rrrrdebugrrrrrrr)rr`r+r,r,r-ensure_removed^s"       zFileOperator.ensure_removedcCsHd}x>|sBtjj|r&tj|tj}Ptjj|}||kr)rKrnrlr)rr,r,r-__repr__s zExportEntry.__repr__cCsDt|tsd}n0|j|jko>|j|jko>|j|jko>|j|jk}|S)NF)r}r-rKrnrlr)rotherr(r,r,r-__eq__s     zExportEntry.__eq__N) rrrrrrr.r0r__hash__r,r,r,r-r-s   r-z(?P(\w|[-.+])+) \s*=\s*(?P(\w+)([:\.]\w+)*) \s*(\[\s*(?P[\w-]+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])? c Cstj|}|s0d}d|ks"d|krtd|n|j}|d}|d}|jd}|dkrf|d}}n"|dkrztd||jd\}}|d } | dkrd|ksd|krtd|g} nd d | jd D} t|||| }|S) Nr>r?zInvalid specification '%s'rKcallable:rrrcSsg|] }|jqSr,)rP)rHrr,r,r-rJsz$get_export_entry..r@)ENTRY_REsearchr groupdictcountrr-) specificationr'r(rrKr`colonsrnrlrr,r,r-rs2    rc Cs|dkr d}tjdkr.dtjkr.tjjd}n tjjd}tjj|rftj|tj}|st j d|n|jdd\}}d|kr.|}n|jdd\}}|rJt|}|rVt|}|||fS)NrArr3)rsplitrr)rUusernamepasswordrnr,r,r-parse_credentials*srMcCstjd}tj||S)N)r_umask)r(r,r,r-get_process_umask9s  rPcCs>d}d}x$t|D]\}}t|tsd}PqW|dk s:t|S)NTF) enumerater}rrb)seqr(rYr+r,r,r-is_string_sequence>s  rSz3([a-z0-9_]+([.-][a-z_][a-z0-9_]*)*)-([a-z0-9_.+-]+)z -py(\d\.?\d?)cCsd}d}t|jdd}tj|}|r@|jd}|d|j}|rt|t|dkrtjtj |d|}|r|j }|d|||dd|f}|dkrt j|}|r|jd|jd|f}|S)zw Extract name, version, python version from a filename (no extension) Return name, version, pyver or None N -rz\br) rr!PYTHON_VERSIONr5rstartrcrerescaperPROJECT_NAME_AND_VERSION)filename project_namer(pyverr'nr,r,r-split_filenameMs"   r_z-(?P[\w .-]+)\s*\(\s*(?P[^\s)]+)\)$cCs:tj|}|std||j}|djj|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'rKver)NAME_VERSION_RErrr6rPr)rr'rr,r,r-parse_name_and_versionis  rbcCst}t|pg}t|pg}d|kr8|jd||O}x|D]x}|dkrV|j|q>|jdr|dd}||krtjd|||kr|j|q>||krtjd||j|q>W|S)N*rUrzundeclared extra: %s)rrrrQrrA) requested availabler(runwantedr,r,r- get_extrasxs&        rhcCsi}yNt|}|j}|jd}|jds8tjd|ntjd|}tj |}Wn0t k r}ztj d||WYdd}~XnX|S)Nz Content-Typezapplication/jsonz(Unexpected response for JSON request: %szutf-8z&Failed to get external data for %s: %s) r rgetrQrrrrrrr exception)rNr(respheadersctreaderer,r,r-_get_external_datas   rpz'https://www.red-dove.com/pypi/projects/cCs*d|dj|f}tt|}t|}|S)Nz%s/%s/project.jsonr)upperr _external_data_base_urlrp)rKrNr(r,r,r-get_project_datas rscCs(d|dj||f}tt|}t|S)Nz%s/%s/package-%s.jsonr)rqr rrrp)rKversionrNr,r,r-get_package_datas ruc@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. cCsPtjj|stj|tj|jd@dkr6tjd|tjjtjj ||_ dS)zu Initialise an instance. :param base: The base directory where the cache should be located. ?rzDirectory '%s' is not privateN) r_r`rrBrrrrArnormpathrk)rrkr,r,r-rs    zCache.__init__cCst|S)zN Converts a resource prefix to a directory name in the cache. )rG)rrnr,r,r- prefix_to_dirszCache.prefix_to_dirc Csg}xtj|jD]r}tjj|j|}y>tjj|s@tjj|rLtj|ntjj|rbt j |Wqt k r|j |YqXqW|S)z" Clear the cache. ) r_rrkr`r$rrrrrrrr")r not_removedfnr,r,r-clears  z Cache.clearN)rrr__doc__rryr|r,r,r,r-rvsrvc@s:eZdZdZddZdddZddZd d Zd d Zd S) EventMixinz1 A very simple publish/subscribe system. cCs i|_dS)N) _subscribers)rr,r,r-rszEventMixin.__init__TcCsD|j}||krt|g||<n"||}|r6|j|n |j|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)rrr" appendleft)revent subscriberr"subssqr,r,r-rs  zEventMixin.addcCs,|j}||krtd|||j|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)rrr)rrrrr,r,r-rs zEventMixin.removecCst|jj|fS)z Return an iterator for the subscribers for an event. :param event: The event to return subscribers for. )iterrri)rrr,r,r-get_subscribersszEventMixin.get_subscribersc Ospg}xT|j|D]F}y||f||}Wn"tk rJtjdd}YnX|j|qWtjd|||||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)rrrrjr"r)rrargskwargsr(rrr,r,r-publish s    zEventMixin.publishN)T) rrrr}rrrrrr,r,r,r-r~s   r~c@s^eZdZddZddZdddZdd Zd d Zd d ZddZ e ddZ e ddZ dS) SequencercCsi|_i|_t|_dS)N)_preds_succsr_nodes)rr,r,r-r(szSequencer.__init__cCs|jj|dS)N)rr)rnoder,r,r-add_node-szSequencer.add_nodeFcCs||jkr|jj||rx&t|jj|fD]}|j||q.Wx&t|jj|fD]}|j||qVWx&t|jjD]\}}|sz|j|=qzWx&t|jjD]\}}|s|j|=qWdS)N)rrrrrirrr)rredgesrr+rrEr,r,r- remove_node0s   zSequencer.remove_nodecCs<||ks t|jj|tj||jj|tj|dS)N)rbr setdefaultrrr)rpredsuccr,r,r-r@s z Sequencer.addcCs||ks ty|j|}|j|}Wn tk rDtd|YnXy|j||j|Wn$tk rtd||fYnXdS)Nz%r not a successor of anythingz%r not a successor of %r)rbrrKeyErrorrr)rrrpredssuccsr,r,r-rEs   zSequencer.removecCs||jkp||jkp||jkS)N)rrr)rstepr,r,r-is_stepRszSequencer.is_stepcCs|j|std|g}g}t}|j|xd|r|jd}||krd||kr|j||j|q0|j||j||jj|f}|j |q0Wt |S)Nz Unknown: %rr) rrrr"rfrrrriextendreversed)rfinalr(todoseenrrr,r,r- get_stepsVs"        zSequencer.get_stepscsVdggiig|jfddxD]}|kr:|q:WS)Nrc sd|<d|<dd7<j|y |}Wntk rVg}YnXxR|D]J}|kr|t|||<q^|kr^t|||<q^W||krg}x j}|j|||krPqWt|}j|dS)Nrr)r"rminrftuple)r successors successorconnected_component component)graphindex index_counterlowlinksr(stack strongconnectr,r-rzs.       z3Sequencer.strong_connections..strongconnect)r)rrr,)rrrrr(rrr-strong_connectionsos"  zSequencer.strong_connectionscCsrdg}x8|jD].}|j|}x|D]}|jd||fq"WqWx|jD]}|jd|qHW|jddj|S)Nz digraph G {z %s -> %s;z %s;} )rr"rr$)rr(rrrrr,r,r-dots     z Sequencer.dotN)F) rrrrrrrrrrpropertyrrr,r,r,r-r's   3r.tar.gz.tar.bz2.tar.zip.tgz.tbz.whlTc sXfdd}tjjtd}|dkr|jdr>d}nH|jdrRd}d }n4|jdrfd }d }n |jdrzd}d}n td|z|dkrt|d}|r|j}xD|D] }||qWn.tj ||}|r|j }x|D] }||qW|dkr6t j ddkr6x.|j D]"} t| jts| jjd| _qW|jWd|rR|jXdS)NcsTt|ts|jd}tjjtjj|}|j sD|tjkrPt d|dS)Nzutf-8zpath outside destination: %r) r}rdecoder_r`rr$rQrar)r`r)dest_dirplenr,r- check_paths   zunarchive..check_path.zip.whlzip.tar.gz.tgztgzzr:gz.tar.bz2.tbztbzzr:bz2z.tartarrfzUnknown format for %rrrzutf-8)rr)rr)rr)r_r`rrcrHrrnamelisttarfilergetnamesryr getmembersr}rKrr extractallr) archive_filenamerformatrrarchivernamesrKtarinfor,)rrr- unarchivesH           rc Cstj}t|}t|db}xZtj|D]L\}}}x@|D]8}tjj||}||d} tjj| |} |j|| q8Wq(WWdQRX|S)z*zip a directory tree into a BytesIO objectrN) ioBytesIOrcrr_walkr`r$r) directoryr(dlenzfrdr!rrKfullrelrmr,r,r-zip_dirs   rrKMGTPc@sreZdZdZdddZddZdd Zd d Zd d Ze ddZ e ddZ ddZ e ddZ e ddZdS)ProgressUNKNOWNrdcCs<|dks||kst||_|_||_d|_d|_d|_dS)NrF)rbrcurmaxstartedelapseddone)rminvalmaxvalr,r,r-rs  zProgress.__init__cCsV|j|kst|jdks&||jks&t||_tj}|jdkrF||_n ||j|_dS)N)rrbrrtimerr)rcurvalnowr,r,r-update s zProgress.updatecCs |dks t|j|j|dS)Nr)rbrr)rincrr,r,r- increments zProgress.incrementcCs|j|j|S)N)rr)rr,r,r-rWs zProgress.startcCs |jdk r|j|jd|_dS)NT)rrr)rr,r,r-stops  z Progress.stopcCs|jdkr|jS|jS)N)runknown)rr,r,r-maximum!szProgress.maximumcCsD|jr d}n4|jdkrd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)rrrr)rr(rEr,r,r- percentage%s zProgress.percentagecCs:|dkr|jdks|j|jkr$d}ntjdtj|}|S)Nrz??:??:??z%H:%M:%S)rrrrstrftimegmtime)rdurationr(r,r,r-format_duration0szProgress.format_durationcCs|jrd}|j}n^d}|jdkr&d}nJ|jdks<|j|jkrBd}n.t|j|j}||j|j}|d|j}d||j|fS)NDonezETA rrz%s: %sr)rrrrrfloatr)rrnrZr,r,r-ETA9s z Progress.ETAcCsN|jdkrd}n|j|j|j}xtD]}|dkr6P|d}q(Wd||fS)Nrgig@@z%d %sB/s)rrrUNITS)rr(unitr,r,r-speedLs   zProgress.speedN)rr)rrrrrrrrWrrrrrrrr,r,r,r-rs     rz \{([^}]*)\}z[^/\\,{]\*\*|\*\*[^/\\,}]z^[^{]*\}|\{[^}]*$cCs<tj|rd}t||tj|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_GLOBr5r_CHECK_MISMATCH_SET_iglob) path_globrr,r,r-ras    rc cstj|d}t|dkrpt|dks,t||\}}}x|jdD](}x"tdj|||fD] }|Vq\WqBWnd|krxt|D] }|VqWn|jdd\}}|dkrd}|dkrd}n|jd}|jd }xHtj |D]:\}}} tj j |}x"ttj j||D] } | VqWqWdS) Nrrr@rz**r&rcr^\) RICH_GLOBrrcrbrr$ std_iglobr%r_rr`rx) rrich_path_globrnrrlitemr`radicaldirrr{r,r,r-rls*       r) HTTPSHandlermatch_hostnameCertificateErrorc@seZdZdZdZddZdS)HTTPSConnectionNTc CsZtj|j|jf|j}t|ddr0||_|jtt dsp|j rHt j }nt j }t j ||j|j|t j|j d|_nt jt j}tt dr|jt jO_|jr|j|j|ji}|j rt j |_|j|j dtt ddr|j|d<|j |f||_|j o|jrVy$t|jj|jtjd |jWn0tk rT|jjtj|jjYnXdS) N _tunnel_hostF SSLContext) cert_reqs ssl_versionca_certs OP_NO_SSLv2)cafileHAS_SNIserver_hostnamezHost verified: %s) rcreate_connectionhostporttimeoutrzsock_tunnelrxsslr CERT_REQUIRED CERT_NONE wrap_socketkey_file cert_filePROTOCOL_SSLv23r optionsrload_cert_chain verify_modeload_verify_locations check_domainr  getpeercertrrr shutdown SHUT_RDWRr)rrrcontextrr,r,r-connects@       zHTTPSConnection.connect)rrrrr&r+r,r,r,r-r sr c@s&eZdZd ddZddZddZdS) rTcCstj|||_||_dS)N)BaseHTTPSHandlerrrr&)rrr&r,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. )r rr&)rrrr(r,r,r- _conn_makers zHTTPSHandler._conn_makercCsVy|j|j|Stk rP}z&dt|jkr>td|jnWYdd}~XnXdS)Nzcertificate verify failedz*Unable to verify server certificate for %s)do_openr-rstrreasonr r)rrVror,r,r- https_opens zHTTPSHandler.https_openN)T)rrrrr-r1r,r,r,r-rs rc@seZdZddZdS)HTTPSOnlyHandlercCstd|dS)NzAUnexpected HTTP request on what should be a secure connection: %s)r)rrVr,r,r- http_openszHTTPSOnlyHandler.http_openN)rrrr3r,r,r,r-r2sr2c@seZdZdddZdS)HTTPrNcKs&|dkr d}|j|j||f|dS)Nr)_setup_connection_class)rrrrr,r,r-rsz HTTP.__init__)rN)rrrrr,r,r,r-r6sr6c@seZdZdddZdS)HTTPSrNcKs&|dkr d}|j|j||f|dS)Nr)r7r8)rrrrr,r,r-rszHTTPS.__init__)rN)rrrrr,r,r,r-r9sr9c@seZdZdddZddZdS) TransportrcCs||_tjj||dS)N)rrr:r)rr use_datetimer,r,r-rszTransport.__init__cCsb|j|\}}}tdkr(t||jd}n6|j s>||jdkrT||_|tj|f|_|jd}|S)Nr4r5)rrr)r4r5) get_host_info _ver_infor6r _connection_extra_headersrHTTPConnection)rrhehx509r(r,r,r-make_connections zTransport.make_connectionN)r)rrrrrDr,r,r,r-r:s r:c@seZdZdddZddZdS) SafeTransportrcCs||_tjj||dS)N)rrrEr)rrr;r,r,r-rszSafeTransport.__init__cCsz|j|\}}}|si}|j|d<tdkr:t|df|}n<|j sP||jdkrl||_|tj|df|f|_|jd}|S)Nrr4r5rr)r4r5)r<rr=r9r>r?rr )rrrArBrr(r,r,r-rDs    zSafeTransport.make_connectionN)r)rrrrrDr,r,r,r-rEs rEc@seZdZddZdS) ServerProxycKst|jdd|_}|dk r^t|d}|jdd}|dkr@t}nt}|||d|d<}||_tjj ||f|dS)Nrrr;https)r; transport) rfrrrirEr:rHrrFr)rrXrrrTr;tclsrZr,r,r-r&s  zServerProxy.__init__N)rrrrr,r,r,r-rF%srFcKs6tjddkr|d7}nd|d<d|d<t||f|S)Nrrbrnewlinezutf-8r)ryrr)r{rrr,r,r- _csv_open;s  rLc@s4eZdZedededdZddZddZd S) CSVBaser@"r) delimiter quotecharlineterminatorcCs|S)Nr,)rr,r,r- __enter__MszCSVBase.__enter__cGs|jjdS)N)rr)rr=r,r,r-__exit__PszCSVBase.__exit__N)rrrr/defaultsrRrSr,r,r,r-rMFs  rMc@s(eZdZddZddZddZeZdS) CSVReadercKs\d|kr4|d}tjddkr,tjd|}||_nt|dd|_tj|jf|j|_dS)Nrrrzutf-8r`rf) ryrrrrrLcsvrnrT)rrrr,r,r-rUszCSVReader.__init__cCs|S)Nr,)rr,r,r-__iter__`szCSVReader.__iter__cCsJt|j}tjddkrFx,t|D] \}}t|ts"|jd||<q"W|S)Nrrzutf-8)nextrnryrrQr}rr)rr(rYrr,r,r-rXcs   zCSVReader.nextN)rrrrrWrX__next__r,r,r,r-rUTs rUc@seZdZddZddZdS) CSVWritercKs$t|d|_tj|jf|j|_dS)Nr)rLrrVwriterrT)rr{rr,r,r-rns zCSVWriter.__init__cCsRtjddkrBg}x*|D]"}t|tr0|jd}|j|qW|}|jj|dS)Nrrzutf-8)ryrr}rrr"r[writerow)rrowrfrr,r,r-r\rs   zCSVWriter.writerowN)rrrrr\r,r,r,r-rZmsrZcsHeZdZeejZded<d fdd ZddZdd Zd d Z Z S) Configurator inc_convertincNcs"tt|j||ptj|_dS)N)superr^rr_rrk)rconfigrk) __class__r,r-rszConfigurator.__init__c sfddjd}t|s*j|}jdd}jdf}|r\tfdd|D}fddD}t|}|||}|rx$|jD]\}} t||| qW|S) Ncszt|ttfr*t|fdd|D}nLt|trld|krHj|}qvi}x(|D]}||||<qRWn j|}|S)Ncsg|] }|qSr,r,)rHrY)convertr,r-rJszBConfigurator.configure_custom..convert..z())r}rrtypedictconfigure_customrd)or(r)rdrr,r-rds    z.Configurator.configure_custom..convertz()r&z[]csg|] }|qSr,r,)rHrh)rdr,r-rJsz1Configurator.configure_custom..cs$g|]}t|r||fqSr,)r)rHr)rbrdr,r-rJs)rfr2r,rrfrsetattr) rrbrpropsrrrr(r^rEr,)rbrdrr-rgs     zConfigurator.configure_customcCs4|j|}t|tr0d|kr0|j||j|<}|S)Nz())rbr}rfrg)rrr(r,r,r- __getitem__s zConfigurator.__getitem__c CsFtjj|stjj|j|}tj|ddd}tj|}WdQRX|S)z*Default converter for the inc:// protocol.rfzutf-8)rN) r_r`isabsr$rkrrrr)rrrr(r,r,r-r_s  zConfigurator.inc_convert)N) rrrrfrvalue_convertersrrgrkr_ __classcell__r,r,)rcr-r^s  r^c@s*eZdZdZd ddZddZdd ZdS) SubprocessMixinzC Mixin for running subprocesses and capturing their output FNcCs||_||_dS)N)verboseprogress)rrprqr,r,r-rszSubprocessMixin.__init__cCsn|j}|j}xT|j}|sP|dk r0|||q|sBtjjdntjj|jdtjjqW|jdS)z Read lines from a subprocess' output stream and either pass to a progress callable (if specified) or write progress information to sys.stderr. Nr&zutf-8) rqrpreadlinerystderrrrflushr)rrr*rqrpr+r,r,r-rns zSubprocessMixin.readercKstj|ftjtjd|}tj|j|jdfd}|jtj|j|jdfd}|j|j |j |j |j dk r|j ddn|j rt jjd|S)N)stdoutrsru)rrrszdone.mainzdone. ) subprocessPopenPIPE threadingThreadrnrurWrswaitr$rqrpryr)rcmdrrt1t2r,r,r- run_commands   zSubprocessMixin.run_command)FN)rrrr}rrnrr,r,r,r-ros rocCstjdd|jS)z,Normalize a python package name a la PEP 503z[-_.]+rU)rXsubr)rKr,r,r-normalize_namesrc@s.eZdZdZdZd ddZddZdd ZdS) PyPIRCFilezhttps://upload.pypi.org/legacy/pypiNcCs.|dkrtjjtjjdd}||_||_dS)Nr<z.pypirc)r_r`r$r@r[rN)rr{rNr,r,r-rszPyPIRCFile.__init__c Csi}tjj|jr|jp|j}tj}|j|j|j }d|kr2|j dd}dd|j dD}|gkr~d|kr|dg}nx|D]}d|i}|j |d|d<xHd |jfd |j fdfD].\}} |j ||r|j ||||<q| ||<qW|dkr||jdfkr|j|d <q|d|kr|d |kri}qWnRd |krd }|j |d r\|j |d }n|j}|j |d|j |d |||j d }|S)N distutilsz index-serverscSs g|]}|jdkr|jqS)r)rP)rHserverr,r,r-rJ sz#PyPIRCFile.read..rrrrK repositoryrealmrLz server-login)rKrLrrr)rLN)r_r`rr[rNDEFAULT_REPOSITORYrRawConfigParserrrrir DEFAULT_REALM has_option) rr(rrbr index_servers_serversrrrr,r,r-rsN                 zPyPIRCFile.readc Csltj}|j}|j||jds,|jd|jdd||jdd|t|d}|j|WdQRXdS)NrrKrLr) rrr[r has_sectionrrrr)rrKrLrbr{rr,r,r-r9s    zPyPIRCFile.update)NN)rrrrrrrrr,r,r,r-rs  :rcCst|jdjS)zG Read the PyPI access configuration as supported by distutils. )rN)rrNr)rr,r,r- _load_pypircEsrcCstj|j|jdS)N)rrrKrL)rr,r,r- _store_pypircKsrc CstjdkrFdtjjkrdSdtjjkr.dSdtjjkr@dStjSdtjkrZtjdStjd kspttd  rvtjStj\}}}}}|jj d d }|j d dj d d}|dddkrd||fS|dddkr*|ddkrd}dt |dd|ddf}ddd}|d|tj 7}n|dddkrNdd l m }|S|dd!d"krd"}tjd#tj}|j|}|r|j}n>|dd!d$krddl} ddl} | j| jj|||\}}}d%|||fS)&aReturn a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact information included depends on the OS; eg. on Linux, the kernel version isn't particularly important. Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u Windows will return one of: win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) win32 (all others - specifically, sys.platform is returned) For other non-POSIX platforms, currently just returns 'sys.platform'. r:amd64z win-amd64z(arm)z win-arm32z(arm64)z win-arm64_PYTHON_HOST_PLATFORMrunamer^rrTr[rUNlinuxz%s-%ssunosr5solarisz%d.%srr432bit64bit)ilz.%saix) aix_platformr5cygwinz[\d.]+darwinz%s-%s-%s)r_rKryrtrplatformr>rxrr!intmaxsizeZ _aix_supportrrXr ASCIIrr _osx_supportdistutils.sysconfigget_platform_osx sysconfigget_config_vars) osnamerreleasertmachinebitnessrrel_rer'rrr,r,r-get_host_platformSsL         rwin32z win-amd64z win-arm32)Zx86Zx64ZarmcCs2tjdkrtStjjd}|tkr*tSt|S)Nr:ZVSCMD_ARG_TGT_ARCH)r_rKrr>ri_TARGET_TO_PLAT)Zcross_compilation_targetr,r,r- get_platforms   r)NN)r)N)N)rrrrrrr)NT)rrrrrr)r4r5)r collectionsr contextlibrVglobrrrrloggingr_r rXrr ImportErrorrwryrrrrzdummy_threadingrrrcompatrrrr r r r r rrrrrrrrrrrrr getLoggerrrr rrCrBr4r;r8rSr#r<r]rur{r~rrrrcontextmanagerrrrrrrrr,r-VERBOSEr4rrErGrIrMrPrSIrZrVr_rarbrhrprrrsrurvr~rARCHIVE_EXTENSIONSrrrrrrrrrr,r r r r2rr=r6r9r:rErFrLrMrUrZr^rorrrrrrrr,r,r,r-s      \         Y}   /  8  )    ,H  6]    +)   7.QR