
&>Oc           @   su  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 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" 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, d  e- d  d j, f Z. d e/ f d     YZ0 e j d  j1 Z2 d    Z3 d!   Z4 d"   Z5 d d#  Z6 d$   Z7 e6 e!  e7  Z7 d%   Z8 d&   Z9 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_namei   c         C   s   |  j    } d \ } } } | j d  r | j d  rL |  d  } d } q | j d d  r~ |  d d !} |  d  } d } q | j d	  r |  d
  } d } q | j d d  r |  d d !} |  d  } d } q n  | | | f S(   s=   Return (base,pyversion) or (None,None) for possible .exe names   .exes
   .win32.exeit   win32s	   .win32-pyiiis   .win-amd64.exeis	   win-amd64s   .win-amd64-pyiN(   NNN(   t   lowert   Nonet   endswitht
   startswith(   t   nameR
   t   baset   py_vert   plat(    (    s<   /usr/lib/python2.7/dist-packages/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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   egg_info_for_url6   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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   <   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 |  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   .exeN(	   R   t   Distributiont   from_locationR   R   R   t   BINARY_DISTt
   EXTENSIONSt   len(   t   locationt   basenameR&   t   win_baseR   t   platformt   ext(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR!   H   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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   distros_for_filename_   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    R1   (   R   t	   enumerateR-   R   t   rangeR)   t   join(	   R.   R/   R&   R7   R    R1   t   partst   it   p(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   f   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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   find_external_links   s    !+s   Python-urllib/%s distribute/%si   t
   distributei    c           B   sL  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# 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   compileR:   RD   R   R#   t   allowst   to_scan(   t   selfRV   t   hostst   argst   kw(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRU      s    			'c   
   
   C   sO  | |  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   } t | t  st | t j  rd } n | j j d	  pd } | j | d
  } n  | j   xE t j |  D]4 } t j | t | j d    }	 |  j  |	  qW| j! |  j"  rKt# | d d  d k rK|  j$ | |  } n  d 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    s   latin-1t   charsett   ignorei   t   codei  (%   RW   t   Truet
   URL_SCHEMEt   process_filenamet   listR   t   url_okt   debugRX   RD   t   addt   infot   open_urlR   R   t   headerst   getR
   t   closet   readt
   isinstanceRE   R   t	   HTTPErrort	   get_paramt   decodeRG   RB   R   RH   RI   R$   t   process_urlR   RV   t   getattrt   process_index(
   R^   R   t   retrievet   distst   fR   RL   Rd   R#   t   link(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRx      sL     !
		
!*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(   R4   R   t   existst   warnt   isdirt   realpatht   listdirRi   R:   Rg   R6   Rl   RD   Rm   (   R^   t   fnt   nestedR   t   itemR|   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRi      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
(   Rh   R$   R
   R\   R   Rg   R   R   (   R^   R   t   fatalt   st   msg(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRk      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(   R4   R   R   R   R   t   scan_egg_link(   R^   t   search_pathR   t   entry(    (    s<   /usr/lib/python2.7/dist-packages/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   RD   RE   RF   t   openR4   R   R:   R-   t   find_distributionsR.   t   SOURCE_DISTR    Rm   (   R^   R   R   t   linesR'   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s    0&	c   
         s    f d   } xT t  j |  D]C } y) | t j | t | j d     Wq t k
 ra q Xq W| |  \ } } | rxy t | |  D]h } t |  \ } }	 | j	 d  r |	 r | r | d | | f 7} q   j
 |  n    j |  q 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   RV   RD   R   R   R-   R   t	   safe_namet   safe_versionRg   RY   t
   setdefaultR
   t   to_filenameR   (   R~   R;   t   pkgt   ver(   R^   (    s<   /usr/lib/python2.7/dist-packages/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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   <lambda>/  s    Rc   N(   RG   RB   R   RH   RI   R$   t
   ValueErrorRQ   R   R   t   need_version_infot   scan_urlt   PYPI_MD5t   sub(
   R^   R   RL   R   R#   R   R   t   new_urlR   t   frag(    (   R^   s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRz   
  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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   6  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)(   RV   RX   R   Rn   R   (   R^   R   R`   (    (    s<   /usr/lib/python2.7/dist-packages/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   RV   t   unsafe_nameRY   Rq   t   keyt   project_namet   not_found_in_indexRj   (   R^   t   requirementR   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   find_packagesD  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   Rl   t   superR   t   obtain(   R^   R   t	   installerR'   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   S  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?(
   RZ   R#   Rl   t	   hexdigestRr   R4   t   unlinkR   R   R/   (   R^   t   csRn   R5   t   tfp(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt	   check_md5_  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   Rh   R   Rj   R   R   t   append(   R^   t   urlsR   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   add_find_linksj  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]   RD   R   R   (   R^   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   y  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   Rn   R   R   R   (   R^   R   t   methR   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     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(   Rt   t   RequirementRh   t   _download_urlR$   R   R   t	   gen_setupR4   R   R   t   parseR   R   Ry   t   fetch_distributionR   (   R^   t   spect   tmpdirR   t   foundR   R   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR@     s"    c   	   	      s   j  d |  i    d } d       f d  } | rf  j    j |  | |  } n  | d k	 r | p | | |  } 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   | d  k r  } n  x | |  j D] } | j t k rn  rn |   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   R    t   DEVELOP_DISTR   R   Rn   t   cloneR@   R.   (   t   reqt   envR'   (   t   skippedt
   develop_okR^   t   sourceR   (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRJ     s    	"	s2   No local packages or download links found for %s%ss   a source distribution of Rc   N(   Rn   R   R   R   R]   R   (	   R^   R   R   t
   force_scanR   R   t   local_indexR'   RJ   (    (   R   R   R^   R   R   s<   /usr/lib/python2.7/dist-packages/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<   /usr/lib/python2.7/dist-packages/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-   R4   R   R/   t   dirnameR:   t   setuptools.command.easy_installR   t   shutilt   copy2R   t   writeR   t   splitextRr   R   (   R^   R5   R   R   R#   t   dR|   R/   t   dstR   R   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   
  s2    	4
i    c         C   s  |  j  d |  d
 \ } } } zp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 | j d  } t |  }
 |  j | | | |	 |
  n  t | d	  } x` t rj| j |	  } | rf| 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(   Rn   R   R   Ro   Rt   R   Ru   R   Rf   R   R   t   dl_blocksizeRq   t   intt
   reporthookR   Rg   Rs   t   updateR   R   Rr   (   R^   R   R5   t   fpR   Rn   R   Rp   t   blocknumt   bst   sizet   content_lengtht   block(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   _download_to4  sD    			
   c         C   s   d  S(   N(    (   R^   R   R5   R   t   blksizeR   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   Z  s    c         C   s  | j  d  r t |  Sy t |  SWndt t j f k
 r } d j g  | j D] } t |  ^ qR  } | r |  j	 | |  qt
 d | | f   n t j k
 r } | St j k
 r } | r |  j	 | | j  qt
 d | | j f   n t j k
 rI} | r-|  j	 | | j  qt
 d | | j f   nE t j k
 r} | rt|  j	 | |  qt
 d | | f   n Xd  S(   Ns   file:t    s   %s %ss   Download error for %s: %ss;   %s returned a bad status line. The server might be down, %s(   R   t
   local_opent   open_with_authR   t   httplibt
   InvalidURLR:   R`   RE   R   R   R   Ru   t   URLErrort   reasont   BadStatusLinet   linet   HTTPException(   R^   R   t   warningt   vt   argR   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRo   ^  s4    
+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   R4   R   R:   R   t   _download_svnt   urllibt   url2pathnameRk   Rg   t   _attempt_download(   R^   R   R   R   R   R5   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s    %
%c         C   s   |  j  | t  d  S(   N(   Rx   Rg   (   R^   R   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s    c         C   sK   |  j  | |  } d | j d d  j   k rC |  j | | |  S| Sd  S(   NRb   s   content-typeRc   (   R   Rq   R
   t   _download_html(   R^   R   R5   Rp   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     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   RF   RZ   RK   Rr   R4   R   R   R   (   R^   R   Rp   R5   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     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   Rn   R4   t   system(   R^   R   R5   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s    c         G   s   t  j | |  d  S(   N(   R   Rl   (   R^   R   R`   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRl     s    c         G   s   t  j | |  d  S(   N(   R   Rn   (   R^   R   R`   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRn     s    c         G   s   t  j | |  d  S(   N(   R   R   (   R^   R   R`   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s    (   R    N($   t   __name__t
   __module__t   __doc__RU   t   FalseRx   Ri   Rk   R   R   Rz   R   R   R   R   R   R   R   R   R   R@   R   R   R   R   R   R   Ro   R   R   R   R   R   Rl   Rn   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR      sB   0
			,								*	C	)	&	!							s!   &(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c         C   s3   t  |  t  s |  S|  d k r) t |   St |   S(   Ni   (   Rt   R   t   unichrt   chr(   t   c(    (    s<   /usr/lib/python2.7/dist-packages/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  Rq   R  (   R#   t   whatR  (    (    s<   /usr/lib/python2.7/dist-packages/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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyRI     s    c            s     f d   } | S(   Nc            s      f d   } | S(   Nc             s?   t  j   } t  j    z  |  |   SWd  t  j |  Xd  S(   N(   t   sockett   getdefaulttimeoutt   setdefaulttimeout(   R`   t   kwargst   old_timeout(   t   timeoutt   func(    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   _socket_timeout  s
    (    (   R  R  (   R  (   R  s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR    s    (    (   R  R  (    (   R  s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   socket_timeout  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   encodeRF   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<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR     s"    !"!$*c         C   s   |  S(   N(    (   R   (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt
   fix_sf_url#  s    c         C   s{  t  j  |   \ } } } } } } t j |  } t j j |  rO t j |   S| j d  rCt j j	 |  rC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 \ } } } 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   R4   R   t   isfileR   R  R   R   R   R   R:   Rs   Rr   R   Ru   t	   cStringIOt   StringIO(   R   R   R   R   t   paramR   R   R5   t   filesR}   R   t   bodyt   statust   message(    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyR   &  s*    !!
!(:   R   t   syst   os.pathR4   RZ   R   R   R   R   t   randomR  R+  R   t   pkg_resourcest	   distutilsR   t   distutils.errorsR   t   hashlibR   t   ImportErrort   fnmatchR   R[   R"   t   IRG   R   R#   Rh   R   R,   t   __all__t   _SOCKET_TIMEOUTR   R   R   R   R!   R6   R   R   RA   RQ   R   t   requireR  RT   R   R   R  R  R  RI   R  R   R'  R   (    (    (    s<   /usr/lib/python2.7/dist-packages/setuptools/package_index.pyt   <module>   sR   x
					!	!  '					