[pypy-svn] pypy fast-forward: Have socket.error inherit from IOError

amauryfa commits-noreply at bitbucket.org
Tue Jan 11 13:08:16 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: fast-forward
Changeset: r40577:bc37a19ee369
Date: 2011-01-11 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/bc37a19ee369/

Log:	Have socket.error inherit from IOError On win32, socket.error.errno
	is now the Winsock error code

diff --git a/pypy/module/_socket/app_socket.py b/pypy/module/_socket/app_socket.py
--- a/pypy/module/_socket/app_socket.py
+++ b/pypy/module/_socket/app_socket.py
@@ -2,7 +2,7 @@
 
 See the socket module for documentation."""
 
-class error(Exception):
+class error(IOError):
     pass
 
 class herror(error):

diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -348,7 +348,7 @@
         assert isinstance(s.fileno(), int)
 
     def test_socket_close(self):
-        import _socket, errno
+        import _socket
         s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
         fileno = s.fileno()
         assert s.fileno() >= 0
@@ -651,17 +651,10 @@
     def test_errno(self):
         from socket import socket, AF_INET, SOCK_STREAM, error
         import errno
-        try:
-            s = socket(AF_INET, SOCK_STREAM)
-            try:
-                import __pypy__
-                print __pypy__.internal_repr(s)
-            except ImportError:
-                pass
-            s.accept()
-        except Exception, e:
-            assert len(e.args) == 2
-            # error is EINVAL, or WSAEINVAL on Windows
-            assert errno.errorcode[e.args[0]].endswith("EINVAL")
-            assert isinstance(e.args[1], str)
-
+        s = socket(AF_INET, SOCK_STREAM)
+        exc = raises(error, s.accept)
+        assert isinstance(exc.value, error)
+        assert isinstance(exc.value, IOError)
+        # error is EINVAL, or WSAEINVAL on Windows
+        assert exc.value.errno == getattr(errno, 'WSAEINVAL', errno.EINVAL)
+        assert isinstance(exc.value.message, str)

diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py
--- a/pypy/rlib/rsocket.py
+++ b/pypy/rlib/rsocket.py
@@ -27,6 +27,7 @@
 locals().update(constants) # Define constants from _c
 
 if _c.WIN32:
+    from pypy.rlib import rwin32
     def rsocket_startup():
         wsadata = lltype.malloc(_c.WSAData, flavor='raw', zero=True)
         res = _c.WSAStartup(1, wsadata)
@@ -1094,8 +1095,12 @@
     def get_msg(self):
         return _c.socket_strerror_str(self.errno)
 
-def last_error():
-    return CSocketError(_c.geterrno())
+if _c.WIN32:
+    def last_error():
+        return CSocketError(rwin32.GetLastError())
+else:
+    def last_error():
+        return CSocketError(_c.geterrno())
 
 class GAIError(SocketErrorWithErrno):
     applevelerrcls = 'gaierror'


More information about the Pypy-commit mailing list