o
    CJeD*                  	   @   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
mZ ddlmZmZmZ eeZdaG dd deZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZedee	jeiZz&zd dlZW n e y   d dl!ZY nw eeej"< eeej#< eeej$< [W n e e%fy   Y nw dd Z&i Z'dd Z(e)e*dZ+dd Z,dS )    )unicode_literalsN   )DistlibException)cached_propertyget_cache_baseCachec                       s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	ResourceCacheNc                    s0   |d u rt jt td}tt| | d S )Nzresource-cache)ospathjoinr   strsuperr   __init__)selfbase	__class__ k/home/seandotau/au.memorygallery.club/gallery/lib/python3.10/site-packages/pip/_vendor/distlib/resources.pyr      s   zResourceCache.__init__c                 C   s   dS )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
   r   r   r   is_stale"   s   	zResourceCache.is_stalec                 C   s   |j |\}}|du r|}|S tj| j| ||}tj|}tj|s-t	| tj
|s6d}n| ||}|rZt|d}||j W d   |S 1 sUw   Y  |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   r   Zprefix_to_dirdirnameisdirmakedirsexistsr   openwritebytes)r   r   prefixr
   resultr   Zstalefr   r   r   get-   s$   

zResourceCache.getN)__name__
__module____qualname__r   r   r%   __classcell__r   r   r   r   r      s    r   c                   @   s   e Zd Zdd ZdS )ResourceBasec                 C   s   || _ || _d S r&   )r   name)r   r   r,   r   r   r   r   H   s   
zResourceBase.__init__N)r'   r(   r)   r   r   r   r   r   r+   G   s    r+   c                   @   s@   e Zd ZdZdZdd Zedd Zedd Zed	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.
    Fc                 C      | 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r   r   r   r   	as_streamU   s   zResource.as_streamc                 C   s   t d u rt a t | S r&   )cacher   r%   r0   r   r   r   	file_path^   s   
zResource.file_pathc                 C   r.   r&   )r   	get_bytesr0   r   r   r   r!   e      zResource.bytesc                 C   r.   r&   )r   get_sizer0   r   r   r   sizei   r5   zResource.sizeN)
r'   r(   r)   __doc__is_containerr1   r   r3   r!   r7   r   r   r   r   r-   M   s    	

r-   c                   @   s   e Zd ZdZedd ZdS )ResourceContainerTc                 C   r.   r&   )r   get_resourcesr0   r   r   r   	resourcesq   r5   zResourceContainer.resourcesN)r'   r(   r)   r9   r   r<   r   r   r   r   r:   n   s    r:   c                   @   s   e Zd ZdZejdrdZndZdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZeejjZdd ZdS )ResourceFinderz4
    Resource finder for file system resources.
    java).pyc.pyoz.class)r?   r@   c                 C   s.   || _ t|dd | _tjt|dd| _d S )N
__loader____file__ )modulegetattrloaderr	   r
   r   r   )r   rD   r   r   r   r      s   zResourceFinder.__init__c                 C      t j|S r&   )r	   r
   realpathr   r
   r   r   r   _adjust_path      zResourceFinder._adjust_pathc                 C   sB   t |trd}nd}||}|d| j tjj| }| |S )N   //r   )	
isinstancer!   splitinsertr   r	   r
   r   rJ   )r   resource_nameseppartsr#   r   r   r   
_make_path   s   


zResourceFinder._make_pathc                 C   rG   r&   )r	   r
   r   rI   r   r   r   _find   rK   zResourceFinder._findc                 C   s
   d |j fS r&   )r
   r   r   r   r   r   r      s   
zResourceFinder.get_cache_infoc                 C   sF   |  |}| |sd }|S | |rt| |}nt| |}||_|S r&   )rT   rU   _is_directoryr:   r-   r
   )r   rQ   r
   r#   r   r   r   find   s   



zResourceFinder.findc                 C   s   t |jdS Nrb)r   r
   rV   r   r   r   r/      rK   zResourceFinder.get_streamc                 C   s8   t |jd}| W  d    S 1 sw   Y  d S rY   )r   r
   read)r   r   r$   r   r   r   r4      s   $zResourceFinder.get_bytesc                 C   s   t j|jS r&   )r	   r
   getsizerV   r   r   r   r6         zResourceFinder.get_sizec                    s*   fdd t  fddt|jD S )Nc                    s   | dko
