U .e* @sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZeeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZzFz ddl Z!Wne"k r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk rXYnXddZ'iZ(ddZ)e *e+dZ,ddZ-dS))unicode_literalsN)DistlibException)cached_propertyget_cache_basepath_to_cache_dirCachecs.eZdZdfdd ZddZddZZS) ResourceCacheNcs0|dkrtjttd}tt||dS)Nzresource-cache)ospathjoinrstrsuperr __init__)selfbase __class__A/usr/lib/python3.8/site-packages/pip/_vendor/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. Trrresourcer rrris_stale#s zResourceCache.is_stalec Cs|j|\}}|dkr|}n~tj|j|||}tj|}tj|sXt |tj |sjd}n | ||}|rt |d}| |jW5QRX|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 r r rZ prefix_to_dirdirnameisdirmakedirsexistsropenwritebytes)rrprefixr resultrZstalefrrrget.s      zResourceCache.get)N)__name__ __module__ __qualname__rrr& __classcell__rrrrr s r c@seZdZddZdS) ResourceBasecCs||_||_dSN)rname)rrr-rrrrIszResourceBase.__init__N)r'r(r)rrrrrr+Hsr+c@s@eZdZdZdZddZeddZeddZed 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. FcCs |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_streamrrrr as_streamVszResource.as_streamcCstdkrtat|Sr,)cacher r&r0rrr file_path_szResource.file_pathcCs |j|Sr,)r get_bytesr0rrrr"fszResource.bytescCs |j|Sr,)rget_sizer0rrrsizejsz Resource.sizeN) r'r(r)__doc__ is_containerr1rr3r"r6rrrrr.Ns   r.c@seZdZdZeddZdS)ResourceContainerTcCs |j|Sr,)r get_resourcesr0rrr resourcesrszResourceContainer.resourcesN)r'r(r)r8rr;rrrrr9osr9c@seZdZdZejdrdZndZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZeejjZddZdS)ResourceFinderz4 Resource finder for file system resources. java).pyc.pyoz.class)r>r?cCs.||_t|dd|_tjt|dd|_dS)N __loader____file__)modulegetattrloaderr r rr)rrCrrrrszResourceFinder.__init__cCs tj|Sr,)r r realpathrr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancer"splitinsertrr r r rH)r resource_nameseppartsr$rrr _make_paths   zResourceFinder._make_pathcCs tj|Sr,)r r rrGrrr_findszResourceFinder._findcCs d|jfSr,)r rrrrrrszResourceFinder.get_cache_infocCsD||}||sd}n&||r0t||}n t||}||_|Sr,)rQrR _is_directoryr9r.r )rrNr r$rrrfinds     zResourceFinder.findcCs t|jdSNrb)r r rSrrrr/szResourceFinder.get_streamc Cs,t|jd}|W5QRSQRXdSrV)r r read)rrr%rrrr4szResourceFinder.get_bytescCstj|jSr,)r r getsizerSrrrr5szResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko|j S)N __pycache__)endswithskipped_extensions)r%r0rralloweds z-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r%)r]rr sz0ResourceFinder.get_resources..)setr listdirr rSr)r]rrr:s zResourceFinder.get_resourcescCs ||jSr,)rTr rSrrrr8szResourceFinder.is_containerccs||}|dk r|g}|r|d}|V|jr|j}|jD]>}|sL|}nd||g}||}|jrv||q>|Vq>qdS)NrrJ)rUpopr8r-r;r append)rrNrZtodoZrnamer-new_nameZchildrrriterators      zResourceFinder.iteratorN)r'r(r)r7sysplatform startswithr\rrHrQrRrrUr/r4r5r:r8 staticmethodr r rrTrerrrrr<ws"    r<cs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S)ZipResourceFinderz6 Resource finder for resources in .zip files. csZtt|||jj}dt||_t|jdr>|jj|_n t j ||_t |j|_ dS)Nr_files) rrjrrEarchivelen prefix_lenhasattrrk zipimport_zip_directory_cachesortedindex)rrCrlrrrrs   zZipResourceFinder.__init__cCs|Sr,rrGrrrrHszZipResourceFinder._adjust_pathcCs||jd}||jkrd}nX|r:|dtjkr:|tj}t|j|}z|j||}Wntk rtd}YnX|st d||j j nt d||j j |S)NTFz_find failed: %r %rz_find worked: %r %r) rnrkr rObisectrsrh IndexErrorloggerdebugrEr#)rr r$irrrrRs   zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rErlr rm)rrr#r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jSr,)rEget_datar rSrrrr4szZipResourceFinder.get_bytescCst||Sr,)ioBytesIOr4rSrrrr/szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rnrkrrrrr5szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}t|j|}|t|jkr|j||shq|j||d}| | tjdd|d7}qH|S)Nrtrr) r rnr rOrmr`rursrhaddrL)rrr Zplenr$rysrrrr:s  zZipResourceFinder.get_resourcescCsj||jd}|r*|dtjkr*|tj7}t|j|}z|j||}Wntk rdd}YnX|S)NrtF)rnr rOrursrhrv)rr ryr$rrrrTs  zZipResourceFinder._is_directory)r'r(r)r7rrHrRrr4r/r5r:rTr*rrrrrjs rjcCs|tt|<dSr,)_finder_registrytype)rE finder_makerrrrregister_finder0srcCs|tkrt|}nv|tjkr$t|tj|}t|dd}|dkrJtdt|dd}tt|}|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_cacherfmodules __import__rDrrr&r)packager$rCr rErrrrr6s      rZ __dummy__cCsRd}t|tj|}tt|}|rNt}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. NrB) pkgutilZ get_importerrfpath_importer_cacher&rr _dummy_moduler r r rAr@)r r$rErrCrrrfinder_for_pathRs  r).Z __future__rrur{Zloggingr rZshutilrftypesrprBrutilrrrrZ getLoggerr'rwr2r objectr+r.r9r<rjr zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderAttributeErrorrrr ModuleTyper rrrrrrsN   ,!ZN