3 Bu_*@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZejeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZyFy ddl Z!Wne"k r$ddl#Z!YnXeee!j$<eee!j%<[!Wne"e&fk rXYnXddZ'iZ(ddZ)e j*e+dZ,ddZ-dS))unicode_literalsN)DistlibException)cached_propertyget_cache_basepath_to_cache_dirCachecs.eZdZdfdd ZddZddZZS) ResourceCacheNcs0|dkrtjjttd}tt|j|dS)Nzresource-cache)ospathjoinrstrsuperr __init__)selfbase) __class__/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.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)rresourcer rrris_stale#s zResourceCache.is_stalec Cs|jj|\}}|dkr|}n~tjj|j|j||}tjj|}tjj|sXtj |tjj |sjd}n |j ||}|rt |d}|j |jWdQRX|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__rr)rrr s r c@seZdZddZdS) ResourceBasecCs||_||_dS)N)rname)rrr,rrrrIszResourceBase.__init__N)r'r(r)rrrrrr+Hsr+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 |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_streamcCstdkrtatj|S)N)cacher r&)rrrr file_path_szResource.file_pathcCs |jj|S)N)r get_bytes)rrrrr!fszResource.bytescCs |jj|S)N)rget_size)rrrrsizejsz Resource.sizeN) r'r(r)__doc__ is_containerr/rr1r!r4rrrrr-Ns   r-c@seZdZdZeddZdS)ResourceContainerTcCs |jj|S)N)r get_resources)rrrr resourcesrszResourceContainer.resourcesN)r'r(r)r6rr9rrrrr7osr7c@seZdZdZejjdrdZnd ZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZeejjZddZdS)!ResourceFinderz4 Resource finder for file system resources. java.pyc.pyo.classcCs.||_t|dd|_tjjt|dd|_dS)N __loader____file__)modulegetattrloaderr r rr)rrBrrrrszResourceFinder.__init__cCs tjj|S)N)r r realpath)rr rrr _adjust_pathszResourceFinder._adjust_pathcCsBt|trd}nd}|j|}|jd|jtjj|}|j|S)N//r) isinstancer!splitinsertrr r r rF)r resource_nameseppartsr#rrr _make_paths   zResourceFinder._make_pathcCs tjj|S)N)r r r)rr rrr_findszResourceFinder._findcCs d|jfS)N)r )rrrrrrszResourceFinder.get_cache_infocCsD|j|}|j|sd}n&|j|r0t||}n t||}||_|S)N)rOrP _is_directoryr7r-r )rrLr r#rrrfinds     zResourceFinder.findcCs t|jdS)Nrb)rr )rrrrrr.szResourceFinder.get_streamc Cs t|jd }|jSQRXdS)NrS)rr read)rrr%rrrr2szResourceFinder.get_bytescCstjj|jS)N)r r getsize)rrrrrr3szResourceFinder.get_sizecs*fddtfddtj|jDS)Ncs|dko|jj S)N __pycache__)endswithskipped_extensions)r%)rrrallowedsz-ResourceFinder.get_resources..allowedcsg|]}|r|qSrr).0r%)rYrr sz0ResourceFinder.get_resources..)setr listdirr )rrr)rYrrr8s zResourceFinder.get_resourcescCs |j|jS)N)rQr )rrrrrr6szResourceFinder.is_containerccs|j|}|dk r|g}xn|r|jd}|V|jr|j}xH|jD]>}|sP|}ndj||g}|j|}|jrz|j|qB|VqBWqWdS)NrrH)rRpopr6r,r9r append)rrLrtodornamer,new_namechildrrriterators      zResourceFinder.iteratorN)r<r=r>)r<r=)r'r(r)r5sysplatform startswithrXrrFrOrPrrRr.r2r3r8r6 staticmethodr r rrQrdrrrrr:ws"    r:cs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S)ZipResourceFinderz6 Resource finder for resources in .zip files. csZtt|j||jj}dt||_t|jdr>|jj|_n t j ||_t |j|_ dS)Nr_files) rrirrDarchivelen prefix_lenhasattrrj zipimport_zip_directory_cachesortedindex)rrBrk)rrrrs   zZipResourceFinder.__init__cCs|S)Nr)rr rrrrFszZipResourceFinder._adjust_pathc Cs||jd}||jkrd}nX|r:|dtjkr:|tj}tj|j|}y|j|j|}Wntk rtd}YnX|stj d||j j ntj d||j j |S)NTrFz_find failed: %r %rz_find worked: %r %r) rmrjr rMbisectrrrg IndexErrorloggerdebugrDr")rr r#irrrrPs   zZipResourceFinder._findcCs&|jj}|jdt|d}||fS)Nr)rDrkr rl)rrr"r rrrrsz ZipResourceFinder.get_cache_infocCs|jj|jS)N)rDget_datar )rrrrrr2szZipResourceFinder.get_bytescCstj|j|S)N)ioBytesIOr2)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|jkr|j|j|sjP|j||d}|j |j tjdd|d7}qJW|S)Nrrrs) r rmr rMrlr\rtrrrgaddrJ)rrr plenr#rxsrrrr8s  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)rrris ricCs|tt|<dS)N)_finder_registrytype)rD finder_makerrrrregister_finder0srcCs|tkrt|}nv|tjkr$t|tj|}t|dd}|dkrJtdt|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_cacheremodules __import__rCrrr&r)packager#rBr rDrrrrr6s      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_importerrepath_importer_cacher&rr _dummy_moduler r r r@r?)r r#rDrrBrrrfinder_for_pathRs  r). __future__rrtrzloggingr rshutilretypesrorArutilrrrr getLoggerr'rvr0r objectr+r-r7r:rir zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderAttributeErrorrrr ModuleTyper rrrrrrsH   ,!ZN