[pypy-svn] r33404 - in pypy/dist/pypy/module/rsocket: . test

ac at codespeak.net ac at codespeak.net
Wed Oct 18 16:08:21 CEST 2006


Author: ac
Date: Wed Oct 18 16:08:20 2006
New Revision: 33404

Modified:
   pypy/dist/pypy/module/rsocket/ctypes_socket.py
   pypy/dist/pypy/module/rsocket/interp_func.py
   pypy/dist/pypy/module/rsocket/interp_socket.py
   pypy/dist/pypy/module/rsocket/rsocket.py
   pypy/dist/pypy/module/rsocket/test/test_sock_app.py
Log:
Get the in-progress tests working again.

Modified: pypy/dist/pypy/module/rsocket/ctypes_socket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/ctypes_socket.py	(original)
+++ pypy/dist/pypy/module/rsocket/ctypes_socket.py	Wed Oct 18 16:08:20 2006
@@ -254,10 +254,10 @@
 
 if MS_WINDOWS:
     socketclose = socketdll.closesocket
-    socketclose.argtypes = [c_int]
-    socketclose.restype = c_int
 else:
-    socketclose = os.close
+    socketclose = socketdll.close
+socketclose.argtypes = [c_int]
+socketclose.restype = c_int
 
 socketconnect = socketdll.connect
 socketconnect.argtypes = [c_int, sockaddr_ptr, socklen_t]

Modified: pypy/dist/pypy/module/rsocket/interp_func.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/interp_func.py	(original)
+++ pypy/dist/pypy/module/rsocket/interp_func.py	Wed Oct 18 16:08:20 2006
@@ -2,6 +2,7 @@
 from pypy.module.rsocket.interp_socket import converted_error, W_RSocket
 from pypy.module.rsocket import rsocket
 from pypy.module.rsocket.rsocket import _c, SocketError
+from pypy.interpreter.error import OperationError
 
 
 def gethostname(space):
@@ -249,6 +250,9 @@
         ip = rsocket.inet_ntop(family, packed)
     except SocketError, e:
         raise converted_error(space, e)
