[pypy-svn] rev 2315 - pypy/trunk/src/pypy/module
rocco at codespeak.net
rocco at codespeak.net
Sat Dec 13 20:49:49 CET 2003
Author: rocco
Date: Sat Dec 13 20:49:48 2003
New Revision: 2315
Modified:
pypy/trunk/src/pypy/module/_randommodule.py
pypy/trunk/src/pypy/module/_sremodule.py
pypy/trunk/src/pypy/module/cStringIOmodule.py
pypy/trunk/src/pypy/module/itertoolsmodule.py
pypy/trunk/src/pypy/module/mathmodule.py
Log:
Handle gracefully when C source modules are not listed in sys.builtin_module_names
Modified: pypy/trunk/src/pypy/module/_randommodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/_randommodule.py (original)
+++ pypy/trunk/src/pypy/module/_randommodule.py Sat Dec 13 20:49:48 2003
@@ -1,20 +1,16 @@
"""Bootstrap the builtin _random module.
"""
-import sys
-
from pypy.interpreter.extmodule import ExtModule
-_names = sys.builtin_module_names
-
# We use the second (metaclassish) meaning of type to construct a subclass
# of ExtModule - can't modify some attributes (like __doc__) after class
# creation, and wrapping code does not properly look at instance variables.
def RandomHelper(space):
- if '_random' in _names:
+ try:
import _random
- _randomhelper = type('_random', (ExtModule,), _random.__dict__)
- return _randomhelper(space)
- else:
+ except ImportError:
return None
+ _randomhelper = type('_random', (ExtModule,), _random.__dict__)
+ return _randomhelper(space)
Modified: pypy/trunk/src/pypy/module/_sremodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/_sremodule.py (original)
+++ pypy/trunk/src/pypy/module/_sremodule.py Sat Dec 13 20:49:48 2003
@@ -1,17 +1,16 @@
"""Bootstrap the builtin _sre module.
"""
-import sys
-
from pypy.interpreter.extmodule import ExtModule
-_names = sys.builtin_module_names
-
# We use the second (metaclassish) meaning of type to construct a subclass
# of ExtModule - can't modify some attributes (like __doc__) after class
# creation, and wrapping code does not properly look at instance variables.
def SreHelper(space):
- import _sre
+ try:
+ import _sre
+ except ImportError:
+ return None
_srehelper = type('_sre', (ExtModule,), _sre.__dict__)
return _srehelper(space)
Modified: pypy/trunk/src/pypy/module/cStringIOmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/cStringIOmodule.py (original)
+++ pypy/trunk/src/pypy/module/cStringIOmodule.py Sat Dec 13 20:49:48 2003
@@ -1,20 +1,16 @@
"""Bootstrap the builtin cStringIO module.
"""
-import sys
-
from pypy.interpreter.extmodule import ExtModule
-_names = sys.builtin_module_names
-
# We use the second (metaclassish) meaning of type to construct a subclass
# of ExtModule - can't modify some attributes (like __doc__) after class
# creation, and wrapping code does not properly look at instance variables.
def CStringIO(space):
- if 'cStringIO' in _names:
+ try:
import cStringIO
- _cStringIO = type('cStringIO', (ExtModule,), cStringIO.__dict__)
- return _cStringIO(space)
- else:
+ except ImportError:
return None
+ _cStringIO = type('cStringIO', (ExtModule,), cStringIO.__dict__)
+ return _cStringIO(space)
Modified: pypy/trunk/src/pypy/module/itertoolsmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/itertoolsmodule.py (original)
+++ pypy/trunk/src/pypy/module/itertoolsmodule.py Sat Dec 13 20:49:48 2003
@@ -1,20 +1,16 @@
"""Bootstrap the builtin itertools module.
"""
-import sys
-
from pypy.interpreter.extmodule import ExtModule
-_names = sys.builtin_module_names
-
# We use the second (metaclassish) meaning of type to construct a subclass
# of ExtModule - can't modify some attributes (like __doc__) after class
# creation, and wrapping code does not properly look at instance variables.
def Itertools(space):
- if 'itertools' in _names:
+ try:
import itertools
- _itertools = type('itertools', (ExtModule,), itertools.__dict__)
- return _itertools(space)
- else:
+ except ImportError:
return None
+ _itertools = type('itertools', (ExtModule,), itertools.__dict__)
+ return _itertools(space)
Modified: pypy/trunk/src/pypy/module/mathmodule.py
==============================================================================
--- pypy/trunk/src/pypy/module/mathmodule.py (original)
+++ pypy/trunk/src/pypy/module/mathmodule.py Sat Dec 13 20:49:48 2003
@@ -1,20 +1,16 @@
"""Bootstrap the builtin math module.
"""
-import sys
-
from pypy.interpreter.extmodule import ExtModule
-_names = sys.builtin_module_names
-
# We use the second (metaclassish) meaning of type to construct a subclass
# of ExtModule - can't modify some attributes (like __doc__) after class
# creation, and wrapping code does not properly look at instance variables.
def Math(space):
- if 'math' in _names:
+ try:
import math
- _math = type('math', (ExtModule,), math.__dict__)
- return _math(space)
- else:
+ except ImportError:
return None
+ _math = type('math', (ExtModule,), math.__dict__)
+ return _math(space)
More information about the Pypy-commit
mailing list