ó
^\kdc           @  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 e j e ƒ Z d e f d „  ƒ  YZ e ƒ  Z 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   Cachec           B  s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   ut   
    A class implementing a cache for resources that need to live in the file system
    e.g. shared libraries.
    c         C  st   | d k rO t j j t ƒ  t d ƒ ƒ } t j j | ƒ sO t j | ƒ qO n  t j j t j j	 | ƒ ƒ |  _
 d S(   u  
        Initialise an instance.

        :param base: The base directory where the cache should be located. If
                     not specified, this will be the ``resource-cache``
                     directory under whatever :func:`get_cache_base` returns.
        u   resource-cacheN(   t   Nonet   ost   patht   joinR   t   strt   isdirt   makedirst   abspatht   normpatht   base(   t   selfR   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   __init__   s
    c         C  s
   t  | ƒ S(   uN   
        Converts a resource prefix to a directory name in the cache.
        (   R   (   R   t   prefix(    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   prefix_to_dir0   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   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   is_stale6   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   R   t   dirnameR   R   t   existsR   R   t   opent   writet   bytes(   R   R   R   R   t   resultR   t   stalet   f(    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   getA   s    	$	c         C  sº   g  } x­ t  j |  j ƒ D]™ } t  j j |  j | ƒ } yZ t  j j | ƒ s^ t  j j | ƒ rn t  j | ƒ n" t  j j | ƒ r� t	 j
 | ƒ n  Wq t k
 r± | j | ƒ q Xq W| S(   u"   
        Clear the cache.
        (   R   t   listdirR   R   R	   t   islinkt   isfilet   removeR   t   shutilt   rmtreet	   Exceptiont   append(   R   t   not_removedt   fn(    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   clearZ   s    $N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R!   R,   (    (    (    sD   /var/www/testScraper/venv/build/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   R1   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   n   s    	(   R-   R.   R   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR0   m   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   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt	   as_stream{   s    c         C  s   t  j |  ƒ S(   N(   t   cacheR!   (   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt	   file_path„   s    c         C  s   |  j  j |  ƒ S(   N(   R   t	   get_bytes(   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   ˆ   s    c         C  s   |  j  j |  ƒ S(   N(   R   t   get_size(   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   sizeŒ   s    (
   R-   R.   R/   t   Falset   is_containerR4   R   R6   R   R9   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR2   s   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   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt	   resources”   s    (   R-   R.   R   R;   R   R>   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR<   ‘   s   t   ResourceFinderc           B  sƒ   e  Z 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 RS(   u4   
    Resource finder for file system resources.
    c         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   R@   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   �   s    	c         C  s   t  j j | ƒ S(   N(   R   R   t   realpath(   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   _adjust_path¢   s    c         C  sA   | j  d ƒ } | j d |  j ƒ t j j | Œ  } |  j | ƒ S(   Nu   /i    (   t   splitt   insertR   R   R   R	   RD   (   R   t   resource_namet   partsR   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt
   _make_path¥   s    c         C  s   t  j j | ƒ S(   N(   R   R   R   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   _find«   s    c         C  s   d  | j f S(   N(   R   R   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   ®   s    c         C  sd   |  j  | ƒ } |  j | ƒ s' d  } n9 |  j | ƒ rH t |  | ƒ } n t |  | ƒ } | | _ | S(   N(   RI   RJ   R   t   _is_directoryR<   R2   R   (   R   RG   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   find±   s    		c         C  s   t  | j d ƒ S(   Nu   rb(   R   R   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR3   ½   s    c         C  s)   t  | j d ƒ � } | j ƒ  SWd  QXd  S(   Nu   rb(   R   R   t   read(   R   R   R    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR7   À   s    c         C  s   t  j j | j ƒ S(   N(   R   R   t   getsize(   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR8   Ä   s    c         C  s>   d „  } t  g  t j | j ƒ D] } | | ƒ r | ^ q ƒ S(   Nc         S  s   |  d k o |  j  d ƒ S(   Nu   __pycache__u   .pycu   .pyo(   u   .pycu   .pyo(   t   endswith(   R    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   allowedÈ   s    (   t   setR   R"   R   (   R   R   RP   R    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR=   Ç   s    	c         C  s   |  j  | j ƒ S(   N(   RK   R   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR;   Ì   s    (   R-   R.   R/   R   RD   RI   RJ   R   RL   R3   R7   R8   R=   R;   t   staticmethodR   R   R   RK   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR?   ™   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(   t   superRS   R   RB   t   archivet   lent
   prefix_lent   hasattrt   _filest	   zipimportt   _zip_directory_cachet   sortedt   index(   R   R@   RU   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   Ö   s    c         C  s   | S(   N(    (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyRD   á   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(   RW   RY   R   R   t   sept   bisectR]   t
   startswitht
   IndexErrorR:   t   loggert   debugRB   R   (   R   R   R   t   i(    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyRJ   ä   s    	
c         C  s-   |  j  j } | j d t | ƒ } | | f S(   Ni   (   RB   RU   R   RV   (   R   R   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   ö   s    c         C  s   |  j  j | j ƒ S(   N(   RB   t   get_dataR   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR7   û   s    c         C  s   t  j |  j | ƒ ƒ S(   N(   t   iot   BytesIOR7   (   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR3   þ   s    c         C  s   | j  |  j } |  j | d S(   Ni   (   R   RW   RY   (   R   R   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR8     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   RW   R   R^   RV   RQ   R_   R]   R`   t   addRE   (   R   R   R   t   plenR   Rd   t   s(    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR=     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ÿÿÿÿ(   RW   R   R^   R_   R]   R`   Ra   R:   (   R   R   Rd   R   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyRK     s    
(   R-   R.   R/   R   RD   RJ   R   R7   R3   R8   R=   RK   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyRS   Ò   s   								c         C  s   | t  t |  ƒ <d  S(   N(   t   _finder_registryt   type(   RB   t   finder_maker(    (    sD   /var/www/testScraper/venv/build/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_cachet   syst   modulest
   __import__RA   R   R   Rk   R!   Rl   (   t   packageR   R@   R   RB   Rm   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyR   2  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_importerRp   t   path_importer_cacheR!   Rk   Rl   t   _dummy_moduleR   R   R	   t   __file__t
   __loader__(   R   R   RB   R   R@   (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   finder_for_pathN  s    	(,   t
   __future__R    R_   Rf   t   loggingR   Rt   R&   Rp   t   typesRZ   t    R   t   utilR   R   R   t	   getLoggerR-   Rb   t   objectR   R5   R0   R2   R<   R?   RS   Rl   R   t   zipimporterRk   t   _frozen_importlibt   SourceFileLoadert
   FileFindert   ImportErrort   AttributeErrorRn   Ro   R   t
   ModuleTypeR
   Rw   Rz   (    (    (    sD   /var/www/testScraper/venv/build/pip/pip/_vendor/distlib/resources.pyt   <module>   sB   Q	9M		