Your IP : 3.129.71.13


Current Path : /opt/alt/python37/lib/python3.7/site-packages/distlib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/distlib/__pycache__/resources.cpython-37.pyc

B

:��aD*�	@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	jeiZyPyddlZWne k
�rddl!ZYnXeeej"<eeej#<eeej$<[Wne e%fk
�rVYnXdd�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|dkrtj�t�td��}tt|��|�dS)Nzresource-cache)�os�path�joinr�str�superr�__init__)�self�base)�	__class__��B/opt/alt/python37/lib/python3.7/site-packages/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�WdQRX|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__rr)rrrsrc@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_streamcCstdkrt�at�|�S)N)�cacherr#)rrrr�	file_path^szResource.file_pathcCs|j�|�S)N)r�	get_bytes)rrrrreszResource.bytescCs|j�|�S)N)r�get_size)rrrr�sizeisz
Resource.sizeN)
r$r%r&�__doc__�is_containerr,rr.rr1rrrrr*Ms	r*c@seZdZdZedd��ZdS)�ResourceContainerTcCs|j�|�S)N)r�
get_resources)rrrr�	resourcesqszResourceContainer.resourcesN)r$r%r&r3rr6rrrrr4nsr4c@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)z.pycz.pyoz.class)z.pycz.pyocCs.||_t|dd�|_tj�t|dd��|_dS)N�
__loader__�__file__�)�module�getattr�loaderr	r
rr)rr<rrrr�szResourceFinder.__init__cCstj�|�S)N)r	r
�realpath)rr
rrr�_adjust_path�szResourceFinder._adjust_pathcCsBt|t�rd}nd}|�|�}|�d|j�tjj|�}|�|�S)N�/�/r)	�
isinstancer�split�insertrr	r
rr@)r�
resource_name�sep�partsr!rrr�
_make_path�s

zResourceFinder._make_pathcCstj�|�S)N)r	r
r)rr
rrr�_find�szResourceFinder._findcCs
d|jfS)N)r
)rrrrrr�szResourceFinder.get_cache_infocCsD|�|�}|�|�sd}n&|�|�r0t||�}n
t||�}||_|S)N)rIrJ�
_is_directoryr4r*r
)rrFr
r!rrr�find�s



zResourceFinder.findcCst|jd�S)N�rb)rr
)rrrrrr+�szResourceFinder.get_streamc	Cs t|jd��
}|��SQRXdS)NrM)rr
�read)rrr"rrrr/�szResourceFinder.get_bytescCstj�|j�S)N)r	r
�getsize)rrrrrr0�szResourceFinder.get_sizecs*�fdd��t�fdd�t�|j�D��S)Ncs|dko|��j�S)N�__pycache__)�endswith�skipped_extensions)r")rrr�allowed�sz-ResourceFinder.get_resources.<locals>.allowedcsg|]}�|�r|�qSrr)�.0r")rSrr�
<listcomp>�sz0ResourceFinder.get_resources.<locals>.<listcomp>)�setr	�listdirr
)rrr)rSrrr5�szResourceFinder.get_resourcescCs|�|j�S)N)rKr
)rrrrrr3�szResourceFinder.is_containerccs�|�|�}|dk	r�|g}xn|r�|�d�}|V|jr|j}xH|jD]>}|sP|}nd�||g�}|�|�}|jrz|�|�qB|VqBWqWdS)NrrB)rL�popr3r)r6r�append)rrFrZtodoZrnamer)�new_nameZchildrrr�iterator�s 


zResourceFinder.iteratorN)r$r%r&r2�sys�platform�
startswithrRrr@rIrJrrLr+r/r0r5r3�staticmethodr	r
rrKr[rrrrr7vs"r7cs`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
r`rr>�archive�len�
prefix_len�hasattrra�	zipimport�_zip_directory_cache�sorted�index)rr<rb)rrrr�szZipResourceFinder.__init__cCs|S)Nr)rr
rrrr@�szZipResourceFinder._adjust_pathcCs�||jd�}||jkrd}nX|r:|dtjkr:|tj}t�|j|�}y|j|�|�}Wntk
rtd}YnX|s�t�	d||j
j�nt�	d||j
j�|S)NT���Fz_find failed: %r %rz_find worked: %r %r)rdrar	rG�bisectrir^�
IndexError�logger�debugr>r )rr
r!�irrrrJ�s


zZipResourceFinder._findcCs&|jj}|jdt|�d�}||fS)Nr)r>rbr
rc)rrr r
rrrr�sz ZipResourceFinder.get_cache_infocCs|j�|j�S)N)r>�get_datar
)rrrrrr/�szZipResourceFinder.get_bytescCst�|�|��S)N)�io�BytesIOr/)rrrrrr+�szZipResourceFinder.get_streamcCs|j|jd�}|j|dS)N�)r
rdra)rrr
rrrr0�szZipResourceFinder.get_sizecCs�|j|jd�}|r,|dtjkr,|tj7}t|�}t�}t�|j|�}xV|t|j�kr�|j|�|�sjP|j||d�}|�	|�
tjd�d�|d7}qJW|S)Nrjrr)r
rdr	rGrcrVrkrir^�addrD)rrr
Zplenr!ro�srrrr5s
zZipResourceFinder.get_resourcescCsj||jd�}|r*|dtjkr*|tj7}t�|j|�}y|j|�|�}Wntk
rdd}YnX|S)NrjF)rdr	rGrkrir^rl)rr
ror!rrrrKs

zZipResourceFinder._is_directory)r$r%r&r2rr@rJrr/r+r0r5rKr'rr)rrr`�sr`cCs|tt|�<dS)N)�_finder_registry�type)r>�finder_makerrrr�register_finder2srycCs�|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 packager9zUnable to locate finder for %r)	�
_finder_cacher\�modules�
__import__r=rrvr#rw)�packager!r<r
r>rxrrrr9s


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.
    Nr;)
�pkgutilZget_importerr\�path_importer_cacher#rvrw�
_dummy_moduler	r
rr:r9)r
r!r>rr<rrr�finder_for_pathUs
r�)-Z
__future__rrkrq�loggingr	rr\�typesrfr;r�utilrrr�	getLoggerr$rmr-r�objectr(r*r4r7r`rw�zipimporterrv�_frozen_importlib_externalZ_fi�ImportError�_frozen_importlib�SourceFileLoader�
FileFinder�SourcelessFileLoader�AttributeErrorryr{r�
ModuleTyperr�r�rrrr�<module>sH
,!ZO





?>