
rOc           @   s5  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Td d l m Z d d l m Z y d d l m Z Wn! e k
 r d d l m Z n Xd d l m Z e j d  Z e j d	 e j  Z e j d
  Z e j d e j  j Z d j   Z d d d d g Z d   Z d   Z  e! d  Z" e! d  Z# e! d  Z$ e! e% e! d  Z& e j d e j  Z' d   Z( d e j) e* d  d j+ f Z, d e- f d     YZ. e j d  j/ Z0 d   Z1 d   Z2 d    Z3 d!   Z4 d"   Z5 d#   Z6 d S($   s#   PyPI and direct package downloadingiN(   t   *(   t   log(   t   DistutilsError(   t   md5(   t	   translates   ^egg=([-A-Za-z0-9_.]+)$s   href\s*=\s*['"]?([^'"> ]+)s   <a href="([^"#]+)">([^<]+)</a>
\s+\(<a (?:title="MD5 hash"
\s+)href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)s   ([-+.a-z0-9]{2,}):s   .tar.gz .tar.bz2 .tar .zip .tgzt   PackageIndext   distros_for_urlt   parse_bdist_wininstt   interpret_distro_namec         C   s|   |  j    } d	 \ } } | j d  rr | j d  rC |  d  } qr | j d d  rr |  d d !} |  d  } qr n  | | f S(
   s=   Return (base,pyversion) or (None,None) for possible .exe names   .exes
   .win32.exeis	   .win32-pyiiiN(   NN(   t   lowert   Nonet   endswitht
   startswith(   t   nameR	   t   baset   py_ver(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR      s    c         C   sn   t  j  |   \ } } } } } } t j | j d  d  } d | k rd | j d d  \ } } n  | | f S(   Nt   /it   #i   (   t   urlparset   urllib2t   unquotet   split(   t   urlt   schemet   servert   patht
   parameterst   queryt   fragmentR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   egg_info_for_url*   s
    ! c         c   s   t  |   \ } } x t |  | |  D] } | Vq% W| r t j |  } | r x1 t |  | j d  | d t D] } | Vqq Wq n  d S(   sE   Yield egg or source distribution objects that might be found at a URLi   t
   precedenceN(   R   t   distros_for_locationt   EGG_FRAGMENTt   matchR   t   groupt   CHECKOUT_DIST(   R   t   metadataR   R   t   distR!   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   0   s     	"c         C   s   | j  d  r | d  } n  | j  d  rM d | k rM t j |  | |  g S| j  d  r t |  \ } } | d k	 r t |  | | | t d  Sn  x> t D]6 } | j  |  r | t |   } t |  | |  Sq Wg  S(   s:   Yield egg or source distribution objects based on basenames   .egg.zipis   .eggt   -s   .exet   win32N(	   R   t   Distributiont   from_locationR   R
   R   t   BINARY_DISTt
   EXTENSIONSt   len(   t   locationt   basenameR$   t   win_baseR   t   ext(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   <   s    c         C   s"   t  t |   t j j |   |  S(   sE   Yield possible egg or source distribution objects based on a filename(   R   t   normalize_patht   osR   R.   (   t   filenameR$   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   distros_for_filenameS   s    c   	      c   s   | j  d  } | s^ xF t | d  D]1 \ } } t |  d k r& | j d  r& d Sq& Wn  xa t d t |  d  D]F } t |  | d j | |   d j | |  d | d | d	 | Vqx Wd S(
   s   Generate 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!
    R&   i   i   s   py2.Ni   t
   py_versionR   t   platform(   R   t	   enumerateR,   R   t   rangeR(   t   join(	   R-   R.   R$   R5   R   R6   t   partst   it   p(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   Z   s    ! )s(   <([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>c         c   s  x t  j |  D] } | j   \ } } t t j | j   j d   } d | k sa d | k r x: t j |  D]& } t	 j
 |  t | j d    Vqq Wq q Wxg d	 D]_ } | j |  } | d k r t j | |  } | rt	 j
 |  t | j d    Vqq q Wd S(
   sE   Find rel="homepage" and rel="download" links in `page`, yielding URLst   ,t   homepaget   downloadi   s   <th>Home Pages   <th>Download URLiN(   s   <th>Home Pages   <th>Download URL(   t   RELt   finditert   groupst   mapt   strt   stripR	   R   t   HREFR   t   urljoint
   htmldecodeR"   t   findt   search(   R   t   pageR!   t   tagt   relt   relst   pos(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   find_external_links   s    !+s   Python-urllib/%s setuptools/%st
   setuptoolsi    c           B   sI  e  Z d  Z d d" d  Z e d  Z e d  Z e d  Z d   Z d   Z	 d	   Z
 d
   Z d# d  Z d   Z d# d  Z d   Z d   Z d   Z d   Z d   Z e e e d  Z e e d  Z d   Z d Z d   Z d   Z d# d  Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# RS($   s;   A distribution index that scans web pages for download URLss   http://pypi.python.org/simpleR    c         O   s}   t  j |  | |  | d | j d   |  _ i  |  _ i  |  _ i  |  _ t j d j	 t
 t |    j |  _ g  |  _ d  S(   NR   t   |(   t   Environmentt   __init__R   t	   index_urlt   scanned_urlst   fetched_urlst   package_pagest   ret   compileR9   RC   R   R!   t   allowst   to_scan(   t   selfRU   t   hostst   argst   kw(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRT      s    			'c   	   
   C   s  | |  j  k r | r d St |  j  | <t |  sD |  j |  d St t |   } | r |  j |  so d S|  j d |  n  | s | s | |  j k r t	 |  j
 |  d S|  j |  s t |  j | <d S|  j d |  |  j | d  } | d k rd St |  j | <|  j | j <d | j j d d  j   k rN| j   d S| j } | j   } | j   | j |  j  rt | d d  d	 k r|  j | |  } n  xE t j |  D]4 } t j | t | j d
    } |  j |  qWd S(   s<   Evaluate a URL as a possible download, and maybe retrieve itNs   Found link: %ss
   Reading %ss5   Download error: %s -- Some packages may not be found!t   htmls   content-typet    t   codei  i   (   RV   t   Truet
   URL_SCHEMEt   process_filenamet   listR   t   url_okt   debugRW   RC   t   addt   infot   open_urlR
   R   t   headerst   getR	   t   closet   readR   RU   t   getattrt   process_indexRF   RA   R   RG   RH   R"   t   process_url(	   R]   R   t   retrievet   distst   fR   RK   R!   t   link(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRs      sB     !
	
*!c         C   s   t  j j |  s& |  j d |  d  St  j j |  r | r t  j j |  } x9 t  j |  D]% } |  j t  j j | |  t	  qa Wn  t
 |  } | r |  j d |  t |  j |  n  d  S(   Ns   Not found: %ss	   Found: %s(   R2   R   t   existst   warnt   isdirt   realpatht   listdirRf   R9   Rd   R4   Ri   RC   Rj   (   R]   t   fnt   nestedR   t   itemRu   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRf      s    &c         C   s   t  |  } | r- | j d  j   d k sI |  j t j |  d  rM t Sd } | rl t | |   n |  j | |  d  S(   Ni   t   files,   
Link to % s ***BLOCKED*** by --allow-hosts
(   Re   R"   R	   R[   R   Rd   R   Ry   (   R]   R   t   fatalt   st   msg(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRh      s    =c         C   sf   x_ | D]W } t  j j |  r x< t  j |  D]( } | j d  r/ |  j | |  q/ q/ Wq q Wd  S(   Ns	   .egg-link(   R2   R   Rz   R|   R   t   scan_egg_link(   R]   t   search_pathR   t   entry(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   scan_egg_links   s
    c         C   s   t  d  t t j t t j j | |     } t	 |  d k r xX t
 t j j | | d   D]4 } t j j | |  | _ t | _ |  j |  qb Wn  d  S(   Ni   i    (   t   filterR
   RC   RD   RE   R   R2   R   R9   R,   t   find_distributionsR-   t   SOURCE_DISTR   Rj   (   R]   R   R   t   linesR%   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR      s    0&	c   
         s     f d   } x< t  j |  D]+ } | t j | t | j d     q W| |  \ } } | r xy t | |  D]h } t |  \ } }	 | j d  r |	 r | r | d | | f 7} q   j	 |  n    j
 |  qv Wt j d   |  Sd Sd S(   s#   Process the contents of a PyPI pagec            s   |  j    j  r t t j |  t   j  j d   } t |  d k r d | d k r t | d  } t | d  } t	   j
 j | j   i   |  <t |  t |  f Sn  d S(   NR   i   R   i   i    (   NN(   R   RU   RC   R   R   R,   R   t	   safe_namet   safe_versionRd   RX   t
   setdefaultR	   t   to_filenameR
   (   Rw   R:   t   pkgt   ver(   R]   (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   scan   s    %"i   s   .pys
   #egg=%s-%sc         S   s   d |  j  d d d  S(   Ns   <a href="%s#md5=%s">%s</a>i   i   i   (   R"   (   t   m(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   <lambda>  s    Rb   N(   RF   RA   R   RG   RH   R"   RP   R   R   t   need_version_infot   scan_urlt   PYPI_MD5t   sub(
   R]   R   RK   R   R!   R   R   t   new_urlR   t   frag(    (   R]   s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRr      s    )c         C   s   |  j  d |  d  S(   NsP   Page at %s links to .py file(s) without version info; an index scan is required.(   t   scan_all(   R]   R   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR      s    c         G   sO   |  j  |  j k r; | r+ |  j | |  n  |  j d  n  |  j |  j   d  S(   Ns6   Scanning index of all packages (this may take a while)(   RU   RW   Ry   Rk   R   (   R]   R   R_   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   &  s     
c         C   s   |  j  |  j | j d  |  j j | j  sN |  j  |  j | j d  n  |  j j | j  ss |  j |  n  x3 t |  j j | j d   D] } |  j  |  q Wd  S(   NR   (    (	   R   RU   t   unsafe_nameRX   Rn   t   keyt   project_namet   not_found_in_indexRg   (   R]   t   requirementR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   find_packages.  s    %c         C   sk   |  j    |  j |  x8 |  | j D]) } | | k r; | S|  j d | |  q% Wt t |   j | |  S(   Ns   %s does not match %s(   t   prescanR   R   Ri   t   superR   t   obtain(   R]   R   t	   installerR%   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   =  s    
 c         C   sy   t  j d |  ru |  j d |  | j   | d k ru | j   t j |  t d t j j	 |  d   qu n  d  S(   Ns   md5=[0-9a-f]{32}$s   Validating md5 checksum for %si   s   MD5 validation failed for s   ; possible download problem?(
   RY   R!   Ri   t	   hexdigestRo   R2   t   unlinkR   R   R.   (   R]   t   csRk   R3   t   tfp(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt	   check_md5I  s    
c         C   sr   xk | D]c } |  j  d k sJ t |  sJ | j d  sJ t t |   rZ |  j |  q |  j  j |  q Wd S(   s;   Add `urls` to the list that will be prescanned for searchess   file:N(   R\   R
   Re   R   Rg   R   R   t   append(   R]   t   urlsR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   add_find_linksT  s    c         C   s,   |  j  r t |  j |  j   n  d |  _  d S(   s7   Scan urls scheduled for prescanning (e.g. --find-links)N(   R\   RC   R   R
   (   R]   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   c  s    	c         C   sN   |  | j  r  |  j d } } n |  j d } } | | | j  |  j   d  S(   Ns#   Couldn't retrieve index page for %rs3   Couldn't find index page for %r (maybe misspelled?)(   R   Rk   Ry   R   R   (   R]   R   t   methR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   i  s    
c         C   s   t  | t  s t |  } | r| |  j | j d  | |  } t |  \ } } | j d  rx |  j | | |  } n  | St j	 j
 |  r | Sy t j |  } Wq t k
 r t d | f   q Xn  t |  j | |  d d  S(   s  Locate 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.
        i   s   .pys1   Not a URL, existing file, or requirement spec: %rR-   N(   t
   isinstancet   RequirementRe   t   _download_urlR"   R   R   t	   gen_setupR2   R   Rx   t   parset
   ValueErrorR   Rq   t   fetch_distributionR
   (   R]   t   spect   tmpdirR   t   foundR   R   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR?   r  s"    c            s    j  d |  i          f d   } | rQ  j    j |  n  | |  } | d k r  j d k	 r  j   | |  } n  | d k r | r  j |  | |  } n  | d k r  j d  r d p d |  n  | S(   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.
        s   Searching for %sc      	      s   x  |  j  D] } | j t k rY  rY |   k r  j d |  d   | <q q n  | |  k r | j t k s{  r  j d |  | j d  j | j    Sq Wd  S(   Ns&   Skipping development or system egg: %si   s   Best match: %sR-   (	   R   R   t   DEVELOP_DISTRy   R   Rk   t   cloneR?   R-   (   t   reqR%   (   t   skippedt
   develop_okR]   t   sourceR   (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRI     s    "	s2   No local packages or download links found for %s%ss   a source distribution of Rb   N(   Rk   R   R   R
   R\   Ry   (   R]   R   R   t
   force_scanR   R   RI   R%   (    (   R   R   R]   R   R   s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR     s&    


c         C   s/   |  j  | | | |  } | d k	 r+ | j Sd S(   s3  Obtain 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(   R   R
   R-   (   R]   R   R   R   R   R%   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   fetch  s    c         C   sq  t  j |  } | rL g  t | | j d  d   D] } | j r1 | ^ q1 pO g  } t |  d k rBt j j	 |  } t j j
 |  | k r t j j | |  } d d l m }	 |	 | |  s t j | |  | } q n  t t j j | d  d  }
 |
 j d | d j | d j t j j |  d f  |
 j   | S| rat d | | f   n t d	   d  S(
   Ni   i(   t   samefiles   setup.pyt   wsI   from setuptools import setup
setup(name=%r, version=%r, py_modules=[%r])
i    s   Can't unambiguously interpret project/version identifier %r; any dashes in the name or version should be escaped using underscores. %rsp   Can't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.(   R    R!   R   R"   R
   t   versionR,   R2   R   R.   t   dirnameR9   t   setuptools.command.easy_installR   t   shutilt   copy2t   opent   writeR   t   splitextRo   R   (   R]   R3   R   R   R!   t   dRu   R.   t   dstR   R   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR     s2    	4
i    c         C   s  |  j  d |  d
 \ } } } zed | k rI | j d d  \ } } n  |  j |  } t | t j  r t d | | j | j	 f   n  t
   } | j    } d } |  j }	 d }
 d | k r t | d  }
 |  j | | | |	 |
  n  t | d	  } x` t r_| j |	  } | r[| j |  | j |  | d 7} |  j | | | |	 |
  q Pq W| r|  j | | | |  n  | SWd  | r| j   n  | r| j   n  Xd  S(   Ns   Downloading %sR   i   s   Can't download %s: %s %si    is   content-lengths   Content-Lengtht   wb(   NNN(   Rk   R
   R   Rl   R   R   t	   HTTPErrorR   Rc   R   R   t   dl_blocksizet   intt
   reporthookR   Rd   Rp   t   updateR   R   Ro   (   R]   R   R3   t   fpR   Rk   R   Rm   t   blocknumt   bst   sizet   block(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   _download_to  sB    			
   c         C   s   d  S(   N(    (   R]   R   R3   R   t   blksizeR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   ;  s    c         C   s   | j  d  r t |  Sy t |  SWna t j k
 r@ } | St j k
 r } | rn |  j | | j  q t d | | j f   n Xd  S(   Ns   file:s   Download error for %s: %s(	   R   t
   local_opent   open_with_authR   R   t   URLErrorRy   t   reasonR   (   R]   R   t   warningt   v(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRl   ?  s    
 c         C   s  t  d  t j |  d j d   } | ri | d } x7 d | k re | j d d  j d d  } q8 Wn d } | j d	  r | d
  } n  t j j | |  } | d k s | j	 d  r |  j
 | |  S| d k r t j t j |  d  S|  j | t  |  j | |  Sd  S(   Ni   R   is   ..t   .s   \t   _t   __downloaded__s   .egg.zipit   svns   svn+R   (   R   R
   R   R   t   replaceR   R2   R   R9   R   t   _download_svnR   t   url2pathnameRh   Rd   t   _attempt_download(   R]   R   R   R   R   R3   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   L  s    %
%c         C   s   |  j  | t  d  S(   N(   Rs   Rd   (   R]   R   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   h  s    c         C   sK   |  j  | |  } d | j d d  j   k rC |  j | | |  S| Sd  S(   NRa   s   content-typeRb   (   R   Rn   R	   t   _download_html(   R]   R   R3   Rm   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   l  s    c         C   s   t  |  } xW | D]O } | j   r t j d |  r^ | j   t j |  |  j | |  SPq q W| j   t j |  t d |   d  S(   Ns    <title>([^- ]+ - )?Revision \d+:s   Unexpected HTML page found at (	   R   RE   RY   RJ   Ro   R2   R   R   R   (   R]   R   Rm   R3   R   t   line(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR   s  s    

c         C   sD   | j  d d  d } |  j d | |  t j d | | f  | S(   NR   i   i    s'   Doing subversion checkout from %s to %ss   svn checkout -q %s %s(   R   Rk   R2   t   system(   R]   R   R3   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR     s    c         G   s   t  j | |  d  S(   N(   R   Ri   (   R]   R   R_   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRi     s    c         G   s   t  j | |  d  S(   N(   R   Rk   (   R]   R   R_   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRk     s    c         G   s   t  j | |  d  S(   N(   R   Ry   (   R]   R   R_   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRy     s    (   R    N($   t   __name__t
   __module__t   __doc__RT   t   FalseRs   Rf   Rh   R   R   Rr   R   R
   R   R   R   R   R   R   R   R?   R   R   R   R   R   R   Rl   R   R   R   R   R   Ri   Rk   Ry   (    (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR      s@   )
			)								*=	)	$								s!   &(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c         C   s3   t  |  t  s |  S|  d k r) t |   St |   S(   Ni   (   R   R   t   unichrt   chr(   t   c(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   uchr  s
     
c         C   s   |  j  d  } | j d  r4 t | d d  } nM | j d  rV t | d  } n+ d d l m } | j | |  j  d   } t |  S(	   Ni   s   #xi   i   R   i(   t   name2codepointi    (   R"   R   R   t   htmlentitydefsR   Rn   R   (   R!   t   whatR   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   decode_entity  s    c         C   s   t  t |   S(   s'   Decode HTML entities in the given text.(   t
   entity_subR   (   t   text(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyRH     s    c         C   sT  t  j  |   \ } } } } } } | d k rE t j |  \ } } n d } | r d t j |  j d  j   } t  j | | | | | | f  }	 t j |	  }
 |
 j	 d |  n t j |   }
 |
 j	 d t
  t j |
  } | rPt  j  | j  \ } } } } } } | | k rP| | k rPt  j | | | | | | f  | _ qPn  | S(	   s4   Open a urllib2 request, handling HTTP authenticationt   httpt   httpss   Basic t   base64t   Authorizations
   User-Agent(   R   R   N(   R   R   t	   splituserR
   R   t   encodeRE   t
   urlunparset   Requestt
   add_headert
   user_agentt   urlopenR   (   R   R   t   netlocR   t   paramsR   R   t   autht   hostR   t   requestR   t   s2t   h2t   path2t   param2t   query2t   frag2(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR     s"    !"!$*c         C   s   |  S(   N(    (   R   (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt
   fix_sf_url  s    c         C   sk  t  j  |   \ } } } } } } t j |  } t j j |  rO t j |   S| j d  r3t j j |  r3g  } x t j	 |  D] }	 |	 d k r t
 t j j | |	  d  j   }
 Pn. t j j t j j | |	   r |	 d 7}	 n  | j d |	 |	 f  q Wd |  d d j |  }
 d \ } } n d \ } } }
 t j |  | | i d d 6t j |
   S(   s7   Read a local path, with special support for directoriesR   s
   index.htmlt   rbs   <a href=%r>%s</a>s   <html><head><title>%s</title>s   </head><body>%s</body></html>s   
i   t   OKi  s   Path not founds	   Not founds	   text/htmls   content-type(   i   R  (   i  s   Path not founds	   Not found(   R   R   R   R2   R   t   isfileR  R   Rz   R|   R   R9   Rp   R   R   t	   cStringIOt   StringIO(   R   R   R   R   t   paramR   R   R3   t   filesRv   t   bodyt   statust   message(    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyR     s&    !!$!(7   R   t   syst   os.pathR2   RY   R   R   R   t   randomt   socketR  t   pkg_resourcest	   distutilsR   t   distutils.errorsR   t   hashlibR   t   ImportErrort   fnmatchR   RZ   R    t   IRF   R   R!   Re   R   R+   t   __all__R   R   R
   R   R   R4   R   R   R@   RP   t   __version__t   requireR   R  RS   R   R   R   R   R   RH   R   R  R   (    (    (    s<   /var/www/python/setuptools-0.6c9/setuptools/package_index.pyt   <module>   sJ   l
					!	   				)	