B :aD* @sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZeeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZyPy ddlZWne k rddl!ZYnXeeej"<eeej#<eeej$<[Wne e%fk rVYnXddZ&iZ'ddZ(e)e*dZ+ddZ,dS))unicode_literalsN)DistlibException)cached_propertyget_cache_baseCachecs.eZdZdfdd ZddZddZZS) ResourceCacheNcs0|dkrtjttd}tt||dS)Nzresource-cache)ospathjoinrstrsuperr__init__)selfbase) __class__B/opt/alt/python37/lib/python3.7/site-packages/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. Tr)rresourcer rrris_stale"s zResourceCache.is_stalec Cs|j|\}}|dkr|}n~tj|j|||}tj|}tj|sXt |tj |sjd}n | ||}|rt |d}| |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 r r rZ prefix_to_dirdirnameisdirmakedirsexistsropenwritebytes)rrprefixr resultrZstalefrrrget-s      zResourceCache.get)N)__name__ __module__ __qualname__rrr# __classcell__rr)rrrs rc@seZdZddZdS) ResourceBasecCs||_||_dS)N)rname)rrr)rrrrHszResourceBase.__init__N)r$r%r&rrrrrr(Gsr(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_stream)rrrr as_streamUszResource.as_streamcCstdkrtat|S)N)cacherr#)rrrr file_path^szResource.file_pathcCs |j|S)N)r get_bytes)rrrrreszResource.bytescCs |j|S)N)rget_size)rrrrsizeisz Resource.sizeN) r$r%r&__doc__ is_containerr,rr.rr1rrrrr*Ms   r*c@seZdZdZeddZdS)ResourceContainerTcCs |j|S)N)r get_resources)rrrr resourcesqszResourceContainer.resourcesN)r$r%r&r3rr6rrrrr4nsr4c@seZdZdZejdrdZndZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZeejjZddZdS)ResourceFinderz4 Resource finder for file system resources. java)z.pycz.pyoz.class)z.pycz.pyocCs.||_t|dd|_tjt|dd|_dS)N __loader____file__)modulegetattrloaderr r rr)rr<rrrrszResourceFinder.__init__cCs tj|S)N)r r realpath)rr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancersplitinsertrr r r r@)r resource_nameseppartsr!rrr _make_paths   zResourceFinder._make_pathcCs tj|S)N)r r r)rr rrr_findszResourceFinder._findcCs d|jfS)N)r )rrrrrrszResourceFinder.get_cache_infocCsD||}||sd}n&||r0t||}n t||}||_|S)N)rIrJ _is_directoryr4r*r )rrFr r!rrrfinds     zResourceFinder.findcCs t|jdS)Nrb)rr )rrrrrr+szResourceFinder.get_streamc Cs t|jd }|SQRXdS)NrM)rr read)rrr"rrrr/szResourceFinder.get_bytescCstj|jS)N)r r getsize)rrrrrr0szResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko|j S)N __pycache__)endswithskipped_extensions)r")rrrallowedsz-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r")rSrr sz0ResourceFinder.get_resources..)setr listdirr )rrr)rSrrr5s zResourceFinder.get_resourcescCs ||jS)N)rKr )rrrrrr3szResourceFinder.is_containerccs||}|dk r|g}xn|r|d}|V|jr|j}xH|jD]>}|sP|}nd||g}||}|jrz||qB|VqBWqWdS)NrrB)rLpopr3r)r6r append)rrFrZtodoZrnamer)new_nameZchildrrriterators      zResourceFinder.iteratorN)r$r%r&r2sysplatform startswithrRrr@rIrJrrLr+r/r0r5r3 staticmethodr r rrKr[rrrrr7vs"    r7cs`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) r r`rr>archivelen prefix_lenhasattrra zipimport_zip_directory_cachesortedindex)rr<rb)rrrrs   zZipResourceFinder.__init__cCs|S)Nr)rr rrrr@szZipResourceFinder._adjust_pathcCs||jd}||jkrd}nX|r:|dtjkr:|tj}t|j|}y|j||}Wntk rtd}YnX|st d||j j nt d||j j |S)NTFz_find failed: %r %rz_find worked: %r %r) rdrar rGbisectrir^ IndexErrorloggerdebugr>r )rr r!irrrrJs   zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)r>rbr rc)rrr r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jS)N)r>get_datar )rrrrrr/szZipResourceFinder.get_bytescCst||S)N)ioBytesIOr/)rrrrrr+szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rdra)rrr rrrr0szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}t|j|}xV|t|jkr|j||sjP|j||d}| | tjdd|d7}qJW|S)Nrjrr) r rdr rGrcrVrkrir^addrD)rrr Zplenr!rosrrrr5s  zZipResourceFinder.get_resourcescCsj||jd}|r*|dtjkr*|tj7}t|j|}y|j||}Wntk rdd}YnX|S)NrjF)rdr rGrkrir^rl)rr ror!rrrrKs  zZipResourceFinder._is_directory)r$r%r&r2rr@rJrr/r+r0r5rKr'rr)rrr`s r`cCs|tt|<dS)N)_finder_registrytype)r> finder_makerrrrregister_finder2srycCs|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 packager9zUnable to locate finder for %r) _finder_cacher\modules __import__r=rrvr#rw)packager!r<r r>rxrrrr9s      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. Nr;) pkgutilZ get_importerr\path_importer_cacher#rvrw _dummy_moduler r r r:r9)r r!r>rr<rrrfinder_for_pathUs  r)-Z __future__rrkrqloggingr rr\typesrfr;rutilrrr getLoggerr$rmr-robjectr(r*r4r7r`rw zipimporterrv_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderSourcelessFileLoaderAttributeErrorryr{r ModuleTyper rrrrrrsH   ,!ZO