Author: Alex Gaynor <[email protected]>
Branch: split-rpython
Changeset: r60010:c4827b57dab7
Date: 2013-01-12 19:38 -0800
http://bitbucket.org/pypy/pypy/changeset/c4827b57dab7/

Log:    try refactoring this to be rpython

diff --git a/pypy/module/_socket/interp_socket.py 
b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -20,23 +20,23 @@
 
 # XXX Hack to seperate rpython and pypy
 def addr_as_object(addr, fd, space):
-    if hasattr(addr, 'family') and addr.family == rsocket.AF_INET:
+    if isinstance(addr, rsocket.INETAddress):
         return space.newtuple([space.wrap(addr.get_host()),
                                space.wrap(addr.get_port())])
-    if hasattr(addr, 'family') and addr.family == rsocket.AF_INET6:
+    elif isinstance(addr, rsocket.INET6Address):
         return space.newtuple([space.wrap(addr.get_host()),
                                space.wrap(addr.get_port()),
                                space.wrap(addr.get_flowinfo()),
                                space.wrap(addr.get_scope_id())])
-    if hasattr(addr, 'family') and hasattr(rsocket, 'AF_PACKET') and 
addr.family == rsocket.AF_PACKET:
+    elif rsocket.HAS_AF_PACKET and isinstance(addr, rsocket.PacketAddress):
         return space.newtuple([space.wrap(addr.get_ifname(fd)),
                                space.wrap(addr.get_protocol()),
                                space.wrap(addr.get_pkttype()),
                                space.wrap(addr.get_hatype()),
                                space.wrap(addr.get_addr())])
-    if hasattr(addr, 'family') and hasattr(rsocket, 'AF_UNIX') and addr.family 
== rsocket.AF_UNIX:
+    elif rsocket.HAS_AF_UNIX and isinstance(addr, rsocket.UNIXAddress):
         return space.wrap(addr.get_path())
-    if hasattr(addr, 'family') and hasattr(rsocket, 'AF_NETLINK') and 
addr.family == rsocket.AF_NETLINK:
+    elif rsocket.HAS_AF_NETLINK and isinstance(addr, rsocket.NETLINKAddress):
         return space.newtuple([space.wrap(addr.get_pid()),
                                space.wrap(addr.get_groups())])
     # If we don't know the address family, don't raise an
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -181,7 +181,8 @@
 
 # ____________________________________________________________
 
-if 'AF_PACKET' in constants:
+HAS_AF_PACKET = 'AF_PACKET' in constants
+if HAS_AF_PACKET:
     class PacketAddress(Address):
         family = AF_PACKET
         struct = _c.sockaddr_ll
@@ -350,7 +351,8 @@
 
 # ____________________________________________________________
 
-if 'AF_UNIX' in constants:
+HAS_AF_UNIX = 'AF_UNIX' in constants
+if HAS_AF_UNIX:
     class UNIXAddress(Address):
         family = AF_UNIX
         struct = _c.sockaddr_un
@@ -399,7 +401,8 @@
             return (isinstance(other, UNIXAddress) and
                     self.get_path() == other.get_path())
 
-if 'AF_NETLINK' in constants:
+HAS_AF_NETLINK = 'AF_NETLINK' in constants
+if HAS_AF_NETLINK:
     class NETLINKAddress(Address):
         family = AF_NETLINK
         struct = _c.sockaddr_nl
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to