U o a* @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__^C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\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 r prefix_to_dirdirnameisdirmakedirsexistsropenwritebytes)rrprefixr resultrstalefrrrget.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(r2rrr file_path_szResource.file_pathcCs |j|Sr.)r get_bytesr2rrrr#fszResource.bytescCs |j|Sr.)rget_sizer2rrrsizejsz Resource.sizeN) r)r*r+__doc__ is_containerr3rr5r#r8rrrrr0Ns   r0c@seZdZdZeddZdS)ResourceContainerTcCs |j|Sr.)r get_resourcesr2rrr resourcesrszResourceContainer.resourcesN)r)r*r+r:rr=rrrrr;osr;c@seZdZdZejdrdZndZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZeejjZddZdS)ResourceFinderz4 Resource finder for file system resources. java).pyc.pyoz.class)r@rAcCs.||_t|dd|_tjt|dd|_dS)N __loader____file__)modulegetattrloaderr r rr)rrErrrrszResourceFinder.__init__cCs tj|Sr.)r r realpathrr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancer#splitinsertrr r r rJ)r resource_nameseppartsr%rrr _make_paths   zResourceFinder._make_pathcCs tj|Sr.)r r r rIrrr_findszResourceFinder._findcCs d|jfSr.)r rrrrrrszResourceFinder.get_cache_infocCsD||}||sd}n&||r0t||}n t||}||_|Sr.)rSrT _is_directoryr;r0r )rrPr r%rrrfinds     zResourceFinder.findcCs t|jdSNrb)r!r rUrrrr1szResourceFinder.get_streamc Cs,t|jd}|W5QRSQRXdSrX)r!r read)rrr'rrrr6szResourceFinder.get_bytescCstj|jSr.)r r getsizerUrrrr7szResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko|j S)N __pycache__)endswithskipped_extensions)r'r2rralloweds z-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r')r_rr sz0ResourceFinder.get_resources..)setr listdirr rUr)r_rrr<s zResourceFinder.get_resourcescCs ||jSr.)rVr rUrrrr:szResourceFinder.is_containerccs||}|dk r|g}|r|d}|V|jr|j}|jD]>}|sL|}nd||g}||}|jrv||q>|Vq>qdS)NrrL)rWpopr:r/r=r append)rrPrtodornamer/new_namechildrrriterators      zResourceFinder.iteratorN)r)r*r+r9sysplatform startswithr^rrJrSrTrrWr1r6r7r<r: staticmethodr r rrVrjrrrrr>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) rrorrGarchivelen prefix_lenhasattrrp zipimport_zip_directory_cachesortedindex)rrErqrrrrs   zZipResourceFinder.__init__cCs|Sr.rrIrrrrJszZipResourceFinder._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) rsrpr rQbisectrxrm IndexErrorloggerdebugrGr$)rr r%irrrrTs   zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rGrqr rr)rrr$r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jSr.)rGget_datar rUrrrr6szZipResourceFinder.get_bytescCst||Sr.)ioBytesIOr6rUrrrr1szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rsrprrrrr7szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}t|j|}|t|jkr|j||shq|j||d}| | tjdd|d7}qH|S)Nryrr) r rsr rQrrrbrzrxrmaddrN)rrr plenr%r~srrrr<s  zZipResourceFinder.get_resourcescCsj||jd}|r*|dtjkr*|tj7}t|j|}z|j||}Wntk rdd}YnX|S)NryF)rsr rQrzrxrmr{)rr r~r%rrrrVs  zZipResourceFinder._is_directory)r)r*r+r9rrJrTrr6r1r7r<rVr,rrrrros rocCs|tt|<dSr.)_finder_registrytype)rG 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 packagerBzUnable to locate finder for %r) _finder_cacherkmodules __import__rFrrr(r)packager%rEr rGrrrrr6s      r __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. NrD) pkgutil get_importerrkpath_importer_cacher(rr _dummy_moduler r r rCrB)r r%rGrrErrrfinder_for_pathRs  r). __future__rrzrloggingr rshutilrktypesrurDrutilrrrr getLoggerr)r|r4r objectr-r0r;r>ror zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderAttributeErrorrrr ModuleTyper rrrrrrsN   ,!ZN