B
    =)H[q+  ã            	   @   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yFyd dl Z!W n e"k
�r$   d dl#Z!Y nX eee!j$< eee!j%< [!W n e"e&fk
�rX   Y nX 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 krt j tƒ tdƒ¡}tt| ƒ |¡ d S )Nzresource-cache)ÚosÚpathÚjoinr   ÚstrÚsuperr	   Ú__init__)ÚselfÚbase)Ú	__class__© ú^C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\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kr|}n~tj | j|  |¡|¡}tj |¡}tj |¡sXt 	|¡ tj 
|¡sjd}n|  ||¡}|rœt|dƒ�}| |j¡ W dQ R X |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 )N)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   s   | 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 krtƒ a t  | ¡S )N)Úcacher	   r&   )r   r   r   r   Ú	file_path_   s    zResource.file_pathc             C   s   | j  | ¡S )N)r   Ú	get_bytes)r   r   r   r   r!   f   s    zResource.bytesc             C   s   | j  | ¡S )N)r   Úget_size)r   r   r   r   Úsizej   s    zResource.sizeN)
r'   r(   r)   Ú__doc__Úis_containerr/   r   r1   r!   r4   r   r   r   r   r-   N   s   	r-   c               @   s   e Zd ZdZedd„ ƒZdS )ÚResourceContainerTc             C   s   | j  | ¡S )N)r   Úget_resources)r   r   r   r   Ú	resourcesr   s    zResourceContainer.resourcesN)r'   r(   r)   r6   r   r9   r   r   r   r   r7   o   s   r7   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)z.pycz.pyoz.class)z.pycz.pyoc             C   s.   || _ t|dd ƒ| _tj t|ddƒ¡| _d S )NÚ
__loader__Ú__file__Ú )ÚmoduleÚgetattrÚloaderr
   r   r   r   )r   r?   r   r   r   r   �   s    zResourceFinder.__init__c             C   s   t j |¡S )N)r
   r   Úrealpath)r   r   r   r   r   Ú_adjust_path†   s    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   rC   )r   Úresource_nameÚsepÚpartsr#   r   r   r   Ú
_make_path‰   s    

zResourceFinder._make_pathc             C   s   t j |¡S )N)r
   r   r   )r   r   r   r   r   Ú_find•   s    zResourceFinder._findc             C   s
   d |j fS )N)r   )r   r   r   r   r   r   ˜   s    zResourceFinder.get_cache_infoc             C   sD   |   |¡}|  |¡sd }n&|  |¡r0t| |ƒ}n
t| |ƒ}||_|S )N)rL   rM   Ú_is_directoryr7   r-   r   )r   rI   r   r#   r   r   r   Úfind›   s    



zResourceFinder.findc             C   s   t |jdƒS )NÚrb)r   r   )r   r   r   r   r   r.   §   s    zResourceFinder.get_streamc          	   C   s    t |jdƒ�
}| ¡ S Q R X d S )NrP   )r   r   Úread)r   r   r%   r   r   r   r2   ª   s    zResourceFinder.get_bytesc             C   s   t j |j¡S )N)r
   r   Úgetsize)r   r   r   r   r   r3   ®   s    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%   )r   r   r   Úallowed²   s    z-ResourceFinder.get_resources.<locals>.allowedc                s   g | ]}ˆ |ƒr|‘qS r   r   )Ú.0r%   )rV   r   r   ú
<listcomp>µ   s    z0ResourceFinder.get_resources.<locals>.<listcomp>)Úsetr
   Úlistdirr   )r   r   r   )rV   r   r   r8   ±   s    zResourceFinder.get_resourcesc             C   s   |   |j¡S )N)rN   r   )r   r   r   r   r   r6   ·   s    zResourceFinder.is_containerc             c   sŒ   |   |¡}|d k	rˆ|g}xn|r†| d¡}|V  |jr|j}xH|jD ]>}|sP|}nd ||g¡}|   |¡}|jrz| |¡ qB|V  qBW qW d S )Nr   rE   )rO   Úpopr6   r,   r9   r   Úappend)r   rI   r   ÚtodoÚrnamer,   Únew_nameÚchildr   r   r   Úiterator¼   s     


