B /g^I2 @sdZddlmZddlmZddlmZy ddlZWn2ek rfZzejdkrRdZWddZ[XYnXy ddl Z Wn&ek rZzeZ WddZ[XYnXddl Z ddl Z dd Z Gd d d e j d ZGd ddeZe eejejejejGdddeZe eejGddde j d ZGdddeZGdddeZe eejejGdddeZe eejGdddejeeZe eejejGdddejeeZe eejGddde j d Ze eejdS)z(Abstract base classes related to import.) _bootstrap)_bootstrap_external) machineryN_frozen_importlibc Gs`xZ|D]R}||tdk rytt|j}Wn tk rLtt|j}YnX||qWdS)N)registerrgetattr__name__AttributeError_frozen_importlib_external) abstract_clsclassescls frozen_clsr%/usr/lib64/python3.7/importlib/abc.py _registers  rc@s eZdZdZejdddZdS)Findera<Legacy abstract base class for import finders. It may be subclassed for compatibility with legacy third party reimplementations of the import system. Otherwise, finder implementations should derive from the more specific MetaPathFinder or PathEntryFinder ABCs. Deprecated since Python 3.3 NcCsdS)zAn abstract method that should find a module. The fullname is a str and the optional path is a str or None. Returns a Loader object or None. Nr)selffullnamepathrrr find_module*szFinder.find_module)N)r __module__ __qualname____doc__abcabstractmethodrrrrrrs r) metaclassc@s eZdZdZddZddZdS)MetaPathFinderz8Abstract base class for import finders on sys.meta_path.cCs<tjdtddt|dsdS|||}|dk r8|jSdS)a_Return a loader for the module. If no module is found, return None. The fullname is a str and the path is a list of strings or None. This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method. zxMetaPathFinder.find_module() is deprecated since Python 3.4 in favor of MetaPathFinder.find_spec() (available since 3.4)) stacklevel find_specN)warningswarnDeprecationWarninghasattrr!loader)rrrfoundrrrr9s   zMetaPathFinder.find_modulecCsdS)zAn optional method for clearing the finder's cache, if any. This method is used by importlib.invalidate_caches(). Nr)rrrrinvalidate_cachesNsz MetaPathFinder.invalidate_cachesN)r rrrrr(rrrrr2src@s&eZdZdZddZejZddZdS)PathEntryFinderz>Abstract base class for path entry finders used by PathFinder.cCs\tjdtddt|ds"dgfS||}|dk rP|js@g}n|j}|j|fSdgfSdS)a[Return (loader, namespace portion) for the path entry. The fullname is a str. The namespace portion is a sequence of path entries contributing to part of a namespace package. The sequence may be empty. If loader is not None, the portion will be ignored. The portion will be discarded if another path entry finder locates the module as a normal module or package. This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() is provided than backwards-compatible functionality is provided. zzPathEntryFinder.find_loader() is deprecated since Python 3.4 in favor of PathEntryFinder.find_spec() (available since 3.4)r)r r!N)r"r#r$r%r!submodule_search_locationsr&)rrr'portionsrrr find_loader^s   zPathEntryFinder.find_loadercCsdS)zAn optional method for clearing the finder's cache, if any. This method is used by PathFinder.invalidate_caches(). Nr)rrrrr(sz!PathEntryFinder.invalidate_cachesN) r rrrr,r_find_module_shimrr(rrrrr)Ws r)c@s(eZdZdZddZddZddZdS) Loaderz'Abstract base class for import loaders.cCsdS)zReturn a module to initialize and into which to load. This method should raise ImportError if anything prevents it from creating a new module. It may return None to indicate that the spec should create the new module. Nr)rspecrrr create_moduleszLoader.create_modulecCst|dstt||S)aReturn the loaded module. The module must be added to sys.modules and have import-related attributes set properly. The fullname is a str. ImportError is raised on failure. This method is deprecated in favor of loader.exec_module(). If exec_module() exists then it is used to provide a backwards-compatible functionality for this method. exec_module)r% ImportErrorr_load_module_shim)rrrrr load_modules zLoader.load_modulecCstdS)zReturn a module's repr. Used by the module type when the method does not raise NotImplementedError. This method is deprecated. N)NotImplementedError)rmodulerrr module_reprs zLoader.module_reprN)r rrrr0r4r7rrrrr.s r.c@seZdZdZejddZdS)ResourceLoaderzAbstract base class for loaders which can return data from their back-end storage. This ABC represents one of the optional protocols specified by PEP 302. cCstdS)zwAbstract method which when implemented should return the bytes for the specified path. The path must be a str.N)OSError)rrrrrget_dataszResourceLoader.get_dataN)r rrrrrr:rrrrr8sr8c@sLeZdZdZddZddZejddZe d d d Z e j j Z e j jZd S) InspectLoaderzAbstract base class for loaders which support inspection about the modules they can load. This ABC represents one of the optional protocols specified by PEP 302. cCstdS)zOptional method which when implemented should return whether the module is a package. The fullname is a str. Returns a bool. Raises ImportError if the module cannot be found. N)r2)rrrrr is_packageszInspectLoader.is_packagecCs ||}|dkrdS||S)aMethod which returns the code object for the module. The fullname is a str. Returns a types.CodeType if possible, else returns None if a code object does not make sense (e.g. built-in module). Raises ImportError if the module cannot be found. N) get_sourcesource_to_code)rrsourcerrrget_codes zInspectLoader.get_codecCstdS)zAbstract method which should return the source code for the module. The fullname is a str. Returns a str. Raises ImportError if the module cannot be found. N)r2)rrrrrr=szInspectLoader.get_sourcecCst||dddS)zCompile 'data' into a code object. The 'data' argument can be anything that compile() can handle. The'path' argument should be where the data was retrieved (when applicable).execT) dont_inherit)compile)datarrrrr>szInspectLoader.source_to_codeN)rA)r rrrr<r@rrr= staticmethodr>r _LoaderBasicsr1r4rrrrr;s   r;c@s&eZdZdZejddZddZdS)ExecutionLoaderzAbstract base class for loaders that wish to support the execution of modules as scripts. This ABC represents one of the optional protocols specified in PEP 302. cCstdS)zAbstract method which should return the value that __file__ is to be set to. Raises ImportError if the module cannot be found. N)r2)rrrrr get_filenameszExecutionLoader.get_filenamecCsP||}|dkrdSy||}Wntk r>||SX|||SdS)zMethod to return the code object for fullname. Should return None if not applicable (e.g. built-in module). Raise ImportError if the module cannot be found. N)r=rIr2r>)rrr?rrrrr@s  zExecutionLoader.get_codeN)r rrrrrrIr@rrrrrHs rHc@seZdZdZdS) FileLoaderz[Abstract base class partially implementing the ResourceLoader and ExecutionLoader ABCs.N)r rrrrrrrrJ!srJc@s(eZdZdZddZddZddZdS) SourceLoaderaAbstract base class for loading source code (and optionally any corresponding bytecode). To support loading from source code, the abstractmethods inherited from ResourceLoader and ExecutionLoader need to be implemented. To also support loading from bytecode, the optional methods specified directly by this ABC is required. Inherited abstractmethods not implemented in this ABC: * ResourceLoader.get_data * ExecutionLoader.get_filename cCs$|jjtjkrtt||dS)z6Return the (int) modification time for the path (str).mtime) path_stats__func__rKr9int)rrrrr path_mtime;szSourceLoader.path_mtimecCs |jjtjkrtd||iS)a Return a metadata dict for the source pointed to by the path (str). Possible keys: - 'mtime' (mandatory) is the numeric timestamp of last source code modification; - 'size' (optional) is the size in bytes of the source code. rL)rPrNrKr9)rrrrrrMAszSourceLoader.path_statscCsdS)aWrite the bytes to the path (if possible). Accepts a str path and data as bytes. Any needed intermediary directories are to be created. If for some reason the file cannot be written because of permissions, fail silently. Nr)rrrErrrset_dataLszSourceLoader.set_dataN)r rrrrPrMrQrrrrrK*s rKc@sHeZdZdZejddZejddZejddZejdd Z d S) ResourceReaderzAbstract base class to provide resource-reading support. Loaders that support resource reading are expected to implement the ``get_resource_reader(fullname)`` method and have it either return None or an object compatible with this ABC. cCstdS)a Return an opened, file-like object for binary reading. The 'resource' argument is expected to represent only a file name and thus not contain any subdirectory components. If the resource cannot be found, FileNotFoundError is raised. N)FileNotFoundError)rresourcerrr open_resourcebs zResourceReader.open_resourcecCstdS)a!Return the file system path to the specified resource. The 'resource' argument is expected to represent only a file name and thus not contain any subdirectory components. If the resource does not exist on the file system, raise FileNotFoundError. N)rS)rrTrrr resource_pathms zResourceReader.resource_pathcCstdS)z7Return True if the named 'name' is consider a resource.N)rS)rnamerrr is_resourceyszResourceReader.is_resourcecCsgS)z?Return an iterable of strings over the contents of the package.r)rrrrcontents~szResourceReader.contentsN) r rrrrrrUrVrXrYrrrrrRYs   rR) rrrrrr2excrWr rr"rABCMetarrBuiltinImporterFrozenImporter PathFinderWindowsRegistryFinderr) FileFinderr.r8r;rHExtensionFileLoaderrJSourceFileLoaderSourcelessFileLoaderrKrRrrrrsF       !  . /2" , +