3 ]Μ@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZmZmZmZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z ddlm!Z!ddl"m#Z#dd l$m%Z%dd l&m'Z'dd l(m)Z)dd l*m+Z+dd l,m-Z-ej.dZ/ej.dej0Z1ej.dZ2ej.dej0j3Z4dj5Z6ddddgZ7dZ8dZ9e9j:ej;ddedZddZ?dEd dZ@dFd!d"ZAdGd#d$ZBdedfd%dZCdHd&d'ZDd(d)ZEej.d*ej0ZFeEd+d,ZGGd-d.d.eHZIGd/d0d0eIZJGd1ddeZKej.d2jLZMd3d4ZNd5d6ZOdId7d8ZPd9d:ZQGd;d<dd>ejSZTejUjVfd?d@ZWePe8eWZWdAdBZXdCdDZYdS)Jz#PyPI and direct package downloadingN)wraps)six)urllib http_client configparsermap) CHECKOUT_DIST Distribution BINARY_DISTnormalize_path SOURCE_DIST Environmentfind_distributions safe_name safe_version to_filename Requirement DEVELOP_DISTEGG_DIST) ssl_support)log)DistutilsError) translate)get_all_headers)unescape)Wheelz^egg=([-A-Za-z0-9_.+!]+)$zhref\s*=\s*['"]?([^'"> ]+)z([^<]+) \s+\(md5\)z([-+.a-z0-9]{2,}):z.tar.gz .tar.bz2 .tar .zip .tgz PackageIndexdistros_for_urlparse_bdist_wininstinterpret_distro_namez/tmp/pip-build-8jg9gmni/setuptools/setuptools/package_index.pyparse_requirement_arg2s  r(cCs|j}d\}}}|jdr|jdr8|dd}d}nn|jddrb|dd}|dd}d}nD|jd r~|dd}d }n(|jd dr|dd}|dd}d }|||fS)z=Return (base,pyversion) or (None,None) for possible .exe nameNz.exez .win32.exe win32z .win32-pyz.win-amd64.exez win-amd64z .win-amd64-py)NNNiiiiiiir0i)lowerendswith startswith)namer1basepy_verplatr&r&r'r;s$            c Csxtjj|}|\}}}}}}tjj|jdd}|dkrX|dkrXtjj|jdd}d|krp|jdd\}}||fS) N/zsourceforge.netdownload#)rr#urlparseunquotesplit) urlpartsschemeserverpath parametersqueryfragmentr5r&r&r'egg_info_for_urlSs rJccsdt|\}}xt|||D] }|VqW|r`tj|}|r`x$t||jd|tdD] }|VqRWdS)zEYield egg or source distribution objects that might be found at a URLr9) precedenceN)rJdistros_for_location EGG_FRAGMENTmatchrgroupr)rBmetadatar5rIdistrNr&r&r'r^s   cCs|jdr|dd }|jdr8d|kr8tj|||gS|jdrxd|krxt|}|js^gSt||j|jtddgS|jd rt|\}}}|dk rt ||||t |Sx4t D],}|j|r|dt | }t |||SqWgS) z:Yield egg or source distribution objects based on basenamez.egg.zipNr-z.egg-z.whlr9)location project_nameversionrKz.exer0) r2r from_locationrZ is_compatiblerTrUrrrr EXTENSIONSlen)rSbasenamerPwheelZwin_baser6platformextr&r&r'rLls.     rLcCstt|tjj||S)zEYield possible egg or source distribution objects based on a filename)rLr osrFrY)filenamerPr&r&r'distros_for_filenamesr_c cs|jd}| r.tdd|ddDr.dSxNtdt|dD]8}t||dj|d|dj||d|||dVqBWdS)zGenerate alternative interpretations of a source distro name Note: if `location` is a filesystem filename, you should call ``pkg_resources.normalize_path()`` on it before passing it to this routine! rRcss|]}tjd|VqdS)z py\d\.\d$N)rerN).0pr&r&r' sz(interpret_distro_name..r;Nr9) py_versionrKr[)rAanyrangerXr join)rSrYrPrdrKr[rCrbr&r&r'rs  $ccsnt}|j}|dkr>xTtjj|j|D]}|||Vq&Wn,x*|D]"}||}||krD|||VqDWdS)zHList unique elements, preserving order. Remember all elements ever seen.N)setaddrmoves filterfalse __contains__)iterablekeyseenZseen_addelementkr&r&r'unique_everseens  rrcstfdd}|S)zs Wrap a function returning an iterable such that the resulting iterable only ever yields unique items. cst||S)N)rr)argskwargs)funcr&r'wrapperszunique_values..wrapper)r)rurvr&)rur' unique_valuessrwz(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>ccsxvtj|D]h}|j\}}tttj|jjd}d|ksFd|kr x,t j|D]}t j j |t |jdVqRWq WxHdD]@}|j|}|d kr~t j||}|r~t j j |t |jdVq~WdS) zEFind rel="homepage" and rel="download" links in `page`, yielding URLs,Zhomepager:r9 Home PageDownload URLN)ryrzr=)RELfinditergroupsrhrstrstripr1rAHREFrr#urljoin htmldecoderOfindsearch)rBpagerNtagrelZrelsposr&r&r'find_external_linkss "   rc@s(eZdZdZddZddZddZdS) ContentCheckerzP A null content checker that defines the interface for checking content cCsdS)z3 Feed a block of data to the hash. Nr&)selfblockr&r&r'feedszContentChecker.feedcCsdS)zC Check the hash. Return False if validation fails. Tr&)rr&r&r'is_validszContentChecker.is_validcCsdS)zu Call reporter with information about the checker (hash name) substituted into the template. Nr&)rreportertemplater&r&r'reportszContentChecker.reportN)__name__ __module__ __qualname____doc__rrrr&r&r&r'rsrc@sBeZdZejdZddZeddZddZ dd Z d d Z d S) HashCheckerzK(?Psha1|sha224|sha384|sha256|sha512|md5)=(?P[a-f0-9]+)cCs||_tj||_||_dS)N) hash_namehashlibnewhashexpected)rrrr&r&r'__init__ s zHashChecker.__init__cCs>tjj|d}|stS|jj|}|s0tS|f|jS)z5Construct a (possibly null) ContentChecker from a URLr9r=)rr#r?rpatternr groupdict)clsrBrIrNr&r&r'from_urls zHashChecker.from_urlcCs|jj|dS)N)rupdate)rrr&r&r'rszHashChecker.feedcCs|jj|jkS)N)r hexdigestr)rr&r&r'r szHashChecker.is_validcCs||j}||S)N)r)rrrmsgr&r&r'r#s zHashChecker.reportN) rrrr`compilerr classmethodrrrrr&r&r&r'rs rcs<eZdZdZdKddZdLd d ZdMd d ZdNd dZddZddZ ddZ ddZ dOddZ ddZ dPfdd ZddZdd Zd!d"Zd#d$Zd%d&ZdQd'd(ZdRd)d*Zd+d,Zd-Zd.d/Zd0d1ZdSd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z!d@dAZ"dBdCZ#dDdEZ$dFdGZ%dHdIZ&Z'S)Urz;A distribution index that scans web pages for download URLshttps://pypi.python.org/simple*NTcOstj|f|||dd|jd |_i|_i|_i|_tjdj t t |j |_ g|_|ortjor|prtj}|rtj||_n tjj|_dS)Nr8|)r rr2 index_url scanned_urls fetched_urls package_pagesr`rrgrrrNallowsto_scanrZ is_availableZfind_ca_bundleZ opener_foropenerrrequesturlopen)rrhostsZ ca_bundleZ verify_sslrskwZuse_sslr&r&r'r+s zPackageIndex.__init__Fc Cs||jkr| rdSd|j|<t|s4|j|dStt|}|r^|j|sRdS|jd||sr| sr||jkrtt|j |dS|j|sd|j|<dS|j d|d|j|<d}|j |||}|dkrdSd|j|j <d|j jddjkr|jdS|j }|j}t|tsRt|tjjr4d }n|j jd pDd }|j|d }|jx6tj|D](} tjj|t| jd } |j| qfW|j |j!rt"|d ddkr|j#||}dS)z.)filterr]rFrr itertoolsstarmap scan_egg_link)r search_pathdirsZ egg_linksr&r&r'scan_egg_linksszPackageIndex.scan_egg_linksc Csttjj||}ttdttj|}WdQRXt |dkrDdS|\}}x>t tjj||D](}tjj|f||_ t |_ |j|q`WdS)Nr;)openr]rFrgrrrr~rrXrrSr rKri)rrFrZ raw_lineslinesZegg_pathZ setup_pathrQr&r&r'rs  zPackageIndex.scan_egg_linkc sfdd}xHtj|D]:}y |tjj|t|jdWqtk rPYqXqW||\}}|rxXt||D]J}t |\}} |j dr| r|r|d||f7}n j |j |qrWt jdd|SdSd S) z#Process the contents of a PyPI pagecs|jjrtttjj|tjdjd}t|dkrd|dkrt |d}t |d}dj j |j i|<t|t|fSdS)Nr8r;r<r9rT)NN)r3rrrrr#r@rXrArrr setdefaultr1r)rrCpkgver)rr&r'scans "  z(PackageIndex.process_index..scanr9z.pyz #egg=%s-%scSsd|jdddS)Nz%sr9r!r;)rO)mr&r&r'sz,PackageIndex.process_index..rN)rr|rr#rrrOr$rrJr2need_version_infoscan_urlPYPI_MD5sub) rrBrrrNrrnew_urlr5fragr&)rr'rs$       zPackageIndex.process_indexcCs|jd|dS)NzPPage at %s links to .py file(s) without version info; an index scan is required.)scan_all)rrBr&r&r'rszPackageIndex.need_version_infocGs:|j|jkr*|r |j|f||jd|j|jdS)Nz6Scanning index of all packages (this may take a while))rrrrr)rrrsr&r&r'rs  zPackageIndex.scan_allcCs~|j|j|jd|jj|js:|j|j|jd|jj|jsR|j|x&t|jj|jfD]}|j|qhWdS)Nr8) rr unsafe_namerrrnrTnot_found_in_indexr)r requirementrBr&r&r' find_packagess zPackageIndex.find_packagescsR|j|j|x,||jD]}||kr.|S|jd||qWtt|j||S)Nz%s does not match %s)prescanrrnrsuperrobtain)rr installerrQ) __class__r&r'rs zPackageIndex.obtaincCsL|j|jd||jsH|jtj|td|jjtj j |fdS)z- checker is a ContentChecker zValidating %%s checksum for %sz7%s validation failed for %s; possible download problem?N) rrrrr]unlinkrrr4rFrY)rcheckerr^tfpr&r&r' check_hashs  zPackageIndex.check_hashcCsTxN|D]F}|jdks4t| s4|jds4tt|r@|j|q|jj|qWdS)z;Add `urls` to the list that will be prescanned for searchesNzfile:)rrr3rrrappend)rurlsrBr&r&r'add_find_links s      zPackageIndex.add_find_linkscCs"|jrtt|j|jd|_dS)z7Scan urls scheduled for prescanning (e.g. --find-links)N)rrrr)rr&r&r'rszPackageIndex.prescancCs<||jr|jd}}n |jd}}|||j|jdS)Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))rnrrrr)rrmethrr&r&r'r!s   zPackageIndex.not_found_in_indexcCs~t|tsjt|}|rR|j|jd||}t|\}}|jdrN|j|||}|Stj j |rb|St |}t |j ||ddS)aLocate and/or download `spec` to `tmpdir`, returning a local path `spec` may be a ``Requirement`` object, or a string containing a URL, an existing local filename, or a project/version requirement spec (i.e. the string form of a ``Requirement`` object). If it is the URL of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is automatically created alongside the downloaded file. If `spec` is a ``Requirement`` object or a string containing a project/version requirement spec, this method returns the location of a matching distribution (possibly after downloading it to `tmpdir`). If `spec` is a locally existing file or directory name, it is simply returned unchanged. If `spec` is a URL, it is downloaded to a subpath of `tmpdir`, and the local filename is returned. Various errors may be raised if a problem occurs during downloading. r9z.pyrSN)rrr _download_urlrOrJr2 gen_setupr]rFrr(rfetch_distribution)rr%tmpdirrDfoundr5rIr&r&r'r:+s    zPackageIndex.downloadc sjd|id}d fdd }|rHjj|||}| r`|dk r`|||}|dkrjdk rzj||}|dkr| rj|||}|dkrˆjdrdpd|njd||j|jd SdS) a|Obtain a distribution suitable for fulfilling `requirement` `requirement` must be a ``pkg_resources.Requirement`` instance. If necessary, or if the `force_scan` flag is set, the requirement is searched for in the (online) package index as well as the locally installed packages. If a distribution matching `requirement` is found, the returned distribution's ``location`` is the value you would have gotten from calling the ``download()`` method with the matching distribution's URL or filename. If no matching distribution is found, ``None`` is returned. If the `source` flag is set, only source distributions and source checkout links will be considered. Unless the `develop_ok` flag is set, development and system eggs (i.e., those using the ``.egg-info`` format) will be ignored. zSearching for %sNcs|dkr }x||jD]t}|jtkrJ rJ|krjd|d|<q||ko`|jtkp` }|rj|j}||_tj j |jr|SqWdS)Nz&Skipping development or system egg: %sr9) rnrKrrr r:rSdownload_locationr]rFr)reqenvrQtestloc) develop_okrskippedsourcerr&r'res z-PackageIndex.fetch_distribution..findz:No local packages or working download links found for %s%sza source distribution of rzBest match: %s)rS)N)rrrrrcloner ) rrr force_scanrrZ local_indexrQrr&)rrrrrr'rMs0       zPackageIndex.fetch_distributioncCs"|j||||}|dk r|jSdS)a3Obtain a file suitable for fulfilling `requirement` DEPRECATED; use the ``fetch_distribution()`` method now instead. For backward compatibility, this routine is identical but returns the ``location`` of the downloaded distribution instead of a distribution object. N)rrS)rrrrrrQr&r&r'fetchszPackageIndex.fetchc Cstj|}|r*ddt||jddDp,g}t|dkrtjj|}tjj||krtjj ||}ddl m }|||st j |||}ttjj |dd2} | jd|dj|djtjj|dfWdQRX|S|rtd ||fntd dS) NcSsg|]}|jr|qSr&)rU)radr&r&r' sz*PackageIndex.gen_setup..r9r)samefilezsetup.pywzIfrom setuptools import setup setup(name=%r, version=%r, py_modules=[%r]) zCan't unambiguously interpret project/version identifier %r; any dashes in the name or version should be escaped using underscores. %rzpCan't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.)rMrNrrOrXr]rFrYdirnamergZsetuptools.command.easy_installrshutilcopy2rwriterTrUsplitextr) rr^rIrrNrrYdstrrr&r&r'rs2       zPackageIndex.gen_setupi c Cs|jd|d}ztj|}|j|}t|tjjrJtd||j |j f|j}d}|j }d}d|krt |d} t tt| }|j|||||t|dZ} xD|j|} | r|j| | j| |d7}|j|||||qPqW|j||| WdQRX|S|r|jXdS) NzDownloading %szCan't download %s: %s %srr9zcontent-lengthzContent-Lengthwbr=)rrrrrrrrrrr dl_blocksizermaxrint reporthookrrrrrr) rrBr^fprrblocknumbssizesizesrrr&r&r' _download_tos:        zPackageIndex._download_tocCsdS)Nr&)rrBr^r%Zblksizer'r&r&r'r#szPackageIndex.reporthookcCs|jdrt|Sy t||jSttjfk r}z>djdd|jD}|r^|j ||nt d||fWYdd}~Xnt j j k r}z|Sd}~Xnt j jk r}z,|r|j ||jnt d||jfWYdd}~Xntjk r8}z.|r|j ||jnt d||jfWYdd}~XnPtjtj fk r}z*|rf|j ||nt d||fWYdd}~XnXdS)Nzfile: cSsg|] }t|qSr&)r~)raargr&r&r'rsz)PackageIndex.open_url..z%s %szDownload error for %s: %sz;%s returned a bad status line. The server might be down, %s)r3 local_openopen_with_authrr$r InvalidURLrgrsrrrrrURLErrorreason BadStatusLineline HTTPExceptionsocket)rrBwarningvrr&r&r'rs6  "zPackageIndex.open_urlcCst|\}}|r4x&d|kr0|jddjdd}qWnd}|jdrN|dd}tjj||}|dksn|jd rz|j||S|d ks|jd r|j||S|jd r|j ||S|d krt j j t j j|dS|j|d|j||SdS)Nz...\_Z__downloaded__z.egg.zipr-svnzsvn+gitzgit+zhg+rr;Tr0)rJreplacer2r]rFrgr3 _download_svn _download_git _download_hgrr url2pathnamer#r?r_attempt_download)rrDrBrr4rIr^r&r&r'rs$         zPackageIndex._download_urlcCs|j|ddS)NT)r)rrBr&r&r'r8szPackageIndex.scan_urlcCs6|j||}d|jddjkr.|j|||S|SdS)Nrz content-typer)r)rr1_download_html)rrBr^rr&r&r'rA;s zPackageIndex._attempt_downloadcCslt|}x@|D]8}|jrtjd|rD|jtj||j||SPqW|jtj|td|dS)Nz ([^- ]+ - )?Revision \d+:zUnexpected HTML page found at ) r���r���r`���r���r���r]���r���r=��r���)r���rB���r���r^���r���r2��r&���r&���r'���rB��B��s����     zPackageIndex._download_htmlc�������������C���s��|j�ddd�}d}|j�jdrd|krtjj|\}}}}}} | �r|jdrd|d d��kr|d d��j�dd\}}tjj|\} } | rd | kr| j�d d\} } d | | f�}nd | �}| }|||||| f}tjj|}|�jd ||�t j d|||f��|S�)Nr<���r9���r���r���zsvn:@z//r8���r;���:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s) rA���r1���r3���r���r#���r?��� splituser urlunparser���r]���system)r���rB���r^���credsrD���netlocrF���rb���qr���authhostuserpwrC���r&���r&���r'���r=��Q��s$����  zPackageIndex._download_svnc�������������C���sp���t�jj|�\}}}}}|jddd�}|jddd�}d�}d|krR|jdd\}}t�jj||||df}�|�|fS�)N+r9���r<���r���rC��r���r=���)r���r#���urlsplitrA���rsplit urlunsplit)rB��� pop_prefixrD���rI��rF���rH���r���revr&���r&���r'���_vcs_split_rev_from_urlf��s����z$PackageIndex._vcs_split_rev_from_urlc�������������C���sl���|j�ddd�}|�j|dd\}}|�jd||�tjd||f��|d�k rh|�jd|�tjd ||f��|S�) Nr<���r9���r���T)rS��zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %sz"(cd %s && git checkout --quiet %s))rA���rU��r���r]���rG��)r���rB���r^���rT��r&���r&���r'���r>��x��s����  zPackageIndex._download_gitc�������������C���sl���|j�ddd�}|�j|dd\}}|�jd||�tjd||f��|d�k rh|�jd|�tjd ||f��|S�) Nr<���r9���r���T)rS��zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %sz(cd %s && hg up -C -r %s -q))rA���rU��r���r]���rG��)r���rB���r^���rT��r&���r&���r'���r?����s����  zPackageIndex._download_hgc�������������G���s���t�j|f|��d�S�)N)r���r���)r���r���rs���r&���r&���r'���r�����s����zPackageIndex.debugc�������������G���s���t�j|f|��d�S�)N)r���r���)r���r���rs���r&���r&���r'���r�����s����zPackageIndex.infoc�������������G���s���t�j|f|��d�S�)N)r���r���)r���r���rs���r&���r&���r'���r�����s����zPackageIndex.warnr���)r���rV��NT)F)F)F)N)N)FFFN)FF)N)F)(r���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r��r���r���r:���r��r��r��r ��r)��r#��r���r��r���rA��rB��r=�� staticmethodrU��r>��r?��r���r���r��� __classcell__r&���r&���)r���r'���r���(��sL����  3   +   #� J )$ # z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c�������������C���s���|�j�d}t|S�)Nr9���)rO���r���)rN���whatr&���r&���r'��� decode_entity��s���� rZ��c�������������C���s ���t�t|�S�)z'Decode HTML entities in the given text.) entity_subrZ��)textr&���r&���r'���r�����s����r���c����������������s����fdd}|S�)Nc����������������s����fdd}|S�)Nc����������� ������s.���t�j�}t�j�z �|�|S�t�j|�X�d�S�)N)r4��getdefaulttimeoutsetdefaulttimeout)rs���rt���Z old_timeout)ru���timeoutr&���r'���_socket_timeout��s ����  z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr&���)ru���r`��)r_��)ru���r'���r`����s����z'socket_timeout.<locals>._socket_timeoutr&���)r_��r`��r&���)r_��r'���socket_timeout��s���� ra��c�������������C���s2���t�jj|�}|j�}tj|}|j�}|jddS�)aq�� A function compatible with Python 2.3-3.3 that will encode auth from a URL suitable for an HTTP header. >>> str(_encode_auth('username%3Apassword')) 'dXNlcm5hbWU6cGFzc3dvcmQ=' Long auth strings should not cause a newline to be inserted. >>> long_auth = 'username:' + 'password'*10 >>> chr(10) in str(_encode_auth(long_auth)) False  r���)r���r#���r@���encodebase64 encodestringr���r<��)rK��Zauth_sZ auth_bytesZ encoded_bytesencodedr&���r&���r'��� _encode_auth��s ����  rg��c���������������@���s(���e�Zd�ZdZdd�Zdd�Zdd�ZdS�) Credentialz: A username/password pair. Use like a namedtuple. c�������������C���s���||�_�||�_d�S�)N)usernamepassword)r���ri��rj��r&���r&���r'���r�����s����zCredential.__init__c�������������c���s���|�j�V��|�jV��d�S�)N)ri��rj��)r���r&���r&���r'���__iter__��s����zCredential.__iter__c�������������C���s ���dt�|��S�)Nz%(username)s:%(password)s)vars)r���r&���r&���r'���__str__��s����zCredential.__str__N)r���r���r���r���r���rk��rm��r&���r&���r&���r'���rh����s���rh��c���������������@���s0���e�Zd�Zdd�Zedd�Zdd�Zdd�Zd S�) PyPIConfigc�������������C���sP���t�jdddgd}tjj|�|�tjjtjjdd}tjj |rL|�j |�dS�)z% Load from ~/.pypirc ri��rj�� repositoryr���~z.pypircN) dictfromkeysr���RawConfigParserr���r]���rF���rg��� expanduserr���r���)r���defaultsrcr&���r&���r'���r�����s ���� zPyPIConfig.__init__c����������������s&����fdd�j��D�}tt�j|S�)Nc����������������s ���g�|�]}�j�|d�j�r|qS�)ro��)r���r���)ra���section)r���r&���r'���r����s����z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)sectionsrq��r���_get_repo_cred)r���Zsections_with_repositoriesr&���)r���r'���creds_by_repository��s����zPyPIConfig.creds_by_repositoryc�������������C���s6���|�j�|dj�}|t|�j�|dj�|�j�|dj�fS�)Nro��ri��rj��)r���r���rh��)r���rw��repor&���r&���r'���ry����s����zPyPIConfig._get_repo_credc�������������C���s*���x$|�j�j�D�]\}}|j|r |S�q W�dS�)z If the URL indicated appears to be a repository defined in this config, return the credential for that repository. N)rz��itemsr3���)r���rB���ro��credr&���r&���r'���find_credential��s���� zPyPIConfig.find_credentialN)r���r���r���r���propertyrz��ry��r~��r&���r&���r&���r'���rn����s��� rn��c�������������C���s:��t�jj|�\}}}}}}|jdr,tjd|d krFt�jj|\}} nd}|s~t�j|�} | r~t | }| j |�f} t j d | ��|rdt |�}|| ||||f} t�jj| } t�jj| }|jd|�n t�jj|�}|jd t�||}|r6t�jj|j\}}}}}}||kr6|| kr6||||||f} t�jj| |_|S�) z4Open a urllib2 request, handling HTTP authenticationrD��znonnumeric port: ''httphttpsN*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz User-Agent)r��r��)r��)r���r#���r?���r2���r���r.��rE��rn��r~��r~���ri��r���r���rg��rF��r���Request add_header user_agentrB���)rB���r���rD���rI��rF���paramsrH���r���rK��rL��r}��r���rC���r���r���r$��s2h2path2Zparam2Zquery2Zfrag2r&���r&���r'���r-����s6����         r-��c�������������C���s���|�S�)Nr&���)rB���r&���r&���r'��� fix_sf_url?��s����r��c���������� ���C���s��t�jj|�\}}}}}}t�jj|}tjj|r<t�jj|�S�|j drtjj |rg�}xtj |D�]b} tjj || } | dkrt | d} | j�} W�dQ�R�X�P�ntjj | r| d7�} |jdj| d�qbW�d} | j|�dj |d } d\}}n d\}}} ddi}tj| }t�jj|�||||S�)z7Read a local path, with special support for directoriesr8���z index.htmlrNz<a href="{name}">{name}</a>)r4���zB<html><head><title>{url}{files}rb)rBfilesOKPath not found Not foundz content-typez text/html)rr)rrr)rr#r?rr@r]rFisfilerr2rrrgrrrformatrStringIOrr)rBrDrErFparamrHrr^rrfilepathr$bodyrstatusmessagerZ body_streamr&r&r'r,Cs,        r,)N)N)N)N)r )Zrsysr]r`rr4rdrr functoolsrZsetuptools.externrZsetuptools.extern.six.movesrrrrr" pkg_resourcesrr r r r r rrrrrrrr distutilsrZdistutils.errorsrfnmatchrZsetuptools.py27compatrZsetuptools.py33compatrZsetuptools.wheelrrrMIrrrNrrArW__all__Z_SOCKET_TIMEOUTZ_tmplrrUrr(rrJrrLr_rrrrwr{robjectrrrrr[rZrrargrhrsrnrrr-rr,r&r&r&r's|  <           !  "   !  &.