o 0¦iß,ã@s*dZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZd dlmZd dlZd dlZd dlZd dlZd dlZdd„Zdd„Zd$dd„Zd$dd„Zedd„ƒZdd„Zdd„Zdd„ZGd d!„d!ejƒZGd"d#„d#eƒZ dS)%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_locationé)ÚcontextmanagerNcCs t t|¡S)zBReturn the hash of *source_bytes* as used in hash-based pyc files.)Ú_impÚ source_hashr)Ú source_bytes©rú5/opt/alt/python310/lib64/python3.10/importlib/util.pyrs rcCs\| d¡s|S|stdt|ƒ›d�ƒ‚d}|D] }|dkrn|d7}qt||d…||ƒS)z2Resolve a relative module name to an absolute one.Ú.zno package specified for z% (required for relative module names)r rN)Ú startswithÚ ImportErrorÚreprr)ÚnameÚpackageÚlevelÚ characterrrrÚ resolve_names  rcCsn|tjvr t||ƒStj|}|durdSz|j}Wnty)td |¡ƒd‚w|dur5td |¡ƒ‚|S)a‡Return 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 not setú{}.__spec__ is None)ÚsysÚmodulesrÚ__spec__ÚAttributeErrorÚ ValueErrorÚformat)rÚpathÚmoduleÚspecrrrÚ_find_spec_from_path*s     ÿr(c Csè| d¡r t||ƒn|}|tjvrG| d¡d}|r@t|dgd�}z|j}Wnty?}z td|›d|›�|d�|‚d}~wwd}t ||ƒStj|}|durRdSz|j }Wntyft d   |¡ƒd‚w|durrt d   |¡ƒ‚|S) a¯Return 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 )rNrr) rrrr Ú rpartitionÚ __import__r)r"ÚModuleNotFoundErrorrr!r#r$) rrÚfullnameÚ parent_nameÚparentÚ parent_pathÚer&r'rrrÚ find_specIs>  ÿþþ€ÿ    ÿr3c csœ�|tjv}tj |¡}|sttƒ|ƒ}d|_|tj|<z-z|VWnty=|s;ztj|=Wn ty:YnwYnwWd|_dSWd|_dSd|_w)NTF)rr ÚgetÚtypeÚ__initializing__Ú ExceptionÚKeyError)rÚ is_reloadr&rrrÚ_module_to_loadvs,€        ÿ€üÿ €r:cót ˆ¡‡fdd„ƒ}|S)zOSet __package__ on the returned module. This function is deprecated. csVtjdtdd�ˆ|i|¤Ž}t|ddƒdur)|j|_t|dƒs)|j d¡d|_|S)NúkThe import system now takes care of this automatically; this decorator is slated for removal in Python 3.12é©Ú stacklevelÚ __package__r)rr )ÚwarningsÚwarnÚDeprecationWarningÚgetattrÚ__name__r@Úhasattrr+)ÚargsÚkwargsr&©ÚfxnrrÚset_package_wrapper–sþ z(set_package..set_package_wrapper©Ú functoolsÚwraps)rJrKrrIrÚ set_package�s rOcr;)zNSet __loader__ on the returned module. This function is deprecated. cs@tjdtdd�ˆ|g|¢Ri|¤Ž}t|ddƒdur||_|S)Nr<r=r>Ú __loader__)rArBrCrDrP)ÚselfrGrHr&rIrrÚset_loader_wrapperªsþz&set_loader..set_loader_wrapperrL)rJrRrrIrÚ set_loader¤srScs*tjdtdd�t ˆ¡‡fdd„ƒ}|S)a*Decorator to handle selecting the proper module for loaders. The decorated function is passed the module to use instead of the module name. The module passed in to the function is either from sys.modules if it already exists or is a new module. If the module is new, then __name__ is set the first argument to the method, __loader__ is set to self, and __package__ is set accordingly (if self.is_package() is defined) will be set before it is passed to the decorated function (if self.is_package() does not work for the module it will be set post-load). If an exception is raised and the decorator created the module it is subsequently removed from sys.modules. The decorator assumes that the decorated function takes the module name as the second argument. r<r=r>c sŒt|ƒ�8}||_z| |¡}Wn ttfyYnw|r!||_n| d¡d|_ˆ||g|¢Ri|¤ŽWdƒS1s?wYdS)Nrr )r:rPÚ is_packagerr"r@r+)rQr.rGrHr&rTrIrrÚmodule_for_loader_wrapperËs ÿ$ôz4module_for_loader..module_for_loader_wrapper)rArBrCrMrN)rJrUrrIrÚmodule_for_loader¶s þrVc@s eZdZdZdd„Zdd„ZdS)Ú _LazyModulezKA subclass of the module type which triggers loading upon attribute access.cCs¾tj|_|jj}|jjd}|j}i}| ¡D]\}}||vr$|||<qt||ƒt||ƒkr4|||<q|jj   |¡|t j vrTt|ƒtt j |ƒkrTt d|›d�ƒ‚|j |¡t||ƒS)z8Trigger the load of the module and return the attribute.Ú__dict__zmodule object for z. substituted in sys.modules during a lazy load)ÚtypesÚ ModuleTypeÚ __class__r!rÚ loader_staterXÚitemsÚidÚloaderÚ exec_modulerr r#ÚupdaterD)rQÚattrÚ original_nameÚ attrs_thenÚ attrs_nowÚ attrs_updatedÚkeyÚvaluerrrÚ__getattribute__âs"  €   z_LazyModule.__getattribute__cCs| |¡t||ƒdS)z/Trigger the load and then perform the deletion.N)riÚdelattr)rQrbrrrÚ __delattr__s z_LazyModule.__delattr__N)rEÚ __module__Ú __qualname__Ú__doc__rirkrrrrrWÞs "rWc@s@eZdZdZedd„ƒZedd„ƒZdd„Zdd „Z d d „Z d S) Ú LazyLoaderzKA loader that creates a module which defers loading until attribute access.cCst|dƒs tdƒ‚dS)Nr`z loader must define exec_module())rFÚ TypeError)r_rrrÚ__check_eager_loaders ÿzLazyLoader.__check_eager_loadercsˆ ˆ¡‡‡fdd„S)z>Construct a callable which returns the eager loader made lazy.csˆˆ|i|¤ŽƒS©Nr)rGrH©Úclsr_rrÚsz$LazyLoader.factory..)Ú_LazyLoader__check_eager_loaderrsrrsrÚfactorys zLazyLoader.factorycCs| |¡||_dSrr)rvr_)rQr_rrrÚ__init__s  zLazyLoader.__init__cCs |j |¡Srr)r_Ú create_module)rQr'rrrrys zLazyLoader.create_modulecCs@|j|j_|j|_i}|j ¡|d<|j|d<||j_t|_dS)zMake the module load lazily.rXr[N)r_r!rPrXÚcopyr[r\rW)rQr&r\rrrr`"s   zLazyLoader.exec_moduleN) rErlrmrnÚ staticmethodrvÚ classmethodrwrxryr`rrrrro s   rorr)!rnÚ_abcrÚ _bootstraprrrrÚ_bootstrap_externalrrr r r r Ú contextlibrrrMrrYrArrr(r3r:rOrSrVrZrWrorrrrÚs:              - (.