U cfD* @sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZeeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZzPz 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__K/opt/hc_python/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 r prefix_to_dirdirnameisdirmakedirsexistsropenwritebytes)rrprefixr resultrstalefrrrget-s      zResourceCache.get)N)__name__ __module__ __qualname__rrr' __classcell__rrrrrs rc@seZdZddZdS) ResourceBasecCs||_||_dSN)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_streamrrrr as_streamUszResource.as_streamcCstdkrtat|Sr-)cacherr'r1rrr file_path^szResource.file_pathcCs |j|Sr-)r get_bytesr1rrrr"eszResource.bytescCs |j|Sr-)rget_sizer1rrrsizeisz Resource.sizeN) r(r)r*__doc__ is_containerr2rr4r"r7rrrrr/Ms   r/c@seZdZdZeddZdS)ResourceContainerTcCs |j|Sr-)r get_resourcesr1rrr resourcesqszResourceContainer.resourcesN)r(r)r*r9rr<rrrrr:nsr:c@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)rrDrrrrszResourceFinder.__init__cCs tj|Sr-)r r realpathrr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancer"splitinsertrr r r rI)r resource_nameseppartsr$rrr _make_paths   zResourceFinder._make_pathcCs tj|Sr-)r r rrHrrr_findszResourceFinder._findcCs d|jfSr-)r rrrrrrszResourceFinder.get_cache_infocCsD||}||sd}n&||r0t||}n t||}||_|Sr-)rRrS _is_directoryr:r/r )rrOr r$rrrfinds     zResourceFinder.findcCs t|jdSNrb)r r rTrrrr0szResourceFinder.get_streamc Cs,t|jd}|W5QRSQRXdSrW)r r read)rrr&rrrr5szResourceFinder.get_bytescCstj|jSr-)r r getsizerTrrrr6szResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko|j S)N __pycache__)endswithskipped_extensions)r&r1rralloweds z-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r&)r^rr sz0ResourceFinder.get_resources..)setr listdirr rTr)r^rrr;s zResourceFinder.get_resourcescCs ||jSr-)rUr rTrrrr9szResourceFinder.is_containerccs||}|dk r|g}|r|d}|V|jr|j}|jD]>}|sL|}nd||g}||}|jrv||q>|Vq>qdS)NrrK)rVpopr9r.r<r append)rrOrtodornamer.new_namechildrrriterators      zResourceFinder.iteratorN)r(r)r*r8sysplatform startswithr]rrIrRrSrrVr0r5r6r;r9 staticmethodr r rrUrirrrrr=vs"    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) r rnrrFarchivelen prefix_lenhasattrro zipimport_zip_directory_cachesortedindex)rrDrprrrrs   zZipResourceFinder.__init__cCs|Sr-rrHrrrrIszZipResourceFinder._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) rrror rPbisectrwrl IndexErrorloggerdebugrFr#)rr r$irrrrSs   zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rFrpr rq)rrr#r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jSr-)rFget_datar rTrrrr5szZipResourceFinder.get_bytescCst||Sr-)ioBytesIOr5rTrrrr0szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rrrorrrrr6szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}t|j|}|t|jkr|j||shq|j||d}| | tjdd|d7}qH|S)Nrxrr) r rrr rPrqraryrwrladdrM)rrr plenr$r}srrrr;s  zZipResourceFinder.get_resourcescCsj||jd}|r*|dtjkr*|tj7}t|j|}z|j||}Wntk rdd}YnX|S)NrxF)rrr rPryrwrlrz)rr r}r$rrrrUs  zZipResourceFinder._is_directory)r(r)r*r8rrIrSrr5r0r6r;rUr+rrrrrns rncCs|tt|<dSr-)_finder_registrytype)rF finder_makerrrrregister_finder2srcCs|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 packagerAzUnable to locate finder for %r) _finder_cacherjmodules __import__rErrr'r)packager$rDr rFrrrrr9s      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. NrC) pkgutil get_importerrjpath_importer_cacher'rr _dummy_moduler r r rBrA)r r$rFrrDrrrfinder_for_pathUs  r)- __future__rryrloggingr rrjtypesrtrCrutilrrr getLoggerr(r{r3robjectr,r/r:r=rnr zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderSourcelessFileLoaderAttributeErrorrrr ModuleTyper rrrrrrsN   ,!ZO