N3{Y @sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZmZmZddlmZddlmZddlmZddlmZm 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-dd lm.Z.dd l/m0Z0dd l1m2Z2dd l3m4Z4ej5d Z6ej5dej7Z8ej5dZ9ej5dej7j:Z;dj<Z=ddddgZ>dZ?ddZ@ddZAdddZBdddZCdddZDdedddZEdd d!ZFd"d#ZGej5d$ej7ZHeGd%d&ZId'ejJdd(ed)djJfZKGd*d+d+eLZMGd,d-d-eMZNGd.ddeZOej5d/jPZQd0d1ZRd2d3ZSd4d5ZTdd6d7ZUd8d9ZVGd:d;d;eLZWGd<d=d=e-j-ZXejYd>d?ZZeUe?eZZZd@dAZ[dBdCZ\dS)Dz#PyPI and direct package downloadingN)wraps) CHECKOUT_DIST Distribution BINARY_DISTnormalize_path SOURCE_DISTrequire Environmentfind_distributions safe_name safe_version to_filename Requirement DEVELOP_DIST) ssl_support)log)DistutilsError)urllib2httplibStringIO HTTPErrorurlparse urlunparseunquote splituser url2pathnamename2codepointunichrurljoinurlsplit urlunsplit ConfigParser) filterfalse) translate)strip_fragment)get_all_headersz^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_namecCs|j}d\}}}|jdr|jdrR|dd}d}q|jddr|dd}|dd}d}q|jd r|dd}d }q|jd dr|dd}|dd}d }qn|||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)NNNiiiiiiir2i)lowerendswith startswith)namer3basepy_verplatr:3/tmp/pip-r2rszybt-build/setuptools/package_index.pyr(.s$     cCst|\}}}}}}t|jdd}|dkrk|dkrkt|jdd}nd|kr|jdd\}}n||fS) N/zsourceforge.netdownload#)rrsplit)urlschemeserverpath parametersqueryfragmentr7r:r:r;egg_info_for_urlFs rKccst|\}}xt|||D] }|Vq%W|rtj|}|rx1t||jd|dtD] }|VqqWqndS)zEYield egg or source distribution objects that might be found at a URLr= precedenceN)rKdistros_for_location EGG_FRAGMENTmatchr)groupr)rDmetadatar7rJdistrOr:r:r;r'Ns "cCs|jdr"|dd}n|jdrSd|krStj|||gS|jdrt|\}}}|dk rt||||t|SnxDtD]<}|j|r|dt| }t|||SqWgS)z:Yield egg or source distribution objects based on basenamez.egg.zipNr/z.egg-z.exer2)r4r from_locationr(r)r EXTENSIONSlen)locationbasenamerQZwin_baser8platformextr:r:r;rMZs  rMcCs"tt|tjj||S)zEYield possible egg or source distribution objects based on a filename)rMrosrGrX)filenamerQr:r:r;distros_for_filenameosr]c cs|jd}|sdxLt|ddD]1\}}t|dkr,|jdr,dSq,Wnxmtdt|dD]R}t||dj|d|dj||dd|d|d |Vq~WdS) 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! rSr?Nzpy2.r= py_versionrLrY)rC enumeraterVr5rangerjoin) rWrXrQr_rLrYpartsipr:r:r;r)vs#!  5 ccst}|j}|dkrMxgt|j|D]}|||Vq1Wn;x8|D]0}||}||krT|||VqTqTWdS)zHList unique elements, preserving order. Remember all elements ever seen.N)setaddr" __contains__)iterablekeyseenZseen_addelementkr:r:r;unique_everseens         rncs"tfdd}|S)zs Wrap a function returning an iterable such that the resulting iterable only ever yields unique items. cst||S)N)rn)argskwargs)funcr:r;wrapperszunique_values..wrapper)r)rqrrr:)rqr; unique_valuessrsz(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>ccsxtj|D]}|j\}}tttj|jjd}d|ksgd|krx7t j|D]#}t |t |j dVqwWqqWxddD]\}|j |}|d krt j||}|rt |t |j dVqqqWdS) zEFind rel="homepage" and rel="download" links in `page`, yielding URLs,homepager>r= Home PageDownload URLN)rvrwrA)RELfinditergroupsrfmapstrstripr3rCHREFr htmldecoderPfindsearch)rDpagerOtagrelrelsposr:r:r;find_external_linkss'(  rzPython-urllib/%s setuptools/%s setuptoolsc@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;rs   rc@saeZdZejdZddZeddZddZ 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__cCsLt|d}|stS|jj|}|s<tS||jS)z5Construct a (possibly null) ContentChecker from a URLr=rA)rrpatternr groupdict)clsrDrJrOr:r:r;from_urlszHashChecker.from_urlcCs|jj|dS)N)rupdate)rrr:r:r;rszHashChecker.feedcCs|jj|jkS)N)r hexdigestr)rr:r:r;rszHashChecker.is_validcCs||j}||S)N)r)rrrmsgr:r:r;rs zHashChecker.reportN) rrrrecompilerr classmethodrrrrr:r:r:r;rs     rcseZdZdZddJddddZdd d Zdd d Zdd dZddZddZ ddZ ddZ dddZ ddZ dfddZddZdd Zd!d"Zd#d$Zd%d&Zddddd'd(Zddd)d*Zd+d,Zd-Zd.d/Zd0d1Zdd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zd<d=Ze dd>d?Z!d@dAZ"dBdCZ#dDdEZ$dFdGZ%dHdIZ&S)Kr&z;A distribution index that scans web pages for download URLszhttps://pypi.python.org/simple*NTcOstj||||dd|jd |_i|_i|_i|_tjdj t t |j |_ g|_|rtjr|stjrtj||_n tj|_dS)Nr<|)r rr4 index_url scanned_urls fetched_urls package_pagesrrrbr{r#rOallowsto_scanrZ is_availableZfind_ca_bundleZ opener_foropenerrurlopen)rrZhostsZ ca_bundleZ verify_sslrokwr:r:r;r s!   ' !zPackageIndex.__init__Fc CsU||jkr| rdSd|j|ks z.PackageIndex.scan_egg_link..r?r) r{r|r}openr[rGrbrVr rWrrLrg)rrGrlinesrRr:r:r;rjs"& zPackageIndex.scan_egg_linkc sfdd}xRtj|D]A}y&|t|t|jdWq"tk rbYq"Xq"W||\}}|rxyt||D]h}t|\}} |jdr| r|r|d||f7}qj |nj |qWt j dd|SdSd S) z#Process the contents of a PyPI pagecs|jjrttt|tjdjd}t|dkrd|dkrt|d}t|d}dj j |j i|.scanr=z.pyz #egg=%s-%scSsd|jdddS)Nz%sr=rr?)rP)mr:r:r;sz,PackageIndex.process_index..rN) r~ryrrrP ValueErrorrrKr4need_version_infoscan_urlPYPI_MD5sub) rrDrrrOrrnew_urlr7fragr:)rr;rss$&  zPackageIndex.process_indexcCs|jd|dS)NzPPage at %s links to .py file(s) without version info; an index scan is required.)scan_all)rrDr:r:r;rszPackageIndex.need_version_infocGsO|j|jkr;|r+|j||n|jdn|j|jdS)Nz6Scanning index of all packages (this may take a while))rrrrr)rrror:r:r;rs  zPackageIndex.scan_allcCs|j|j|jd|jj|jsN|j|j|jdn|jj|jss|j|nx3t|jj|jfD]}|j|qWdS)Nr<) rr unsafe_namerrrj project_namenot_found_in_indexr)r requirementrDr:r:r; find_packagess%zPackageIndex.find_packagescsk|j|j|x8||jD])}||kr;|S|jd||q%Wtt|j||S)Nz%s does not match %s)prescanrrjrsuperr&obtain)rr installerrR) __class__r:r;rs   zPackageIndex.obtaincCsi|j|jd||jse|jtj|td|jjtj j |fndS)z- checker is a ContentChecker zValidating %%s checksum for %sz7%s validation failed for %s; possible download problem?N) rrrrr[unlinkrrr6rGrX)rcheckerr\tfpr:r:r; check_hashs     zPackageIndex.check_hashcCsrxk|D]c}|jdksJt| sJ|jdsJtt|rZ|j|q|jj|qWdS)z;Add `urls` to the list that will be prescanned for searchesNzfile:)rrr5rr'rappend)rurlsrDr:r:r;add_find_linkss  zPackageIndex.add_find_linkscCs2|jr%tt|j|jnd|_dS)z7Scan urls scheduled for prescanning (e.g. --find-links)N)rrr{r)rr:r:r;rs zPackageIndex.prescancCsN||jr |jd}}n|jd}}|||j|jdS)Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))rjrrrr)rrmethrr:r:r;rs   zPackageIndex.not_found_in_indexc Cst|tst|}|r||j|jd||}t|\}}|jdrx|j|||}n|Stj j |r|Sytj |}Wqt k rt d|fYqXnt|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. r=z.pyz1Not a URL, existing file, or requirement spec: %rrWN)rrr _download_urlrPrKr4 gen_setupr[rGrparserrrfetch_distribution)rspectmpdirrEfoundr7rJr:r:r;r>s"  zPackageIndex.downloadc sNjd|id}dfdd}|rfjj|||}n|dk r|p|||}n|dkrjdk rj||}n|dkr| rj|||}n|dkrjdrdpd|n/jd||jd j|j|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}nx||jD]q}|jtkrn rn|kr#jd|d|.findz2No local packages or download links found for %s%sza source distribution of rzBest match: %srW)rrrrrcloner>rW) rrr force_scanr rZ local_indexrRrr:)rrr r r;rs.       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)rrW)rrrr r rRr:r:r;fetch[s zPackageIndex.fetchc Csbtj|}|r=ddt||jddDp@g}t|dkr3tjj|}tjj||krtjj ||}ddl m }|||st j |||}qnttjj |dd} | jd|dj|djtjj|df| j|S|rRtd ||fn td dS) NcSsg|]}|jr|qSr:)version)rdr:r:r;rks z*PackageIndex.gen_setup..r=r)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.)rNrOr)rPrVr[rGrXdirnamerbZsetuptools.command.easy_installrshutilcopy2rwriterrsplitextrr) rr\rJrrOrrXdstrrr:r:r;rhs4   zPackageIndex.gen_setupi c Cs|jd|d\}}}zItj|}|jt|}t|trwtd||j|j fn|j}d}|j } d } d|krt |d} t t t| } |j|||| | nt|d}xZ|j| } | rK|j| |j| |d7}|j|||| | qPqW|j||||SWd|r~|jn|r|jnXdS) NzDownloading %szCan't download %s: %s %srr=zcontent-lengthzContent-Lengthwb)NNNrA)rrrrr$rrrrr dl_blocksizer%maxr{int reporthookrrrrrr) rrDr\fprrrrblocknumbssizeZsizesrr:r:r; _download_tos>       zPackageIndex._download_tocCsdS)Nr:)rrDr\rZblksizer r:r:r;rszPackageIndex.reporthookc Cs|jdrt|Syt||jSWnttjfk rtjd}dj dd|j D}|r|j ||nt d||fYn.t jk rtjd}|SYnt jk r)tjd}|r |j ||jnt d||jfYntjk rtjd}|re|j ||jnt d||jfYnTtjk rtjd}|r|j ||nt d||fYnXdS) Nzfile:r= cSsg|]}t|qSr:)r|)rargr:r:r;rs z)PackageIndex.open_url..z%s %szDownload error for %s: %sz;%s returned a bad status line. The server might be down, %s)r5 local_openopen_with_authrrr InvalidURLsysexc_inforbrorrrrURLErrorreason BadStatusLineline HTTPException)rrDwarningvrr:r:r;rs@ zPackageIndex.open_urlcCsBt|\}}|rLx7d|krH|jddjdd}qWnd}|jdrt|dd}ntjj||}|dks|jd r|j||S|d ks|jd r|j||S|jd r|j ||S|d krt t |dS|j |d|j ||SdS)Nz...\_Z__downloaded__z.egg.zipr/svnzsvn+gitzgit+zhg+rr?Tr2)rKreplacer4r[rGrbr5 _download_svn _download_git _download_hgrrr_attempt_download)rrErDrr6rJr\r:r:r;rs$% zPackageIndex._download_urlcCs|j|ddS)NT)r)rrDr:r:r;rszPackageIndex.scan_urlcCsK|j||}d|jddjkrC|j|||S|SdS)Nrz content-typer)r!rr3_download_html)rrDr\rr:r:r;r9szPackageIndex._attempt_downloadcCst|}xW|D]O}|jrtjd|r^|jtj||j||SPqqW|jtj|td|dS)Nz ([^- ]+ - )?Revision \d+:zUnexpected HTML page found at ) r���r}���r���r���r���r[���r���r6��r���)r���rD���r���r\���r���r,��r:���r:���r;���r:�� ��s����       zPackageIndex._download_htmlc�������������C���s`��|�j��d�d��d�}�d�}�|�j���j�d��r/d�|�k�r/t�|��\�}�}�}�}�}�} �|� r/|�j�d��r/d�|�d �d���k�r/|�d �d���j��d�d��\�}�}�t�|��\�} �} �| �r,d �| �k�r�| �j��d �d��\�} �} �d �| �| �f�}�n �d �| �}�| �}�t�|�|�|�|�|�| �f��}�q,q/n��|��j�d �|�|��t�j�d�|�|�|�f��|�S)Nr@���r=���r���r���zsvn:@z//r<���r?���:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s) rC���r3���r5���r���r���r���r���r[���system)r���rD���r\���credsrE���netlocrG���re���qr���authhostuserpwr:���r:���r;���r6����s"����!,"  'zPackageIndex._download_svnc�������������C���s���t��|���\�}�}�}�}�}�|�j�d�d��d�}�|�j�d�d��d�}�d��}�d�|�k�rt�|�j�d�d��\�}�}�n��t�|�|�|�|�d�f��}��|��|�f�S)N+r=���r@���r���r;��r���rA���)r���rC���rsplitr ���)rD��� pop_prefixrE���r?��rG���rI���r���revr:���r:���r;���_vcs_split_rev_from_url,��s���� z$PackageIndex._vcs_split_rev_from_urlc�������������C���s���|�j��d�d��d�}�|��j�|�d�d�\�}�}�|��j�d�|�|��t�j�d�|�|�f��|�d��k �r�|��j�d�|��t�j�d �|�|�f��n��|�S) Nr@���r=���r���rG��TzDoing git clone from %s to %szgit clone --quiet %s %szChecking out %sz"(cd %s && git checkout --quiet %s))rC���rI��r���r[���r=��)r���rD���r\���rH��r:���r:���r;���r7��>��s����  zPackageIndex._download_gitc�������������C���s���|�j��d�d��d�}�|��j�|�d�d�\�}�}�|��j�d�|�|��t�j�d�|�|�f��|�d��k �r�|��j�d�|��t�j�d �|�|�f��n��|�S) Nr@���r=���r���rG��TzDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %sz(cd %s && hg up -C -r %s >&-))rC���rI��r���r[���r=��)r���rD���r\���rH��r:���r:���r;���r8��N��s����  zPackageIndex._download_hgc�������������G���s���t��j�|�|��d��S)N)r���r���)r���r���ro���r:���r:���r;���r���^��s����zPackageIndex.debugc�������������G���s���t��j�|�|��d��S)N)r���r���)r���r���ro���r:���r:���r;���r���a��s����zPackageIndex.infoc�������������G���s���t��j�|�|��d��S)N)r���r���)r���r���ro���r:���r:���r;���r���d��s����zPackageIndex.warn)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���r���r9��r:��r6�� staticmethodrI��r7��r8��r���r���r���r:���r:���)r���r;���r&�����sL���  0  *      )A * $ (         z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c�������������C���s3���t��|��t��s�|��S|��d�k�r)�t�|���St�|���S)N���)r���r��r���chr)cr:���r:���r;���uchrk��s ���� � rN��c�������������C���s���|��j��d��}�|�j�d��r:�t�|�d�d���d��}�nC�|�j�d��rb�t�|�d�d����}�n�t�j�|�|��j��d���}�t�|��S)Nr=���z#xr?���r-���r@���r���)rP���r5���r��r���r���rN��)rO���whatr:���r:���r;��� decode_entityq��s����rP��c�������������C���s ���t��t�|���S)z'Decode HTML entities in the given text.) entity_subrP��)textr:���r:���r;���r���{��s����r���c����������������s�����f�d�d���}�|�S)Nc����������������s������f�d�d���}�|�S)Nc����������� ������s?���t��j���}�t��j���z���|��|���SWd��t��j�|��Xd��S)N)socketgetdefaulttimeoutsetdefaulttimeout)ro���rp���Z old_timeout)rq���timeoutr:���r;���_socket_timeout��s ����  z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr:���)rq���rW��)rV��)rq���r;���rW����s����z'socket_timeout.<locals>._socket_timeoutr:���)rV��rW��r:���)rV��r;���socket_timeout��s���� rX��c�������������C���sC���t��|���}�|�j���}�t�j�|��}�|�j���}�|�j�d�d��S)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���encodebase64 encodestringr���r5��)rA��Zauth_sZ auth_bytesZ encoded_bytesencodedr:���r:���r;��� _encode_auth��s ����   r^��c���������������@���s:���e��Z�d��Z�d�Z�d�d���Z�d�d���Z�d�d���Z�d�S) Credentialz: A username/password pair. Use like a namedtuple. c�������������C���s���|�|��_��|�|��_�d��S)N)usernamepassword)r���r`��ra��r:���r:���r;���r�����s���� zCredential.__init__c�������������c���s���|��j��V|��j�Vd��S)N)r`��ra��)r���r:���r:���r;���__iter__��s����zCredential.__iter__c�������������C���s���d�t��|���S)Nz%(username)s:%(password)s)vars)r���r:���r:���r;���__str__��s����zCredential.__str__N)r���r���r���r���r���rb��rd��r:���r:���r:���r;���r_����s���   r_��c���������������@���sF���e��Z�d��Z�d�d���Z�e�d�d����Z�d�d���Z�d�d���Z�d �S) PyPIConfigc�������������C���su���t��j�d�d�d�g�d��}�t�j�j�|��|��t�j�j�t�j�j�d��d��}�t�j�j�|��rq�|��j �|��n��d�S)z% Load from ~/.pypirc r`��ra�� repositoryr���~z.pypircN) dictfromkeysr!���r���r[���rG���rb��� expanduserr���r���)r���defaultsrcr:���r:���r;���r�����s ����!zPyPIConfig.__init__c����������������s5�����f�d�d�����j����D�}�t�t���j�|���S)Nc����������������s.���g��|��]$�}���j��|�d���j���r�|��q�S)rf��)r���r}���)r���section)r���r:���r;���r�����s��� �z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)sectionsrh��r{���_get_repo_cred)r���Zsections_with_repositoriesr:���)r���r;���creds_by_repository��s����zPyPIConfig.creds_by_repositoryc�������������C���sO���|��j��|�d��j���}�|�t�|��j��|�d��j���|��j��|�d��j����f�S)Nrf��r`��ra��)r���r}���r_��)r���rm��repor:���r:���r;���ro����s����zPyPIConfig._get_repo_credc�������������C���s7���x0�|��j��j���D]�\�}�}�|�j�|��r�|�Sq�Wd�S)z If the URL indicated appears to be a repository defined in this config, return the credential for that repository. N)rp��itemsr5���)r���rD���rf��credr:���r:���r;���find_credential��s����zPyPIConfig.find_credentialN)r���r���r���r���propertyrp��ro��rt��r:���r:���r:���r;���re����s���   re��c�������������C���s��t��|���\�}�}�}�}�}�}�|�j�d��r?�t�j�d���n��|�d �k�r`�t�|��\�}�} �n�d�}�|�s�t���j�|���} �| �r�t�| ��}�| �j�|��f�} �t �j �d�| ��q�n��|�r d�t �|��}�t �|�| �|�|�|�|�f��} �t �j�| ��} �| �j�d�|��n�t �j�|���} �| �j�d �t��|�| ��}�|�rt��|�j��\�}�}�}�}�}�}�|�|�k�r|�| �k�rt �|�|�|�|�|�|�f��|�_�qn��|�S) z4Open a urllib2 request, handling HTTP authenticationr<��znonnumeric port: ''httphttpsNz*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz User-Agent)zhttpzhttps)r���r4���r���r&��r���re��rt��r|���r`��r���r���r^��r���r���Request add_header user_agentrD���)rD���r���rE���r?��rG���paramsrI���r���rA��rB��rs��r���r���requestr��s2h2Zpath2Zparam2Zquery2Zfrag2r:���r:���r;���r%����s2����   !'r%��c�������������C���s���|��S)Nr:���)rD���r:���r:���r;��� fix_sf_url��s����r��c�������������C���su��t��|���\�}�}�}�}�}�}�t�|��}�t�j�j�|��rI�t�j�|���S|�j�d��r=t�j�j�|��r=g��}�x�t�j �|��D]�} �| �d�k�r�t �t�j�j �|�| ��d��} �| �j ���} �| �j ���Pn.�t�j�j�t�j�j �|�| ���r�| �d�7} �n��|�j�d�| �| �f��q�Wd�|��d�d�j �|��} �d�\�} �} �n�d�\�} �} �} �i�d �d�6}�t�|��| �| �|�t�| ���S)z7Read a local path, with special support for directoriesr<���z index.htmlrz<a href=%r>%s</a>z<html><head><title>%sz%srYOKPath not found Not foundz text/htmlz content-type)rzOK)rrr)rrr[rGisfilerrr4rrrrbrrrrr)rDrErFrGparamrIrr\filesrrbodystatusmessagerr:r:r;r$s*  !   !  r$)]rr'r[rrrSr[r functoolsr pkg_resourcesrrrrrrr r r r r rrrr distutilsrdistutils.errorsrZsetuptools.compatrrrrrrrrrrrrrr r!r"fnmatchr#Zsetuptools.py26compatr$Zsetuptools.py27compatr%rrNIr~rrOrrCrU__all__Z_SOCKET_TIMEOUTr(rKr'rMr]r)rnrsrxrrr{objectrrr&rrQrNrPrrXr^r_rerr%rr$r:r:r:r;sp       Xd       " '!e   '+