U e5d@% @sddlZddlZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZddlmZdd lmZdd lmZmZmZmZmZdd lmZdd lmZmZdd lmZdddddddddg Zee efZ!ee ej"fZ#edddZ$e dddZ%eeej&dddZ'dd Z(e!e#ed!d"dZ)d-e!e#e e ed%d&dZ*e!e#e+d!d'dZ,d.e!e#e e e d%d(dZ-ee!e#eed!d)dZ.e!e e/d*d+dZ0e!ee dd,dZ1dS)/N)abc)contextmanagersuppress) import_module)ResourceLoader)BytesIO TextIOWrapper)Path) ModuleType)IterableIteratorOptionalSetUnion)cast)BinaryIOTextIO)ZipImportErrorPackageResourcecontents is_resource open_binary open_textpath read_binary read_text)returncCs\t|dr0|jjdkr*td|jjqX|Sn(t|}|jjdkrTtd|n|SdS)N__spec__z{!r} is not a package)hasattrrsubmodule_search_locations TypeErrorformatnamer)packagemoduler'+/usr/lib64/python3.8/importlib/resources.py _get_package"s   r)cCs,tj|\}}|r$td|n|SdS)Nz{!r} must be only a file name)osrsplit ValueErrorr#)rparent file_namer'r'r(_normalize_path6sr/)r%rcCs,|j}t|jdr(ttj|j|jSdS)Nget_resource_reader)rr loaderr resources_abcResourceReaderr0r$)r%specr'r'r(_get_resource_readerBs   r5cCs&|jjdks|jjs"td|dS)NzPackage has no location )rorigin has_locationFileNotFoundError)r%r'r'r(_check_locationPsr9)r%resourcerc Cst|}t|}t|}|dk r*||St|tj|jj }tj |}tj ||}zt |ddWSt k rtt|jj}d}t|jjdrtt ||}W5QRX|dkr|jj}d||} t| n t|YSYnXdS)Nrb)modeget_data{!r} resource not found in {!r})r/r)r5 open_resourcer9r*rabspathrr6dirnamejoinopenOSErrorrrr1r rr=r$r#r8r) r%r:readerabsolute_package_path package_path full_pathr1data package_namemessager'r'r(rUs2    utf-8strict)r%r:encodingerrorsrc Cs t|}t|}t|}|dk r2t||||St|tj|j j }tj |}tj ||}zt |d||dWStk rtt|j j}d} t|j jdrtt||} W5QRX| dkr|j j} d|| } t| ntt| ||YSYnXdS)Nr)r<rNrOr=r>)r/r)r5r r?r9r*rr@rr6rArBrCrDrrr1r rr=r$r#r8r) r%r:rNrOrErFrGrHr1rIrJrKr'r'r(rts2   c Cs:t|}t|}t||}|W5QRSQRXdSN)r/r)rread)r%r:fpr'r'r(rs c Cs>t|}t|}t||||}|W5QRSQRXdSrQ)r/r)rrR)r%r:rNrOrSr'r'r(rs c cst|}t|}t|}|dk rNzt||VWdStk rJYqVXnt|d}|jjdk r|t|jjj }||}|dk r| r|Vnxt ||}| }W5QRXt \}}z$t||t|t|VW5zt|Wntk rYnXXdSrQ)r/r)r5r resource_pathr8r9rr6r-existsrrRtempfileZmkstempr*removewriteclose) r%r:rEZ file_pathpackage_directoryrSrIfdZraw_pathr'r'r(rs6      )r%r$rc Cs|t|}t|t|}|dk r*||Sztt|}Wnttfk rTYdSX||krbdSt|j j j |}| S)NF) r)r/r5rsetrNotADirectoryErrorr8r rr6r-is_file)r%r$rEZpackage_contentsrr'r'r(rs cCsTt|}t|}|dk r |S|jjdks4|jjs8dSt|jjj}t |SdS)Nr') r)r5rrr6r7r r-r*listdir)r%rErZr'r'r(rs)rLrM)rLrM)2r*rVrr2 contextlibrr importlibr importlib.abcriorr pathlibr typesr typingr r rrrrZ typing.iorrZ zipimportr__all__strrPathLikerr)r/r3r5r9rrbytesrrrboolrrr'r'r'r(sh          ! "  .