U  e@sdddlmZddlmZddlmZGdddZGdddZdd d ZGd d d Z ddZ dS))suppress) TextIOWrapper)abcc@s(eZdZdZddfddZddZdS) SpecLoaderAdapterz> Adapt a package spec to adapt the underlying loader. cCs|jSN)loaderspecr K/opt/hc_python/lib/python3.8/site-packages/importlib_resources/_adapters.py zSpecLoaderAdapter.cCs||_|||_dSr)r r)selfr adapterr r r __init__ szSpecLoaderAdapter.__init__cCs t|j|Sr)getattrr rnamer r r __getattr__szSpecLoaderAdapter.__getattr__N)__name__ __module__ __qualname____doc__rrr r r r rsrc@s eZdZdZddZddZdS)TraversableResourcesLoaderz9 Adapt a loader to provide TraversableResources. cCs ||_dSrr rr r r r rsz#TraversableResourcesLoader.__init__cCst|jSr)CompatibilityFilesr _nativerr r r get_resource_readersz.TraversableResourcesLoader.get_resource_readerN)rrrrrrr r r r rsrrcOs8|dkrt|f||S|dkr$|Std|ddS)NrrbzInvalid mode value 'z"', only 'r' and 'rb' are supported)r ValueError)filemodeargskwargsr r r _io_wrapper s r&c@sreZdZdZGdddejZGdddejZGdddejZdd Z e d d Z d d Z ddZ ddZdS)rzj Adapter for an existing or non-existent resource reader to provide a compatibility .files(). c@sJeZdZdZddZddZddZeZdd Ze d d Z dd dZ dS)zCompatibilityFiles.SpecPathzk Path tied to a module spec. Can be read and exposes the resource reader children. cCs||_||_dSr)_spec_reader)rr readerr r r r4sz$CompatibilityFiles.SpecPath.__init__cs*jstdStfddjDS)Nr c3s|]}tj|VqdSr)r ChildPathr().0pathrr r ;sz6CompatibilityFiles.SpecPath.iterdir..)r(itercontentsr-r r-r iterdir8s  z#CompatibilityFiles.SpecPath.iterdircCsdSNFr r-r r r is_file@sz#CompatibilityFiles.SpecPath.is_filecCs|jst|St|j|Sr)r(r OrphanPathr*rotherr r r joinpathEs z$CompatibilityFiles.SpecPath.joinpathcCs|jjSr)r'rr-r r r rJsz CompatibilityFiles.SpecPath.namercOst|jd|f||Sr)r&r( open_resourcerr#r$r%r r r openNsz CompatibilityFiles.SpecPath.openN)r rrrrrr1r3is_dirr7propertyrr:r r r r SpecPath.s r>c@sNeZdZdZddZddZddZdd Zd d Ze d d Z dddZ dS)zCompatibilityFiles.ChildPathzw Path tied to a resource reader child. Can be read but doesn't expose any meaningful children. cCs||_||_dSr)r(_name)rr)rr r r rWsz%CompatibilityFiles.ChildPath.__init__cCstdSNr r/r-r r r r1[sz$CompatibilityFiles.ChildPath.iterdircCs|j|jSr)r( is_resourcerr-r r r r3^sz$CompatibilityFiles.ChildPath.is_filecCs | Sr)r3r-r r r r<asz#CompatibilityFiles.ChildPath.is_dircCst|j|Sr)rr4rr5r r r r7dsz%CompatibilityFiles.ChildPath.joinpathcCs|jSr)r?r-r r r rgsz!CompatibilityFiles.ChildPath.namercOst|j|j|f||Sr)r&r(r8rr9r r r r:ks z!CompatibilityFiles.ChildPath.openN)rr;r r r r r*Qs r*c@sJeZdZdZddZddZddZeZdd Ze d d Z dd dZ dS)zCompatibilityFiles.OrphanPathz Orphan path, not tied to a module spec or resource reader. Can't be read and doesn't expose any meaningful children. cGst|dkrtd||_dS)Nrz/Need at least one path part to construct a path)lenr!_path)r path_partsr r r rvs z&CompatibilityFiles.OrphanPath.__init__cCstdSr@rAr-r r r r1{sz%CompatibilityFiles.OrphanPath.iterdircCsdSr2r r-r r r r3~sz%CompatibilityFiles.OrphanPath.is_filecCstj|j|fSr)rr4rDr5r r r r7sz&CompatibilityFiles.OrphanPath.joinpathcCs |jdS)N)rDr-r r r rsz"CompatibilityFiles.OrphanPath.namercOs tddS)NzCan't open orphan path)FileNotFoundErrorr9r r r r:sz"CompatibilityFiles.OrphanPath.openN)rr;r r r r r4ps r4cCs ||_dSrr rr r r rszCompatibilityFiles.__init__c Cs2tt |jj|jjW5QRSQRXdSr)rAttributeErrorr rrrr-r r r r(s zCompatibilityFiles._readercCs|j}t|dr|S|S)zB Return the native reader if it supports files(). files)r(hasattr)rr)r r r rszCompatibilityFiles._nativecCs t|j|Sr)rr()rattrr r r rszCompatibilityFiles.__getattr__cCst|j|jSr)rr>r r(r-r r r rIszCompatibilityFiles.filesN)rrrrrZ Traversabler>r*r4rr=r(rrrIr r r r r(s# rcCs t|jtS)z` Construct a package spec with traversable compatibility on the spec/loader/reader. )r__spec__r)packager r r wrap_specsrNN)r) contextlibriorrrrr&rrNr r r r s     {