fX*dZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZd dlZd dlZd dlZd dlZdZdZddZddZGddZGddej0ZGddeZy)z-Utility code for constructing importers, etc.)Loader)module_from_spec) _resolve_name)spec_from_loader) _find_spec) MAGIC_NUMBER)_RAW_MAGIC_NUMBER)cache_from_source) decode_source)source_from_cache)spec_from_file_locationNc6tjt|S)zBReturn the hash of *source_bytes* as used in hash-based pyc files.)_imp source_hashr ) source_bytess %/usr/lib/python3.12/importlib/util.pyrrs   -| <<c|jds|S|stdt|dd}|D]}|dk7rn|dz }t||d||S)z2Resolve a relative module name to an absolute one..zno package specified for z% (required for relative module names)rrN) startswith ImportErrorreprr)namepackagelevel characters r resolve_namers| ??3  5d4j\BAAB B E      efw 66rc|tjvr t||Stj|}|y |j}|t |d|S#t $rt |ddwxYw)aReturn the spec for the specified module. First, sys.modules is checked to see if the module was already imported. If so, then sys.modules[name].__spec__ is returned. If that happens to be set to None, then ValueError is raised. If the module is not in sys.modules, then sys.meta_path is searched for a suitable spec with the value of 'path' given to the finders. None is returned if no spec could be found. Dotted names do not have their parent packages implicitly imported. You will most likely need to explicitly import all parent packages in the proper order for a submodule to get the correct spec. N.__spec__ is None.__spec__ is not set)sysmodulesr__spec__ ValueErrorAttributeError)rpathmodulespecs r_find_spec_from_pathr*(s 3;;$%%T" > ??D| D6):!;<<K  Fv%9:; E Fs AA-c|jdr t||n|}|tjvr@|j dd}|rt |dg} |j }nd}t||Stj|}|y |j}|t|d |S#t$r}td|d|||d}~wwxYw#t$rt|d dwxYw) aReturn the spec for the specified module. First, sys.modules is checked to see if the module was already imported. If so, then sys.modules[name].__spec__ is returned. If that happens to be set to None, then ValueError is raised. If the module is not in sys.modules, then sys.meta_path is searched for a suitable spec with the value of 'path' given to the finders. None is returned if no spec could be found. If the name is for submodule (contains a dot), the parent module is automatically imported. The name and package arguments work the same as importlib.import_module(). In other words, relative module names (with leading dots) work. rr__path__)fromlistz __path__ attribute not found on z while trying to find )rNr r!) rrr"r# rpartition __import__r,r&ModuleNotFoundErrorrr$r%) rrfullname parent_nameparent parent_pather(r)s r find_specr6Gs"/3ooc.B|D'*Hs{{"))#.q1  zlCF P$oo K(K00X& > ??D| D6):!;<<K%" P)6{oF,,4<9?GINOP P Fv%9:; E Fs$ B' C ' C 0CC  C%c2eZdZdZdZdZdZedZy)+_incompatible_extension_module_restrictionsagA context manager that can temporarily skip the compatibility check. NOTE: This function is meant to accommodate an unusual case; one which is likely to eventually go away. There's is a pretty good chance this is not what you were looking for. WARNING: Using this function to disable the check can lead to unexpected behavior and even crashes. It should only be used during extension module development. If "disable_check" is True then the compatibility check will not happen while the context manager is active. Otherwise the check *will* happen. Normally, extensions that do not support multiple interpreters may not be imported in a subinterpreter. That implies modules that do not implement multi-phase init or that explicitly of out. Likewise for modules import in a subinterpeter with its own GIL when the extension does not support a per-interpreter GIL. This implies the module does not have a Py_mod_multiple_interpreters slot set to Py_MOD_PER_INTERPRETER_GIL_SUPPORTED. In both cases, this context manager may be used to temporarily disable the check for compatible extension modules. You can get the same effect as this function by implementing the basic interface of multi-phase init (PEP 489) and lying about support for multiple interpreters (or per-interpreter GIL). c$t||_yN)bool disable_check)selfr<s r__init__z4_incompatible_extension_module_restrictions.__init__s!-0rcNtj|j|_|Sr:)r'_override_multi_interp_extensions_checkoverrideoldr=s r __enter__z5_incompatible_extension_module_restrictions.__enter__s?? N rcJ|j}|`tj|yr:)rBrr@)r=argsrBs r__exit__z4_incompatible_extension_module_restrictions.__exit__shh H 44S9rc"|jrdSdS)Nr)r<rCs rrAz4_incompatible_extension_module_restrictions.overrides''r.Q.rN) __name__ __module__ __qualname____doc__r>rDrGpropertyrArrr8r8xs*>1: //rr8ceZdZdZdZdZy) _LazyModulezKA subclass of the module type which triggers loading upon attribute access.ctj|d}|j}|d5tj|dtur#|drtj||cdddSd|d<tj|d}|j}|d}|}i}|j D]2\} } | |vr| || <t || t || k7s.| || <4|jj||tjvr7t |t tj|k7rtd|d |j|tj|_dddt!||S#1swYxYw) z8Trigger the load of the module and return the attribute.r$lock __class__ is_loadingNT__dict__zmodule object for z. substituted in sys.modules during a lazy load)object__getattribute__ loader_staterQritemsidloader exec_moduler"r#r%updatetypes ModuleTyperTgetattr) r=attrr$rYrV original_name attrs_then attrs_now attrs_updatedkeyvalues rrXz_LazyModule.__getattribute__s**4<,, & !+ 2&&t[9[H  -!224>+ 2+ 2.2 \*!224D !) **5 $ " "+//"33JC*,-2 c*IcN+r*S//BB-2 c* 3++D1!CKK/$x2ckk-&@#AA(+=m=NO1*122  .!&!1!1W+ 2ZtT""[+ 2+ 2s8E=*A-E=BE==Fc>|j|t||y)z/Trigger the load and then perform the deletion.N)rXdelattr)r=rbs r __delattr__z_LazyModule.__delattr__s d#drN)rJrKrLrMrXrkrOrrrQrQsU1#frrQcBeZdZdZedZedZdZdZ dZ y) LazyLoaderzKA loader that creates a module which defers loading until attribute access.c2t|ds tdy)Nr]z loader must define exec_module())hasattr TypeError)r\s r__check_eager_loaderzLazyLoader.__check_eager_loadersv}->? ?.rc4jfdS)z>Construct a callable which returns the eager loader made lazy.c |i|Sr:rO)rFkwargsclsr\s rz$LazyLoader.factory..ss64+B6+B'Cr)_LazyLoader__check_eager_loader)rur\s``rfactoryzLazyLoader.factorys   (CCrc4|j|||_yr:)rwr\)r=r\s rr>zLazyLoader.__init__s !!&) rc8|jj|Sr:)r\ create_module)r=r)s rr{zLazyLoader.create_modules{{((..rc(|j|j_|j|_i}|jj |d<|j |d<t j|d<d|d<||j_t|_y)zMake the module load lazily.rVrTrSFrUN) r\r$ __loader__rVcopyrT threadingRLockrYrQ)r=r(rYs rr]zLazyLoader.exec_modules{!% KK  #)??#7#7#9 Z $*$4$4 [!(0 V%* \"'3$&rN) rJrKrLrM staticmethodrw classmethodrxr>r{r]rOrrrmrms>U@@DD /'rrmr:)rM_abcr _bootstraprrrr_bootstrap_externalrr r r r r rr"rr_rrr*r6r8r`rQrmrOrrrst3(%("-22.28  = 7>*b././b<%""<~$'$'r