[pypy-svn] r42137 - in pypy/dist/pypy: module/rsocket module/rsocket/test rlib

afa at codespeak.net afa at codespeak.net
Tue Apr 17 22:08:09 CEST 2007


Author: afa
Date: Tue Apr 17 22:08:09 2007
New Revision: 42137

Modified:
   pypy/dist/pypy/module/rsocket/__init__.py
   pypy/dist/pypy/module/rsocket/test/test_sock_app.py
   pypy/dist/pypy/rlib/rsocket.py
Log:
Hide socket.inet_pton (inet_ntop does exist and works) on win32
+ win32 may return errno.WSAEINVAL instead of EINVAL

Only one failing test in rsocket module!
But many functions are not tested at all...


Modified: pypy/dist/pypy/module/rsocket/__init__.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/__init__.py	(original)
+++ pypy/dist/pypy/module/rsocket/__init__.py	Tue Apr 17 22:08:09 2007
@@ -27,6 +27,9 @@
             getaddrinfo getnameinfo
             getdefaulttimeout setdefaulttimeout
             """.split():
+
+            if name in ('inet_pton',) and not hasattr(rsocket, name):
+                continue
             
             Module.interpleveldefs[name] = 'interp_func.%s' % (name, )
 

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	Tue Apr 17 22:08:09 2007
@@ -131,7 +131,7 @@
 
 def test_pton_ntop_ipv4():
     if not hasattr(socket, 'inet_pton'):
-        py.test.skip('No socket.(inet_pton|inet_ntop) on this platform')
+        py.test.skip('No socket.inet_pton on this platform')
     tests = [
         ("123.45.67.89", "\x7b\x2d\x43\x59"),
         ("0.0.0.0", "\x00" * 4),
@@ -147,7 +147,7 @@
 
 def test_ntop_ipv6():
     if not hasattr(socket, 'inet_pton'):
-        py.test.skip('No socket.(inet_pton|inet_ntop) on this platform')
+        py.test.skip('No socket.inet_pton on this platform')
     if not socket.has_ipv6:
         py.test.skip("No IPv6 on this platform")
     tests = [
@@ -168,7 +168,7 @@
 
 def test_pton_ipv6():
     if not hasattr(socket, 'inet_pton'):
-        py.test.skip('No socket.(inet_pton|inet_ntop) on this platform')
+        py.test.skip('No socket.inet_pton on this platform')
     if not socket.has_ipv6:
         py.test.skip("No IPv6 on this platform")
     tests = [
@@ -256,6 +256,8 @@
 
     def test_pton_exceptions(self):
         import _socket
+        if not hasattr(_socket, 'inet_pton'):
+            skip('No socket.inet_pton on this platform')
         tests = [
             (_socket.AF_INET + _socket.AF_INET6, ""),
             (_socket.AF_INET, "127.0.0.256"),
@@ -455,6 +457,7 @@
             s.accept()
         except Exception, e:
             assert len(e.args) == 2
-            assert e.args[0] == errno.EINVAL
+            # error is EINVAL, or WSAEINVAL on Windows
+            assert errno.errorcode[e.args[0]].endswith("EINVAL")
             assert isinstance(e.args[1], str)
 

Modified: pypy/dist/pypy/rlib/rsocket.py
==============================================================================
--- pypy/dist/pypy/rlib/rsocket.py	(original)
+++ pypy/dist/pypy/rlib/rsocket.py	Tue Apr 17 22:08:09 2007
@@ -1040,22 +1040,23 @@
     buf.raw = packed
     return _c.inet_ntoa(cast(buf, POINTER(_c.in_addr)).contents)
 
-def inet_pton(family, ip):
-    "human-readable string -> packed string"
-    if family == AF_INET:
-        size = sizeof(_c.in_addr)
-    elif AF_INET6 is not None and family == AF_INET6:
-        size = sizeof(_c.in6_addr)
-    else:
-        raise RSocketError("unknown address family")
-    buf = create_string_buffer(size)
-    res = _c.inet_pton(family, ip, cast(buf, c_void_p))
-    if res < 0:
-        raise last_error()
-    elif res == 0:
-        raise RSocketError("illegal IP address string passed to inet_pton")
-    else:
-        return buf.raw
+if hasattr(_c, 'inet_pton'):
+    def inet_pton(family, ip):
+        "human-readable string -> packed string"
+        if family == AF_INET:
+            size = sizeof(_c.in_addr)
+        elif AF_INET6 is not None and family == AF_INET6:
+            size = sizeof(_c.in6_addr)
+        else:
+            raise RSocketError("unknown address family")
+        buf = create_string_buffer(size)
+        res = _c.inet_pton(family, ip, cast(buf, c_void_p))
+        if res < 0:
+            raise last_error()
+        elif res == 0:
+            raise RSocketError("illegal IP address string passed to inet_pton")
+        else:
+            return buf.raw
 
 def inet_ntop(family, packed):
     "packed string -> human-readable string"


More information about the pypy-svn mailing list