3 Pfi@s>ddlZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZy 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/e j0e1Z2dZ3e j4e3Z5dZ6d e6d Z7e6d Z8d Z9d e9de8de3d e9de8dZ:dZ;de:de;de:dZde6de>de<dZ?e j4e?Z@de9de8d ZAe j4eAZBdd ZCd!d"ZDd#d$ZEd%d&ZFdd'd(ZGd)d*ZHd+d,ZId-d.ZJejKd/d0ZLejKd1d2ZMejKdd4d5ZNGd6d7d7eOZPd8d9ZQGd:d;d;eOZRdd?d?eOZTe j4d@e jUZVdAdBZWddCdDZXdEdFZYdGdHZZdIdJZ[dKdLZ\dMdNZ]e j4dOe j^Z_e j4dPZ`ddQdRZae j4dSZbdTdUZcdVdWZddXdYZedZZfd[d\Zgd]d^ZhGd_d`d`eOZiGdadbdbeOZjGdcddddeOZkdZlddmdnZmdodpZndZoGdwdxdxeOZpe j4dyZqe j4dzZre j4d{Zsd|d}Zd~dZter\ddlmuZvmwZwmxZxGddde$jyZyGdddevZuGdddeue'Zzej{ddZ|e|dkrGddde$j}Z}erGddde$j~Z~Gddde%jZerGddde%jZGddde%jZddZGdddeOZGdddeZGdddeZGddde(ZGdddeOZddZdS)N)deque)iglob)DistlibException) string_types text_typeshutil raw_inputStringIOcache_from_sourceurlopenurljoinhttplib xmlrpclib splittype HTTPHandlerBaseConfigurator valid_ident Container configparserURLErrorZipFilefsdecodeunquotez\s*,\s*z (\w|[.-])+z(\*|:(\*|\w+):|)z\*?z([<>=!~]=)|[<>](z)?\s*(z)(z)\s*(z))*z(from\s+(?P.*))z \(\s*(?P|z)\s*\)|(?Pz\s*)z)*z \[\s*(?Pz)?\s*\]z(?Pz \s*)?(\s*z)?$z(?Pz )\s*(?Pc sddd}tj|}|r|j}|d}|dp8|d}|dsHd}nd}|dj}|snd}d}|d}nL|dd krd |}tj|} fd d | D}d |djdd |Df}|dsd} ntj|d} t ||| |||d}|S)NcSs|j}|d|dfS)NopZvn) groupdict)mdr!/usr/lib/python3.6/util.pyget_constraintYsz)parse_requirement..get_constraintZdnZc1Zc2Zdirefrz<>!=z~=csg|] }|qSr!r!).0r)r#r!r" qsz%parse_requirement..z%s (%s)z, cSsg|] }d|qS)z%s %sr!)r%Zconr!r!r"r&rsZex)nameZ constraintsextrasZ requirementsourceurl) REQUIREMENT_REmatchrstripRELOP_IDENT_REfinditerjoinCOMMA_REsplitr) sresultrr r'Zconsr*ZconstrZrsiteratorr(r!)r#r"parse_requirementWs4      r6cCsdd}i}x|D]\}}}tjj||}xt|D]t}tjj||} x`t| D]T} ||| } |dkrt|j| dqP||| } |jtjjdjd} | d| || <qPWq4WqW|S)z%Find destinations for resources filescSs6|jtjjd}|jtjjd}|t|djdS)N/)replaceospathseplenlstrip)baser:r!r!r" get_rel_pathsz)get_resources_dests..get_rel_pathNr7)r9r:r0rpopr8r;rstrip)Zresources_rootZrulesr?Z destinationsr>suffixdestprefixZabs_baseZabs_globZabs_pathZ resource_fileZrel_pathZrel_destr!r!r"get_resources_dests|s  rEcCs(ttdrd}ntjttdtjk}|S)NZ real_prefixT base_prefix)hasattrsysrDgetattr)r4r!r!r"in_venvs rJcCs$tjjtj}t|ts t|}|S)N)r9r:normcaserH executable isinstancerr)r4r!r!r"get_executables  rNcCsT|}xJt|}|}| r |r |}|r|dj}||kr:P|rd|||f}qW|S)Nrz %c: %s %s)r lower)promptZ allowed_charsZ error_promptdefaultpr3cr!r!r"proceeds  rTcCs<t|tr|j}i}x |D]}||kr||||<qW|S)N)rMrr2)r keysr4keyr!r!r"extract_by_keys  rWcCsntjddkrtjd|}|j}t|}yftj|}|ddd}xF|jD]:\}}x0|jD]$\}}d||f}t |} | ||<qdWqRW|St k r|j ddYnXdd } t j } y| | |Wn<t jk r|jtj|}t|}| | |YnXi}xT| jD]H} i|| <}x4| j| D]&\} }d| |f}t |} | || <q:WqW|S) Nrzutf-8 extensionszpython.exportsexportsz%s = %scSs$t|dr|j|n |j|dS)N read_file)rGr[Zreadfp)cpstreamr!r!r" read_streams  z!read_exports..read_stream)rH version_infocodecs getreaderreadr jsonloaditemsget_export_entry Exceptionseekr ConfigParserZMissingSectionHeaderErrorclosetextwrapdedentZsections)r]dataZjdatar4groupZentrieskvr3entryr^r\rVr'valuer!r!r" read_exportss@     rscCstjddkrtjd|}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)NrrXzutf-8z%s:%sz%s [%s]z, )rHr_r` getwriterrrireZ add_sectionvaluesrBrDflagsr0setr'write)rZr]r\rorprqr3r!r!r" write_exportss  ryc cs$tj}z |VWdtj|XdS)N)tempfilemkdtemprrmtree)Ztdr!r!r"tempdir s r}c cs.tj}ztj|dVWdtj|XdS)N)r9getcwdchdir)r cwdr!r!r"rs   rc cs.tj}ztj|dVWdtj|XdS)N)socketZgetdefaulttimeoutZsetdefaulttimeout)ZsecondsZctor!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__)robjclsrrr!r!r"__get__.s  zcached_property.__get__)N)r __module__ __qualname__rrr!r!r!r"r(srcCstjdkr|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. r7rzpath '%s' cannot be absoluterzpath '%s' cannot end with '/')r9r; ValueErrorr2curdirremover:r0)pathnamepathsr!r!r" convert_path6s       rc@seZdZd$ddZddZddZdd Zd%d d Zd&ddZddZ ddZ ddZ ddZ ddZ d'ddZddZddZd d!Zd"d#Zd S)( FileOperatorFcCs||_t|_|jdS)N)dry_runrwensured _init_record)rrr!r!r"rRszFileOperator.__init__cCsd|_t|_t|_dS)NF)recordrw files_written dirs_created)rr!r!r"rWszFileOperator._init_recordcCs|jr|jj|dS)N)rradd)rr:r!r!r"record_as_written\szFileOperator.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)r9r:existsrabspathstatst_mtime)rr)targetr!r!r"newer`s  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_dirr9r:dirnameloggerinforislinkrisfilerrZcopyfiler)rZinfileoutfilecheckmsgr!r!r" copy_filets    zFileOperator.copy_fileNc Cst|jtjj|tjd|||jsf|dkr:t|d}ntj|d|d}zt j ||Wd|j X|j |dS)NzCopying stream %s to %swbw)encoding) rr9r:rrrropenr`rZ copyfileobjrjr)rZinstreamrrZ outstreamr!r!r" copy_streams  zFileOperator.copy_streamc CsF|jtjj||js8t|d}|j|WdQRX|j|dS)Nr)rr9r:rrrrxr)rr:rmfr!r!r"write_binary_files  zFileOperator.write_binary_filec CsL|jtjj||js>t|d}|j|j|WdQRX|j|dS)Nr) rr9r:rrrrxencoder)rr:rmrrr!r!r"write_text_files  zFileOperator.write_text_filecCsrtjdkstjdkrntjdkrnxN|D]F}|jrszFileOperator.cCs~tjj|}||jkrztjj| rz|jj|tjj|\}}|j|tj d||j shtj ||j rz|j j|dS)Nz Creating %s)r9r:rrrrr2rrrrmkdirrr)rr:r rr!r!r"rs    zFileOperator.ensure_dircCsht|| }tjd|||jsZ|s0|j||rJ|s:d}n|t|d}tj|||d|j||S)NzByte-compiling %s to %sT) r rrrrr< py_compilecompiler)rr:optimizeforcerDZdpathZdiagpathr!r!r" byte_compiles  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)r9r:risdirrrdebugrrr|rrrr)rr:r3r!r!r"ensure_removeds"       zFileOperator.ensure_removedcCsHd}x>|sBtjj|r&tj|tj}Ptjj|}||kr)r'rDrBrv)rr!r!r"__repr__!s zExportEntry.__repr__cCsDt|tsd}n0|j|jko>|j|jko>|j|jko>|j|jk}|S)NF)rMrr'rDrBrv)rotherr4r!r!r"__eq__%s     zExportEntry.__eq__N) rrrrrrrrrr__hash__r!r!r!r"rs   rz(?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) N[]zInvalid specification '%s'r'callable:rrrvcSsg|] }|jqSr!)r-)r%rr!r!r"r&Qsz$get_export_entry..,)ENTRY_REsearchrrcountr2r) Z specificationrr4r r'r:ZcolonsrDrBrvr!r!r"rf7s2    rfc Cs|dkr d}tjdkr.dtjkr.tjjd}n tjjd}tjj|rftj|tj}|st j d|n|jdd\}}d|kr.|}n|jdd\}}|||fS)N@rr)r2)ZnetlocZusernameZpasswordrDr!r!r"parse_credentialssrcCstjd}tj||S)N)r9umask)r4r!r!r"get_process_umasks  rcCs2d}d}x$t|D]\}}t|tsd}PqW|S)NTF) enumeraterMr)seqr4ir3r!r!r"is_string_sequences rz3([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\brX) rr8PYTHON_VERSIONrrnstartr<rer,escapeendPROJECT_NAME_AND_VERSION)filenameZ project_namer4Zpyverrnr!r!r"split_filenames"   rz-(?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'r'Zver)NAME_VERSION_REr,rrr-rO)rRrr r!r!r"parse_name_and_versions  rcCst}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*rrzundeclared extra: %s)rwrr startswithrr)Z requestedZ availabler4rZunwantedr!r!r" get_extrass&        rcCsi}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 rgetrrrr`rarcrdrg exception)r*r4ZrespZheadersZctreaderer!r!r"_get_external_datas   rz'https://www.red-dove.com/pypi/projects/cCs*d|dj|f}tt|}t|}|S)Nz%s/%s/project.jsonr)upperr _external_data_base_urlr)r'r*r4r!r!r"get_project_datas rcCs(d|dj||f}tt|}t|S)Nz%s/%s/package-%s.jsonr)rr rr)r'versionr*r!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. 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) r9r:rrrrrrrnormpathr>)rr>r!r!r"r"s    zCache.__init__cCst|S)zN Converts a resource prefix to a directory name in the cache. )r)rrDr!r!r" prefix_to_dir0szCache.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. ) r9rr>r:r0rrrrrr|rgappend)rZ not_removedfnr!r!r"clear6s  z Cache.clearN)rrr__doc__rr$r'r!r!r!r"r!sr!c@s:eZdZdZddZdddZddZd d Zd d Zd S) EventMixinz1 A very simple publish/subscribe system. cCs i|_dS)N) _subscribers)rr!r!r"rKszEventMixin.__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)r*rr% appendleft)revent subscriberr%subsZsqr!r!r"rNs  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)r*rr)rr,r-r.r!r!r"rbs zEventMixin.removecCst|jj|fS)z Return an iterator for the subscribers for an event. :param event: The event to return subscribers for. )iterr*r)rr,r!r!r"get_subscribersnszEventMixin.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)r0rgrrr%r)rr,argskwargsr4r-rrr!r!r"publishus    zEventMixin.publishN)T) rrrr(rrrr0r3r!r!r!r"r)Gs   r)c@s^eZdZddZddZdddZdd Zd d Zd d ZddZ e ddZ e ddZ dS) SequencercCsi|_i|_t|_dS)N)_preds_succsrw_nodes)rr!r!r"rszSequencer.__init__cCs|jj|dS)N)r7r)rnoder!r!r"add_nodeszSequencer.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)r7rrwr5rr6rre)rr8ZedgesrRr3rorpr!r!r" remove_nodes   zSequencer.remove_nodecCs0|jj|tj||jj|tj|dS)N)r5 setdefaultrwrr6)rpredsuccr!r!r"rsz Sequencer.addcCs|y|j|}|j|}Wn tk r8td|YnXy|j||j|Wn$tk rvtd||fYnXdS)Nz%r not a successor of anythingz%r not a successor of %r)r5r6KeyErrorrr)rr<r=predsZsuccsr!r!r"rs  zSequencer.removecCs||jkp||jkp||jkS)N)r5r6r7)rstepr!r!r"is_stepszSequencer.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) rArrwr%r@rrr5rextendreversed)rfinalr4Ztodoseenr@r?r!r!r" get_stepss"        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%rgminr@tuple)r8Z successorsZ successorZconnected_componentZ component)graphindex index_counterlowlinksr4stack strongconnectr!r"rNs.       z3Sequencer.strong_connections..strongconnect)r6)rr8r!)rIrJrKrLr4rMrNr"strong_connectionss"  zSequencer.strong_connectionscCsrdg}x8|jD].}|j|}x|D]}|jd||fq"WqWx|jD]}|jd|qHW|jddj|S)Nz digraph G {z %s -> %s;z %s;} )r5r%r7r0)rr4r=r?r<r8r!r!r"dot s     z Sequencer.dotN)F) rrrrr9r:rrrArFpropertyrOrRr!r!r!r"r4s   3r4.tar.gz.tar.bz2.tar.zip.tgz.tbz.whlTc sffdd}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| _qWdd} | |_|jWd|r`|jXdS)NcsTt|ts|jd}tjjtjj|}|j sD|tjkrPt d|dS)Nzutf-8zpath outside destination: %r) rMrdecoder9r:rr0rr;r)r:rR)dest_dirplenr!r" check_paths   zunarchive..check_path.zip.whlzip.tar.gz.tgzZtgzzr:gz.tar.bz2.tbzZtbzzr:bz2z.tarZtarrzUnknown format for %rrrXzutf-8cSsBy tj||Stjk r<}ztt|WYdd}~XnXdS)z:Run tarfile.tar_fillter, but raise the expected ValueErrorN)tarfileZ tar_filterZ FilterErrorrstr)memberr:excr!r!r"extraction_filterPs z$unarchive..extraction_filter)r_r`)rbrc)rdre)r9r:rr<rrrZnamelistrfrZgetnamesrHr_Z getmembersrMr'rr[rjZ extractallrj) Zarchive_filenamer\formatrr^archivernamesr'Ztarinforjr!)r\r]r" unarchivesL           rnc 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) ioBytesIOr<rr9walkr:r0rx) Z directoryr4ZdlenZzfrootrrr'ZfullZrelrCr!r!r"zip_dir`s   rsr$KMGTPc@sreZdZdZdddZddZdd Zd d Zd d Ze ddZ e ddZ ddZ e ddZ e ddZdS)ProgressZUNKNOWNrdcCs(||_|_||_d|_d|_d|_dS)NrF)rGcurmaxstartedelapseddone)rZminvalZmaxvalr!r!r"rws  zProgress.__init__cCs0||_tj}|jdkr ||_n ||j|_dS)N)r{timer}r~)rZcurvalZnowr!r!r"updates  zProgress.updatecCs|j|j|dS)N)rr{)rZincrr!r!r" incrementszProgress.incrementcCs|j|j|S)N)rrG)rr!r!r"r s zProgress.startcCs |jdk r|j|jd|_dS)NT)r|rr)rr!r!r"stops  z Progress.stopcCs|jdkr|jS|jS)N)r|unknown)rr!r!r"maximumszProgress.maximumcCsD|jr d}n4|jdkrd}n$d|j|j|j|j}d|}|S)Nz100 %z ?? %gY@z%3d %%)rr|r{rG)rr4rpr!r!r" percentages zProgress.percentagecCs:|dkr|jdks|j|jkr$d}ntjdtj|}|S)Nrz??:??:??z%H:%M:%S)r|r{rGrZstrftimeZgmtime)rZdurationr4r!r!r"format_durationszProgress.format_durationcCs|jrd}|j}n^d}|jdkr&d}nJ|jdks<|j|jkrBd}n.t|j|j}||j|j}|d|j}d||j|fS)NZDonezETA rrz%s: %sr)rr~r|r{rGfloatr)rrDtr!r!r"ETAs z Progress.ETAcCsN|jdkrd}n|j|j|j}xtD]}|dkr6P|d}q(Wd||fS)Nrgig@@z%d %sB/s)r~r{rGUNITS)rr4Zunitr!r!r"speeds   zProgress.speedN)rrz)rrrrrrrr rrSrrrrrr!r!r!r"ryts     ryz \{([^}]*)\}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_GLOBrr_CHECK_MISMATCH_SET_iglob) path_globrr!r!r"rs    rc cstj|d}t|dkr\|\}}}x|jdD](}x"tdj|||fD] }|VqHWq.Wnd|kr~xt|D] }|VqnWn|jdd\}}|dkrd}|dkrd}n|jd}|jd}xFtj|D]8\}}} tj j |}x ttj j||D] } | VqWqWdS) Nrrr$z**rrr7\) RICH_GLOBr2r<rr0 std_iglobr=r9rqr:r#) rZrich_path_globrDrwrBitemr:Zradicaldirrr&r!r!r"rs(       r) HTTPSHandlermatch_hostnameCertificateErrorc@seZdZdZdZddZdS)HTTPSConnectionNTc CsPtj|j|jf|j}t|ddr0||_|jtt dsp|j rHt j }nt j }t j ||j|j|t j|j d|_nxt jt j}|jt jO_|jr|j|j|ji}|j rt j |_|j|j dtt ddr|j|d<|j |f||_|j o|jrLy$t|jj|jtjd|jWn0tk rJ|jjtj|jjYnXdS) NZ _tunnel_hostF SSLContext) cert_reqsZ ssl_versionca_certs)ZcafileZHAS_SNIZserver_hostnamezHost verified: %s) rZcreate_connectionhostporttimeoutrIsockZ_tunnelrGsslrZ CERT_REQUIREDZ CERT_NONEZ wrap_socketZkey_fileZ cert_fileZPROTOCOL_SSLv23rZoptionsZ OP_NO_SSLv2Zload_cert_chainZ verify_modeZload_verify_locations check_domainrZ getpeercertrrrZshutdownZ SHUT_RDWRrj)rrrcontextr2r!r!r"connect s>      zHTTPSConnection.connect)rrrrrrr!r!r!r"rsrc@s&eZdZd ddZddZddZdS) rTcCstj|||_||_dS)N)BaseHTTPSHandlerrrr)rrrr!r!r"r0s 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)rr1r2r4r!r!r" _conn_maker5s zHTTPSHandler._conn_makercCsVy|j|j|Stk rP}z&dt|jkr>td|jnWYdd}~XnXdS)Nzcertificate verify failedz*Unable to verify server certificate for %s)Zdo_openrrrgreasonrr)rreqrr!r!r" https_openEs zHTTPSHandler.https_openN)T)rrrrrrr!r!r!r"r/s rc@seZdZddZdS)HTTPSOnlyHandlercCstd|dS)NzAUnexpected HTTP request on what should be a secure connection: %s)r)rrr!r!r" http_openYszHTTPSOnlyHandler.http_openN)rrrrr!r!r!r"rXsrc@seZdZdddZdS)HTTPr$NcKs&|dkr d}|j|j||f|dS)Nr)_setup_connection_class)rrrr2r!r!r"resz HTTP.__init__)r$N)rrrrr!r!r!r"rdsrc@seZdZdddZdS)HTTPSr$NcKs&|dkr d}|j|j||f|dS)Nr)rr)rrrr2r!r!r"rmszHTTPS.__init__)r$N)rrrrr!r!r!r"rlsrc@seZdZdddZddZdS) TransportrcCs||_tjj||dS)N)rrrr)rr use_datetimer!r!r"rtszTransport.__init__cCsb|j|\}}}tdkr(t||jd}n6|j s>||jdkrT||_|tj|f|_|jd}|S)Nrr)rrr)rr) get_host_info _ver_inforr _connection_extra_headersrZHTTPConnection)rrhehZx509r4r!r!r"make_connectionxs zTransport.make_connectionN)r)rrrrrr!r!r!r"rss rc@seZdZdddZddZdS) SafeTransportrcCs||_tjj||dS)N)rrrr)rrrr!r!r"rszSafeTransport.__init__cCsz|j|\}}}|si}|j|d<tdkr:t|df|}n<|j sP||jdkrl||_|tj|df|f|_|jd}|S)Nrrrrr)rr)rrrrrrrr)rrrrr2r4r!r!r"rs    zSafeTransport.make_connectionN)r)rrrrrr!r!r!r"rs rc@seZdZddZdS) ServerProxyc Kst|jdd|_}|dk r^t|\}}|jdd}|dkr@t}nt}|||d|d<}||_tjj ||f|dS)NrrrZhttps)r transport) r@rrrrrrrrr) rZurir2rscheme_rZtclsrr!r!r"rs  zServerProxy.__init__N)rrrrr!r!r!r"rsrcKs.tjddkr|d7}nd|d<t||f|S)NrrXbr$newline)rHr_r)r&rr2r!r!r" _csv_opens rc@s4eZdZedededdZddZddZd S) CSVBaser"rQ)Z delimiterZ quotecharZlineterminatorcCs|S)Nr!)rr!r!r" __enter__szCSVBase.__enter__cGs|jjdS)N)r]rj)rrr!r!r"__exit__szCSVBase.__exit__N)rrrrgdefaultsrrr!r!r!r"rs  rc@s(eZdZddZddZddZeZdS) CSVReadercKs\d|kr4|d}tjddkr,tjd|}||_nt|dd|_tj|jf|j|_dS)Nr]rrXzutf-8r:r) rHr_r`rar]rcsvrr)rr2r]r!r!r"rszCSVReader.__init__cCs|S)Nr!)rr!r!r"__iter__szCSVReader.__iter__cCsJt|j}tjddkrFx,t|D] \}}t|ts"|jd||<q"W|S)NrrXzutf-8)nextrrHr_rrMrr[)rr4rrr!r!r"rs   zCSVReader.nextN)rrrrrr__next__r!r!r!r"rs rc@seZdZddZddZdS) CSVWritercKs$t|d|_tj|jf|j|_dS)Nr)rr]rwriterr)rr&r2r!r!r"rs zCSVWriter.__init__cCsRtjddkrBg}x*|D]"}t|tr0|jd}|j|qW|}|jj|dS)NrrXzutf-8)rHr_rMrrr%rwriterow)rrowrrr!r!r"rs   zCSVWriter.writerowN)rrrrrr!r!r!r"rsrcsHeZdZeejZded<d fdd ZddZdd Zd d Z Z S) Configurator inc_convertZincNcs"tt|j||ptj|_dS)N)superrrr9r~r>)rconfigr>) __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!)r%r)convertr!r"r&szBConfigurator.configure_custom..convert..z())rMrrHtypedictconfigure_customr)or4ro)rrr!r"rs    z.Configurator.configure_custom..convertz()rz[]csg|] }|qSr!r!)r%r)rr!r"r&sz1Configurator.configure_custom..cs$g|]}t|r||fqSr!)r)r%ro)rrr!r"r&s)r@rrrHrresetattr) rrrSZpropsr1rer2r4rrpr!)rrrr"rs     zConfigurator.configure_customcCs4|j|}t|tr0d|kr0|j||j|<}|S)Nz())rrMrr)rrVr4r!r!r" __getitem__s zConfigurator.__getitem__c CsFtjj|stjj|j|}tj|ddd}tj|}WdQRX|S)z*Default converter for the inc:// protocol.rzutf-8)rN) r9r:isabsr0r>r`rrcrd)rrrrr4r!r!r"rs  zConfigurator.inc_convert)N) rrrrrZvalue_convertersrrrr __classcell__r!r!)rr"rs  rc@s&eZdZd ddZddZddZdS) SubprocessMixinFNcCs||_||_dS)N)verboseprogress)rrrr!r!r"r+szSubprocessMixin.__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. Nrzutf-8) rrreadlinerHstderrrxr[flushrj)rr]rrrr3r!r!r"r/s zSubprocessMixin.readercKstj|ftjtjd|}tj|j|jdfd}|jtj|j|jdfd}|j|j |j |j |j dk r|j ddn|j rt jjd|S)N)stdoutrr)rr1rzdone.mainzdone. ) subprocessPopenPIPE threadingZThreadrrr rwaitr0rrrHrx)rcmdr2rRZt1Zt2r!r!r" run_commandDs   zSubprocessMixin.run_command)FN)rrrrrrr!r!r!r"r*s rcCstjdd|jS)z,Normalize a python package name a la PEP 503z[-_.]+r)r subrO)r'r!r!r"normalize_nameUsr)NN)r)N)N)rTrUrVrWrXrYrZ)NT)r$rtrurvrwrx)rr)r` collectionsr contextlibrZglobrrrorcZloggingr9rr rrr ImportErrorrrHrfrzrkrZdummy_threadingrr$rcompatrrr r r r r rrrrrrrrrrrrZ getLoggerrrCOMMArr1ZIDENTZ EXTRA_IDENTZVERSPECZRELOPZBARE_CONSTRAINTSZ DIRECT_REFZ CONSTRAINTSZ EXTRA_LISTZEXTRASZ REQUIREMENTr+Z RELOP_IDENTr.r6rErJrNrTrWrsrycontextmanagerr}rrrrrrrrVERBOSErrfrrrrrrIr rrrrrrrrr r!r)r4ZARCHIVE_EXTENSIONSrnrsrryrrrrrrrrrrr_rrrrrrrrrrrrrr!r!r!r"s      X   ,   %   /  7  )     ,H  C]    *)  :+