+    except ValueError, e:
+        raise OperationError(space.w_ValueError,
+                  space.wrap(str(e))
     return space.wrap(ip)
 inet_ntop.unwrap_spec = [ObjSpace, int, str]
 

Modified: pypy/dist/pypy/module/rsocket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/interp_socket.py	(original)
+++ pypy/dist/pypy/module/rsocket/interp_socket.py	Wed Oct 18 16:08:20 2006
@@ -4,6 +4,7 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.module.rsocket.rsocket import RSocket, _c
 from pypy.module.rsocket.rsocket import SocketError, SocketErrorWithErrno
+from pypy.interpreter.error import OperationError
 
 
 class W_RSocket(Wrappable, RSocket):
@@ -56,6 +57,9 @@
             self.connect(self.addr_from_object(space, w_addr))
         except SocketError, e:
             raise converted_error(space, e)
+        except TypeError, e:
+            raise OperationError(space.w_TypeError,
+                                 space.wrap(str(e)))
     connect_w.unwrap_spec = ['self', ObjSpace, W_Root]
 
     def connect_ex_w(self, space, w_addr):
@@ -227,7 +231,10 @@
     # on the standard object space, so this is not really correct.
     #sock = space.allocate_instance(W_RSocket, w_subtype)
     #Socket.__init__(sock, space, fd, family, type, proto)
-    sock = W_RSocket(family, type, proto)
+    try:
+        sock = W_RSocket(family, type, proto)
+    except SocketError, e:
+        raise converted_error(space, e)
     return space.wrap(sock)
 descr_socket_new = interp2app(newsocket,
                                unwrap_spec=[ObjSpace, W_Root, int, int, int])

Modified: pypy/dist/pypy/module/rsocket/rsocket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/rsocket.py	(original)
+++ pypy/dist/pypy/module/rsocket/rsocket.py	Wed Oct 18 16:08:20 2006
@@ -20,7 +20,6 @@
 from pypy.rpython.rctypes.astruct import offsetof
 from pypy.module.rsocket.socketerror import socket_strerror
 
-
 class Address(object):
     """The base class for RPython-level objects representing addresses.
     Fields:  addr    - a _c.sockaddr structure
@@ -166,7 +165,10 @@
 
     def from_object(space, w_address):
         # Parse an app-level object representing an AF_INET address
-        w_host, w_port = space.unpackiterable(w_address, 2)
+        try:
+            w_host, w_port = space.unpackiterable(w_address, 2)
+        except ValueError:
+            raise TypeError("AF_INET address must be a tuple of length 2")
         host = space.str_w(w_host)
         port = space.int_w(w_port)
         return INETAddress(host, port)
@@ -249,8 +251,8 @@
     def from_object(space, w_address):
         pieces_w = space.unpackiterable(w_address)
         if not (2 <= len(pieces_w) <= 4):
-            raise RSocketError("AF_INET6 address must be a tuple of length 2 "
-                               "to 4, not %d" % len(pieces))
+            raise TypeError("AF_INET6 address must be a tuple of length 2 "
+                               "to 4, not %d" % len(pieces_w))
         host = space.str_w(pieces_w[0])
         port = space.int_w(pieces_w[1])
         if len(pieces_w) > 2: flowinfo = space.int_w(pieces_w[2])
@@ -357,6 +359,7 @@
 
 def familyclass(family):
     return _FAMILIES.get(family, Address)
+af_get = familyclass
 
 def make_address(addrptr, addrlen, result=None):
     family = addrptr.contents.sa_family
@@ -462,7 +465,9 @@
         fd = self.fd
         if fd != _c.INVALID_SOCKET:
             self.fd = _c.INVALID_SOCKET
-            _c.socketclose(fd)
+            res = _c.socketclose(fd)
+            if res != 0:
+                raise self.error_handler()
 
     def connect(self, address):
         """Connect the socket to a remote address."""
@@ -826,7 +831,7 @@
     else:
         raise RSocketError("unknown address family")
     if len(packed) != srcsize:
-        raise RSocketError("packed IP wrong length for inet_ntop")
+        raise ValueError("packed IP wrong length for inet_ntop")
     srcbuf = create_string_buffer(srcsize)
     srcbuf.raw = packed
     dstbuf = create_string_buffer(dstsize)

Modified: pypy/dist/pypy/module/rsocket/test/test_sock_app.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/test/test_sock_app.py	(original)
+++ pypy/dist/pypy/module/rsocket/test/test_sock_app.py	Wed Oct 18 16:08:20 2006
@@ -240,18 +240,16 @@
         raises(_socket.error, _socket.inet_ntoa, "ab")
 
     def test_aton_exceptions(self):
-        skip('In-progress')
         import _socket
         tests = ["127.0.0.256", "127.0.0.255555555555555555", "127.2b.0.0",
-            "127.2.0.0.1", "127.2..0", "255.255.255.255"]
+            "127.2.0.0.1", "127.2..0"]
         for ip in tests:
             raises(_socket.error, _socket.inet_aton, ip)
 
     def test_ntop_exceptions(self):
-        skip('In-progress')
         import _socket
         for family, packed, exception in \
-                    [(_socket.AF_INET + _socket.AF_INET6, "", ValueError),
+                    [(_socket.AF_INET + _socket.AF_INET6, "", _socket.error),
                      (_socket.AF_INET, "a", ValueError),
                      (_socket.AF_INET6, "a", ValueError),
                      (_socket.AF_INET, u"aa\u2222a", UnicodeEncodeError)]:
@@ -278,7 +276,6 @@
             raises(_socket.error, _socket.inet_pton, family, ip)
 
     def test_newsocket_error(self):
-        skip('In-progress')
         import _socket
         raises(_socket.error, _socket.socket, 10001, _socket.SOCK_STREAM, 0)
 
@@ -302,14 +299,12 @@
             assert 0
 
     def test_socket_close_error(self):
-        skip('In-progress')
         import _socket, os
         s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
         os.close(s.fileno())
         raises(_socket.error, s.close)
 
     def test_socket_connect(self):
-        skip('In-progress')
         import _socket, os
         s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
         # XXX temporarily we use codespeak to test, will have more robust tests in
@@ -321,7 +316,6 @@
         s.close()
 
     def test_socket_connect_typeerrors(self):
-        skip('In-progress')
         tests = [
             "",
             ("80"),



More information about the Pypy-commit mailing list