
0c@_i  ã               @   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 d  d l Z e j d d „  ƒ Z d d „  Z	 d d „  Z
 d S)é    Nc              c   s*   t  j ƒ  }  z	 |  VWd t j |  ƒ Xd S)z2Create a temporary directory in a context manager.N)ÚtempfileÚmkdtempÚshutilÚrmtree)Útd© r   ú:/tmp/pip-build-jynh7p1z/pip/pip/_vendor/pep517/dirtools.pyÚtempdir
   s    	r	   c              O   sU   y t  j |  | Ž  SWn: t k
 rP } z | j t j k r> ‚  WYd d } ~ Xn Xd S)zWLike `mkdir`, but does not raise an exception if the
    directory already exists.
    N)ÚosÚmkdirÚOSErrorÚerrnoÚEEXIST)ÚargsÚkwargsÚexcr   r   r   Úmkdir_p   s
    r   c             C   sß   t  j ƒ  } t j | d ƒ } xº t j |  ƒ D]© \ }  } } xL | D]D } t j j |  | ƒ } t j j | |  ƒ } | j	 | d d ƒ qD WxH | D]@ } t j j |  | ƒ } t j j | |  ƒ } | j
 | | ƒ q“ Wq. W| S)z0Construct an in-memory zip file for a directory.Úwú/Ú )ÚioÚBytesIOÚzipfileÚZipFiler
   ÚwalkÚpathÚjoinÚrelpathÚwritestrÚwrite)ÚrootÚbufferZzip_fileÚdirsÚfilesr   Zfs_pathÚrel_pathr   r   r   Údir_to_zipfile   s    r%   )r
   r   Ú
contextlibr   r   r   r   Úcontextmanagerr	   r   r%   r   r   r   r   Ú<module>   s   
