a Z^9,c@s(ddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z d d lmZd dlZd dlZd dlZd dlZd dlZddZddZd#ddZd$ddZeddZddZddZddZGdd d ejZGd!d"d"ejZ dS)%)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|SN)_imp source_hashr)Z source_bytesr&/usr/lib64/python3.9/importlib/util.pyrsrcCs\|ds|S|s&tdt|dd}|D]}|dkr>qH|d7}q.t||d||S)N.zno package specified for z% (required for relative module names)r r) startswith ImportErrorZreprr)namepackageZlevelZ characterrrr resolve_names   rcCsv|tjvrt||Stj|}|dur*dSz |j}Wn"tyVtd|dYn0|durntd||SdS)N{}.__spec__ is not set{}.__spec__ is None)sysmodulesr__spec__AttributeError ValueErrorformat)rZpathmodulespecrrr_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) Nrr __path__)Zfromlistz __path__ attribute not found on z while trying to find )rrr) rrrr rpartitionZ __import__r$rZModuleNotFoundErrorrrrr ) rrfullnameZ parent_nameZparentZ parent_pathZer!r"rrr find_specIs<      r'c cs|tjv}tj|}|s6tt|}d|_|tj|<zLz |VWn6tyx|stz tj|=WntyrYn0Yn0Wd|_nd|_0dS)NTF)rrZgetZtypeZ__initializing__Z ExceptionZKeyError)rZ is_reloadr!rrr_module_to_loadvs        r(ctfdd}|S)NcsVtjdtdd|i|}t|dddurR|j|_t|dsR|jdd|_|S)N7The import system now takes care of this automatically.Z stacklevel __package__r$rr )warningswarnDeprecationWarninggetattr__name__r-hasattrr%)argskwargsr!fxnrrset_package_wrappers z(set_package..set_package_wrapper functoolswraps)r7r8rr6r set_packages r<cr))Ncs@tjdtdd|g|Ri|}t|dddur<||_|S)Nr*r+r, __loader__)r.r/r0r1r=)selfr4r5r!r6rrset_loader_wrappersz&set_loader..set_loader_wrapperr9)r7r?rr6r set_loadersr@cs*tjdtddtfdd}|S)Nr*r+r,c st|p}||_z||}Wnttfy4Yn0|rB||_n|dd|_||g|Ri|WdS1s~0YdS)Nrr )r(r= is_packagerrr-r%)r>r&r4r5r!rAr6rrmodule_for_loader_wrappers z4module_for_loader..module_for_loader_wrapper)r.r/r0r:r;)r7rBrr6rmodule_for_loaders rCc@seZdZddZddZdS) _LazyModulec 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)N__dict__ __class__zmodule object for z. substituted in sys.modules during a lazy load)types ModuleTyperFrr loader_staterEZitemsZidloader exec_modulerrrZupdater1) r>attrZ original_nameZ attrs_thenZ original_typeZ attrs_nowZ attrs_updatedZkeyZvaluerrr__getattribute__s&       z_LazyModule.__getattribute__cCs||t||dSr)rMZdelattr)r>rLrrr __delattr__s z_LazyModule.__delattr__N)r2 __module__ __qualname__rMrNrrrrrDs#rDc@s<eZdZeddZeddZddZddZd d Z d S) LazyLoadercCst|dstddS)NrKz loader must define exec_module())r3Z TypeError)rJrrrZ__check_eager_loaders zLazyLoader.__check_eager_loadercsfddS)Ncs|i|Srr)r4r5ZclsrJrrZsz$LazyLoader.factory..)_LazyLoader__check_eager_loaderrRrrRrfactorys zLazyLoader.factorycCs||||_dSr)rSrJ)r>rJrrr__init__s zLazyLoader.__init__cCs |j|Sr)rJ create_module)r>r"rrrrVszLazyLoader.create_modulecCs@|j|j_|j|_i}|j|d<|j|d<||j_t|_dS)NrErF)rJrr=rEZcopyrFrIrD)r>r!rIrrrrK s  zLazyLoader.exec_moduleN) r2rOrPZ staticmethodrSZ classmethodrTrUrVrKrrrrrQ s  rQrr)!ZrZ _bootstraprrrrZ_bootstrap_externalrrrr r r Z contextlibr rr:rrGr.rrr#r'r(r<r@rCrHrDZLoaderrQrrrrZs6              - '/