e f;@sdZddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z d d l m Z d d l Z d d l Z d d lZd dZd ddZd ddZe ddZddZddZddZd S)z-Utility code for constructing importers, etc.) MAGIC_NUMBER)cache_from_source) decode_source)source_from_cache)spec_from_loader)spec_from_file_location) _resolve_name) _find_spec)contextmanagerNcCs||jds|S|s1tdj|nd}x(|D] }|dkrTPn|d7}q>Wt||d||S)z2Resolve a relative module name to an absolute one..z,{!r} is not a relative name (no leading dot)r rN) startswith ValueErrorformatr)namepackagelevel characterr3/opt/alt/python34/lib64/python3.4/importlib/util.py resolve_names   rc Cs|tjkrt||Stj|}|dkr9dSy |j}Wn'tk rotdj|Yn)X|dkrtdj|n|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. Nz{}.__spec__ is not setz{}.__spec__ is None)sysmodulesr __spec__AttributeErrorrr)rpathmodulespecrrr_find_spec_from_path!s      rc Cs|jdrt||n|}|tjkr|jdd}|rqt|ddg}t||jSt|dSn|tj|}|dkrdSy |j}Wn't k rt dj |Yn)X|dkrt dj |n|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. r r fromlist__path__Nz{}.__spec__ is not setz{}.__spec__ is None) r rrr rpartition __import__r r rrrr)rrfullname parent_nameparentrrrrr find_spec@s"$     r&ccs|tjk}tjj|}|sRtt|}d|_|tj|tk r|sytj|=Wqtk rYqXnYnXWdd|_XdS)NTF)rrgettype__initializing__ ExceptionKeyError)r is_reloadrrrr_module_to_loadhs    r-cs%tjfdd}|S)zOSet __package__ on the returned module. This function is deprecated. cs{tjdtdd||}t|dddkrw|j|_t|dsw|jjdd|_qwn|S)Nz7The import system now takes care of this automatically. stacklevel __package__r r r )warningswarnDeprecationWarninggetattr__name__r0hasattrr!)argskwargsr)fxnrrset_package_wrappers   z(set_package..set_package_wrapper) functoolswraps)r9r:r)r9r set_packages! r=cs%tjfdd}|S)zNSet __loader__ on the returned module. This function is deprecated. csPtjdtdd|||}t|dddkrL||_n|S)Nz7The import system now takes care of this automatically.r.r/ __loader__)r1r2r3r4r>)selfr7r8r)r9rrset_loader_wrappers    z&set_loader..set_loader_wrapper)r;r<)r9r@r)r9r set_loaders!rAcs;tjdtddtjfdd}|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. z7The import system now takes care of this automatically.r.r/cst|y}||_y|j|}Wnttfk rEYn)X|rX||_n|jdd|_||||SWdQXdS)Nr r )r-r> is_package ImportErrorrr0r!)r?r#r7r8rrB)r9rrmodule_for_loader_wrappers  z4module_for_loader..module_for_loader_wrapper)r1r2r3r;r<)r9rDr)r9rmodule_for_loaders  !rE)__doc__ _bootstraprrrrrrrr contextlibr r;rr1rrr&r-r=rArErrrrs&    (