[pypy-svn] r16422 - in pypy/dist/pypy: interpreter module/errno module/errno/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Aug 24 19:40:00 CEST 2005


Author: cfbolz
Date: Wed Aug 24 19:39:58 2005
New Revision: 16422

Added:
   pypy/dist/pypy/module/errno/
   pypy/dist/pypy/module/errno/__init__.py
   pypy/dist/pypy/module/errno/interp_errno.py
   pypy/dist/pypy/module/errno/test/
   pypy/dist/pypy/module/errno/test/test_errno.py
Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
Log:
implemented errno module: very easy because it just contains constants that I
steal from the underlying python implementation. not tested with translation
:-(


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Wed Aug 24 19:39:58 2005
@@ -164,12 +164,13 @@
             pass
 
         modules = ['sys', '__builtin__', 'exceptions', 'unicodedata', '_codecs',
-            'array', 'marshal']
+            'array', 'marshal', 'errno']
 
         if self.options.nofaking:
             modules.append('posix')
             modules.append('math')
             modules.append('time')
+            modules.append('errno')
 
         # there also are the '_sre' and 'marshal' modules 
         # but those currently cause translation problems.  You can

Added: pypy/dist/pypy/module/errno/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/errno/__init__.py	Wed Aug 24 19:39:58 2005
@@ -0,0 +1,26 @@
+# Package initialisation
+from pypy.interpreter.mixedmodule import MixedModule
+import errno
+
+class Module(MixedModule):
+    """This module makes available standard errno system symbols.
+
+    The value of each symbol is the corresponding integer value,
+    e.g., on most systems, errno.ENOENT equals the integer 2.
+
+    The dictionary errno.errorcode maps numeric codes to symbol names,
+    e.g., errno.errorcode[2] could be the string 'ENOENT'.
+
+    Symbols that are not relevant to the underlying system are not defined.
+
+    To map error codes to error messages, use the function os.strerror(),
+    e.g. os.strerror(2) could return 'No such file or directory'."""
+
+    appleveldefs = {}
+    interpleveldefs = {"errorcode": "interp_errno.get_errorcode(space)"}
+    
+for name in dir(errno):
+    if name in ["__name__", "__doc__", "errorcode"]:
+        continue
+    Module.interpleveldefs[name] = ("space.wrap(%s)" %
+                                    (getattr(errno, name), ))

Added: pypy/dist/pypy/module/errno/interp_errno.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/errno/interp_errno.py	Wed Aug 24 19:39:58 2005
@@ -0,0 +1,5 @@
+import errno
+
+def get_errorcode(space):
+    return space.wrap(errno.errorcode)
+

Added: pypy/dist/pypy/module/errno/test/test_errno.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/errno/test/test_errno.py	Wed Aug 24 19:39:58 2005
@@ -0,0 +1,21 @@
+from pypy.objspace.std import StdObjSpace 
+import py
+import errno
+def setup_module(mod): 
+    mod.space = StdObjSpace(usemodules=['errno'])
+
+class AppTestErrno: 
+    def setup_class(cls): 
+        cls.space = space 
+        cls.w_errno = space.appexec([], "(): import errno ; return errno")
+        cls.w_errorcode = space.wrap(errno.errorcode)
+
+    def test_posix(self):
+        assert self.errno.__file__
+
+    def test_constants(self):
+        for code, name in self.errorcode.iteritems():
+            assert getattr(self.errno, name) == code
+
+    def test_errorcode(self):
+        assert self.errorcode == self.errno.errorcode



More information about the Pypy-commit mailing list