[pypy-svn] r49564 - pypy/branch/clr-module-improvements/pypy/module/clr
regmee at codespeak.net
regmee at codespeak.net
Sat Dec 8 22:06:37 CET 2007
Author: regmee
Date: Sat Dec 8 22:06:36 2007
New Revision: 49564
Modified:
pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py
pypy/branch/clr-module-improvements/pypy/module/clr/app_importer.py
pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
Log:
Removing the hardcoded Valid Namespaces used during import check. Introducing Valid Namespaces list for the check by scanning the Assemblies
Modified: pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py (original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py Sat Dec 8 22:06:36 2007
@@ -14,6 +14,9 @@
'_CliObject_internal': 'interp_clr.W_CliObject',
'call_staticmethod': 'interp_clr.call_staticmethod',
'load_cli_class': 'interp_clr.load_cli_class',
+ 'load_valid_namespaces': 'interp_clr.load_valid_namespaces',
+ 'isDotNetType': 'interp_clr.isDotNetType',
+ 'load_assembly': 'interp_clr.load_assembly',
}
def setup_after_space_initialization(self):
Modified: pypy/branch/clr-module-improvements/pypy/module/clr/app_importer.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/app_importer.py (original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/app_importer.py Sat Dec 8 22:06:36 2007
@@ -6,14 +6,6 @@
import imp
import sys
-DotNetModuleList = ['System',
- 'System.Collections',
- 'System.Collections.ArrayList',
- 'System.Collections.Stack',
- 'System.Collections.Queue',
- 'System.Math']
-
-
class loader(object):
'''
This method returns the loaded module or raises an exception, ImportError
@@ -46,26 +38,18 @@
'''
# If it is a call for a Class then return with the Class reference
- code = 0
- if fullname == "System.Math":
- code = 1
- import clr
- sys.modules[fullname] = clr.load_cli_class('System','Math')
- if fullname == "System.Collections.Queue":
- code = 1
- import clr
- sys.modules[fullname] = clr.load_cli_class('System.Collections','Queue')
- if fullname == "System.Collections.Stack":
- code = 1
- import clr
- sys.modules[fullname] = clr.load_cli_class('System.Collections','Stack')
- if fullname == "System.Collections.ArrayList":
- code = 1
- import clr
- sys.modules[fullname] = clr.load_cli_class('System.Collections','ArrayList')
+ import clr
+ if clr.isDotNetType(fullname):
+ ''' Task is to breakup System.Collections.ArrayList and call
+ clr.load_cli_class('System.Collections','ArrayList')
+ '''
+ rindex = fullname.rfind('.')
+ if rindex != -1:
+ leftStr = fullname[:rindex]
+ rightStr= fullname[rindex+1:]
+ sys.modules[fullname] = clr.load_cli_class(leftStr, rightStr)
- # if not a call for actual class assign an empty module for it.
- if not code:
+ else: # if not a call for actual class (say for namespaces) assign an empty module
mod = imp.new_module(fullname)
mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
mod.__file__ = "<%s>" % self.__class__.__name__
@@ -92,11 +76,15 @@
been imported and added to sys.modules.
'''
def __init__(self):
+ import clr
+ # this might not be the correct place to load the valid NameSpaces
+ self.ValidNameSpaces = clr.load_valid_namespaces()
self.loader = loader()
def find_module(self, fullname, path = None):
- #print "( fullname = %s ) + ( path = %s )"%(fullname, path)
- if fullname in DotNetModuleList:
+ # check for true NAMESPACE or .NET TYPE
+ import clr
+ if fullname in self.ValidNameSpaces or clr.isDotNetType(fullname):
# fullname is a .Net Module
if path != None:
__path__ = path
Modified: pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py (original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py Sat Dec 8 22:06:36 2007
@@ -184,6 +184,65 @@
return self.cache.get(fullname, None)
CliClassCache = _CliClassCache()
+def load_valid_namespaces(space):
+ """
+ We use this function to play with reflection
+ and then return useful data to the app_importer module
+
+ Parameters:
+
+ Return: List of Valid .NET namespaces
+ """
+
+ listOfNamespaces = []
+ currentDomain = System.AppDomain.get_CurrentDomain()
+ asEvidence = currentDomain.get_Evidence()
+
+# assembly1 = System.Reflection.Assembly.LoadFile("System.Xml.dll")
+# assembly2 = System.Reflection.Assembly.LoadFile("mscorlib.dll")
+# assembly3 = System.Reflection.Assembly.LoadFile("/home/amit/clrModImprove/pypy/module/clr/System.Windows.Forms.dll")
+
+# currentDomain.Load("System.Xml",asEvidence)
+# currentDomain.Load("mscorlib",asEvidence)
+# currentDomain.Load("System.Web",asEvidence)
+# currentDomain.Load("System.Drawing",asEvidence)
+# currentDomain.Load("System.Data",asEvidence)
+# currentDomain.Load("System.Windows.Forms",asEvidence)
+
+ assems = currentDomain.GetAssemblies()
+ for assembly in assems:
+ typesInAssembly = assembly.GetTypes();
+ for type in typesInAssembly:
+ namespace = type.get_Namespace()
+ if namespace != None and namespace not in listOfNamespaces:
+ listOfNamespaces.append(namespace)
+ w_listOfNamespaces = wrap_list_of_strings(space, listOfNamespaces)
+ return w_listOfNamespaces
+
+def isDotNetType(space, nameFromImporter):
+ """
+ determines if the string input is a DotNetType
+
+ Return:
+ Boolean
+ """
+ if System.Type.GetType(nameFromImporter) != None:
+ return space.wrap(True)
+ return space.wrap(False)
+
+isDotNetType.unwrap_spec = [ObjSpace, str]
+
+def load_assembly(space, assemblyName):
+ """
+ Load the given .NET assembly into the PyPy interpreter
+
+ Parameters:
+
+ - assemblyName: the full name of the assembly
+ (e.g., ``System.Xml.dll``).
+ """
+ pass
+
def load_cli_class(space, namespace, classname):
"""
Load the given .NET class into the PyPy interpreter and return a
More information about the Pypy-commit
mailing list