zResourceFinder.iteratorN)r'   r(   r)   r5   ÚsysÚplatformÚ
startswithrU   r   rC   rL   rM   r   rO   r.   r2   r3   r8   r6   Ústaticmethodr
   r   r   rN   ra   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   rf   r   rA   ÚarchiveÚlenÚ
prefix_lenÚhasattrrg   Ú	zipimportÚ_zip_directory_cacheÚsortedÚindex)r   r?   rh   )r   r   r   r   Õ   s    zZipResourceFinder.__init__c             C   s   |S )Nr   )r   r   r   r   r   rC   à   s    zZipResourceFinder._adjust_pathc             C   s¤   || j d … }|| jkrd}nX|r:|d tjkr:|tj }t | j|¡}y| j|  |¡}W n tk
rt   d}Y nX |sŽt 	d|| j
j¡ nt 	d|| j
j¡ |S )NTéÿÿÿÿFz_find failed: %r %rz_find worked: %r %r)rj   rg   r
   rJ   Úbisectro   rd   Ú
IndexErrorÚloggerÚdebugrA   r"   )r   r   r#   Úir   r   r   rM   ã   s    


zZipResourceFinder._findc             C   s&   | j j}|jdt|ƒ d … }||fS )Nr   )rA   rh   r   ri   )r   r   r"   r   r   r   r   r   õ   s    z ZipResourceFinder.get_cache_infoc             C   s   | j  |j¡S )N)rA   Úget_datar   )r   r   r   r   r   r2   ú   s    zZipResourceFinder.get_bytesc             C   s   t  |  |¡¡S )N)ÚioÚBytesIOr2   )r   r   r   r   r   r.   ý   s    zZipResourceFinder.get_streamc             C   s   |j | jd … }| j| d S )Né   )r   rj   rg   )r   r   r   r   r   r   r3      s    zZipResourceFinder.get_sizec             C   s¤   |j | jd … }|r,|d tjkr,|tj7 }t|ƒ}tƒ }t | j|¡}xV|t| jƒk rž| j|  |¡sjP | j| |d … }| 	| 
tjd¡d ¡ |d7 }qJW |S )Nrp   r   r   )r   rj   r
   rJ   ri   rY   rq   ro   rd   ÚaddrG   )r   r   r   Úplenr#   ru   Úsr   r   r   r8     s    
zZipResourceFinder.get_resourcesc             C   sj   || j d … }|r*|d tjkr*|tj7 }t | j|¡}y| j|  |¡}W n tk
rd   d}Y nX |S )Nrp   F)rj   r
   rJ   rq   ro   rd   rr   )r   r   ru   r#   r   r   r   rN     s    

zZipResourceFinder._is_directory)r'   r(   r)   r5   r   rC   rM   r   r2   r.   r3   r8   rN   r*   r   r   )r   r   rf   Ñ   s   rf   c             C   s   |t t| ƒ< d S )N)Ú_finder_registryÚtype)rA   Úfinder_makerr   r   r   Úregister_finder0  s    r€   c             C   sŒ   | t krt |  }nv| tjkr$t| ƒ tj|  }t|ddƒ}|dkrJtdƒ‚t|ddƒ}t t|ƒ¡}|dkrxt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 packager<   zUnable to locate finder for %r)	Ú_finder_cacherb   ÚmodulesÚ
__import__r@   r   r}   r&   r~   )Úpackager#   r?   r   rA   r   r   r   r   r   6  s    


r   Ú	__dummy__c             C   sR   d}t  | ¡ tj | ¡}t t|ƒ¡}|rNt}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.
    Nr>   )ÚpkgutilÚget_importerrb   Úpath_importer_cacher&   r}   r~   Ú_dummy_moduler
   r   r   r=   r<   )r   r#   rA   r   r?   r   r   r   Úfinder_for_pathR  s    
r‹   ).Ú
__future__r   rq   rw   Úloggingr
   r‡   Úshutilrb   Útypesrl   r>   r   Úutilr   r   r   r   Ú	getLoggerr'   rs   r0   r	   Úobjectr+   r-   r7   r:   rf   r~   Úzipimporterr}   Ú_frozen_importlib_externalZ_fiÚImportErrorÚ_frozen_importlibÚSourceFileLoaderÚ
FileFinderÚAttributeErrorr€   r‚   r   Ú
ModuleTyper   rŠ   r‹   r   r   r   r   Ú<module>   sH   
,!ZN


