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

afa at codespeak.net afa at codespeak.net
Tue Apr 17 22:41:20 CEST 2007


Author: afa
Date: Tue Apr 17 22:41:19 2007
New Revision: 42139

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:
Correction of previous checkin: on win32 inet_ntop can detect correctly bogus args,
but is unable to work in the normal case... :(
Untested code never works!


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:41:19 2007
@@ -28,7 +28,8 @@
             getdefaulttimeout setdefaulttimeout
             """.split():
 
-            if name in ('inet_pton',) and not hasattr(rsocket, name):
+            if name in ('inet_pton', 'inet_ntop',
+                        ) 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:41:19 2007
@@ -247,6 +247,8 @@
 
     def test_ntop_exceptions(self):
         import _socket
+        if not hasattr(_socket, 'inet_ntop'):
+            skip('No socket.inet_pton on this platform')
         for family, packed, exception in \
                     [(_socket.AF_INET + _socket.AF_INET6, "", _socket.error),
                      (_socket.AF_INET, "a", ValueError),

Modified: pypy/dist/pypy/rlib/rsocket.py
==============================================================================
--- pypy/dist/pypy/rlib/rsocket.py	(original)
+++ pypy/dist/pypy/rlib/rsocket.py	Tue Apr 17 22:41:19 2007
@@ -1058,25 +1058,26 @@
         else:
             return buf.raw
 
-def inet_ntop(family, packed):
-    "packed string -> human-readable string"
-    if family == AF_INET:
-        srcsize = sizeof(_c.in_addr)
-        dstsize = _c.INET_ADDRSTRLEN
-    elif AF_INET6 is not None and family == AF_INET6:
-        srcsize = sizeof(_c.in6_addr)
-        dstsize = _c.INET6_ADDRSTRLEN
-    else:
-        raise RSocketError("unknown address family")
-    if len(packed) != srcsize:
-        raise ValueError("packed IP wrong length for inet_ntop")
-    srcbuf = create_string_buffer(srcsize)
-    srcbuf.raw = packed
-    dstbuf = create_string_buffer(dstsize)
-    res = _c.inet_ntop(family, cast(srcbuf, c_void_p), dstbuf, dstsize)
-    if res is None:
-        raise last_error()
-    return res
+if hasattr(_c, 'inet_ntop'):
+    def inet_ntop(family, packed):
+        "packed string -> human-readable string"
+        if family == AF_INET:
+            srcsize = sizeof(_c.in_addr)
+            dstsize = _c.INET_ADDRSTRLEN
+        elif AF_INET6 is not None and family == AF_INET6:
+            srcsize = sizeof(_c.in6_addr)
+            dstsize = _c.INET6_ADDRSTRLEN
+        else:
+            raise RSocketError("unknown address family")
+        if len(packed) != srcsize:
+            raise ValueError("packed IP wrong length for inet_ntop")
+        srcbuf = create_string_buffer(srcsize)
+        srcbuf.raw = packed
+        dstbuf = create_string_buffer(dstsize)
+        res = _c.inet_ntop(family, cast(srcbuf, c_void_p), dstbuf, dstsize)
+        if res is None:
+            raise last_error()
+        return res
 
 def setdefaulttimeout(timeout):
     if timeout < 0.0:



More information about the Pypy-commit mailing list