C# Class IronPython.Runtime.Importer

Importer class - used for importing modules. Used by Ops and __builtin__ Singleton living on Python engine.
Show file Open project: jschementi/iron Class Usage Examples

Public Methods

Method Description
Import ( CodeContext context, string fullName, PythonTuple from, int level ) : object

Gateway into importing ... called from Ops. Performs the initial import of a module and returns the module.

ImportFrom ( CodeContext context, object from, string name ) : object

Gateway into importing ... called from Ops. This is called after importing the module and is used to return individual items from the module. The outer modules dictionary is then updated with the result.

ImportModule ( CodeContext context, object globals, string modName, bool bottom, int level ) : object

Called by the __builtin__.__import__ functions (general importing) and ScriptEngine (for site.py) level indiciates whether to perform absolute or relative imports. -1 indicates both should be performed 0 indicates only absolute imports should be performed Positive numbers indicate the # of parent directories to search relative to the calling module

ReloadModule ( CodeContext context, PythonModule module ) : object

Private Methods

Method Description
CreateFullName ( string baseName, string name ) : string
ExecuteSourceUnit ( IronPython.Runtime.PythonContext context, SourceUnit sourceUnit ) : PythonModule
FindAndLoadModuleFromImporter ( CodeContext context, object importer, string fullName, List path, object &ret ) : bool

Given a user defined importer object as defined in PEP 302 tries to load a module. First the find_module(fullName, path) is invoked to get a loader, then load_module(fullName) is invoked

FindImportFunction ( CodeContext context ) : object
FindImporterForPath ( CodeContext context, string dirname ) : object

Finds a user defined importer for the given path or returns null if no importer handles this path.

GetFullPathAndValidateCase ( Microsoft.Scripting.LanguageContext context, string path, bool isDir ) : string
GetParentPackageName ( int level, string names ) : string
GetParentPathAndModule ( CodeContext context, string parentModuleName, PythonModule &parentModule ) : List

Given the parent module name looks up the __path__ property.

ImportBuiltin ( CodeContext context, string name ) : object
ImportFromPath ( CodeContext context, string name, string fullName, List path ) : object
ImportFromPathHook ( CodeContext context, string name, string fullName, List path, Func defaultLoader ) : object
ImportLightThrow ( CodeContext context, string fullName, PythonTuple from, int level ) : object
ImportModuleFrom ( CodeContext context, object from, string name ) : object
ImportNestedModule ( CodeContext context, PythonModule module, string name, List path ) : object
ImportReflected ( CodeContext context, string name ) : object
ImportTopAbsolute ( CodeContext context, string name ) : object
IsReflected ( object module ) : bool
LoadFromDisk ( CodeContext context, string name, string fullName, string str ) : object
LoadFromSourceUnit ( CodeContext context, SourceUnit sourceCode, string name, string path ) : PythonModule
LoadModuleFromSource ( CodeContext context, string name, string path ) : PythonModule
LoadPackageFromSource ( CodeContext context, string name, string path ) : PythonModule
MemberTrackerToPython ( CodeContext context, object ret ) : object
ReloadBuiltinModule ( CodeContext context, PythonModule module ) : void
ReloadModule ( CodeContext context, PythonModule module, IronPython.Runtime.PythonFile file ) : object
TryFindSourceFile ( IronPython.Runtime.PythonContext context, string name ) : SourceUnit
TryGetExistingModule ( CodeContext context, string fullName, object &ret ) : bool
TryGetExistingOrMetaPathModule ( CodeContext context, string fullName, List path, object &ret ) : bool

Trys to get an existing module and if that fails fall backs to searching

TryGetNameAndPath ( CodeContext context, object globals, string name, int level, string package, string &full, List &path, PythonModule &parentMod ) : bool

Interrogates the importing module for __name__ and __path__, which determine whether the imported module (whose name is 'name') is being imported as nested module (__path__ is present) or as sibling. For sibling import, the full name of the imported module is parent.sibling For nested import, the full name of the imported module is parent.module.nested where parent.module is the mod.__name__

TryGetNestedModule ( CodeContext context, PythonModule scope, string name, object &nested ) : bool
TryImportSourceFile ( IronPython.Runtime.PythonContext context, string name ) : PythonModule
TryLoadMetaPathModule ( CodeContext context, string fullName, List path, object &ret ) : bool

Attempts to load a module from sys.meta_path as defined in PEP 302. The meta_path provides a list of importer objects which can be used to load modules before searching sys.path but after searching built-in modules.

Method Details

Import() public static method

Gateway into importing ... called from Ops. Performs the initial import of a module and returns the module.
public static Import ( CodeContext context, string fullName, PythonTuple from, int level ) : object
context CodeContext
fullName string
from PythonTuple
level int
return object

ImportFrom() public static method

Gateway into importing ... called from Ops. This is called after importing the module and is used to return individual items from the module. The outer modules dictionary is then updated with the result.
public static ImportFrom ( CodeContext context, object from, string name ) : object
context CodeContext
from object
name string
return object

ImportModule() public static method

Called by the __builtin__.__import__ functions (general importing) and ScriptEngine (for site.py) level indiciates whether to perform absolute or relative imports. -1 indicates both should be performed 0 indicates only absolute imports should be performed Positive numbers indicate the # of parent directories to search relative to the calling module
public static ImportModule ( CodeContext context, object globals, string modName, bool bottom, int level ) : object
context CodeContext
globals object
modName string
bottom bool
level int
return object

ReloadModule() public static method

public static ReloadModule ( CodeContext context, PythonModule module ) : object
context CodeContext
module PythonModule
return object