Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/distlib/__pycache__/resources.cpython-36.pyc

3

aj*@sddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZmZejeZdaGdddeZGdd	d	eZGd
ddeZGdd
d
eZGdddeZGdddeZedee
jeiZyFyddl Z!Wne"k
r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk
rXYnXddZ'iZ(ddZ)e	j*e+dZ,ddZ-dS))unicode_literalsN)DistlibException)cached_propertyget_cache_basepath_to_cache_dirCachecs.eZdZdfdd	ZddZddZZS)	
ResourceCacheNcs0|dkrtjjttd}tt|j|dS)Nzresource-cache)ospathjoinrstrsuperr	__init__)selfbase)	__class__/usr/lib/python3.6/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)rresourcerrrris_stale#s	zResourceCache.is_stalec	Cs|jj|\}}|dkr|}n~tjj|j|j||}tjj|}tjj|sXtj	|tjj
|sjd}n|j||}|rt|d}|j
|jWdQRX|S)z
        Get a resource into the cache,

        :param resource: A :class:`Resource` instance.
        :return: The pathname of the resource in the cache.
        NTwb)finderget_cache_infor
rrrZ
prefix_to_dirdirnameisdirmakedirsexistsropenwritebytes)rrprefixrresultrZstalefrrrget.s
zResourceCache.get)N)__name__
__module____qualname__rrr$
__classcell__rr)rrr	sr	c@seZdZddZdS)ResourceBasecCs||_||_dS)N)rname)rrr*rrrrIszResourceBase.__init__N)r%r&r'rrrrrr)Hsr)c@s@eZdZdZdZddZeddZeddZed	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|jj|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_streamVszResource.as_streamcCstdkrtatj|S)N)cacher	r$)rrrr	file_path_szResource.file_pathcCs|jj|S)N)r	get_bytes)rrrrr fszResource.bytescCs|jj|S)N)rget_size)rrrrsizejsz
Resource.sizeN)
r%r&r'__doc__is_containerr-rr/r r2rrrrr+Ns	r+c@seZdZdZeddZdS)ResourceContainerTcCs|jj|S)N)r
get_resources)rrrr	resourcesrszResourceContainer.resourcesN)r%r&r'r4rr7rrrrr5osr5c@seZdZdZejjdrdZnd ZddZdd	Z	d
dZ
dd
ZddZddZ
ddZddZddZddZddZeejjZddZdS)!ResourceFinderz4
    Resource finder for file system resources.
    java.pyc.pyo.classcCs.||_t|dd|_tjjt|dd|_dS)N
__loader____file__)modulegetattrloaderr
rrr)rr@rrrrszResourceFinder.__init__cCstjj|S)N)r
rrealpath)rrrrr_adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}|j|}|jd|jtjj|}|j|S)N//r)	
isinstancer splitinsertrr
rrrD)r
resource_nameseppartsr"rrr
_make_paths

zResourceFinder._make_pathcCstjj|S)N)r
rr)rrrrr_findszResourceFinder._findcCs
d|jfS)N)r)rrrrrrszResourceFinder.get_cache_infocCsD|j|}|j|sd}n&|j|r0t||}n
t||}||_|S)N)rMrN
_is_directoryr5r+r)rrJrr"rrrfinds



zResourceFinder.findcCst|jdS)Nrb)rr)rrrrrr,szResourceFinder.get_streamc	Cs t|jd
}|jSQRXdS)NrQ)rrread)rrr#rrrr0szResourceFinder.get_bytescCstjj|jS)N)r
rgetsize)rrrrrr1szResourceFinder.get_sizecs*fddtfddtj|jDS)Ncs|dko|jjS)N__pycache__)endswithskipped_extensions)r#)rrrallowedsz-ResourceFinder.get_resources.<locals>.allowedcsg|]}|r|qSrr).0r#)rWrr
<listcomp>sz0ResourceFinder.get_resources.<locals>.<listcomp>)setr
listdirr)rrr)rWrrr6szResourceFinder.get_resourcescCs|j|jS)N)rOr)rrrrrr4szResourceFinder.is_containerccs|j|}|dk	r|g}xn|r|jd}|V|jr|j}xH|jD]>}|sP|}ndj||g}|j|}|jrz|j|qB|VqBWqWdS)NrrF)rPpopr4r*r7rappend)rrJrZtodoZrnamer*new_nameZchildrrriterators 


zResourceFinder.iteratorN)r:r;r<)r:r;)r%r&r'r3sysplatform
startswithrVrrDrMrNrrPr,r0r1r6r4staticmethodr
rrrOr_rrrrr8ws"r8cs`eZdZdZfddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZZ
S)ZipResourceFinderz6
    Resource finder for resources in .zip files.
    csZtt|j||jj}dt||_t|jdr>|jj|_nt	j
||_t|j|_dS)Nr_files)
rrdrrBarchivelen
prefix_lenhasattrre	zipimport_zip_directory_cachesortedindex)rr@rf)rrrrszZipResourceFinder.__init__cCs|S)Nr)rrrrrrDszZipResourceFinder._adjust_pathcCs||jd}||jkrd}nX|r:|dtjkr:|tj}tj|j|}y|j|j|}Wntk
rtd}YnX|stj	d||j
jntj	d||j
j|S)NTrFz_find failed: %r %rz_find worked: %r %r)rhrer
rKbisectrmrb
IndexErrorloggerdebugrBr!)rrr"irrrrNs


zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rBrfrrg)rrr!rrrrrsz ZipResourceFinder.get_cache_infocCs|jj|jS)N)rBget_datar)rrrrrr0szZipResourceFinder.get_bytescCstj|j|S)N)ioBytesIOr0)rrrrrr,szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)rrhre)rrrrrrr1szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}tj|j|}xV|t|jkr|j|j|sjP|j||d}|j	|j
tjdd|d7}qJW|S)Nrrrn)rrhr
rKrgrZrormrbaddrH)rrrZplenr"rssrrrr6s
zZipResourceFinder.get_resourcescCsj||jd}|r*|dtjkr*|tj7}tj|j|}y|j|j|}Wntk
rdd}YnX|S)NrFrn)rhr
rKrormrbrp)rrrsr"rrrrOs

zZipResourceFinder._is_directory)r%r&r'r3rrDrNrr0r,r1r6rOr(rr)rrrdsrdcCs|tt|<dS)N)_finder_registrytype)rBfinder_makerrrrregister_finder0sr}cCs|tkrt|}nv|tjkr$t|tj|}t|dd}|dkrJtdt|dd}tjt|}|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 packager=zUnable to locate finder for %r)	
_finder_cacher`modules
__import__rArrzr$r{)packager"r@rrBr|rrrr6s


rZ	__dummy__cCsRd}tj|tjj|}tjt|}|rNt}tj	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?)
pkgutilZget_importerr`path_importer_cacher$rzr{
_dummy_moduler
rrr>r=)rr"rBrr@rrrfinder_for_pathRs
r).Z
__future__rroruZloggingr
rZshutilr`typesrjr?rutilrrrrZ	getLoggerr%rqr.r	objectr)r+r5r8rdr{zipimporterrz_frozen_importlib_externalZ_fiImportError_frozen_importlibSourceFileLoader
FileFinderAttributeErrorr}rr
ModuleTyper
rrrrrr<module>sH
,!ZN



Back to Directory File Manager