U AT^$c @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)/iNi)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)hasattrrZsubmodule_search_locationsZ TypeErrorformatnamer)packageZmoduler!+/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)osrZsplitZ ValueErrorr)rparentZ file_namer!r!r"_normalize_path6sr&)r rcCs,|j}t|jdr(ttj|j|jSdS)Nget_resource_reader)rrloaderr resources_abcResourceReaderr'r)r Zspecr!r!r"_get_resource_readerBs   r+cCs&|jjdks|jjs"td|dS)NzPackage has no location )rorigin has_locationFileNotFoundError)r r!r!r"_check_locationPsr/)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)NZrb)modeget_data{!r} resource not found in {!r})r&r#r+ open_resourcer/r$rabspathrr,dirnamejoinopenOSErrorrrr(rrr2rrr.r) r r0readerabsolute_package_path package_path full_pathr(data package_namemessager!r!r"rUs2    utf-8strict)r r0encodingerrorsrc 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)NZr)r1rCrDr2r3)r&r#r+rr4r/r$rr5rr,r6r7r8r9rrr(rrr2rrr.r) r r0rCrDr:r;r<r=r(r>r?r@r!r!r"rts2   c Cs:t|}t|}t||}|W5QRSQRXdSN)r&r#rread)r r0fpr!r!r"rs c Cs>t|}t|}t||||}|W5QRSQRXdSrE)r&r#rrF)r r0rCrDrGr!r!r"rs c cst|}t|}t|}|dk rNzt||VWdStk rJYqVXnt|t|jjj }||}| r||Vnvt ||}| }W5QRXt \}}z$t||t|t|VW5zt|Wntk rYnXXdSrE)r&r#r+rZ resource_pathr.r/rr,r%ZexistsrrFtempfileZmkstempr$ZremoveZwriteZclose) r r0r:package_directoryZ file_pathrGr>ZfdZraw_pathr!r!r"rs2     )r rrc Cs|t|}t|t|}|dk r*||Sztt|}Wnttfk rTYdSX||krbdSt|j j j |}| S)NF) r#r&r+rZsetrZNotADirectoryErrorr.rrr,r%Zis_file)r rr:Zpackage_contentsrr!r!r"rs cCsTt|}t|}|dk r |S|jjdks4|jjs8dSt|jjj}t |SdS)Nr!) r#r+rrr,r-rr%r$Zlistdir)r r:rIr!r!r"rsrArBrJ)2r$rHZrr)Z contextlibrrZ importlibrZ importlib.abcrZiorrZpathlibrZtypesrZtypingr r r r r rZ typing.iorrZ zipimportrZ__all__ZstrrZPathLikerr#r&r*r+r/rrZbytesrrrZboolrrr!r!r!r"Zsh          ! "  ,