a RaD* @sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZeeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZzNz ddlZWne yddl!ZYn0eeej"<eeej#<eeej$<[Wne e%fyRYn0ddZ&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__N/opt/alt/python39/lib/python3.9/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|}ntj|j|||}tj|}tj|sXt |tj |sjd}n | ||}|rt |d}| |jWdn1s0Y|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__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_streamcCstdurtat|Sr+)cacherr%r/rrr file_path^szResource.file_pathcCs |j|Sr+)r get_bytesr/rrrr!eszResource.bytescCs |j|Sr+)rget_sizer/rrrsizeisz Resource.sizeN) r&r'r(__doc__ is_containerr0rr2r!r5rrrrr-Ms   r-c@seZdZdZeddZdS)ResourceContainerTcCs |j|Sr+)r get_resourcesr/rrr resourcesqszResourceContainer.resourcesN)r&r'r(r7rr:rrrrr8nsr8c@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)rrBrrrrszResourceFinder.__init__cCs tj|Sr+)r r realpathrr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}||}|d|jtjj|}||S)N//r) isinstancer!splitinsertrr r r rG)r resource_nameseppartsr#rrr _make_paths   zResourceFinder._make_pathcCs tj|Sr+)r r rrFrrr_findszResourceFinder._findcCs d|jfSr+)r rrrrrrszResourceFinder.get_cache_infocCsD||}||sd}n&||r0t||}n t||}||_|Sr+)rPrQ _is_directoryr8r-r )rrMr r#rrrfinds     zResourceFinder.findcCs t|jdSNrb)rr rRrrrr.szResourceFinder.get_streamcCs8t|jd}|WdS1s*0YdSrU)rr read)rrr$rrrr3szResourceFinder.get_bytescCstj|jSr+)r r getsizerRrrrr4szResourceFinder.get_sizecs*fddtfddt|jDS)Ncs|dko|j S)N __pycache__)endswithskipped_extensions)r$r/rralloweds z-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r$)r\rr z0ResourceFinder.get_resources..)setr listdirr rRr)r\rrr9s zResourceFinder.get_resourcescCs ||jSr+)rSr rRrrrr7szResourceFinder.is_containerccs||}|dur|g}|r|d}|V|jr|j}|jD]>}|sL|}nd||g}||}|jrv||q>|Vq>qdS)NrrI)rTpopr7r,r:r append)rrMrZtodoZrnamer,new_namechildrrriterators      zResourceFinder.iteratorN)r&r'r(r6sysplatform startswithr[rrGrPrQrrTr.r3r4r9r7 staticmethodr r rrSrfrrrrr;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 rkrrDarchivelen prefix_lenhasattrrl zipimport_zip_directory_cachesortedindex)rrBrmrrrrs   zZipResourceFinder.__init__cCs|Sr+rrFrrrrGszZipResourceFinder._adjust_pathcCs||jd}||jvrd}nV|r:|dtjkr:|tj}t|j|}z|j||}Wntyrd}Yn0|st d||j j nt d||j j |S)NTFz_find failed: %r %rz_find worked: %r %r) rorlr rNbisectrtri IndexErrorloggerdebugrDr")rr r#irrrrQs    zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rDrmr rn)rrr"r rrrrsz ZipResourceFinder.get_cache_infocCs|j|jSr+)rDget_datar rRrrrr3szZipResourceFinder.get_bytescCst||Sr+)ioBytesIOr3rRrrrr.szZipResourceFinder.get_streamcCs|j|jd}|j|dS)N)r rorlrrrrr4szZipResourceFinder.get_sizecCs|j|jd}|r,|dtjkr,|tj7}t|}t}t|j|}|t|jkr|j||shq|j||d}| | tjdd|d7}qH|S)Nrurr) r ror rNrnr`rvrtriaddrK)rrr Zplenr#rzsrrrr9s  zZipResourceFinder.get_resourcescCsh||jd}|r*|dtjkr*|tj7}t|j|}z|j||}Wntybd}Yn0|S)NruF)ror rNrvrtrirw)rr rzr#rrrrSs   zZipResourceFinder._is_directory)r&r'r(r6rrGrQrr3r.r4r9rSr)rrrrrks rkcCs|tt|<dSr+)_finder_registrytype)rD finder_makerrrrregister_finder2srcCs|tvrt|}nv|tjvr$t|tj|}t|dd}|durJtdt|dd}tt|}|durxtd|||}|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_cachergmodules __import__rCrrr%r)packager#rBr rDrrrrr9s      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. NrA) pkgutilZ get_importerrgpath_importer_cacher%rr _dummy_moduler r r r@r?)r r#rDrrBrrrfinder_for_pathUs  r)-Z __future__rrvr|Zloggingr rrgtypesrqrArutilrrrZ getLoggerr&rxr1robjectr*r-r8r;rkr zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderSourcelessFileLoaderAttributeErrorrrr ModuleTyper rrrrrrsJ   ,!ZO