ó
Ð²Ebc           @  sM  d  d l  m 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
 m Z d  d l m Z d  d l m Z m Z m Z d  d l m Z d  d l m Z m Z m Z m Z m Z m Z e j d k r	d  d	 l m Z d
 „  Z n	 d „  Z e j  d e j! ƒ Z" d d „ Z$ d e f d „  ƒ  YZ% d S(   iÿÿÿÿ(   t   print_functionN(   t   OrderedDict(   t   log(   t   ZIP_DEFLATEDt   ZipInfot   ZipFile(   t
   WheelError(   t   urlsafe_b64decodet
   as_unicodet   nativet   urlsafe_b64encodet   as_bytest   StringIOi   (   t   TextIOWrapperc         C  s   t  j t |  d d d d ƒƒ S(   Nt   newlinet    t   encodings   utf-8(   t   csvt   readerR   (   t   fp(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyt   read_csv   s    c         c  s?   x8 t  j |  ƒ D]' } g  | D] } | j d ƒ ^ q Vq Wd  S(   Ns   utf-8(   R   R   t   decode(   R   t   linet   column(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyR      s    st   ^(?P<namever>(?P<name>.+?)-(?P<ver>.+?))(-(?P<build>\d[^-]*))?
     -(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)\.whl$c         C  s;   t  t j j d |  p t j ƒ  ƒ ƒ }  t j |  ƒ d d !S(   Nt   SOURCE_DATE_EPOCHi    i   (   t   intt   ost   environt   gett   timet   gmtime(   t	   timestamp(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyt   get_zipinfo_datetime#   s    't	   WheelFilec           B  sb   e  Z d  Z e j Z d e d „ Z d d d „ Z	 d „  Z
 d d d „ Z d d „ Z d „  Z RS(	   s‚   A ZipFile derivative class that also reads SHA-256 hashes from
    .dist-info/RECORD and checks any read files against those.
    t   rc      
   C  s*  t  j j | ƒ } t j | ƒ |  _ | j d ƒ sC |  j d  k r[ t d j	 | ƒ ƒ ‚ n  t
 j |  | | d | d t ƒd j	 |  j j d ƒ ƒ |  _ |  j d |  _ t ƒ  |  _ i  |  _ | d k r&d |  j |  j <d |  j |  j d	 <d |  j |  j d
 <y |  j |  j ƒ } Wn) t k
 rBt d j	 |  j ƒ ƒ ‚ n X| Ø xÐ t | ƒ D]Â } | \ } } }	 | sxqWn  | j d ƒ \ }
 } y t j |
 ƒ Wn& t k
 rÆt d j	 |
 ƒ ƒ ‚ n X|
 j ƒ  d d h k r÷t d j	 |
 ƒ ƒ ‚ n  |
 t | j d ƒ ƒ f |  j | <qWWWd  QXn  d  S(   Ns   .whls   Bad wheel filename {!r}t   compressiont
   allowZip64s   {}.dist-infot   namevers   /RECORDR"   s   .jwss   .p7ss   Missing {} fileu   =s   Unsupported hash algorithm: {}t   md5t   sha1s4   Weak hash algorithm ({}) is not permitted by PEP 427t   ascii(   NN(   NN(   NN(   R   t   patht   basenamet   WHEEL_INFO_REt   matcht   parsed_filenamet   endswitht   NoneR   t   formatR   t   __init__t   Truet   groupt   dist_info_patht   record_pathR   t   _file_hashest   _file_sizest   opent   KeyErrorR   t   splitt   hashlibt   newt
   ValueErrort   lowerR   t   encode(   t   selft   filet   modeR#   R*   t   recordR   R)   t   hash_sumt   sizet	   algorithm(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyR1   1   s@    	c           s
  d  ‡  ‡ ‡ ‡ ‡ f d † } t t | t ƒ r9 | j n | ƒ ‰ | d k r‹ ˆ j d ƒ r‹ ˆ |  j k r‹ t d j t	 ˆ ƒ ƒ ƒ ‚ n  t
 j |  | | | ƒ ‰  | d k rˆ j d ƒ r|  j ˆ \ } ‰ ˆ d  k	 rt j | ƒ ‰ ˆ  j | ‰ ˆ  _ qn  ˆ  S(   Nc           sv   | d  k r" ˆ  j } ˆ |  ƒ n ˆ |  | ƒ ˆ j |  ƒ | rr ˆ j ƒ  ˆ k rr t d j t ˆ ƒ ƒ ƒ ‚ n  d  S(   Ns   Hash mismatch for file '{}'(   R/   t   _eoft   updatet   digestR   R0   R	   (   t   newdatat   eof(   t   eft   ef_namet   expected_hasht   running_hasht   update_crc_orig(    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyt   _update_crc^   s    	R"   t   /s   No hash found for file '{}'(   R/   R   t
   isinstanceR   t   filenameR.   R6   R   R0   R	   R   R8   R;   R<   RQ   (   R@   t   name_or_infoRB   t   pwdRQ   RF   (    (   RL   RM   RN   RO   RP   s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyR8   ]   s    	+c   	      C  s9  t  j d |  j | ƒ g  } xå t j | ƒ D]Ô \ } } } | j ƒ  x¸ t | ƒ D]ª } t j j t j j	 | | ƒ ƒ } t j j
 | ƒ rR t j j | | ƒ j t j j d ƒ } | |  j k rÄ qü | j d ƒ ré | j | | f ƒ qü |  j | | ƒ qR qR Wq, W| j ƒ  x$ | D] \ } } |  j | | ƒ qWd  S(   Ns#   creating '%s' and adding '%s' to itRR   s
   .dist-info(   t   loggert   infoRT   R   t   walkt   sortt   sortedR)   t   normpatht   joint   isfilet   relpatht   replacet   sepR5   R.   t   appendt   write(	   R@   t   base_dirt   deferredt   roott   dirnamest	   filenamest   nameR)   t   arcname(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyt   write_filesx   s     
!'
c         C  s¬   t  | d ƒ ( } t j | j ƒ  ƒ } | j ƒ  } Wd  QXt | pE | d t | j ƒ ƒ} t j	 | j
 ƒ t j | j
 ƒ Bd >| _ | p |  j | _ |  j | | | ƒ d  S(   Nt   rbt	   date_timei   (   R8   R   t   fstatt   filenot   readR   R    t   st_mtimet   statt   S_IMODEt   st_modet   S_IFMTt   external_attrR#   t   compress_typet   writestr(   R@   RT   Rj   Rw   t   ft   stt   datat   zinfo(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyRc   Ž   s    !)c         C  s¤   t  j |  | | | ƒ t | t ƒ r. | j n | } t j d | ƒ | |  j k r  |  j | ƒ } | j	 t
 t | j ƒ  ƒ ƒ f |  j | <t | ƒ |  j | <n  d  S(   Ns   adding '%s'(   R   Rx   RS   R   RT   RW   RX   R5   t   _default_algorithmRi   R	   R
   RI   R6   t   lenR7   (   R@   t   zinfo_or_arcnamet   bytesRw   t   fnamet   hash_(    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyRx   ˜   s    (c           sù   ˆ  j  d  k	 rè ˆ  j d k rè ˆ  j rè t ƒ  } t j | d d d d d d ƒ} | j ‡  f d †  ˆ  j j ƒ  Dƒ ƒ | j	 t
 ˆ  j ƒ d	 d	 f ƒ t t ˆ  j ƒ d
 t ƒ  ƒ} ˆ  j | _ d | _ ˆ  j | t | j ƒ  ƒ ƒ n  t j ˆ  ƒ d  S(   Nt   wt	   delimitert   ,t	   quotechart   "t   lineterminators   
c         3  s9   |  ]/ \ } \ } } | | d  | ˆ  j  | f Vq d S(   t   =N(   R7   (   t   .0R   RF   R‚   (   R@   (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pys	   <genexpr>¨   s   R   Rm   i´  i   i  ´(   R   R/   RB   R6   R   R   t   writert	   writerowst   itemst   writerowR0   R5   R   R	   R    R#   Rw   Rv   Rx   R   t   getvalueR   t   close(   R@   R{   R‹   R|   (    (   R@   s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyR   ¢   s    '	!	N(   t   __name__t
   __module__t   __doc__R;   t   sha256R}   R   R1   R/   R8   Rk   Rc   Rx   R   (    (    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyR!   *   s   	,	

(   i   (&   t
   __future__R    R   R;   t   os.pathR   t   reRr   t   sysR   t   collectionsR   t	   distutilsR   RW   t   zipfileR   R   R   t	   wheel.cliR   t
   wheel.utilR   R   R	   R
   R   R   t   version_infot   ioR   R   t   compilet   VERBOSER+   R/   R    R!   (    (    (    s.   /tmp/pip-build-UPPWic/wheel/wheel/wheelfile.pyt   <module>   s*   .	