
Rc           @   s	  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k Z d  d k	 Z	 d  d k
 l Z d  d k l Z d  d k l Z l Z l Z l Z l Z d  d k l Z l Z e i e  Z d Z d Z d	 Z d
 e f d     YZ d S(   iN(   t   ascii_lowercase(   t   Thread(   t   DistlibException(   t   HTTPBasicAuthHandlert   Requestt   HTTPPasswordMgrt   urlparset   build_opener(   t   cached_propertyt   zip_dirs   last.pypi.python.orgs   http://pypi.python.org/pypit   pypit   PackageIndexc           B   s   e  Z d  Z d Z d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d d
  Z d   Z d d d d d  Z d   Z d   Z d   Z d d d  Z d   Z d   Z e d    Z RS(   sc   
    This class represents a package index compatible with PyPI, the Python
    Package Index.
    s.   ----------ThIs_Is_tHe_distlib_index_bouNdaRY_$c         C   sB  | p t  |  _ | p t |  _ |  i   t |  i  \ } } } } } } | p | p | p | d j o t d |  i   n d |  _ d |  _	 d |  _
 d |  _ t t i d  i i   }	 zt |	 ~	 }
 xd d D]\ } y@ t i | d g d |
 d	 |
 } | d
 j o | |  _
 Pn Wq t j
 o q Xq WWd QXd S(   s  
        Initialise an instance.

        :param url: The URL of the index. If not specified, the URL for PyPI is
                    used.
        :param mirror_host: If not specified, ``last.pypi.python.org`` is used.
                            This is expected to have a canonial name which
                            allows all mirror hostnames to be divined (e.g. if
                            the canonical hostname for ``last.pypi.python.org``
                            is ``g.pypi.python.org``, then the mirrors that are
                            available would be assumed to be
                            ``a.pypi.python.org``, ``b.pypi.python.org``, ...
                            up to and including ``g.pypi.python.org``.
        t   httpt   httpss   invalid repository: %st   wt   gpg2t   gpgs	   --versiont   stdoutt   stderri    N(   s   https   https(   R   s   gpg(   t   DEFAULT_INDEXt   urlt   DEFAULT_MIRROR_HOSTt   mirror_hostt   read_configurationR   R   t   Nonet   password_handlert   ssl_verifierR   t   gpg_homet   opent   ost   devnullt   __exit__t	   __enter__t
   subprocesst
   check_callt   OSError(   t   selfR   R   t   schemet   netloct   patht   paramst   queryt   fragt   _[1]t   sinkt   st   rc(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   __init__%   s*    
!"				) 			c         C   s3   d d k  l } d d k l } |   } | |  S(   ss   
        Get the distutils command for interacting with PyPI configurations.
        :return: the command.
        i(   t   Distribution(   t   PyPIRCCommand(   t   distutils.coreR0   t   distutils.configR1   (   R$   R0   R1   t   d(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   _get_pypirc_commandI   s    	c         C   sy   |  i    } |  i | _ | i   } | i d  |  _ | i d  |  _ | i d d  |  _ | i d |  i  |  _ d S(   s   
        Read the PyPI access configuration as supported by distutils, getting
        PyPI to do the acutal work. This populates ``username``, ``password``,
        ``realm`` and ``url`` attributes from the configuration.
        t   usernamet   passwordt   realmR
   t
   repositoryN(   R5   R   R9   t   _read_pypirct   getR6   R7   R8   (   R$   t   ct   cfg(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyR   S   s    c         C   s0   |  i    |  i   } | i |  i |  i  d S(   s   
        Save the PyPI access configuration. You must have set ``username`` and
        ``password`` attributes before calling this method.

        Again, distutils is used to do the actual work.
        N(   t   check_credentialsR5   t   _store_pypircR6   R7   (   R$   R<   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   save_configurationb   s    
c         C   s   |  i  d j p |  i d j o t d   n t   } t |  i  \ } } } } } } | i |  i | |  i  |  i  t	 |  |  _
 d S(   sp   
        Check that ``username`` and ``password`` have been set, and raise an
        exception if not.
        s!   username and password must be setN(   R6   R   R7   R   R   R   R   t   add_passwordR8   R   R   (   R$   t   pmt   _R&   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyR>   n   s     	!c         C   s   |  i    | i t  \ } } t i d | |  | i t  } d | d <|  i | i   g   } |  i |  } d | d <|  i | i   g   } |  i |  S(   sq  
        Register a distribution on PyPI, using the provided metadata.

        :param metadata: A :class:`Metadata` instance defining at least a name
                         and version number for the distribution to be
                         registered.
        :return: The HTTP response received from PyPI upon submission of the
                request.
        s*   result of check: missing: %s, warnings: %st   verifys   :actiont   submit(	   R>   t   checkt   Truet   loggert   debugt   todictt   encode_requestt   itemst   send_request(   R$   t   metadatat   missingt   warningsR4   t   requestt   response(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   registerz   s    

	


c         C   sn   x] t  oU | i   } | p Pn | i d  i   } | i |  t i d | | f  q W| i   d S(   sr  
        Thread runner for reading lines of from a subprocess into a buffer.

        :param name: The logical name of the stream (used for logging only).
        :param stream: The stream to read from. This will typically a pipe
                       connected to the output stream of a subprocess.
        :param outbuf: The list to append the read lines to.
        s   utf-8s   %s: %sN(   RG   t   readlinet   decodet   rstript   appendRH   RI   t   close(   R$   t   namet   streamt   outbufR-   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   _reader   s    	 c         C   s   |  i  d d d g } |  i o | i d |  i g  n | d j	 o | i d d d g  n t i   } t i i | t i i	 |  d  } | i d	 d
 d | d | | g  t
 i d d i |   | | f S(   s  
        Return a suitable command for signing a file.

        :param filename: The pathname to the file to be signed.
        :param signer: The identifier of the signer of the file.
        :param sign_password: The passphrase for the signer's
                              private key used for signing.
        :return: The signing command as a list suitable to be
                 passed to :class:`subprocess.Popen`.
        s   --status-fdt   2s   --no-ttys	   --homedirs   --batchs   --passphrase-fdt   0s   .ascs   --detach-signs   --armors   --local-users   --outputs   invoking: %st    N(   R   R   t   extendR   t   tempfilet   mkdtempR   R'   t   joint   basenameRH   RI   (   R$   t   filenamet   signert   sign_passwordt   cmdt   tdt   sf(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   get_sign_command   s    
%c   	      C   s  h t  i d 6t  i d 6} | d j	 o t  i | d <n g  } g  } t  i | |  } t d |  i d d | i | f  } | i   t d |  i d d | i | f  } | i   | d j	 o! | i	 i
 |  | i	 i   n | i   | i   | i   | i | | f S(   s  
        Run a command in a child process , passing it any input data specified.

        :param cmd: The command to run.
        :param input_data: If specified, this must be a byte string containing
                           data to be sent to the child process.
        :return: A tuple consisting of the subprocess' exit code, a list of
                 lines read from the subprocess' ``stdout``, and a list of
                 lines read from the subprocess' ``stderr``.
        R   R   t   stdint   targett   argsN(   R!   t   PIPER   t   PopenR   R\   R   t   startR   Rl   t   writeRX   t   waitRc   t
   returncode(	   R$   Rh   t
   input_datat   kwargsR   R   t   pt   t1t   t2(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   run_command   s&    
$
$



c   	      C   sd   |  i  | | |  \ } } |  i | | i d   \ } } } | d j o t d |   n | S(   s}  
        Sign a file.

        :param filename: The pathname to the file to be signed.
        :param signer: The identifier of the signer of the file.
        :param sign_password: The passphrase for the signer's
                              private key used for signing.
        :return: The absolute pathname of the file where the signature is
                 stored.
        s   utf-8i    s&   sign command failed with error code %s(   Rk   Rz   t   encodeR   (	   R$   Re   Rf   Rg   Rh   t   sig_fileR.   R   R   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt	   sign_file   s    	t   sdistt   sourcec      
   C   s  |  i    t i i |  p t d |   n | i t  \ } } t i d | |  | i	 t  }	 d }
 | o4 |  i p t i d  q |  i | | |  }
 n t | d  i i   } z | ~ } | i   } Wd QXt i |  i   } |	 i h d d 6d d	 6| d
 6| d 6| d 6 d t i i |  | f g } |
 ow t |
 d  i i   } z | ~ } | i   } Wd QX| i d t i i |
  | f  t i t i i |
   n t i d |  |  i |	 i   |  } |  i |  S(   s  
        Upload a release file to the index.

        :param metadata: A :class:`Metadata` instance defining at least a name
                         and version number for the file to be uploaded.
        :param filename: The pathname of the file to be uploaded.
        :param signer: The identifier of the signer of the file.
        :param sign_password: The passphrase for the signer's
                              private key used for signing.
        :param filetype: The type of the file being uploaded. This is the
                        distutils command which produced that file, e.g.
                        ``sdist`` or ``bdist_wheel``.
        :param pyversion: The version of Python which the release relates
                          to. For code compatible with any Python, this would
                          be ``source``, otherwise it would be e.g. ``3.2``.
        :return: The HTTP response received from PyPI upon submission of the
                request.
        s   not found: %ss*   result of check: missing: %s, warnings: %ss)   no signing program available - not signedt   rbNt   file_uploads   :actiont   1t   protcol_versiont   filetypet	   pyversiont
   md5_digestt   contentt   gpg_signatures	   files: %s(   R>   R   R'   t   existsR   RF   RG   RH   RI   RJ   R   R   t   warningR}   R   R   R    t   readt   hashlibt   md5t	   hexdigestt   updateRd   RW   t   shutilt   rmtreet   dirnameRK   RL   RM   (   R$   RN   Re   Rf   Rg   R   R   RO   RP   R4   R|   R+   t   ft	   file_datat   digestt   filest   _[2]t   sig_dataRQ   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   upload_file   s>    
	

&	&
c         C   s  |  i    t i i |  p t d |   n t i i | d  } t i i |  p t d |   n | i t  \ } } t	 i
 d | |  | i | i } } t |  i   } d
 d | f d | f g }	 d	 | | f g }
 |  i |	 |
  } |  i |  S(   s2  
        Upload documentation to the index.

        :param metadata: A :class:`Metadata` instance defining at least a name
                         and version number for the documentation to be
                         uploaded.
        :param doc_dir: The pathname of the directory which contains the
                        documentation. This should be the directory that
                        contains the ``index.html`` for the documentation.
        :return: The HTTP response received from PyPI upon submission of the
                request.
        s   not a directory: %rs
   index.htmls   not found: %rs*   result of check: missing: %s, warnings: %ss   :actiont
   doc_uploadRY   t   versionR   (   s   :actionR   (   R>   R   R'   t   isdirR   Rc   R   RF   RG   RH   RI   RY   R   R	   t   getvalueRK   RM   (   R$   RN   t   doc_dirt   fnRO   RP   RY   R   t   zip_datat   fieldsR   RQ   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   upload_documentation%  s     
	
c         C   sl   |  i  d d d g } |  i o | i d |  i g  n | i d | | g  t i d d i |   | S(   s  
        Return a suitable command for verifying a file.

        :param signature_filename: The pathname to the file containing the
                                   signature.
        :param data_filename: The pathname to the file containing the
                              signed data.
        :return: The verifying command as a list suitable to be
                 passed to :class:`subprocess.Popen`.
        s   --status-fdR]   s   --no-ttys	   --homedirs   --verifys   invoking: %sR_   (   R   R   R`   RH   RI   Rc   (   R$   t   signature_filenamet   data_filenameRh   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   get_verify_commandC  s    
c         C   so   |  i  p t d   n |  i | |  } |  i |  \ } } } | d j o t d |   n | d j S(   s\  
        Verify a signature for a file.

        :param signature_filename: The pathname to the file containing the
                                   signature.
        :param data_filename: The pathname to the file containing the
                              signed data.
        :return: True if the signature was verified, else False.
        s0   verification unavailable because gpg unavailablei    i   s(   verify command failed with error code %s(   i    i   (   R   R   R   Rz   (   R$   R   R   Rh   R.   R   R   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   verify_signatureU  s    

c         C   s  | d	 j o
 d	 } n? t | t t f  o | \ } } n d } t t |    } t | d  i i   } z| ~ } |  i	 t
 |   }	 z |	 i   }
 d } d } d } d } d |
 j o t |
 d  } n | o | | | |  n x t oy |	 i |  } | p Pn | t |  7} | i |  | o | i |  n | d 7} | o | | | |  q q WWd	 |	 i   XWd	 QX| d j o' | | j  o t d
 | | f   n | o: | i   } | | j o t d | | | f   qn d	 S(   s  
        This is a convenience method for downloading a file from an URL.
        Normally, this will be a file from the index, though currently
        no check is made for this (i.e. a file can be downloaded from
        anywhere).

        The method is just like the :func:`urlretrieve` function in the
        standard library, except that it allows digest computation to be
        done during download and checking that the downloaded data
        matched any expected value.

        :param url: The URL of the file to be downloaded (assumed to be
                    available via an HTTP GET request).
        :param destfile: The pathname where the downloaded file is to be
                         saved.
        :param digest: If specified, this must be a (hasher, value)
                       tuple, where hasher is the algorithm used (e.g.
                       ``'md5'``) and ``value`` is the expected value.
        :param reporthook: The same as for :func:`urlretrieve` in the
                           standard library.
        R   t   wbi    ii    s   content-lengths   Content-Lengthi   Ns1   retrieval incomplete: got only %d out of %d bytess/   MD5 digest mismatch for %s: expected %s, got %s(   R   t
   isinstancet   listt   tuplet   getattrR   R   R   R    RM   R   t   infot   intRG   R   t   lenRr   R   RX   R   R   (   R$   R   t   destfileR   t
   reporthookt   digestert   hasherR+   t   dfpt   sfpt   headerst	   blocksizet   sizeR   t   blocknumt   blockt   actual(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   download_filei  sR    
& 
c         C   s[   g  } |  i  o | i |  i   n |  i o | i |  i  n t |   } | i |  S(   s   
        Send a standard library :class:`Request` to PyPI and return its
        response.

        :param req: The request to send.
        :return: The HTTP response from PyPI (a standard library HTTPResponse).
        (   R   RW   R   R   R   (   R$   t   reqt   handlerst   opener(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyRM     s    

c         C   s>  g  } |  i  } x{ | D]s \ } } t | t t f  p | g } n xA | D]9 } | i d | d | i d  d | i d  f  qL Wq WxG | D]? \ } }	 }
 | i d | d | |	 f i d  d |
 f  q W| i d | d d f  d i |  } d | } h | d 6t t |   d	 6} t	 |  i
 | |  S(
   s&  
        Encode fields and files for posting to an HTTP server.

        :param fields: The fields to send as a list of (fieldname, value)
                       tuples.
        :param files: The files to send as a list of (fieldname, filename,
                      file_bytes) tuple.
        s   --s)   Content-Disposition: form-data; name="%s"s   utf-8t    s8   Content-Disposition: form-data; name="%s"; filename="%s"s   
s   multipart/form-data; boundary=s   Content-types   Content-length(   t   boundaryR   R   R   R`   R{   Rc   t   strR   R   R   (   R$   R   R   t   partsR   t   kt   valuest   vt   keyRe   t   valuet   bodyt   ctR   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyRK     s:    	   
c      
   C   s   g  } y t  i |  i  d } Wn t  i j
 o d } n X| o | i d d  \ } } t |  } d   t i i	 d   t
 d | d  D  D } x@ | D]4 } | i d i | | f   | | j o Pq q Wn | S(   s   
        Return the list of hostnames which are mirrors for this index.
        :return: A (possibly empty) list of hostnames of mirrors.
        i    t   .i   c         s   s"   x |  ] } d  i  |  Vq Wd S(   R   N(   Rc   (   t   .0R   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pys	   <genexpr>  s   	 c         s   s(   x! |  ] } t  i t d  | Vq Wd S(   t   repeatN(   t	   itertoolst   productR    (   R   t   i(    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pys	   <genexpr>  s   	N(   t   sockett   gethostbyname_exR   t   gaierrorR   t   splitR   R   t   chaint   from_iterablet   rangeRW   Rc   (   R$   t   resultt   hostt   lastt   restt   nt	   host_listR-   (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   mirrors  s"     N(   t   __name__t
   __module__t   __doc__R   R   R/   R5   R   R@   R>   RS   R\   Rk   Rz   R}   R   R   R   R   R   RM   RK   R   R   (    (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyR      s*   $	
						#	5			J		+(   R   R   t   loggingR   R   R   t   stringR    R!   Ra   t	   threadingR   t   distlibR   t   distlib.compatR   R   R   R   R   t   distlib.utilR   R	   t	   getLoggerR   RH   R   R   t   DEFAULT_REALMt   objectR   (    (    (    sT   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/vendor/distlib/index.pyt   <module>   s"   (