def addr_as_object(addr, fd, space): if isinstance(addr, rsocket.INETAddress): return space.newtuple([space.wrap(addr.get_host()), space.wrap(addr.get_port())]) 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())]) 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())]) elif rsocket.HAS_AF_UNIX and isinstance(addr, rsocket.UNIXAddress): return space.wrap(addr.get_path()) 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 # exception -- return it as a tuple. from rpython.rlib import _rsocket_rffi as _c a = addr.lock() family = rffi.cast(lltype.Signed, a.c_sa_family) datalen = addr.addrlen - rsocket.offsetof(_c.sockaddr, 'c_sa_data') rawdata = ''.join([a.c_sa_data[i] for i in range(datalen)]) addr.unlock() return space.newtuple([space.wrap(family), space.wrap(rawdata)])
def addr_as_object(addr, fd, space): if isinstance(addr, rsocket.INETAddress): return space.newtuple([space.wrap(addr.get_host()), space.wrap(addr.get_port())]) 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())]) 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_haddr())]) elif rsocket.HAS_AF_UNIX and isinstance(addr, rsocket.UNIXAddress): return space.wrap(addr.get_path()) 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 # exception -- return it as a tuple. from rpython.rlib import _rsocket_rffi as _c a = addr.lock() family = rffi.cast(lltype.Signed, a.c_sa_family) datalen = addr.addrlen - rsocket.offsetof(_c.sockaddr, 'c_sa_data') rawdata = ''.join([a.c_sa_data[i] for i in range(datalen)]) addr.unlock() return space.newtuple([space.wrap(family), space.wrap(rawdata)])