a `9,@s,dZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZd dlmZd dlZd dlZd dlZd dlZd dlZddZddZd$ddZd%ddZeddZddZddZddZGd d!d!ejZGd"d#d#ej Z!dS)&z-Utility code for constructing importers, etc.)abc)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 tt|S)zBReturn the hash of *source_bytes* as used in hash-based pyc files.)_imp source_hashr) source_bytesr1/usr/local/src/Python-3.9.6/Lib/importlib/util.pyrsrcCs\|ds|S|s&tdt|dd}|D]}|dkr>qH|d7}q.t||d||S)z2Resolve a relative module name to an absolute one..zno package specified for z% (required for relative module names)r rN) startswith ImportErrorreprr)namepackagelevel characterrrr resolve_names  rcCsv|tjvrt||Stj|}|dur*dSz |j}Wn"tyVtd|dYn0|durntd||SdS)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 not set{}.__spec__ is None)sysmodulesr__spec__AttributeError ValueErrorformat)rpathmodulespecrrr_find_spec_from_path*s     r(c Cs|drt||n|}|tjvr|dd}|rt|dgd}z |j}Wqty}z&td|d||d|WYd}~qd}~00nd}t ||Stj|}|durdSz |j }Wn"tyt d |dYn0|durt d ||SdS) 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 )rNrr) rrrr rpartition __import__r)r"ModuleNotFoundErrorrr!r#r$) rrfullname parent_nameparent parent_pather&r'rrr find_specIs8      r3c cs|tjv}tj|}|s6tt|}d|_|tj|<zLz |VWn6tyx|stz tj|=WntyrYn0Yn0Wd|_nd|_0dS)NTF)rr gettypeZ__initializing__ ExceptionKeyError)r is_reloadr&rrr_module_to_loadvs        r9cstfdd}|S)zOSet __package__ on the returned module. This function is deprecated. csVtjdtdd|i|}t|dddurR|j|_t|dsR|jdd|_|S)N7The import system now takes care of this automatically. stacklevel __package__r)rr )warningswarnDeprecationWarninggetattr__name__r>hasattrr+)argskwargsr&fxnrrset_package_wrappers z(set_package..set_package_wrapper functoolswraps)rHrIrrGr set_packages rMcstfdd}|S)zNSet __loader__ on the returned module. This function is deprecated. cs@tjdtdd|g|Ri|}t|dddur<||_|S)Nr:r;r< __loader__)r?r@rArBrN)selfrErFr&rGrrset_loader_wrappersz&set_loader..set_loader_wrapperrJ)rHrPrrGr set_loadersrQcs*tjdtddtfdd}|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 st|p}||_z||}Wnttfy4Yn0|rB||_n|dd|_||g|Ri|WdS1s~0YdS)Nrr )r9rN is_packagerr"r>r+)rOr.rErFr&rRrGrrmodule_for_loader_wrappers z4module_for_loader..module_for_loader_wrapper)r?r@rArKrL)rHrSrrGrmodule_for_loaders rTc@s eZdZdZddZddZdS) _LazyModulezKA subclass of the module type which triggers loading upon attribute access.c Cstj|_|jj}|jjd}|jjd}|j}i}|D]:\}}||vrT|||<q:t||t||kr:|||<q:|jj ||t j vrt|tt j |krt d|d|j|t||S)z8Trigger the load of the module and return the attribute.__dict__ __class__zmodule object for z. substituted in sys.modules during a lazy load)types ModuleTyperWr!r loader_staterVitemsidloader exec_modulerr r#updaterB) rOattrZ original_nameZ attrs_thenZ original_typeZ attrs_nowZ attrs_updatedkeyvaluerrr__getattribute__s"      z_LazyModule.__getattribute__cCs||t||dS)z/Trigger the load and then perform the deletion.N)rcdelattr)rOr`rrr __delattr__s z_LazyModule.__delattr__N)rC __module__ __qualname____doc__rcrerrrrrUs#rUc@s@eZdZdZeddZeddZddZdd Z d d Z d S) LazyLoaderzKA loader that creates a module which defers loading until attribute access.cCst|dstddS)Nr^z loader must define exec_module())rD TypeError)r]rrrZ__check_eager_loaders zLazyLoader.__check_eager_loadercsfddS)z>Construct a callable which returns the eager loader made lazy.cs|i|SNr)rErFclsr]rrz$LazyLoader.factory..)_LazyLoader__check_eager_loaderrlrrlrfactorys zLazyLoader.factorycCs||||_dSrk)rpr])rOr]rrr__init__s zLazyLoader.__init__cCs |j|Srk)r] create_module)rOr'rrrrsszLazyLoader.create_modulecCs@|j|j_|j|_i}|j|d<|j|d<||j_t|_dS)zMake the module load lazily.rVrWN)r]r!rNrVcopyrWrZrU)rOr&rZrrrr^ s  zLazyLoader.exec_moduleN) rCrfrgrh staticmethodrp classmethodrqrrrsr^rrrrri s  ri)N)N)"rhr _bootstraprrrr_bootstrap_externalrrr r r r Z contextlibrrrKrrXr?rrr(r3r9rMrQrTrYrUZLoaderrirrrrs8              - '/