U ÀÒ.e*ã @sˆddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZe e¡ZdaGdd„deƒZGdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZedƒee jeiZzFz ddl Z!Wne"k �r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk �rXYnXdd„Z'iZ(dd„Z)e  *e+dƒ¡Z,dd„Z-dS)é)Úunicode_literalsNé)ÚDistlibException)Úcached_propertyÚget_cache_baseÚpath_to_cache_dirÚCachecs.eZdZd‡fdd„ Zdd„Zdd„Z‡ZS) Ú ResourceCacheNcs0|dkrtj tƒtdƒ¡}tt|ƒ |¡dS)Nzresource-cache)ÚosÚpathÚjoinrÚstrÚsuperr Ú__init__)ÚselfÚbase©Ú __class__©úA/usr/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. Tr©rÚresourcer rrrÚis_stale#s zResourceCache.is_stalec Cs |j |¡\}}|dkr|}n~tj |j| |¡|¡}tj |¡}tj |¡sXt  |¡tj  |¡sjd}n |  ||¡}|rœt |dƒ�}|  |j¡W5QRX|S)z¤ Get a resource into the cache, :param resource: A :class:`Resource` instance. :return: The pathname of the resource in the cache. NTÚwb)ÚfinderÚget_cache_infor r r rZ prefix_to_dirÚdirnameÚisdirÚmakedirsÚexistsrÚopenÚwriteÚbytes)rrÚprefixr ÚresultrZstaleÚfrrrÚget.s      zResourceCache.get)N)Ú__name__Ú __module__Ú __qualname__rrr&Ú __classcell__rrrrr s r c@seZdZdd„ZdS)Ú ResourceBasecCs||_||_dS©N)rÚname)rrr-rrrrIszResourceBase.__init__N)r'r(r)rrrrrr+Hsr+c@s@eZdZdZdZdd„Zedd„ƒZedd„ƒZed 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_streamVszResource.as_streamcCstdkrtƒat |¡Sr,)Úcacher r&r0rrrÚ file_path_szResource.file_pathcCs |j |¡Sr,)rÚ get_bytesr0rrrr"fszResource.bytescCs |j |¡Sr,)rÚget_sizer0rrrÚsizejsz Resource.sizeN) r'r(r)Ú__doc__Ú is_containerr1rr3r"r6rrrrr.Ns   r.c@seZdZdZedd„ƒZdS)ÚResourceContainerTcCs |j |¡Sr,)rÚ get_resourcesr0rrrÚ resourcesrszResourceContainer.resourcesN)r'r(r)r8rr;rrrrr9osr9c@s’eZdZdZej d¡rdZndZdd„Zdd„Z d d „Z d d „Z d d„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„ZeejjƒZdd„ZdS)ÚResourceFinderz4 Resource finder for file system resources. Újava)ú.pycú.pyoz.class)r>r?cCs.||_t|ddƒ|_tj t|ddƒ¡|_dS)NÚ __loader__Ú__file__Ú)ÚmoduleÚgetattrÚloaderr r rr)rrCrrrr�szResourceFinder.__init__cCs tj |¡Sr,)r r Úrealpath©rr rrrÚ _adjust_path†szResourceFinder._adjust_pathcCsBt|tƒrd}nd}| |¡}| d|j¡tjj|Ž}| |¡S)Nó/ú/r) Ú isinstancer"ÚsplitÚinsertrr r r rH)rÚ resource_nameÚsepÚpartsr$rrrÚ _make_path‰s   zResourceFinder._make_pathcCs tj |¡Sr,)r r rrGrrrÚ_find•szResourceFinder._findcCs d|jfSr,)r ©rrrrrr˜szResourceFinder.get_cache_infocCsD| |¡}| |¡sd}n&| |¡r0t||ƒ}n t||ƒ}||_|Sr,)rQrRÚ _is_directoryr9r.r )rrNr r$rrrÚfind›s     zResourceFinder.findcCs t|jdƒS©NÚrb)r r rSrrrr/§szResourceFinder.get_streamc Cs,t|jdƒ�}| ¡W5QR£SQRXdSrV)r r Úread)rrr%rrrr4ªszResourceFinder.get_bytescCstj |j¡Sr,)r r ÚgetsizerSrrrr5®szResourceFinder.get_sizecs*‡fdd„‰t‡fdd„t |j¡DƒƒS)Ncs|dko| ˆj¡ S)NÚ __pycache__)ÚendswithÚskipped_extensions)r%r0rrÚallowed²s ÿz-ResourceFinder.get_resources..allowedcsg|]}ˆ|ƒr|‘qSrr)Ú.0r%)r]rrÚ µsz0ResourceFinder.get_resources..)Úsetr Úlistdirr rSr)r]rrr:±s zResourceFinder.get_resourcescCs | |j¡Sr,)rTr rSrrrr8·szResourceFinder.is_containerccs„| |¡}|dk r€|g}|r€| d¡}|V|jr|j}|jD]>}|sL|}nd ||g¡}| |¡}|jrv| |¡q>|Vq>qdS)NrrJ)rUÚpopr8r-r;r Úappend)rrNrZtodoZrnamer-Únew_nameZchildrrrÚiterator¼s      zResourceFinder.iteratorN)r'r(r)r7ÚsysÚplatformÚ startswithr\rrHrQrRrrUr/r4r5r:r8Ú staticmethodr r rrTrerrrrr<ws"    r<cs`eZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z ‡Z S)ÚZipResourceFinderz6 Resource finder for resources in .zip files. csZtt|ƒ |¡|jj}dt|ƒ|_t|jdƒr>|jj|_n t j ||_t |jƒ|_ dS)NrÚ_files) rrjrrEÚarchiveÚlenÚ prefix_lenÚhasattrrkÚ zipimportÚ_zip_directory_cacheÚsortedÚindex)rrCrlrrrrÕs   zZipResourceFinder.__init__cCs|Sr,rrGrrrrHàszZipResourceFinder._adjust_pathcCs¤||jd…}||jkrd}nX|r:|dtjkr:|tj}t |j|¡}z|j| |¡}Wntk rtd}YnX|sŽt  d||j j ¡nt  d||j j ¡|S)NTéÿÿÿÿFz_find failed: %r %rz_find worked: %r %r) rnrkr rOÚbisectrsrhÚ IndexErrorÚloggerÚdebugrEr#)rr r$ÚirrrrRãs   zZipResourceFinder._findcCs&|jj}|jdt|ƒd…}||fS)Nr)rErlr rm)rrr#r rrrrõsz ZipResourceFinder.get_cache_infocCs|j |j¡Sr,)rEÚget_datar rSrrrr4úszZipResourceFinder.get_bytescCst | |¡¡Sr,)ÚioÚBytesIOr4rSrrrr/ýszZipResourceFinder.get_streamcCs|j|jd…}|j|dS)Né)r rnrkrrrrr5szZipResourceFinder.get_sizecCs |j|jd…}|r,|dtjkr,|tj7}t|ƒ}tƒ}t |j|¡}|t|jƒkrœ|j| |¡shqœ|j||d…}|  |  tjd¡d¡|d7}qH|S)Nrtrr) r rnr rOrmr`rursrhÚaddrL)rrr Zplenr$ryÚsrrrr:s  zZipResourceFinder.get_resourcescCsj||jd…}|r*|dtjkr*|tj7}t |j|¡}z|j| |¡}Wntk rdd}YnX|S)NrtF)rnr rOrursrhrv)rr ryr$rrrrTs  zZipResourceFinder._is_directory)r'r(r)r7rrHrRrr4r/r5r:rTr*rrrrrjÑs rjcCs|tt|ƒ<dSr,)Ú_finder_registryÚtype)rEÚ finder_makerrrrÚregister_finder0srƒcCsŒ|tkrt|}nv|tjkr$t|ƒtj|}t|ddƒ}|dkrJtdƒ‚t|ddƒ}t t|ƒ¡}|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 packager@zUnable to locate finder for %r) Ú _finder_cacherfÚmodulesÚ __import__rDrr€r&r�)Úpackager$rCr rEr‚rrrr6s      rZ __dummy__cCsRd}t |¡tj |¡}t t|ƒ¡}|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. NrB) ÚpkgutilZ get_importerrfÚpath_importer_cacher&r€r�Ú _dummy_moduler r r rAr@)r r$rErrCrrrÚfinder_for_pathRs  rŒ).Z __future__rrur{Zloggingr r‰ZshutilrfÚtypesrprBrÚutilrrrrZ getLoggerr'rwr2r Úobjectr+r.r9r<rjr�Ú zipimporterr€Ú_frozen_importlib_externalZ_fiÚ ImportErrorÚ_frozen_importlibÚSourceFileLoaderÚ FileFinderÚAttributeErrorrƒr…rÚ ModuleTyper r‹rŒrrrrÚsN   ,!ZNþ