ó
Ð²Ebc           @@  s#  d  d l  m Z d  d l Z d  d l m Z m Z m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z e rÞ d  d l m Z m Z m Z m Z m Z d  d l m Z e rË d  d	 l m Z qÞ d  d
 l m Z n  d Z d d d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   absolute_importN(   t	   iteritemst   iterkeyst
   itervalues(   t   HashMismatcht   HashMissingt   InstallationError(   t   read_chunks(   t   MYPY_CHECK_RUNNING(   t   BinaryIOt   Dictt   Iteratort   Listt   NoReturn(   t   PY3(   t   _Hash(   t   _hasht   sha256t   sha384t   sha512t   Hashesc           B@  sƒ   e  Z d  Z d d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   sa   A wrapper that builds multiple hashes at once and checks them against
    known-good values

    c         C@  sO   i  } | d k	 rB x- | j ƒ  D] \ } } t | ƒ | | <q Wn  | |  _ d S(   so   
        :param hashes: A dict of algorithm names pointing to lists of allowed
            hex digests
        N(   t   Nonet   itemst   sortedt   _allowed(   t   selft   hashest   allowedt   algt   keys(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __init__$   s
    c         C@  sœ   t  | t ƒ s t S| s |  S|  s' | Si  } xb t | j ƒ D]Q \ } } | |  j k r^ q= n  g  | D] } | |  j | k re | ^ qe | | <q= Wt | ƒ S(   N(   t
   isinstanceR   t   NotImplementedR   R   (   R   t   othert   newR   t   valuest   v(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __and__1   s    4c         C@  s   t  d „  |  j j ƒ  Dƒ ƒ S(   Nc         s@  s   |  ] } t  | ƒ Vq d  S(   N(   t   len(   t   .0t   digests(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pys	   <genexpr>H   s    (   t   sumR   R#   (   R   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   digest_countE   s    c         C@  s   | |  j  j | g  ƒ k S(   s/   Return whether the given hex digest is allowed.(   R   t   get(   R   t	   hash_namet
   hex_digest(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   is_hash_allowedJ   s    c         C@  sæ   i  } x] t  |  j ƒ D]L } y t j | ƒ | | <Wq t t f k
 ra t d j | ƒ ƒ ‚ q Xq Wx2 | D]* } x! t | ƒ D] } | j	 | ƒ q€ Wqm Wx7 t
 | ƒ D]) \ } } | j ƒ  |  j | k r¨ d Sq¨ W|  j | ƒ d S(   s‚   Check good hashes against ones built from iterable of chunks of
        data.

        Raise HashMismatch if none match.

        s   Unknown hash name: {}N(   R   R   t   hashlibR"   t
   ValueErrort	   TypeErrorR   t   formatR   t   updateR   t	   hexdigestt   _raise(   R   t   chunkst   gotsR,   t   chunkt   hasht   got(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   check_against_chunksS   s    c         C@  s   t  |  j | ƒ ‚ d  S(   N(   R   R   (   R   R7   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyR5   m   s    c         C@  s   |  j  t | ƒ ƒ S(   sa   Check good hashes against a file-like object

        Raise HashMismatch if none match.

        (   R;   R   (   R   t   file(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   check_against_fileq   s    c         C@  s)   t  | d ƒ  } |  j | ƒ SWd  QXd  S(   Nt   rb(   t   openR=   (   R   t   pathR<   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   check_against_pathz   s    c         C@  s   t  |  j ƒ S(   s,   Return whether I know any known-good hashes.(   t   boolR   (   R   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __nonzero__   s    c         C@  s
   |  j  ƒ  S(   N(   RC   (   R   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __bool__„   s    c         C@  s#   t  | t ƒ s t S|  j | j k S(   N(   R   R   R    R   (   R   R!   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __eq__ˆ   s    c         C@  s,   t  d j t d „  |  j j ƒ  Dƒ ƒ ƒ ƒ S(   Nt   ,c         s@  s7   |  ]- \ } } | D] } d  j  | | f ƒ Vq q d S(   t   :N(   t   join(   R'   R   t   digest_listt   digest(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pys	   <genexpr>’   s   	(   R9   RH   R   R   R   (   R   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   __hash__Ž   s    	N(   t   __name__t
   __module__t   __doc__R   R   R%   t   propertyR*   R.   R;   R5   R=   RA   RC   RD   RE   RK   (    (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyR      s   											t   MissingHashesc           B@  s    e  Z d  Z d „  Z d „  Z RS(   sÀ   A workalike for Hashes used when we're missing a hash for a requirement

    It computes the actual hash of the requirement and raises a HashMissing
    exception showing it to the user.

    c         C@  s$   t  t |  ƒ j d i g  t 6ƒ d S(   s!   Don't offer the ``hashes`` kwarg.R   N(   t   superRP   R   t   FAVORITE_HASH(   R   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyR       s    c         C@  s   t  | t j ƒ  ƒ ‚ d  S(   N(   R   RR   R4   (   R   R7   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyR5   §   s    (   RL   RM   RN   R   R5   (    (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyRP   ™   s   	(   t
   __future__R    R/   t   pip._vendor.sixR   R   R   t   pip._internal.exceptionsR   R   R   t   pip._internal.utils.miscR   t   pip._internal.utils.typingR   t   typingR	   R
   R   R   R   R   R   R   RR   t   STRONG_HASHESt   objectR   RP   (    (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_internal/utils/hashes.pyt   <module>   s   (z