[pypy-svn] r67592 - pypy/branch/windowserror/pypy/interpreter

afa at codespeak.net afa at codespeak.net
Wed Sep 9 17:50:12 CEST 2009


Author: afa
Date: Wed Sep  9 17:50:12 2009
New Revision: 67592

Modified:
   pypy/branch/windowserror/pypy/interpreter/error.py
Log:
wrap_oserror now recognizes WindowsError and raises OperationError accordingly.
Previous test passes


Modified: pypy/branch/windowserror/pypy/interpreter/error.py
==============================================================================
--- pypy/branch/windowserror/pypy/interpreter/error.py	(original)
+++ pypy/branch/windowserror/pypy/interpreter/error.py	Wed Sep  9 17:50:12 2009
@@ -262,8 +262,33 @@
     # 31: ANSI color code "red"
     ansi_print(text, esc="31", file=file, newline=newline)
 
+try:
+    WindowsError
+except NameError:
+    _WINDOWS = False
+else:
+    _WINDOWS = True
+
+    def wrap_windowserror(space, e):
+        from pypy.rlib import rwin32
+
+        winerror = e.winerror
+        try:
+            msg = rwin32.FormatError(winerror)
+        except ValueError:
+            msg = 'Windows Error %d' % winerror
+        exc = space.w_WindowsError
+        w_error = space.call_function(exc,
+                                      space.wrap(winerror),
+                                      space.wrap(msg))
+        return OperationError(exc, w_error)
+
 def wrap_oserror(space, e, exception_name='w_OSError'): 
     assert isinstance(e, OSError) 
+
+    if _WINDOWS and isinstance(e, WindowsError):
+        return wrap_windowserror(space, e)
+
     errno = e.errno
     try:
         msg = os.strerror(errno)



More information about the Pypy-commit mailing list