Author: Timo Paulssen <[email protected]>
Branch:
Changeset: r44126:30fd93406692
Date: 2011-05-12 10:15 +0200
http://bitbucket.org/pypy/pypy/changeset/30fd93406692/
Log: implement PyImport_GetModuleDict with test case.
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -73,3 +73,10 @@
w_mod = Module(space, space.wrap(modulename))
return borrow_from(None, w_mod)
+@cpython_api([], PyObject)
+def PyImport_GetModuleDict(space):
+ """Return the dictionary used for the module administration (a.k.a.
+ sys.modules). Note that this is a per-interpreter variable."""
+ w_modulesDict = space.sys.get('modules')
+ return borrow_from(None, w_modulesDict)
+
diff --git a/pypy/module/cpyext/test/test_import.py
b/pypy/module/cpyext/test/test_import.py
--- a/pypy/module/cpyext/test/test_import.py
+++ b/pypy/module/cpyext/test/test_import.py
@@ -18,6 +18,19 @@
assert space.str_w(space.getattr(w_foobar,
space.wrap('__name__'))) == 'foobar'
+ def test_getmoduledict(self, space, api):
+ testmod = "binascii"
+ w_pre_dict = api.PyImport_GetModuleDict()
+ assert not space.is_true(space.contains(w_pre_dict,
space.wrap(testmod)))
+
+ with rffi.scoped_str2charp(testmod) as modname:
+ w_module = api.PyImport_ImportModule(modname)
+ print w_module
+ assert w_module
+
+ w_dict = api.PyImport_GetModuleDict()
+ assert space.is_true(space.contains(w_dict, space.wrap(testmod)))
+
def test_reload(self, space, api):
pdb = api.PyImport_Import(space.wrap("pdb"))
space.delattr(pdb, space.wrap("set_trace"))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit