RhS2ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z m Z ddlmZmZddlmZe ej&efZeZdZedde edefd Zd ej&de efd Zej4d e edej&fd Zej8d edej&fdZej8d ddej&fdZdZd ej&fdZej@ dejBddZ"dZ#dede$fdZ%ej4dZ&e&j9ejNej@dZej@dejPfdZ)ej@dZ*dZ+y)N)UnionOptionalcast)ResourceReader Traversable) wrap_specc`ttjffd }|S)a 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 c|ur1|ur ||Stjdtd|S|urS|S)Nz/First parameter to files is renamed to 'anchor') stacklevel)warningswarnDeprecationWarning)anchorpackagefunc undefineds 2/usr/lib/python3.12/importlib/resources/_common.pywrapperz"package_to_anchor..wrapper!sZ ) #Y&FG,, MMA"  = y 6MF|)object functoolswraps)rrrs` @rpackage_to_anchorrs3I__T )   Nrrreturnc*tt|S)z3 Get a Traversable resource for an anchor. ) from_packageresolve)rs rfilesr 3s  ((rrcr|j}t|jdd}|y||jS)z? Return the package's loader if it's a ResourceReader. get_resource_readerN)__spec__getattrloadernamerspecreaders rr"r";s9   D T[["7 >F ~ $)) rcandc6ttj|SN)rtypes ModuleTyper*s rrrKs   $ ''rc,tj|Sr,) importlib import_moduler/s r_r3Ps  " "4 ((rcBttjdS)N__name__)r _infer_caller f_globalsr/s rr3r3Us =?,,Z8 99rcd}d}tj|tj}tj||}t |j S)zS Walk the stack and find the frame of the first caller not in this module. c(|jtk(Sr,)filename__file__ frame_infos r is_this_filez#_infer_caller..is_this_file_s""h..rc |jdk(S)Nr)functionr<s r is_wrapperz!_infer_caller..is_wrapperbs""i//r) itertools filterfalseinspectstacknextframe)r>rA not_this_filecallerss rr6r6ZsH /0)), HM##J >G =  rct|}|jj|j}|j S)z= Return a Traversable object for the given package. )r r%r"r&r r's rrrks2 W D [[ , ,TYY 7F <<>r) _os_removec#pKtj|\}} tj||tj|~t j | ||y#tj|wxYw#t$rYywxYw# ||w#t$rYwwxYwxYwwN)suffix)tempfilemkstemposwriteclosepathlibPathFileNotFoundError)r)rNrKfdraw_paths r _tempfilerYus##62LB   HHR " HHRL ll8$$  x HHRL !     x     soB6A0-B'B /B60BB BB6BB6B3B$#B3$ B0-B3/B00B33B6cDt|j|jSrM)rY read_bytesr&paths r _temp_filer^s T__TYY 77rr]ctjt5|jcdddS#1swYyxYw)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. NF) contextlibsuppressrVis_dirr\s r_is_present_dirrcs4   . /{{} s4=cDt|r t|St|S)zu Given a Traversable object, return that object as a path on the local file system in a context manager. )rc _temp_dirr^r\s ras_filerfs .d39T?ID9IIrc#K|yw)z7 Degenerate behavior for pathlib.Path objects. Nr\s rr3r3s Jsdirc#hK|5}tj|dddy#1swYyxYww)zD Wrap tempfile.TemporyDirectory to return a pathlib object. N)rTrU)riresults r _temp_pathrls0 #ll6""###s2& 2/2c#K|jsJttj5}t ||dddy#1swYyxYww)zt Given a traversable dir, recursively replicate the whole tree to the file system in a context manager. N)rbrlrOTemporaryDirectory_write_contents)r]temp_dirs rreresJ ;;== H//1 2.hh--...s0AA  A AAc|j|j}|jr3|j|j D]}t |||S|j |j|Sr,)joinpathr&rbmkdiriterdirro write_bytesr[)targetsourcechilditems rrorosk OOFKK (E }} NN$ )D E4 ( ) L &++-. Lrr,)),rQrTrOrr`r-r1rDrrBtypingrrrabcrr _adaptersr r.strPackageAnchorrr r"singledispatchrregisterr3r6rcontextmanagerremoverYr^boolrcrfrUrnrlrerorhrrrs  ((,   #% & <)(6")k)) !1!1 h~6N   ((6"(u'7'7(( )C)E$$)) :D:U%%::"%**   yy 48 + $  JJ ',,   #H//## ..r