U  e@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddZ Gdd d ejZGd d d ejZGd d d ejZGdddejZddZdS)N)abc)only)ZipPathcCsttj|SN)iter collections OrderedDictfromkeys)itemsr I/opt/hc_python/lib/python3.8/site-packages/importlib_resources/readers.pyremove_duplicatessrc@s$eZdZddZddZddZdS) FileReadercCst|jj|_dSr)pathlibPathpathparent)selfloaderr r r __init__szFileReader.__init__cCst|j|Sz{ Return the file system path to prevent `resources.path()` from creating a temporary copy. strrjoinpathrresourcer r r resource_pathszFileReader.resource_pathcCs|jSrrrr r r filesszFileReader.filesN)__name__ __module__ __qualname__rrr r r r r rsrcs4eZdZddZfddZddZddZZS) ZipReadercCs4|d\}}}|jdd|d|_|j|_dS)N.\/) rpartitionprefixreplacearchive)rrmodule_namer r r r$szZipReader.__init__c sDzt|WStk r>}zt|jdW5d}~XYnXdSNr)super open_resourceKeyErrorFileNotFoundErrorargs)rrexc __class__r r r1)szZipReader.open_resourcecCs||}|o|S)zf Workaround for `zipfile.Path.is_file` returning true for non-existent paths. )r ris_fileexists)rrtargetr r r is_resource/szZipReader.is_resourcecCst|j|jSr)rr+r)rr r r r 7szZipReader.files)r!r"r#rr1r;r __classcell__r r r6r r$#s r$csxeZdZdZddZddZddZdd Zd d Zd d Z fddZ e ddZ ddZ eddZddZZS)MultiplexedPathz Given a series of Traversable objects, implement a merged version of the interface across all objects. Useful for namespace packages which may be multihomed at a single name. cGsFtttt||_|js&d}t|tdd|jDsBtddS)Nz.MultiplexedPath must contain at least one pathcss|]}|VqdSris_dir.0rr r r Hsz+MultiplexedPath.__init__..z)MultiplexedPath only supports directories)listmap_ensure_traversabler_pathsr3allNotADirectoryError)rpathsmessager r r rCs zMultiplexedPath.__init__cCsFdd|jD}td}tjt||d|d}t|jdd|DS)Ncss |]}|D] }|VqqdSr)iterdir)rArchildr r r rBLs z*MultiplexedPath.iterdir..r.)keycss|]\}}|VqdSrr )rAr.Zlocsr r r rBOs)rFoperator attrgetter itertoolsgroupbysortedrD_follow)rchildrenZby_namegroupsr r r rKKs zMultiplexedPath.iterdircCst|ddSNz is not a filer3rr r r read_bytesQszMultiplexedPath.read_bytescOst|ddSrVrWrr4kwargsr r r read_textTszMultiplexedPath.read_textcCsdS)NTr rr r r r?WszMultiplexedPath.is_dircCsdS)NFr rr r r r8ZszMultiplexedPath.is_filecs:ztj|WStjk r4|jdj|YSXdSr/)r0rrZTraversalErrorrF)rZ descendantsr6r r r]szMultiplexedPath.joinpathc Csft|d\}}}z t|WStk r`z||WYStk rZt|YYSXYnXdS)z Construct a MultiplexedPath if needed. If children contains a sole element, return it. Otherwise, return a MultiplexedPath of the items. Unless one of the items is not a Directory, then return the first. N)rPteer ValueErrorrHnext)clsrTsubdirsZone_dirZone_filer r r rSes  zMultiplexedPath._followcOst|ddSrVrWrYr r r openxszMultiplexedPath.opencCs |jdjSr/)rFr.rr r r r.{szMultiplexedPath.namecCs"ddd|jD}d|dS)Nz, css|]}d|dVqdS)'Nr r@r r r rBsz+MultiplexedPath.__repr__..zMultiplexedPath())joinrF)rrIr r r __repr__szMultiplexedPath.__repr__)r!r"r#__doc__rrKrXr[r?r8r classmethodrSrbpropertyr.rfr<r r r6r r=;s   r=c@sPeZdZddZeejdddZeddZe dd Z d d Z d d Z dS)NamespaceReadercCs*dt|krtdtt|j||_dS)NZ NamespacePathz Invalid path)rr^r=rD_resolver)rnamespace_pathr r r rs zNamespaceReader.__init__)returncCsdd||D\}|S)a' Given an item from a namespace path, resolve it to a Traversable. path_str might be a directory on the filesystem or a path to a zipfile plus the path within the zipfile, e.g. ``/foo/bar`` or ``/foo/baz.zip/inner_dir`` or ``foo\baz.zip\inner_dir\sub``. css|]}|r|VqdSrr>)rAcandr r r rBsz+NamespaceReader._resolve..)_candidate_paths)r`path_strdirr r r rks zNamespaceReader._resolveccs t|V||EdHdSr)rr_resolve_zip_path)r`rpr r r ros z NamespaceReader._candidate_pathsc csttttd|D]Z}ttttt @|| d ddd}t |d| |dVW5QRXqdS)Nz[\\/]r&r')reversedrCrefinditer contextlibsuppressr3IsADirectoryErrorrHPermissionErrorendr*rstartlstrip)rpmatchinnerr r r rrsz!NamespaceReader._resolve_zip_pathcCst|j|Srrrr r r rszNamespaceReader.resource_pathcCs|jSrrrr r r r szNamespaceReader.filesN) r!r"r#rrhr Traversablerkro staticmethodrrrr r r r r rjs   rjcCs(t|ts|Stjdtddt|S)zk Convert deprecated string arguments to traversables (pathlib.Path). Remove with Python 3.15. zs   I/