U ��.e*� @s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZe�e�ZdaGdd�de�ZGdd �d e�ZGd d �d e�ZGd d �d e�ZGdd�de�ZGdd�de�Zed�ee jeiZzFz ddl Z!Wne"k �r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk �rXYnXdd�Z'iZ(dd�Z)e �*e+d��Z,dd�Z-dS)�)�unicode_literalsN�)�DistlibException)�cached_property�get_cache_base�path_to_cache_dir�Cachecs.eZdZd�fdd� Zdd�Zdd�Z�ZS) � ResourceCacheNcs0|dkrtj�t�td��}tt|��|�dS)Nzresource-cache)�os�path�joinr�str�superr �__init__)�self�base�� __class__��A/usr/lib/python3.8/site-packages/pip/_vendor/distlib/resources.pyrszResourceCache.__init__cCsdS)z� 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. Tr�r�resourcer rrr�is_stale#s zResourceCache.is_stalec Cs�|j�|�\}}|dkr|}n~tj�|j|�|�|�}tj�|�}tj�|�sXt� |�tj� |�sjd}n |� ||�}|r�t |d��}|� |j�W5QRX|S)z� Get a resource into the cache, :param resource: A :class:`Resource` instance. :return: The pathname of the resource in the cache. NT�wb)�finder�get_cache_infor r r rZ prefix_to_dir�dirname�isdir�makedirs�existsr�open�write�bytes)rr�prefixr �resultrZstale�frrr�get.s      zResourceCache.get)N)�__name__� __module__� __qualname__rrr&� __classcell__rrrrr s r c@seZdZdd�ZdS)� ResourceBasecCs||_||_dS�N)r�name)rrr-rrrrIszResourceBase.__init__N)r'r(r)rrrrrr+Hsr+c@s@eZdZdZdZdd�Zedd��Zedd��Zed d ��Z d S) �Resourcez� 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. FcCs |j�|�S)z� Get the resource as a stream. This is not a property to make it obvious that it returns a new stream each time. )r� get_stream�rrrr� as_streamVszResource.as_streamcCstdkrt�at�|�Sr,)�cacher r&r0rrr� file_path_szResource.file_pathcCs |j�|�Sr,)r� get_bytesr0rrrr"fszResource.bytescCs |j�|�Sr,)r�get_sizer0rrr�sizejsz Resource.sizeN) r'r(r)�__doc__� is_containerr1rr3r"r6rrrrr.Ns   r.c@seZdZdZedd��ZdS)�ResourceContainerTcCs |j�|�Sr,)r� get_resourcesr0rrr� resourcesrszResourceContainer.resourcesN)r'r(r)r8rr;rrrrr9osr9c@s�eZdZdZej�d�rdZndZdd�Zdd�Z d d �Z d d �Z d d�Z dd�Z dd�Zdd�Zdd�Zdd�Zdd�Zeejj�Zdd�ZdS)�ResourceFinderz4 Resource finder for file system resources. �java)�.pyc�.pyoz.class)r>r?cCs.||_t|dd�|_tj�t|dd��|_dS)N� __loader__�__file__�)�module�getattr�loaderr r rr)rrCrrrr�szResourceFinder.__init__cCs tj�|�Sr,)r r �realpath�rr rrr� _adjust_path�szResourceFinder._adjust_pathcCsBt|t�rd}nd}|�|�}|�d|j�tjj|�}|�|�S)N�/�/r) � isinstancer"�split�insertrr r r rH)r� resource_name�sep�partsr$rrr� _make_path�s   zResourceFinder._make_pathcCs tj�|�Sr,)r r rrGrrr�_find�szResourceFinder._findcCs d|jfSr,)r �rrrrrr�szResourceFinder.get_cache_infocCsD|�|�}|�|�sd}n&|�|�r0t||�}n t||�}||_|Sr,)rQrR� _is_directoryr9r.r )rrNr r$rrr�find�s     zResourceFinder.findcCs t|jd�S�N�rb)r r rSrrrr/�szResourceFinder.get_streamc Cs,t|jd��}|��W5QR�SQRXdSrV)r r �read)rrr%rrrr4�szResourceFinder.get_bytescCstj�|j�Sr,)r r �getsizerSrrrr5�szResourceFinder.get_sizecs*�fdd��t�fdd�t�|j�D��S)Ncs|dko|��j� S)N� __pycache__)�endswith�skipped_extensions)r%r0rr�allowed�s �z-ResourceFinder.get_resources..allowedcsg|]}�|�r|�qSrr)�.0r%)r]rr� �sz0ResourceFinder.get_resources..)�setr �listdirr rSr)r]rrr:�s zResourceFinder.get_resourcescCs |�|j�Sr,)rTr rSrrrr8�szResourceFinder.is_containerccs�|�|�}|dk r�|g}|r�|�d�}|V|jr|j}|jD]>}|sL|}nd�||g�}|�|�}|jrv|�|�q>|Vq>qdS)NrrJ)rU�popr8r-r;r �append)rrNrZtodoZrnamer-�new_nameZchildrrr�iterator�s      zResourceFinder.iteratorN)r'r(r)r7�sys�platform� startswithr\rrHrQrRrrUr/r4r5r:r8� staticmethodr r rrTrerrrrr<ws"    r<cs`eZdZdZ�fdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dd�Z �Z S)�ZipResourceFinderz6 Resource finder for resources in .zip files. csZtt|��|�|jj}dt|�|_t|jd�r>|jj|_n t j ||_t |j�|_ dS)Nr�_files) rrjrrE�archive�len� prefix_len�hasattrrk� zipimport�_zip_directory_cache�sorted�index)rrCrlrrrr�s   zZipResourceFinder.__init__cCs|Sr,rrGrrrrH�szZipResourceFinder._adjust_pathcCs�||jd�}||jkrd}nX|r:|dtjkr:|tj}t�|j|�}z|j|�|�}Wntk rtd}YnX|s�t� d||j j �nt� d||j j �|S)NT�����Fz_find failed: %r %rz_find worked: %r %r) rnrkr rO�bisectrsrh� IndexError�logger�debugrEr#)rr r$�irrrrR�s   zZipResourceFinder._findcCs&|jj}|jdt|�d�}||fS)Nr)rErlr rm)rrr#r rrrr�sz ZipResourceFinder.get_cache_infocCs|j�|j�Sr,)rE�get_datar rSrrrr4�szZipResourceFinder.get_bytescCst�|�|��Sr,)�io�BytesIOr4rSrrrr/�szZipResourceFinder.get_streamcCs|j|jd�}|j|dS)N�)r rnrkrrrrr5szZipResourceFinder.get_sizecCs�|j|jd�}|r,|dtjkr,|tj7}t|�}t�}t�|j|�}|t|j�kr�|j|�|�shq�|j||d�}|� |� tjd�d�|d7}qH|S)Nrtrr) r rnr rOrmr`rursrh�addrL)rrr Zplenr$ry�srrrr:s  zZipResourceFinder.get_resourcescCsj||jd�}|r*|dtjkr*|tj7}t�|j|�}z|j|�|�}Wntk rdd}YnX|S)NrtF)rnr rOrursrhrv)rr ryr$rrrrTs  zZipResourceFinder._is_directory)r'r(r)r7rrHrRrr4r/r5r:rTr*rrrrrj�s rjcCs|tt|�<dSr,)�_finder_registry�type)rE� finder_makerrrr�register_finder0sr�cCs�|tkrt|}nv|tjkr$t|�tj|}t|dd�}|dkrJtd��t|dd�}t�t|��}|dkrxtd|��||�}|t|<|S)z� Return a resource finder for a package. :param package: The name of the package. :return: A :class:`ResourceFinder` instance for the package. �__path__Nz8You cannot get a finder for a module, only for a packager@zUnable to locate finder for %r) � _finder_cacherf�modules� __import__rDrr�r&r�)�packager$rCr rEr�rrrr6s      rZ __dummy__cCsRd}t�|�tj�|�}t�t|��}|rNt}tj � |d�|_ ||_ ||�}|S)z� Return a resource finder for a path, which should represent a container. :param path: The path. :return: A :class:`ResourceFinder` instance for the path. NrB) �pkgutilZ get_importerrf�path_importer_cacher&r�r�� _dummy_moduler r r rAr@)r r$rErrCrrr�finder_for_pathRs  r�).Z __future__rrur{Zloggingr r�Zshutilrf�typesrprBr�utilrrrrZ getLoggerr'rwr2r �objectr+r.r9r<rjr�� zipimporterr��_frozen_importlib_externalZ_fi� ImportError�_frozen_importlib�SourceFileLoader� FileFinder�AttributeErrorr�r�r� ModuleTyper r�r�rrrr�sN   ,!ZN