1. Remi Meier
  2. pypy-stm-logging

Commits

Alex Gaynor  committed c4827b5

try refactoring this to be rpython

  • Participants
  • Parent commits dc531ba
  • Branches split-rpython

Comments (0)

Files changed (2)

File pypy/module/_socket/interp_socket.py

View file
 
 # 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

File rpython/rlib/rsocket.py

View file
 
 # ____________________________________________________________
 
-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
 
 # ____________________________________________________________
 
-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
             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