ó
^†êWc           @  sâ  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	 Z	 d  d l
 Z
 d d l m Z d d l m Z m Z m Z m Z e j e ƒ Z d a d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ i e e d ƒ 6e e
 j 6Z  y* d  d l! Z! e e  e! j" <e e  e! j# <Wn e$ e% f k
 r§n Xd „  Z& i  Z' d „  Z( e	 j) e* d ƒ ƒ Z+ d „  Z, d S(   iÿÿÿÿ(   t   unicode_literalsNi   (   t   DistlibException(   t   cached_propertyt   get_cache_baset   path_to_cache_dirt   Cachet   ResourceCachec           B  s&   e  Z d d  „ Z d „  Z d „  Z RS(   c         C  sG   | d  k r- t j j t ƒ  t d ƒ ƒ } n  t t |  ƒ j | ƒ d  S(   Nu   resource-cache(	   t   Nonet   ost   patht   joinR   t   strt   superR   t   __init__(   t   selft   base(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR      s    !c         C  s   t  S(   uã   
        Is the cache stale for the given resource?

        :param resource: The :class:`Resource` being cached.
        :param path: The path of the resource in the cache.
        :return: True if the cache is stale.
        (   t   True(   R   t   resourceR	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   is_stale#   s    	c         C  sç   | j  j | ƒ \ } } | d k r- | } n¶ t j j |  j |  j | ƒ | ƒ } t j j | ƒ } t j j	 | ƒ s… t j
 | ƒ n  t j j | ƒ s  t } n |  j | | ƒ } | rã t | d ƒ  } | j | j ƒ Wd QXn  | S(   u¤   
        Get a resource into the cache,

        :param resource: A :class:`Resource` instance.
        :return: The pathname of the resource in the cache.
        u   wbN(   t   findert   get_cache_infoR   R   R	   R
   R   t   prefix_to_dirt   dirnamet   isdirt   makedirst   existsR   R   t   opent   writet   bytes(   R   R   t   prefixR	   t   resultR   t   stalet   f(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   get.   s    	$	N(   t   __name__t
   __module__R   R   R   R!   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR      s   	t   ResourceBasec           B  s   e  Z d  „  Z RS(   c         C  s   | |  _  | |  _ d  S(   N(   R   t   name(   R   R   R%   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   I   s    	(   R"   R#   R   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR$   H   s   t   Resourcec           B  sJ   e  Z d  Z e Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 RS(   uÇ   
    A class representing an in-package resource, such as a data file. This is
    not normally instantiated by user code, but rather by a
    :class:`ResourceFinder` which manages the resource.
    c         C  s   |  j  j |  ƒ S(   u’   
        Get the resource as a stream.

        This is not a property to make it obvious that it returns a new stream
        each time.
        (   R   t
   get_stream(   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt	   as_streamV   s    c         C  s%   t  d  k r t ƒ  a  n  t  j |  ƒ S(   N(   t   cacheR   R   R!   (   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt	   file_path_   s    c         C  s   |  j  j |  ƒ S(   N(   R   t	   get_bytes(   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   f   s    c         C  s   |  j  j |  ƒ S(   N(   R   t   get_size(   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   sizej   s    (
   R"   R#   t   __doc__t   Falset   is_containerR(   R   R*   R   R-   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR&   N   s   		t   ResourceContainerc           B  s   e  Z e Z e d  „  ƒ Z RS(   c         C  s   |  j  j |  ƒ S(   N(   R   t   get_resources(   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt	   resourcesr   s    (   R"   R#   R   R0   R   R3   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR1   o   s   t   ResourceFinderc           B  s­   e  Z d  Z e j j d ƒ r' d Z n d Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e e j j ƒ Z d „  Z RS(   u4   
    Resource finder for file system resources.
    u   javau   .pycu   .pyou   .classc         C  sC   | |  _  t | d d  ƒ |  _ t j j t | d d ƒ ƒ |  _ d  S(   Nu
   __loader__u   __file__u    (   t   modulet   getattrR   t   loaderR   R	   R   R   (   R   R5   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR      s    	c         C  s   t  j j | ƒ S(   N(   R   R	   t   realpath(   R   R	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   _adjust_path†   s    c         C  s_   t  | t ƒ r d } n d } | j | ƒ } | j d |  j ƒ t j j | Œ  } |  j | ƒ S(   Nt   /u   /i    (	   t
   isinstanceR   t   splitt   insertR   R   R	   R
   R9   (   R   t   resource_namet   sept   partsR   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt
   _make_path‰   s    	c         C  s   t  j j | ƒ S(   N(   R   R	   R   (   R   R	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   _find•   s    c         C  s   d  | j f S(   N(   R   R	   (   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   ˜   s    c         C  sd   |  j  | ƒ } |  j | ƒ s' d  } n9 |  j | ƒ rH t |  | ƒ } n t |  | ƒ } | | _ | S(   N(   RA   RB   R   t   _is_directoryR1   R&   R	   (   R   R>   R	   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   find›   s    		c         C  s   t  | j d ƒ S(   Nu   rb(   R   R	   (   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR'   §   s    c         C  s)   t  | j d ƒ  } | j ƒ  SWd  QXd  S(   Nu   rb(   R   R	   t   read(   R   R   R    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR+   ª   s    c         C  s   t  j j | j ƒ S(   N(   R   R	   t   getsize(   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR,   ®   s    c           sD   ‡  f d †  } t  g  t j | j ƒ D] } | | ƒ r% | ^ q% ƒ S(   Nc           s   |  d k o |  j  ˆ  j ƒ S(   Nu   __pycache__(   t   endswitht   skipped_extensions(   R    (   R   (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   allowed²   s    (   t   setR   t   listdirR	   (   R   R   RI   R    (    (   R   sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR2   ±   s    c         C  s   |  j  | j ƒ S(   N(   RC   R	   (   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR0   ·   s    c         c  sÆ   |  j  | ƒ } | d  k	 rÂ | g } x› | r¾ | j d ƒ } | V| j r' | j } xe | j D]W } | sr | } n d j | | g ƒ } |  j  | ƒ } | j r¯ | j | ƒ q] | Vq] Wq' q' Wn  d  S(   Ni    u   /(   RD   R   t   popR0   R%   R3   R
   t   append(   R   R>   R   t   todot   rnameR%   t   new_namet   child(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   iterator¼   s     						(   u   .pycu   .pyou   .class(   u   .pycu   .pyo(   R"   R#   R.   t   syst   platformt
   startswithRH   R   R9   RA   RB   R   RD   R'   R+   R,   R2   R0   t   staticmethodR   R	   R   RC   RR   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR4   w   s"   												t   ZipResourceFinderc           B  s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   u6   
    Resource finder for resources in .zip files.
    c         C  s   t  t |  ƒ j | ƒ |  j j } d t | ƒ |  _ t |  j d ƒ rY |  j j |  _ n t	 j
 | |  _ t |  j ƒ |  _ d  S(   Ni   u   _files(   R   RW   R   R7   t   archivet   lent
   prefix_lent   hasattrt   _filest	   zipimportt   _zip_directory_cachet   sortedt   index(   R   R5   RX   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   Õ   s    c         C  s   | S(   N(    (   R   R	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR9   à   s    c         C  sÖ   | |  j  } | |  j k r% t } nr | rN | d t j k rN | t j } n  t j |  j | ƒ } y |  j | j | ƒ } Wn t k
 r– t	 } n X| s¹ t
 j d | |  j j ƒ n t
 j d | |  j j ƒ | S(   Niÿÿÿÿu   _find failed: %r %ru   _find worked: %r %r(   RZ   R\   R   R   R?   t   bisectR`   RU   t
   IndexErrorR/   t   loggert   debugR7   R   (   R   R	   R   t   i(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyRB   ã   s    	
c         C  s-   |  j  j } | j d t | ƒ } | | f S(   Ni   (   R7   RX   R	   RY   (   R   R   R   R	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   õ   s    c         C  s   |  j  j | j ƒ S(   N(   R7   t   get_dataR	   (   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR+   ú   s    c         C  s   t  j |  j | ƒ ƒ S(   N(   t   iot   BytesIOR+   (   R   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR'   ý   s    c         C  s   | j  |  j } |  j | d S(   Ni   (   R	   RZ   R\   (   R   R   R	   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR,      s    c         C  sØ   | j  |  j } | r9 | d t j k r9 | t j 7} n  t | ƒ } t ƒ  } t j |  j | ƒ } xn | t |  j ƒ k  rÓ |  j | j | ƒ s• Pn  |  j | | } | j	 | j
 t j d ƒ d ƒ | d 7} qf W| S(   Niÿÿÿÿi   i    (   R	   RZ   R   R?   RY   RJ   Ra   R`   RU   t   addR<   (   R   R   R	   t   plenR   Re   t   s(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR2     s    	 c         C  sƒ   | |  j  } | r6 | d t j k r6 | t j 7} n  t j |  j | ƒ } y |  j | j | ƒ } Wn t k
 r~ t } n X| S(   Niÿÿÿÿ(   RZ   R   R?   Ra   R`   RU   Rb   R/   (   R   R	   Re   R   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyRC     s    
(   R"   R#   R.   R   R9   RB   R   R+   R'   R,   R2   RC   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyRW   Ñ   s   								c         C  s   | t  t |  ƒ <d  S(   N(   t   _finder_registryt   type(   R7   t   finder_maker(    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   register_finder+  s    c         C  sÏ   |  t  k r t  |  } n² |  t j k r5 t |  ƒ n  t j |  } t | d d ƒ } | d k ro t d ƒ ‚ n  t | d d ƒ } t j t	 | ƒ ƒ } | d k rµ t d |  ƒ ‚ n  | | ƒ } | t  |  <| S(   uŸ   
    Return a resource finder for a package.
    :param package: The name of the package.
    :return: A :class:`ResourceFinder` instance for the package.
    u   __path__u8   You cannot get a finder for a module, only for a packageu
   __loader__u   Unable to locate finder for %rN(
   t   _finder_cacheRS   t   modulest
   __import__R6   R   R   Rl   R!   Rm   (   t   packageR   R5   R	   R7   Rn   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyR   1  s    
u	   __dummy__c         C  sz   d } t j |  ƒ t j j |  ƒ } t j t | ƒ ƒ } | rv t } t	 j
 j |  d ƒ | _ | | _ | | ƒ } n  | S(   u¬   
    Return a resource finder for a path, which should represent a container.

    :param path: The path.
    :return: A :class:`ResourceFinder` instance for the path.
    u    N(   R   t   pkgutilt   get_importerRS   t   path_importer_cacheR!   Rl   Rm   t   _dummy_moduleR   R	   R
   t   __file__t
   __loader__(   R	   R   R7   R   R5   (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   finder_for_pathM  s    	(-   t
   __future__R    Ra   Rg   t   loggingR   Rt   t   shutilRS   t   typesR]   t    R   t   utilR   R   R   R   t	   getLoggerR"   Rc   R   R)   R   t   objectR$   R&   R1   R4   RW   Rm   t   zipimporterRl   t   _frozen_importlibt   SourceFileLoadert
   FileFindert   ImportErrort   AttributeErrorRo   Rp   R   t
   ModuleTypeR   Rw   Rz   (    (    (    sn   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/resources.pyt   <module>   sB   ",!ZM		