U  e@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z m Z ddlmZmZddlmZe ejefZeZddZed,e eedd d Zeje ed d d Zeje eejdddZejeejdddZejdejdddZddZejdddZej d-ej!dddZ"ddZ#ee$dd d!Z%ejd"d#Z&e&ej'ej d$dZej ej(d%d&d'Z)ej d(d)Z*d*d+Z+dS).N)UnionOptionalcast)ResourceReader Traversable) wrap_speccs(ttffdd }|S)a1 Replace 'package' parameter as 'anchor' and warn about the change. Other errors should fall through. >>> files('a', 'b') Traceback (most recent call last): TypeError: files() takes from 0 to 1 positional arguments but 2 were given Remove this compatibility in Python 3.14. csH|k r2|k r||Stjdtdd|S|kr@S|S)Nz/First parameter to files is renamed to 'anchor') stacklevel)warningswarnDeprecationWarning)anchorpackagefunc undefinedI/opt/hc_python/lib/python3.8/site-packages/importlib_resources/_common.pywrapper#s z"package_to_anchor..wrapper)object functoolswraps)rrrrrpackage_to_anchors r)rreturncCs tt|S)z3 Get a Traversable resource for an anchor. ) from_packageresolve)rrrrfiles5sr)rrcCs*|j}t|jdd}|dkr dS||jS)z? Return the package's loader if it's a ResourceReader. get_resource_readerN)__spec__getattrloadernamerspecreaderrrrr=s r)candrcCs ttj|SN)rtypes ModuleTyper&rrrrMsrcCs t|Sr') importlib import_moduler*rrr_Rsr-cCsttjdS)N__name__)r _infer_caller f_globalsr*rrrr-WscCs6dd}dd}t|t}t||}t|jS)zS Walk the stack and find the frame of the first caller not in this module. cSs |jtkSr')filename__file__ frame_inforrr is_this_fileasz#_infer_caller..is_this_filecSs |jdkS)Nr)functionr3rrr is_wrapperdsz!_infer_caller..is_wrapper) itertools filterfalseinspectstacknextframe)r5r7Z not_this_filecallersrrrr/\s  r/)rcCst|}|j|j}|S)z= Return a Traversable object for the given package. )rr!rr"rr#rrrrmsr) _os_removeccsltj|d\}}z2zt||W5t|X~t|VW5z ||Wntk rdYnXXdSN)suffix)tempfilemkstempFileNotFoundErrorosclosewritepathlibPath)r%rBr@fdraw_pathrrr _tempfilews   rMcCst|j|jdSrA)rM read_bytesr"pathrrr _temp_filesrQ)rPrc Cs*tt|W5QRSQRXdS)a Some Traversables implement ``is_dir()`` to raise an exception (i.e. ``FileNotFoundError``) when the directory doesn't exist. This function wraps that call to always return a boolean and only return True if there's a dir and it exists. F) contextlibsuppressrEis_dirrOrrr_is_present_dirs rUcCst|rt|St|S)zu Given a Traversable object, return that object as a path on the local file system in a context manager. )rU _temp_dirrQrOrrras_filesrWccs |VdS)z7 Degenerate behavior for pathlib.Path objects. NrrOrrrr-s)dirc cs |}t|VW5QRXdS)zD Wrap tempfile.TemporyDirectory to return a pathlib object. N)rIrJ)rXresultrrr _temp_pathsrZc cs4|s ttt}t||VW5QRXdS)zt Given a traversable dir, recursively replicate the whole tree to the file system in a context manager. N)rTAssertionErrorrZrCTemporaryDirectory_write_contents)rPtemp_dirrrrrVs rVcCsH||j}|r6||D]}t||q$n|||Sr')joinpathr"rTmkdiriterdirr] write_bytesrN)targetsourcechilditemrrrr]s  r])N)r?),rFrIrCrrRr(r+r:r r8typingrrrabcrrZfuture.adaptersrr)strPackageZAnchorrrrsingledispatchrregisterr-r/rcontextmanagerremoverMrQboolrUrWrJr\rZrVr]rrrrsV