o EcD* @s~ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZeeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZz&zddlZWn e yddl!ZYnweeej"<eeej#<eeej$<[Wn e e%fyYnwddZ&iZ'ddZ(e)e*dZ+ddZ,dS))unicode_literalsN)DistlibException)cached_propertyget_cache_baseCachecs.eZdZdfdd ZddZddZZS) ResourceCacheNcs0|durtjttd}tt||dS)Nzresource-cache)ospathjoinrstrsuperr__init__)selfbase __class__P/opt/alt/python310/lib/python3.10/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_stalecCs|j|\}}|dur|}|Stj|j|||}tj|}tj|s-t |tj |s6d}n| ||}|rZt |d}| |jWd|S1sUwY|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.getN)__name__ __module__ __qualname__rrr% __classcell__rrrrrs rc@seZdZddZdS) ResourceBasecCs||_||_dSr&)rname)rrr,rrrrHs zResourceBase.__init__N)r'r(r)rrrrrr+Gs r+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. FcC |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_streamUs zResource.as_streamcCstdurtat|Sr&)cacherr%r0rrr file_path^s zResource.file_pathcCr.r&)r get_bytesr0rrrr!e zResource.bytescCr.r&)rget_sizer0rrrsizeir5z Resource.sizeN) r'r(r)__doc__ is_containerr1rr3r!r7rrrrr-Ms  r-c@seZdZdZeddZdS)ResourceContainerTcCr.r&)r get_resourcesr0rrr resourcesqr5zResourceContainer.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__cC tj|Sr&)r r realpathrr rrr _adjust_path zResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancer!splitinsertrr r r rJ)r resource_nameseppartsr#rrr _make_paths    zResourceFinder._make_pathcCrGr&)r r rrIrrr_findrKzResourceFinder._findcCs d|jfSr&)r rrrrrrs zResourceFinder.get_cache_infocCsF||}||sd}|S||rt||}nt||}||_|Sr&)rTrU _is_directoryr:r-r )rrQr r#rrrfinds    zResourceFinder.findcCs t|jdSNrb)rr rVrrrr/rKzResourceFinder.get_streamcCs8t|jd }|WdS1swYdSrY)rr read)rrr$rrrr4s$zResourceFinder.get_bytescCstj|jSr&)r r getsizerVrrrr6zResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko |j S)N __pycache__)endswithskipped_extensions)r$r0rralloweds z-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r$)rarr sz0ResourceFinder.get_resources..)setr listdirr rVr)rarrr;s zResourceFinder.get_resourcescCs ||jSr&)rWr rVrrrr9rKzResourceFinder.is_containerccs||}|durD|g}|rF|d}|V|jr@|j}|jD]}|s'|}nd||g}||}|jr<||q |Vq |sdSdSdS)NrrM)rXpopr9r,r<r append)rrQrZtodoZrnamer,new_namechildrrriterators(     zResourceFinder.iteratorN)r'r(r)r8sysplatform startswithr`rrJrTrUrrXr/r4r6r;r9 staticmethodr r rrWrjrrrrr=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|_nt j ||_t |j|_ dS)Nr_files) r rorrFarchivelen prefix_lenhasattrrp zipimport_zip_directory_cachesortedindex)rrDrqrrrrs   zZipResourceFinder.__init__cCs|Sr&rrIrrrrJszZipResourceFinder._adjust_pathcCs||jd}||jvrd}n+|r|dtjkr|tj}t|j|}z |j||}Wn ty9d}Ynw|sGt d||j j |St d||j j |S)NTFz_find failed: %r %rz_find worked: %r %r) rsrpr rRbisectrxrm IndexErrorloggerdebugrFr")rr r#irrrrUs    zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rFrqr rr)rrr"r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jSr&)rFget_datar rVrrrr4r]zZipResourceFinder.get_bytescCst||Sr&)ioBytesIOr4rVrrrr/zZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rsrprrrrr6szZipResourceFinder.get_sizecCs|j|jd}|r|dtjkr|tj7}t|}t}t|j|}|t|jkrV|j||s6 |S|j||d}| | tjdd|d7}|t|jks+|S)Nryrr) r rsr rRrrrdrzrxrmaddrO)rrr Zplenr#r~srrrr;s zZipResourceFinder.get_resourcescCsh||jd}|r|dtjkr|tj7}t|j|}z |j||}W|Sty3d}Y|Sw)NryF)rsr rRrzrxrmr{)rr r~r#rrrrWs  zZipResourceFinder._is_directory)r'r(r)r8rrJrUrr4r/r6r;rWr*rrrrros  rocCs|tt|<dSr&)_finder_registrytype)rF finder_makerrrrregister_finder2rrcCs|tvr t|}|S|tjvrt|tj|}t|dd}|dur&tdt|dd}tt|}|dur=td|||}|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_cacherkmodules __import__rErrr%r)packager#rDr rFrrrrr9s      rZ __dummy__cCsRd}t|tj|}tt|}|r't}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) pkgutilZ get_importerrkpath_importer_cacher%rr _dummy_moduler r r rBrA)r r#rFrrDrrrfinder_for_pathUs  r)-Z __future__rrzrZloggingr rrktypesrurCrutilrrrZ getLoggerr'r|r2robjectr+r-r:r=ror zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderSourcelessFileLoaderAttributeErrorrrr ModuleTyper rrrrrrsP   ,!ZO