HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/distlib/__pycache__/resources.cpython-310.pyc
o

;jD*�	@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	jeiZz&zddlZWn
e y�ddl!ZYnweeej"<eeej#<eeej$<[Wne e%fy�Ynwdd�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__��E/opt/saltstack/salt/lib/python3.10/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_stalecCs�|j�|�\}}|dur|}|Stj�|j|�|�|�}tj�|�}tj�|�s-t�	|�tj�
|�s6d}n|�||�}|rZt|d��}|�
|j�Wd�|S1sUwY|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||_||_dSr&)r�name)rrr,rrrrHs
zResourceBase.__init__N)r'r(r)rrrrrr+Gsr+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.
    FcC�|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_streamUszResource.as_streamcCstdurt�at�|�Sr&)�cacherr%r0rrr�	file_path^s
zResource.file_pathcCr.r&)r�	get_bytesr0rrrr!e�zResource.bytescCr.r&)r�get_sizer0rrr�sizeir5z
Resource.sizeN)
r'r(r)�__doc__�is_containerr1rr3r!r7rrrrr-Ms	

r-c@seZdZdZedd��ZdS)�ResourceContainerTcCr.r&)r�
get_resourcesr0rrr�	resourcesqr5zResourceContainer.resourcesN)r'r(r)r9rr<rrrrr:nsr:c@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)rrDrrrr�szResourceFinder.__init__cC�tj�|�Sr&)r	r
�realpath�rr
rrr�_adjust_path��zResourceFinder._adjust_pathcCsBt|t�rd}nd}|�|�}|�d|j�tjj|�}|�|�S)N�/�/r)	�
isinstancer!�split�insertrr	r
rrJ)r�
resource_name�sep�partsr#rrr�
_make_path�s


zResourceFinder._make_pathcCrGr&)r	r
rrIrrr�_find�rKzResourceFinder._findcCs
d|jfSr&)r
�rrrrrr�s
zResourceFinder.get_cache_infocCsF|�|�}|�|�sd}|S|�|�rt||�}nt||�}||_|Sr&)rTrU�
_is_directoryr:r-r
)rrQr
r#rrr�find�s


�
zResourceFinder.findcCst|jd�S�N�rb)rr
rVrrrr/�rKzResourceFinder.get_streamcCs8t|jd��}|��Wd�S1swYdSrY)rr
�read)rrr$rrrr4�s$�zResourceFinder.get_bytescCstj�|j�Sr&)r	r
�getsizerVrrrr6��zResourceFinder.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.<locals>.allowedcsg|]}�|�r|�qSrr)�.0r$)rarr�
<listcomp>�sz0ResourceFinder.get_resources.<locals>.<listcomp>)�setr	�listdirr
rVr)rarrr;�szResourceFinder.get_resourcescCs|�|j�Sr&)rWr
rVrrrr9�rKzResourceFinder.is_containerccs��|�|�}|durD|g}|rF|�d�}|V|jr@|j}|jD]}|s'|}nd�||g�}|�|�}|jr<|�|�q |Vq |sdSdSdS)NrrM)rX�popr9r,r<r�append)rrQrZtodoZrnamer,�new_name�childrrr�iterator�s(�



��zResourceFinder.iteratorN)r'r(r)r8�sys�platform�
startswithr`rrJrTrUrrXr/r4r6r;r9�staticmethodr	r
rrWrjrrrrr=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|_nt	j
||_t|j�|_dS)Nr�_files)
r
rorrF�archive�len�
prefix_len�hasattrrp�	zipimport�_zip_directory_cache�sorted�index)rrDrqrrrr�szZipResourceFinder.__init__cCs|Sr&rrIrrrrJ�szZipResourceFinder._adjust_pathcCs�||jd�}||jvrd}n+|r|dtjkr|tj}t�|j|�}z
|j|�|�}Wnty9d}Ynw|sGt�	d||j
j�|St�	d||j
j�|S)NT���Fz_find failed: %r %rz_find worked: %r %r)rsrpr	rR�bisectrxrm�
IndexError�logger�debugrFr")rr
r#�irrrrU�s 

��zZipResourceFinder._findcCs&|jj}|jdt|�d�}||fS)Nr)rFrqr
rr)rrr"r
rrrr�sz ZipResourceFinder.get_cache_infocCs|j�|j�Sr&)rF�get_datar
rVrrrr4�r]zZipResourceFinder.get_bytescCst�|�|��Sr&)�io�BytesIOr4rVrrrr/��zZipResourceFinder.get_streamcCs|j|jd�}|j|dS)N�)r
rsrprrrrr6�szZipResourceFinder.get_sizecCs�|j|jd�}|r|dtjkr|tj7}t|�}t�}t�|j|�}|t|j�krV|j|�|�s6	|S|j||d�}|�	|�
tjd�d�|d7}|t|j�ks+|S)Nryrr)r
rsr	rRrrrdrzrxrm�addrO)rrr
Zplenr#r~�srrrr;s
��zZipResourceFinder.get_resourcescCsh||jd�}|r|dtjkr|tj7}t�|j|�}z|j|�|�}W|Sty3d}Y|Sw)NryF)rsr	rRrzrxrmr{)rr
r~r#rrrrWs
��zZipResourceFinder._is_directory)r'r(r)r8rrJrUrr4r/r6r;rWr*rrrrro�srocCs|tt|�<dSr&)�_finder_registry�type)rF�finder_makerrrr�register_finder2r�r�cCs�|tvr
t|}|S|tjvrt|�tj|}t|dd�}|dur&td��t|dd�}t�t|��}|dur=td|��||�}|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 packagerAzUnable to locate finder for %r)	�
_finder_cacherk�modules�
__import__rErr�r%r�)�packager#rDr
rFr�rrrr9s 
�
rZ	__dummy__cCsRd}t�|�tj�|�}t�t|��}|r't}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.
    NrC)
�pkgutil�get_importerrk�path_importer_cacher%r�r��
_dummy_moduler	r
rrBrA)r
r#rFrrDrrr�finder_for_pathUs
r�)-�
__future__rrzr��loggingr	r�rk�typesrurCr�utilrrr�	getLoggerr'r|r2r�objectr+r-r:r=ror��zipimporterr��_frozen_importlib_externalZ_fi�ImportError�_frozen_importlib�SourceFileLoader�
FileFinder�SourcelessFileLoader�AttributeErrorr�r�r�
ModuleTyperr�r�rrrr�<module>sP
,!ZO��


