o
    ä§Êh*  ã                	   @   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
Z
ddlmZ ddlmZ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%< [!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Úpath_to_cache_dirÚ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__© úC/var/www/html/env/lib/python3.10/site-packages/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   Úprefix_to_dirÚdirnameÚisdirÚmakedirsÚexistsr   ÚopenÚwriteÚbytes)r   r   Úprefixr   Úresultr   Ú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   I   s   
zResourceBase.__init__N)r*   r+   r,   r   r   r   r   r   r.   H   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_streamV   s   zResource.as_streamc                 C   s   t d u rtƒ a t  | ¡S r)   )Úcacher	   r(   r3   r   r   r   Ú	file_path_   s   
zResource.file_pathc                 C   r1   r)   )r   Ú	get_bytesr3   r   r   r   r#   f   ó   zResource.bytesc                 C   r1   r)   )r   Úget_sizer3   r   r   r   Úsizej   r8   zResource.sizeN)
r*   r+   r,   Ú__doc__Úis_containerr4   r   r6   r#   r:   r   r   r   r   r0   N   s    	

r0   c                   @   s   e Zd ZdZedd„ ƒZdS )ÚResourceContainerTc                 C   r1   r)   )r   Úget_resourcesr3   r   r   r   Ú	resourcesr   r8   zResourceContainer.resourcesN)r*   r+   r,   r<   r   r?   r   r   r   r   r=   o   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)rB   rC   c                 C   s.   || _ t|dd ƒ| _tj t|ddƒ¡| _d S )NÚ
__loader__Ú__file__Ú )ÚmoduleÚgetattrÚloaderr
   r   r   r   )r   rG   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   rM   )r   Úresource_nameÚsepÚpartsr%   r   r   r   Ú
_make_path‰   s   


zResourceFinder._make_pathc                 C   rJ   r)   )r
   r   r    rL   r   r   r   Ú_find•   rN   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)   )rW   rX   Ú_is_directoryr=   r0   r   )r   rT   r   r%   r   r   r   Úfind›   s   


û
zResourceFinder.findc                 C   s   t |jdƒS ©NÚrb)r!   r   rY   r   r   r   r2   §   rN   zResourceFinder.get_streamc                 C   s8   t |jdƒ�}| ¡ W  d   ƒ S 1 sw   Y  d S r\   )r!   r   Úread)r   r   r'   r   r   r   r7   ª   s   $ÿzResourceFinder.get_bytesc                 C   s   t j |j¡S r)   )r
   r   ÚgetsizerY   r   r   r   r9   ®   ó   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'   r3   r   r   Úallowed²   s   
ÿz-ResourceFinder.get_resources.<locals>.allowedc                    s   g | ]}ˆ |ƒr|‘qS r   r   )Ú.0r'   )rd   r   r   Ú
<listcomp>µ   s    z0ResourceFinder.get_resources.<locals>.<listcomp>)Úsetr
   Úlistdirr   rY   r   )rd   r   r   r>   ±   s   zResourceFinder.get_resourcesc                 C   s   |   |j¡S r)   )rZ   r   rY   r   r   r   r<   ·   rN   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   rP   )r[   Úpopr<   r/   r?   r   Úappend)r   rT   r   ÚtodoÚrnamer/   Únew_nameÚchildr   r   r   Úiterator¼   s(   €



òþzResourceFinder.iteratorN)r*   r+   r,   r;   ÚsysÚplatformÚ
startswithrc   r   rM   rW   rX   r   r[   r2   r7   r9   r>   r<   Ústaticmethodr
   r   r   rZ   ro   r   r   r   r   r@   w   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   rt   r   rI   ÚarchiveÚlenÚ
prefix_lenÚhasattrru   Ú	zipimportÚ_zip_directory_cacheÚsortedÚindex)r   rG   rv   r   r   r   r   Õ   s   zZipResourceFinder.__init__c                 C   s   |S r)   r   rL   r   r   r   rM   à   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 )NTéÿÿÿÿFz_find failed: %r %rz_find worked: %r %r)rx   ru   r
   rU   Úbisectr}   rr   Ú
IndexErrorÚloggerÚdebugrI   r$   )r   r   r%   Úir   r   r   rX   ã   s    

ÿÿzZipResourceFinder._findc                 C   s&   | j j}|jdt|ƒ d … }||fS )Nr   )rI   rv   r   rw   )r   r   r$   r   r   r   r   r   õ   s   z ZipResourceFinder.get_cache_infoc                 C   s   | j  |j¡S r)   )rI   Úget_datar   rY   r   r   r   r7   ú   r`   zZipResourceFinder.get_bytesc                 C   s   t  |  |¡¡S r)   )ÚioÚBytesIOr7   rY   r   r   r   r2   ý   ó   zZipResourceFinder.get_streamc                 C   s   |j | jd … }| j| d S )Né   )r   rx   ru   r   r   r   r   r9      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 )Nr~   r   r   )r   rx   r
   rU   rw   rg   r   r}   rr   ÚaddrR   )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 )Nr~   F)rx   r
   rU   r   r}   rr   r€   )r   r   rƒ   r%   r   r   r   rZ     s   
þþzZipResourceFinder._is_directory)r*   r+   r,   r;   r   rM   rX   r   r7   r2   r9   r>   rZ   r-   r   r   r   r   rt   Ñ   s    rt   c                 C   s   |t t| ƒ< d S r)   )Ú_finder_registryÚtype)rI   Úfinder_makerr   r   r   Úregister_finder0  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 packagerD   zUnable to locate finder for %r)	Ú_finder_cacherp   ÚmodulesÚ
__import__rH   r   rŒ   r(   r�   )Úpackager%   rG   r   rI   rŽ   r   r   r   r   6  s    
ó
r   Ú	__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.
    NrF   )ÚpkgutilÚget_importerrp   Úpath_importer_cacher(   rŒ   r�   Ú_dummy_moduler
   r   r   rE   rD   )r   r%   rI   r   rG   r   r   r   Úfinder_for_pathR  s   
rš   ).Ú
__future__r   r   r…   Úloggingr
   r–   Úshutilrp   Útypesrz   rF   r   Úutilr   r   r   r   Ú	getLoggerr*   r�   r5   r	   Úobjectr.   r0   r=   r@   rt   r�   ÚzipimporterrŒ   Ú_frozen_importlib_externalÚ_fiÚImportErrorÚ_frozen_importlibÚSourceFileLoaderÚ
FileFinderÚAttributeErrorr�   r‘   r   Ú
ModuleTyper   r™   rš   r   r   r   r   Ú<module>   sP   
,!ZNþÿ

ÿ