kSc@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?dZ@dZAeBdZCeBdZDeBdZEeBeeBdZFeBdZGdZHej5dej7ZIeHd ZJd!ejKd" ed#d$jKfZLd%eMfd&YZNd'eNfd(YZOdefd)YZPej5d*jQZRd+ZSd,ZTd-ZUdd.ZVd/ZWd0eMfd1YZXd2e-j-fd3YZYejZd4Z[eVe?e[Z[d5Z\d6Z]dS(7s#PyPI and direct package downloadingiN(twraps( t CHECKOUT_DISTt Distributiont BINARY_DISTtnormalize_patht SOURCE_DISTtrequiret Environmenttfind_distributionst safe_namet safe_versiont to_filenamet Requirementt DEVELOP_DIST(t ssl_support(tlog(tDistutilsError(turllib2thttplibtStringIOt HTTPErrorturlparset urlunparsetunquotet splitusert url2pathnametname2codepointtunichrturljointurlsplitt urlunsplitt ConfigParser(t filterfalse(t translate(tstrip_fragment(tget_all_headerss^egg=([-A-Za-z0-9_.]+)$shref\s*=\s*['"]?([^'"> ]+)s([^<]+) \s+\(md5\)s([-+.a-z0-9]{2,}):s.tar.gz .tar.bz2 .tar .zip .tgzt PackageIndextdistros_for_urltparse_bdist_wininsttinterpret_distro_nameicCs|j}d\}}}|jdr|jdrL|d }d}q|jddr~|dd!}|d }d}q|jd r|d }d }q|jd d r|dd!}|d }d }qn|||fS(s=Return (base,pyversion) or (None,None) for possible .exe names.exes .win32.exeitwin32s .win32-pyiiis.win-amd64.exeis win-amd64s .win-amd64-pyiN(NNN(tlowertNonetendswitht startswith(tnameR)tbasetpy_vertplat((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR&.s$           cCst|\}}}}}}t|jdd}|dkrk|dkrkt|jdd}nd|kr|jdd\}}n||fS(Nt/issourceforge.nettdownloadit#i(RRtsplit(turltschemetservertpatht parameterstquerytfragmentR.((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytegg_info_for_urlFs ccst|\}}xt|||D] }|Vq%W|rtj|}|rx1t||jd|dtD] }|VqqWqndS(sEYield egg or source distribution objects that might be found at a URLit precedenceN(R<tdistros_for_locationt EGG_FRAGMENTtmatchR'tgroupR(R5tmetadataR.R;tdistR@((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR%Ns "cCs|jdr|d }n|jdrMd|krMtj|||gS|jdrt|\}}}|dk rt||||t|Snx>tD]6}|j|r|t| }t|||SqWgS(s:Yield egg or source distribution objects based on basenames.egg.zipis.eggt-s.exeN( R+Rt from_locationR&R*R'Rt EXTENSIONStlen(tlocationtbasenameRBtwin_baseR/tplatformtext((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR>Zs   cCs"tt|tjj||S(sEYield possible egg or source distribution objects based on a filename(R>RtosR8RI(tfilenameRB((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytdistros_for_filenameosc cs|jd}|s^xFt|dD]1\}}t|dkr&|jdr&dSq&Wnxatdt|dD]F}t||dj|| dj||d|d|d |VqxWdS( sGenerate 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! RDiispy2.Nit py_versionR=RK(R4t enumerateRGR,trangeRtjoin( RHRIRBRPR=RKtpartstitp((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR'vs!  ) ccst}|j}|dkrMxgt|j|D]}|||Vq1Wn;x8|D]0}||}||krT|||VqTqTWdS(sHList unique elements, preserving order. Remember all elements ever seen.N(tsettaddR*R t __contains__(titerabletkeytseentseen_addtelementtk((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytunique_everseens         cstfd}|S(ss Wrap a function returning an iterable such that the resulting iterable only ever yields unique items. cst||S(N(R`(targstkwargs(tfunc(sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytwrappers(R(RcRd((RcsB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt unique_valuesss(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>ccsxtj|D]}|j\}}tttj|jjd}d|ksgd|krx7t j|D]#}t |t |j dVqwWqqWxdd D]\}|j |}|dkrt j||}|rt |t |j dVqqqWdS( sEFind rel="homepage" and rel="download" links in `page`, yielding URLst,thomepageR2is Home PagesDownload URLiN(s Home PagesDownload URL(tRELtfinditertgroupsRWtmaptstrtstripR)R4tHREFRt htmldecodeRAtfindtsearch(R5tpageR@ttagtreltrelstpos((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytfind_external_linkss'(  sPython-urllib/%s setuptools/%sit setuptoolsitContentCheckercBs)eZdZdZdZdZRS(sP A null content checker that defines the interface for checking content cCsdS(s3 Feed a block of data to the hash. N((tselftblock((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytfeedscCstS(sC Check the hash. Return False if validation fails. (tTrue(Rz((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytis_validscCsdS(su Call reporter with information about the checker (hash name) substituted into the template. N((Rztreporterttemplate((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytreports(t__name__t __module__t__doc__R|R~R(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRys  t HashCheckercBsJeZejdZdZedZdZdZ dZ RS(sK(?Psha1|sha224|sha384|sha256|sha512|md5)=(?P[a-f0-9]+)cCs(||_tj||_||_dS(N(t hash_namethashlibtnewthashtexpected(RzRR((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt__init__s cCsLt|d}|stS|jj|}|s<tS||jS(s5Construct a (possibly null) ContentChecker from a URLi(RRytpatternRqt groupdict(tclsR5R;R@((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytfrom_urlscCs|jj|dS(N(Rtupdate(RzR{((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR|scCs|jj|jkS(N(Rt hexdigestR(Rz((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR~scCs||j}||S(N(R(RzRRtmsg((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs ( RRtretcompileRRt classmethodRR|R~R(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs    cBsveZdZdd%d&edZedZedZedZ dZ dZ d Z d Z d&d Zd Zd&d ZdZdZdZdZdZeeed&dZeedZdZdZdZdZd&dZdZdZdZdZ dZ!e"edZ#d Z$d!Z%d"Z&d#Z'd$Z(RS('s;A distribution index that scans web pages for download URLsshttps://pypi.python.org/simplet*cOstj||||d|jd |_i|_i|_i|_tjdj t t |j |_ g|_|rtjr|stjrtj||_n tj|_dS(NR1t|(RRR+t index_urlt scanned_urlst fetched_urlst package_pagesRRRSRkR!R@tallowstto_scanRt is_availabletfind_ca_bundlet opener_fortopenerRturlopen(RzRthostst ca_bundlet verify_sslRatkw((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR s   ' !c CsU||jkr| rdSt|j|%siii(RA(tm((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytsRN( RnRiRRoRAt ValueErrorRwR<R+tneed_version_infotscan_urltPYPI_MD5tsub( RzR5RrRR@RRtnew_urlR.tfrag((RzsB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRss$&  cCs|jd|dS(NsPPage at %s links to .py file(s) without version info; an index scan is required.(tscan_all(RzR5((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRscGsO|j|jkr;|r+|j||n|jdn|j|jdS(Ns6Scanning index of all packages (this may take a while)(RRRRR(RzRRa((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs  cCs|j|j|jd|jj|jsN|j|j|jdn|jj|jss|j|nx3t|jj|jdD]}|j|qWdS(NR1(( RRt unsafe_nameRRR[t project_nametnot_found_in_indexR(Rzt requirementR5((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt find_packagess%cCsk|j|j|x8||jD])}||kr;|S|jd||q%Wtt|j||S(Ns%s does not match %s(tprescanRR[RtsuperR$tobtain(RzRt installerRC((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs   cCsi|j|jd||jse|jtj|td|jjtj j |fndS(s- checker is a ContentChecker sValidating %%s checksum for %ss7%s validation failed for %s; possible download problem?N( RRR~RRMtunlinkRRR-R8RI(RztcheckerRNttfp((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt check_hashs     cCsrxk|D]c}|jdksJt| sJ|jdsJtt|rZ|j|q|jj|qWdS(s;Add `urls` to the list that will be prescanned for searchessfile:N(RR*RR,RR%Rtappend(RzturlsR5((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytadd_find_linkss  cCs2|jr%tt|j|jnd|_dS(s7Scan urls scheduled for prescanning (e.g. --find-links)N(RRRkRR*(Rz((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs cCsN||jr |jd}}n|jd}}|||j|jdS(Ns#Couldn't retrieve index page for %rs3Couldn't find index page for %r (maybe misspelled?)(R[RRRR(RzRtmethR((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs   cCst|tst|}|r||j|jd||}t|\}}|jdrx|j|||}n|Stj j |r|Sytj |}Wqt k rt d|fqXnt|j||ddS(sLocate 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. is.pys1Not a URL, existing file, or requirement spec: %rRHN(RR Rt _download_urlRAR<R+t gen_setupRMR8RtparseRRRtfetch_distributionR*(RztspecttmpdirR6tfoundR.R;((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR2s"  c sNjd|id}dfd}|rcjj|||}n|dk r|p|||}n|dkrjdk rjn||}n|dkr| rj|||}n|dkrjdrdpd|n/jd||jdj|j|SdS( s|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. sSearching for %scs|dkr}nx||jD]q}|jtkrn rn|kr#jd|d|([^- ]+ - )?Revision \d+:sUnexpected HTML page found at ( RRmRRqRRMRR-R(RzR5RRNRR"((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR1s       cCsT|jddd}d}|jjdr#d|kr#t|\}}}}}} | r#|jdr#d|d kr#|d jdd\}}t|\} } | r d | kr| jd d\} } d | | f}n d | }| }t|||||| f}q q#n|jd ||tjd|||f|S(NR3iiRssvn:t@s//R1it:s --username=%s --password=%ss --username=s'Doing subversion checkout from %s to %sssvn checkout%s -q %s %s( R4R)R,RRRRRMtsystem(RzR5RNtcredsR6tnetlocR8RVtqRtauththosttusertpw((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR-s"!&  'cCst|\}}}}}|jddd}|jddd}d}d|krt|jdd\}}nt||||df}||fS(Nt+iiR3iR2R(RR4R*trsplitR(R5t pop_prefixR6R6R8R:Rtrev((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt_vcs_split_rev_from_url+s cCs|jddd}|j|dt\}}|jd||tjd||f|dk r|jd|tjd||fn|S( NR3iiR>sDoing git clone from %s to %ssgit clone --quiet %s %ssChecking out %ss"(cd %s && git checkout --quiet %s)(R4R@R}RRMR4R*(RzR5RNR?((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR.=s  cCs|jddd}|j|dt\}}|jd||tjd||f|dk r|jd|tjd||fn|S( NR3iiR>sDoing hg clone from %s to %sshg clone --quiet %s %ssUpdating to %ss(cd %s && hg up -C -r %s >&-)(R4R@R}RRMR4R*(RzR5RNR?((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR/Ms  cGstj||dS(N(RR(RzRRa((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR]scGstj||dS(N(RR(RzRRa((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR`scGstj||dS(N(RR(RzRRa((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRcs(RN()RRRR*R}RtFalseRRRRRRRRRRRRRRR2RRRRRRRRRR0R1R-t staticmethodR@R.R/RRR(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR$sL 0   *       )B ) #  (         s!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?cCs3t|ts|S|dkr)t|St|S(Ni(RRRtchr(tc((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytuchrjs  cCs{|jd}|jdr4t|dd}n=|jdrVt|d}ntj||jd}t|S(Nis#xiiR3i(RAR,RRRRE(R@twhat((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt decode_entitypscCs tt|S(s'Decode HTML entities in the given text.(t entity_subRG(ttext((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRozscsfd}|S(Ncsfd}|S(Ncs?tj}tjz||SWdtj|XdS(N(tsockettgetdefaulttimeouttsetdefaulttimeout(RaRbt old_timeout(Rcttimeout(sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt_socket_timeouts   ((RcRO(RN(RcsB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyROs((RNRO((RNsB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytsocket_timeout~s cCsCt|}|j}tj|}|j}|jddS(sq 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 s R(Rtencodetbase64t encodestringRR,(R8tauth_st auth_bytest encoded_bytestencoded((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt _encode_auths   t CredentialcBs)eZdZdZdZdZRS(s: A username/password pair. Use like a namedtuple. cCs||_||_dS(N(tusernametpassword(RzRZR[((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs ccs|jV|jVdS(N(RZR[(Rz((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt__iter__scCsdt|S(Ns%(username)s:%(password)s(tvars(Rz((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt__str__s(RRRRR\R^(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRYs  t PyPIConfigcBs2eZdZedZdZdZRS(cCsutjdddgd}tjj||tjjtjjdd}tjj|rq|j |ndS(s% Load from ~/.pypirc RZR[t repositoryRt~s.pypircN( tdicttfromkeysRRRMR8RSt expanduserRR(Rztdefaultstrc((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs !cCsMg|jD]$}|j|djr |^q }tt|j|S(NR`(tsectionsRRmRbRkt_get_repo_cred(Rztsectiontsections_with_repositories((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytcreds_by_repositorys$cCsO|j|dj}|t|j|dj|j|djfS(NR`RZR[(RRmRY(RzRitrepo((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRhscCs7x0|jjD]\}}|j|r|SqWdS(s If the URL indicated appears to be a repository defined in this config, return the credential for that repository. N(RktitemsR,(RzR5R`tcred((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytfind_credentials(RRRtpropertyRkRhRo(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyR_s  cCst|\}}}}}}|jdr?tjdn|d kr`t|\}} nd }|stj|} | rt| }| j |f} t j d| qn|r dt |}t || ||||f} tj| } | jd|ntj|} | jdt|| }|rt|j\}}}}}}||kr|| krt ||||||f|_qn|S( s4Open a urllib2 request, handling HTTP authenticationR3snonnumeric port: ''thttpthttpss*Authenticating as %s for %s (from .pypirc)sBasic t Authorizations User-Agent(shttpshttpsN(RR+RRRR*R_RoRlRZRRRXRRtRequestt add_headert user_agentR5(R5RR6R6R8tparamsR:RR8R9RnRRtrequestRts2th2tpath2tparam2tquery2tfrag2((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs2   !'cCs|S(N((R5((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyt fix_sf_urlscCstt|\}}}}}}t|}tjj|rItj|S|jdr<tjj|r<g}xtj |D]} | dkrt tjj || d} | j } WdQXPn.tjjtjj || r| d7} n|j d| | fqWd|ddj |} d\} } nd\} } } idd6}t|| | |t| S(s7Read a local path, with special support for directoriesR1s index.htmltrNs%ss%ss%ss itOKisPath not founds Not founds text/htmls content-type(isOK(isPath not founds Not found(RRRMR8tisfileRRR+RRRRSRRRR(R5R6R7R8tparamR:RRNtfilesRRtbodytstatustmessageR((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pyRs(  ! !!  (^RRRMRRRJRRRt functoolsRt pkg_resourcesRRRRRRRRR R R R R RxRt distutilsRtdistutils.errorsRtsetuptools.compatRRRRRRRRRRRRRRRR tfnmatchR!tsetuptools.py26compatR"tsetuptools.py27compatR#RR?tIRnRR@RR4RFt__all__t_SOCKET_TIMEOUTR&R<R*R%R>ROR'R`ReRhRwRRvtobjectRyRR$RRHRERGRoRPRXRYR_RRRR(((sB/usr/local/lib/python2.7/site-packages/setuptools/package_index.pytsp       Xd         "  !!d   '+