ó
^\kdc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l m Z Wn! e k
 r d  d l	 m Z n Xd  d l
 m Z d  d l m Z m Z m Z m Z m Z d  d l m Z m Z e j e ƒ Z d Z d Z d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿN(   t   Thread(   t   DistlibException(   t   HTTPBasicAuthHandlert   Requestt   HTTPPasswordMgrt   urlparset   build_opener(   t   cached_propertyt   zip_dirs   https://pypi.python.org/pypit   pypit   PackageIndexc           B   sÅ   e  Z d  Z d Z 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 RS(   sc   
    This class represents a package index compatible with PyPI, the Python
    Package Index.
    s.   ----------ThIs_Is_tHe_distlib_index_bouNdaRY_$c         C   s  | p	 t  |  _ |  j ƒ  t |  j ƒ \ } } } } } } | sX | sX | sX | d k rn t d |  j ƒ ‚ n  d |  _ d |  _ d |  _ d |  _	 t
 t j d ƒ �j } x` d D]X }	 y> t j |	 d g d | d	 | ƒ}
 |
 d
 k rñ |	 |  _ Pn  Wq® t k
 r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.
        t   httpt   httpss   invalid repository: %st   wt   gpg2t   gpgs	   --versiont   stdoutt   stderri    N(   s   https   https(   R   s   gpg(   t   DEFAULT_INDEXt   urlt   read_configurationR   R   t   Nonet   password_handlert   ssl_verifierR   t   gpg_homet   opent   ost   devnullt
   subprocesst
   check_callt   OSError(   t   selfR   t   schemet   netloct   patht   paramst   queryt   fragt   sinkt   st   rc(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   __init__$   s&    
!						c         C   s3   d d l  m } d d l m } | ƒ  } | | ƒ S(   ss   
        Get the distutils command for interacting with PyPI configurations.
        :return: the command.
        iÿÿÿÿ(   t   Distribution(   t   PyPIRCCommand(   t   distutils.coreR*   t   distutils.configR+   (   R   R*   R+   t   d(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   _get_pypirc_command?   s    	c         C   sy   |  j  ƒ  } |  j | _ | j ƒ  } | j d ƒ |  _ | j d ƒ |  _ | j d d ƒ |  _ | j d |  j ƒ |  _ 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(   R/   R   R3   t   _read_pypirct   getR0   R1   R2   (   R   t   ct   cfg(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyR   I   s    c         C   s0   |  j  ƒ  |  j ƒ  } | j |  j |  j ƒ 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_credentialsR/   t   _store_pypircR0   R1   (   R   R6   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   save_configurationX   s    
c         C   s‰   |  j  d k s |  j d k r- t d ƒ ‚ n  t ƒ  } t |  j ƒ \ } } } } } } | j |  j | |  j  |  j ƒ 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(   R0   R   R1   R   R   R   R   t   add_passwordR2   R   R   (   R   t   pmt   _R!   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyR8   d   s    	!c         C   s€   |  j  ƒ  | j ƒ  | j ƒ  } d | d <|  j | j ƒ  g  ƒ } |  j | ƒ } d | d <|  j | j ƒ  g  ƒ } |  j | ƒ 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.
        t   verifys   :actiont   submit(   R8   t   validatet   todictt   encode_requestt   itemst   send_request(   R   t   metadataR.   t   requestt   response(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   registerp   s    




c         C   sj   xY t  r[ | j ƒ  } | s Pn  | j d ƒ j ƒ  } | j | ƒ t j d | | f ƒ q W| j ƒ  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(   t   Truet   readlinet   decodet   rstript   appendt   loggert   debugt   close(   R   t   namet   streamt   outbufR'   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   _reader„   s    		c         C   sÒ   |  j  d d d g } |  j r7 | j d |  j g ƒ n  | d k	 r\ | j d d d g ƒ n  t j ƒ  } t j j | t j j	 | ƒ d ƒ } | j d	 d
 d | d | | g ƒ t
 j d d j | ƒ ƒ | | 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   basenameRN   RO   (   R   t   filenamet   signert   sign_passwordt   cmdt   tdt   sf(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   get_sign_command–   s    	%c   	      C   s
  i t  j d 6t  j d 6} | d k	 r6 t  j | d <n  g  } g  } t  j | | � } t d |  j d d | j | f ƒ } | j ƒ  t d |  j d d | j | f ƒ } | j ƒ  | d k	 rÜ | j	 j
 | ƒ | j	 j ƒ  n  | j ƒ  | j ƒ  | j ƒ  | j | | 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    RT   R   t   startR   Rd   t   writeRP   t   waitR[   t
   returncode(	   R   R`   t
   input_datat   kwargsR   R   t   pt   t1t   t2(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   run_command­   s&    
$
$



c   	      C   sb   |  j  | | | ƒ \ } } |  j | | j d ƒ ƒ \ } } } | d k r^ 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(   Rc   Rr   t   encodeR   (	   R   R]   R^   R_   R`   t   sig_fileR(   R   R   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt	   sign_fileÐ   s    	t   sdistt   sourcec         C   s²  |  j  ƒ  t j j | ƒ s/ t d | ƒ ‚ n  | j ƒ  | j ƒ  } d } | r‚ |  j sj t	 j
 d ƒ q‚ |  j | | | ƒ } n  t | d ƒ � }	 |	 j ƒ  }
 Wd QXt j |
 ƒ j ƒ  } t j |
 ƒ j ƒ  } | j i d d 6d d 6| d	 6| d
 6| d 6| d 6ƒ d t j j | ƒ |
 f g } | r�t | d ƒ � }	 |	 j ƒ  } Wd QX| j d t j j | ƒ | f ƒ t j t j j | ƒ ƒ n  |  j | j ƒ  | ƒ } |  j | ƒ 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)   no signing program available - not signedt   rbNt   file_uploads   :actiont   1t   protcol_versiont   filetypet	   pyversiont
   md5_digestt   sha256_digestt   contentt   gpg_signature(   R8   R   R"   t   existsR   R@   RA   R   R   RN   t   warningRu   R   t   readt   hashlibt   md5t	   hexdigestt   sha256t   updateR\   RM   t   shutilt   rmtreet   dirnameRB   RC   RD   (   R   RE   R]   R^   R_   R|   R}   R.   Rt   t   ft	   file_dataR~   R   t   filest   sig_dataRF   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   upload_fileã   s<    

		
c   
      C   sä   |  j  ƒ  t j j | ƒ s/ t d | ƒ ‚ n  t j j | d ƒ } t j j | ƒ si t d | ƒ ‚ n  | j ƒ  | j | j	 } } t
 | ƒ j ƒ  } d	 d | f d | f g } d | | f g } |  j | | ƒ }	 |  j |	 ƒ 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   :actiont
   doc_uploadRQ   t   versionR€   (   s   :actionR’   (   R8   R   R"   t   isdirR   R[   R‚   R@   RQ   R“   R   t   getvalueRB   RD   (
   R   RE   t   doc_dirt   fnRQ   R“   t   zip_datat   fieldsR�   RF   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   upload_documentation  s    

c         C   sj   |  j  d d d g } |  j r7 | j d |  j g ƒ n  | j d | | g ƒ t j d d j | ƒ ƒ | 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-fdRU   s   --no-ttys	   --homedirs   --verifys   invoking: %sRW   (   R   R   RX   RN   RO   R[   (   R   t   signature_filenamet   data_filenameR`   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   get_verify_command4  s    	c         C   sk   |  j  s t d ƒ ‚ n  |  j | | ƒ } |  j | ƒ \ } } } | d k ra t d | ƒ ‚ n  | d k 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�   Rr   (   R   R›   Rœ   R`   R(   R   R   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   verify_signatureF  s    
	c         C   s  | d k r" d } t j d ƒ nM t | t t f ƒ rF | \ } } n d } t t | ƒ ƒ  } t j d | ƒ t | d ƒ �} |  j	 t
 | ƒ ƒ } zÜ | j ƒ  }	 d }
 d } d } d } d |	 k rÜ t |	 d	 ƒ } n  | rõ | | |
 | ƒ n  xy t rp| j |
 ƒ } | sPn  | t | ƒ 7} | j | ƒ | rJ| j | ƒ n  | d
 7} | rø | | |
 | ƒ qø qø WWd | j ƒ  XWd QX| d k r·| | k  r·t d | | f ƒ ‚ n  | r| j ƒ  } | | k rôt d | | | | f ƒ ‚ n  t j d | ƒ 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.
        s   No digest specifiedR†   s   Digest specified: %st   wbi    iÿÿÿÿi    s   content-lengths   Content-Lengthi   Ns1   retrieval incomplete: got only %d out of %d bytess.   %s digest mismatch for %s: expected %s, got %ss   Digest verified: %s(   R   RN   RO   t
   isinstancet   listt   tuplet   getattrR…   R   RD   R   t   infot   intRI   R„   t   lenRj   R‰   RP   R   R‡   (   R   R   t   destfilet   digestt
   reporthookt   digestert   hashert   dfpt   sfpt   headerst	   blocksizet   sizeR„   t   blocknumt   blockt   actual(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   download_fileZ  sV    	
c         C   sW   g  } |  j  r" | j |  j  ƒ n  |  j r> | j |  j ƒ n  t | Œ  } | j | ƒ 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   RM   R   R   R   (   R   t   reqt   handlerst   opener(    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyRD   §  s    		c         C   s<  g  } |  j  } xy | D]q \ } } t | t t f ƒ sC | g } n  xA | D]9 } | j d | d | j d ƒ d | j d ƒ f ƒ qJ Wq WxG | D]? \ } }	 }
 | j d | d | |	 f j d ƒ d |
 f ƒ q’ W| j d | d d f ƒ d j | ƒ } d | } i | d 6t t | ƒ ƒ d	 6} t	 |  j
 | | ƒ 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¢   RX   Rs   R[   t   strR¦   R   R   (   R   R™   R�   t   partsR¹   t   kt   valuest   vt   keyR]   t   valuet   bodyt   ctR®   (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyRB   ·  s4    	
N(   t   __name__t
   __module__t   __doc__R¹   R   R)   R/   R   R:   R8   RH   RT   Rc   Rr   Ru   R‘   Rš   R�   Rž   R´   RD   RB   (    (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyR
      s(   	
						#	4			M	(   R…   t   loggingR   RŠ   R   RY   t	   threadingR    t   ImportErrort   dummy_threadingt   distlibR   t   distlib.compatR   R   R   R   R   t   distlib.utilR   R   t	   getLoggerRÃ   RN   R   t   DEFAULT_REALMt   objectR
   (    (    (    s@   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/index.pyt   <module>   s    (