|   j S )N__pycache__)endswithskipped_extensions)r$   r0   r   r   allowed   s   
z-ResourceFinder.get_resources.<locals>.allowedc                    s   g | ]} |r|qS r   r   ).0r$   )ra   r   r   
<listcomp>   s    z0ResourceFinder.get_resources.<locals>.<listcomp>)setr	   listdirr
   rV   r   )ra   r   r   r;      s   zResourceFinder.get_resourcesc                 C   s   |  |jS r&   )rW   r
   rV   r   r   r   r9      rK   zResourceFinder.is_containerc                 c   s    |  |}|d urD|g}|rF|d}|V  |jr@|j}|jD ]}|s'|}nd||g}|  |}|jr<|| q |V  q |sd S d S d S )Nr   rM   )rX   popr9   r,   r<   r   append)r   rQ   r   todoZrnamer,   new_namechildr   r   r   iterator   s(   



zResourceFinder.iteratorN)r'   r(   r)   r8   sysplatform
startswithr`   r   rJ   rT   rU   r   rX   r/   r4   r6   r;   r9   staticmethodr	   r
   r   rW   rk   r   r   r   r   r=   v   s$    r=   c                       s`   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Z  ZS )ZipResourceFinderz6
    Resource finder for resources in .zip files.
    c                    sZ   t t| | | jj}dt| | _t| jdr| jj| _nt	j
| | _t| j| _d S )Nr   _files)r   rp   r   rF   archivelen
prefix_lenhasattrrq   	zipimport_zip_directory_cachesortedindex)r   rD   rr   r   r   r   r      s   zZipResourceFinder.__init__c                 C   s   |S r&   r   rI   r   r   r   rJ      s   zZipResourceFinder._adjust_pathc                 C   s   || j d  }|| jv rd}n+|r|d tjkr|tj }t| j|}z
| j| |}W n ty9   d}Y nw |sGt	d|| j
j |S t	d|| j
j |S )NTFz_find failed: %r %rz_find worked: %r %r)rt   rq   r	   rR   bisectry   rn   
IndexErrorloggerdebugrF   r"   )r   r
   r#   ir   r   r   rU      s    

zZipResourceFinder._findc                 C   s&   | j j}|jdt| d  }||fS )Nr   )rF   rr   r
   rs   )r   r   r"   r
   r   r   r   r      s   z ZipResourceFinder.get_cache_infoc                 C   s   | j |jS r&   )rF   get_datar
   rV   r   r   r   r4      r]   zZipResourceFinder.get_bytesc                 C   s   t | |S r&   )ioBytesIOr4   rV   r   r   r   r/         zZipResourceFinder.get_streamc                 C   s   |j | jd  }| j| d S )N   )r
   rt   rq   r   r   r   r   r6      s   zZipResourceFinder.get_sizec                 C   s   |j | jd  }|r|d tjkr|tj7 }t|}t }t| j|}|t| jk rV| j| |s6	 |S | j| |d  }|	|
tjdd  |d7 }|t| jk s+|S )Nrz   r   r   )r
   rt   r	   rR   rs   rd   r{   ry   rn   addrO   )r   r   r
   plenr#   r   sr   r   r   r;     s   
zZipResourceFinder.get_resourcesc                 C   sh   || j d  }|r|d tjkr|tj7 }t| j|}z| j| |}W |S  ty3   d}Y |S w )Nrz   F)rt   r	   rR   r{   ry   rn   r|   )r   r
   r   r#   r   r   r   rW     s   
zZipResourceFinder._is_directory)r'   r(   r)   r8   r   rJ   rU   r   r4   r/   r6   r;   rW   r*   r   r   r   r   rp      s    rp   c                 C   s   |t t| < d S r&   )_finder_registrytype)rF   finder_makerr   r   r   register_finder2  r   r   c                 C   s   | t v r
t |  }|S | tjvrt|  tj|  }t|dd}|du r&tdt|dd}tt|}|du r=td|  ||}|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 packagerA   zUnable to locate finder for %r)	_finder_cacherl   modules
__import__rE   r   r   r%   r   )packager#   rD   r
   rF   r   r   r   r   r   9  s    

r   Z	__dummy__c                 C   sR   d}t |  tj| }tt|}|r't}tj	
| 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   )pkgutilZget_importerrl   path_importer_cacher%   r   r   _dummy_moduler	   r
   r   rB   rA   )r
   r#   rF   r   rD   r   r   r   finder_for_pathU  s   
r   )-
__future__r   r{   r   loggingr	   r   rl   typesrv   rC   r   utilr   r   r   	getLoggerr'   r}   r2   r   objectr+   r-   r:   r=   rp   r   zipimporterr   _frozen_importlib_externalZ_fiImportError_frozen_importlibSourceFileLoader
FileFinderSourcelessFileLoaderAttributeErrorr   r   r   
ModuleTyper   r   r   r   r   r   r   <module>   sP   
,!ZO


