Current File : //lib/python3.9/site-packages/pip/_vendor/distlib/__pycache__/resources.cpython-39.pyc
a

[��fD*�	@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZe�e�ZdaGdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�Zed�ee	jeiZzNzddlZWne �yddl!ZYn0eeej"<eeej#<eeej$<[Wne e%f�yRYn0dd�Z&iZ'dd�Z(e�)e*d��Z+dd�Z,dS)�)�unicode_literalsN�)�DistlibException)�cached_property�get_cache_base�Cachecs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	�
ResourceCacheNcs0|durtj�t�td��}tt|��|�dS)Nzresource-cache)�os�path�joinr�str�superr�__init__)�self�base��	__class__��A/usr/lib/python3.9/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_stalecCs�|j�|�\}}|dur|}n�tj�|j|�|�|�}tj�|�}tj�|�sXt�	|�tj�
|�sjd}n|�||�}|r�t|d��}|�
|j�Wd�n1s�0Y|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
rrZ
prefix_to_dir�dirname�isdir�makedirs�existsr�open�write�bytes)rr�prefixr
�resultrZstale�frrr�get-s
*zResourceCache.get)N)�__name__�
__module__�__qualname__rrr%�
__classcell__rrrrrsrc@seZdZdd�ZdS)�ResourceBasecCs||_||_dS�N)r�name)rrr,rrrrHszResourceBase.__init__N)r&r'r(rrrrrr*Gsr*c@s@eZdZdZdZdd�Zedd��Zedd��Zed	d
��Z	dS)�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_streamUszResource.as_streamcCstdurt�at�|�Sr+)�cacherr%r/rrr�	file_path^szResource.file_pathcCs|j�|�Sr+)r�	get_bytesr/rrrr!eszResource.bytescCs|j�|�Sr+)r�get_sizer/rrr�sizeisz
Resource.sizeN)
r&r'r(�__doc__�is_containerr0rr2r!r5rrrrr-Ms	

r-c@seZdZdZedd��ZdS)�ResourceContainerTcCs|j�|�Sr+)r�
get_resourcesr/rrr�	resourcesqszResourceContainer.resourcesN)r&r'r(r7rr:rrrrr8nsr8c@s�eZdZdZej�d�rdZndZdd�Zdd�Z	d	d
�Z
dd�Zd
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)rrBrrrr�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
rrG)r�
resource_name�sep�partsr#rrr�
_make_path�s

zResourceFinder._make_pathcCstj�|�Sr+)r	r
rrFrrr�_find�szResourceFinder._findcCs
d|jfSr+)r
�rrrrrr�szResourceFinder.get_cache_infocCsD|�|�}|�|�sd}n&|�|�r0t||�}n
t||�}||_|Sr+)rPrQ�
_is_directoryr8r-r
)rrMr
r#rrr�find�s



zResourceFinder.findcCst|jd�S�N�rb)rr
rRrrrr.�szResourceFinder.get_streamcCs8t|jd��}|��Wd�S1s*0YdSrU)rr
�read)rrr$rrrr3�szResourceFinder.get_bytescCstj�|j�Sr+)r	r
�getsizerRrrrr4�szResourceFinder.get_sizecs*�fdd��t�fdd�t�|j�D��S)Ncs|dko|��j�S)N�__pycache__)�endswith�skipped_extensions)r$r/rr�allowed�s
�z-ResourceFinder.get_resources.<locals>.allowedcsg|]}�|�r|�qSrr)�.0r$)r\rr�
<listcomp>��z0ResourceFinder.get_resources.<locals>.<listcomp>)�setr	�listdirr
rRr)r\rrr9�szResourceFinder.get_resourcescCs|�|j�Sr+)rSr
rRrrrr7�szResourceFinder.is_containerccs�|�|�}|dur�|g}|r�|�d�}|V|jr|j}|jD]>}|sL|}nd�||g�}|�|�}|jrv|�|�q>|Vq>qdS)NrrI)rT�popr7r,r:r�append)rrMrZtodoZrnamer,�new_name�childrrr�iterator�s 



zResourceFinder.iteratorN)r&r'r(r6�sys�platform�
startswithr[rrGrPrQrrTr.r3r4r9r7�staticmethodr	r
rrSrfrrrrr;vs"r;cs`eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�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)
r
rkrrD�archive�len�
prefix_len�hasattrrl�	zipimport�_zip_directory_cache�sorted�index)rrBrmrrrr�szZipResourceFinder.__init__cCs|Sr+rrFrrrrG�szZipResourceFinder._adjust_pathcCs�||jd�}||jvrd}nV|r:|dtjkr:|tj}t�|j|�}z|j|�|�}Wntyrd}Yn0|s�t�	d||j
j�nt�	d||j
j�|S)NT���Fz_find failed: %r %rz_find worked: %r %r)rorlr	rN�bisectrtri�
IndexError�logger�debugrDr")rr
r#�irrrrQ�s


zZipResourceFinder._findcCs&|jj}|jdt|�d�}||fS)Nr)rDrmr
rn)rrr"r
rrrr�sz ZipResourceFinder.get_cache_infocCs|j�|j�Sr+)rD�get_datar
rRrrrr3�szZipResourceFinder.get_bytescCst�|�|��Sr+)�io�BytesIOr3rRrrrr.�szZipResourceFinder.get_streamcCs|j|jd�}|j|dS)N�)r
rorlrrrrr4�szZipResourceFinder.get_sizecCs�|j|jd�}|r,|dtjkr,|tj7}t|�}t�}t�|j|�}|t|j�kr�|j|�|�shq�|j||d�}|�	|�
tjd�d�|d7}qH|S)Nrurr)r
ror	rNrnr`rvrtri�addrK)rrr
�plenr#rz�srrrr9s

zZipResourceFinder.get_resourcescCsh||jd�}|r*|dtjkr*|tj7}t�|j|�}z|j|�|�}Wntybd}Yn0|S)NruF)ror	rNrvrtrirw)rr
rzr#rrrrSs

zZipResourceFinder._is_directory)r&r'r(r6rrGrQrr3r.r4r9rSr)rrrrrk�srkcCs|tt|�<dSr+)�_finder_registry�type)rD�finder_makerrrr�register_finder2sr�cCs�|tvrt|}nv|tjvr$t|�tj|}t|dd�}|durJtd��t|dd�}t�t|��}|durxtd|��||�}|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_cacherg�modules�
__import__rCrr�r%r�)�packager#rBr
rDr�rrrr9s


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.
    NrA)
�pkgutil�get_importerrg�path_importer_cacher%r�r��
_dummy_moduler	r
rr@r?)r
r#rDrrBrrr�finder_for_pathUs
r�)-Z
__future__rrvr|Zloggingr	r�rg�typesrqrAr�utilrrrZ	getLoggerr&rxr1r�objectr*r-r8r;rkr��zipimporterr��_frozen_importlib_externalZ_fi�ImportError�_frozen_importlib�SourceFileLoader�
FileFinder�SourcelessFileLoader�AttributeErrorr�r�r�
ModuleTyperr�r�rrrr�<module>sJ
,!ZO