3 ”Re*ã@sˆddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZejeƒZdaGdd„deƒZGdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZedƒee jeiZyFy ddl Z!Wne"k �r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk �rXYnXdd„Z'iZ(dd„Z)e j*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|dkrtjjtƒtdƒƒ}tt|ƒj|ƒdS)Nzresource-cache)ÚosÚpathÚjoinrÚstrÚsuperr Ú__init__)ÚselfÚbase)Ú __class__©úŒ/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/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 |jj|ƒ\}}|dkr|}n~tjj|j|j|ƒ|ƒ}tjj|ƒ}tjj|ƒsXtj |ƒtjj |ƒsjd}n |j ||ƒ}|rœt |dƒ�}|j |jƒWdQRX|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 rÚ prefix_to_dirÚdirnameÚisdirÚmakedirsÚexistsrÚopenÚwriteÚbytes)rrÚprefixr ÚresultrÚstaleÚfrrrÚget.s      zResourceCache.get)N)Ú__name__Ú __module__Ú __qualname__rrr&Ú __classcell__rr)rrr 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 |jj|ƒ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ƒatj|ƒS)N)Úcacher r&)rrrrÚ file_path_szResource.file_pathcCs |jj|ƒS)N)rÚ get_bytes)rrrrr!fszResource.bytescCs |jj|ƒS)N)rÚget_size)rrrrÚsizejsz Resource.sizeN) r'r(r)Ú__doc__Ú is_containerr/rr1r!r4rrrrr-Ns   r-c@seZdZdZedd„ƒZdS)ÚResourceContainerTcCs |jj|ƒS)N)rÚ get_resources)rrrrÚ resourcesrszResourceContainer.resourcesN)r'r(r)r6rr9rrrrr7osr7c@s’eZdZdZejjdƒrdZnd Zdd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„ZeejjƒZdd„ZdS)!ÚResourceFinderz4 Resource finder for file system resources. Újavaú.pycú.pyoú.classcCs.||_t|ddƒ|_tjjt|ddƒƒ|_dS)NÚ __loader__Ú__file__Ú)ÚmoduleÚgetattrÚloaderr r rr)rrBrrrr�szResourceFinder.__init__cCs tjj|ƒS)N)r r Úrealpath)rr rrrÚ _adjust_path†szResourceFinder._adjust_pathcCsBt|tƒrd}nd}|j|ƒ}|jd|jƒtjj|Ž}|j|ƒS)Nó/ú/r) Ú isinstancer!ÚsplitÚinsertrr r r rF)rÚ resource_nameÚsepÚpartsr#rrrÚ _make_path‰s   zResourceFinder._make_pathcCs tjj|ƒS)N)r r r)rr rrrÚ_find•szResourceFinder._findcCs d|jfS)N)r )rrrrrr˜szResourceFinder.get_cache_infocCsD|j|ƒ}|j|ƒsd}n&|j|ƒr0t||ƒ}n t||ƒ}||_|S)N)rOrPÚ _is_directoryr7r-r )rrLr r#rrrÚfind›s     zResourceFinder.findcCs t|jdƒS)NÚrb)rr )rrrrrr.§szResourceFinder.get_streamc Cs t|jdƒ� }|jƒSQRXdS)NrS)rr Úread)rrr%rrrr2ªszResourceFinder.get_bytescCstjj|jƒS)N)r r Úgetsize)rrrrrr3®szResourceFinder.get_sizecs*‡fdd„‰t‡fdd„tj|jƒDƒƒS)Ncs|dko|jˆjƒ S)NÚ __pycache__)ÚendswithÚskipped_extensions)r%)rrrÚallowed²sz-ResourceFinder.get_resources..allowedcsg|]}ˆ|ƒr|‘qSrr)Ú.0r%)rYrrú µsz0ResourceFinder.get_resources..)Úsetr Úlistdirr )rrr)rYrrr8±s zResourceFinder.get_resourcescCs |j|jƒS)N)rQr )rrrrrr6·szResourceFinder.is_containerccsŒ|j|ƒ}|dk rˆ|g}xn|r†|jdƒ}|V|jr|j}xH|jD]>}|sP|}ndj||gƒ}|j|ƒ}|jrz|j|ƒqB|VqBWqWdS)NrrH)rRÚpopr6r,r9r Úappend)rrLrÚtodoÚrnamer,Únew_nameÚchildrrrÚiterator¼s      zResourceFinder.iteratorN)r<r=r>)r<r=)r'r(r)r5ÚsysÚplatformÚ startswithrXrrFrOrPrrRr.r2r3r8r6Ú staticmethodr r rrQrdrrrrr: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|ƒj|ƒ|jj}dt|ƒ|_t|jdƒr>|jj|_n t j ||_t |jƒ|_ dS)NrÚ_files) rrirrDÚarchiveÚlenÚ prefix_lenÚhasattrrjÚ zipimportÚ_zip_directory_cacheÚsortedÚindex)rrBrk)rrrrÕs   zZipResourceFinder.__init__cCs|S)Nr)rr rrrrFàszZipResourceFinder._adjust_pathc Cs¤||jd…}||jkrd}nX|r:|dtjkr:|tj}tj|j|ƒ}y|j|j|ƒ}Wntk rtd}YnX|sŽtj d||j j ƒntj d||j j ƒ|S)NTrFz_find failed: %r %rz_find worked: %r %réÿÿÿÿ) rmrjr rMÚbisectrrrgÚ IndexErrorÚloggerÚdebugrDr")rr r#ÚirrrrPãs   zZipResourceFinder._findcCs&|jj}|jdt|ƒd…}||fS)Nr)rDrkr rl)rrr"r rrrrõsz ZipResourceFinder.get_cache_infocCs|jj|jƒS)N)rDÚget_datar )rrrrrr2úszZipResourceFinder.get_bytescCstj|j|ƒƒS)N)ÚioÚBytesIOr2)rrrrrr.ýszZipResourceFinder.get_streamcCs|j|jd…}|j|dS)Né)r rmrj)rrr rrrr3szZipResourceFinder.get_sizecCs¤|j|jd…}|r,|dtjkr,|tj7}t|ƒ}tƒ}tj|j|ƒ}xV|t|jƒkrž|j|j|ƒsjP|j||d…}|j |j tjdƒdƒ|d7}qJW|S)Nrrrs) r rmr rMrlr\rtrrrgÚaddrJ)rrr Úplenr#rxÚsrrrr8s  zZipResourceFinder.get_resourcesc Csj||jd…}|r*|dtjkr*|tj7}tj|j|ƒ}y|j|j|ƒ}Wntk rdd}YnX|S)NrFrs)rmr rMrtrrrgru)rr rxr#rrrrQs  zZipResourceFinder._is_directory)r'r(r)r5rrFrPrr2r.r3r8rQr*rr)rrriÑs ricCs|tt|ƒ<dS)N)Ú_finder_registryÚtype)rDÚ finder_makerrrrÚregister_finder0srƒcCsŒ|tkrt|}nv|tjkr$t|ƒtj|}t|ddƒ}|dkrJtdƒ‚t|ddƒ}tjt|ƒƒ}|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_cachereÚmodulesÚ __import__rCrr€r&r�)Úpackager#rBr rDr‚rrrr6s      rÚ __dummy__cCsRd}tj|ƒtjj|ƒ}tjt|ƒƒ}|rNt}tj j |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) ÚpkgutilÚ get_importerreÚpath_importer_cacher&r€r�Ú _dummy_moduler r r r@r?)r r#rDrrBrrrÚfinder_for_pathRs  rŽ).Ú __future__rrtrzÚloggingr rŠÚshutilreÚtypesrorArÚutilrrrrÚ getLoggerr'rvr0r Úobjectr+r-r7r:rir�Ú zipimporterr€Ú_frozen_importlib_externalZ_fiÚ ImportErrorÚ_frozen_importlibÚSourceFileLoaderÚ FileFinderÚAttributeErrorrƒr…rÚ ModuleTyper r�rŽrrrrÚsH   ,!ZN