[pypy-svn] r33383 - in pypy/dist/pypy/module/rsocket: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Oct 17 18:29:57 CEST 2006
Author: arigo
Date: Tue Oct 17 18:29:54 2006
New Revision: 33383
Modified:
pypy/dist/pypy/module/rsocket/__init__.py
pypy/dist/pypy/module/rsocket/ctypes_socket.py
pypy/dist/pypy/module/rsocket/interp_func.py
pypy/dist/pypy/module/rsocket/interp_socket.py
pypy/dist/pypy/module/rsocket/rsocket.py
pypy/dist/pypy/module/rsocket/test/test_sock_app.py
Log:
General progress. With a few skips, tests from module/_socket pass again
with module/rsocket. A test that was failing there passes here.
Modified: pypy/dist/pypy/module/rsocket/__init__.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/__init__.py (original)
+++ pypy/dist/pypy/module/rsocket/__init__.py Tue Oct 17 18:29:54 2006
@@ -13,14 +13,14 @@
}
interpleveldefs = {
- 'SocketType': 'interp_socket.Socket',
- 'socket' : 'interp_socket.Socket',
+ 'SocketType': 'interp_socket.W_RSocket',
+ 'socket' : 'interp_socket.W_RSocket',
}
def buildloaders(cls):
from pypy.module.rsocket import ctypes_socket as _c
for name in """
- gethostbyname_ex gethostbyaddr gethostname
+ gethostbyname gethostbyname_ex gethostbyaddr gethostname
getservbyname getservbyport getprotobyname
fromfd socketpair
ntohs ntohl htons htonl inet_aton inet_ntoa inet_pton inet_ntop
Modified: pypy/dist/pypy/module/rsocket/ctypes_socket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/ctypes_socket.py (original)
+++ pypy/dist/pypy/module/rsocket/ctypes_socket.py Tue Oct 17 18:29:54 2006
@@ -128,6 +128,7 @@
CConfig.sockaddr_in6 = ctypes_platform.Struct('struct sockaddr_in6',
[('sin6_family', c_int),
('sin6_flowinfo', c_int),
+ ('sin6_addr', CConfig.in6_addr),
('sin6_scope_id', c_int)])
CConfig.sockaddr_un = ctypes_platform.Struct('struct sockaddr_un',
@@ -150,7 +151,7 @@
('h_aliases', POINTER(c_char_p)),
('h_addrtype', c_int),
('h_length', c_int),
- ('h_addr_list', POINTER(c_char_p))
+ ('h_addr_list', POINTER(c_void_p)),
])
@@ -166,6 +167,11 @@
pass
cConfig.__dict__.update(ctypes_platform.configure(CConfig))
+# fill in missing constants with reasonable defaults
+cConfig.NI_MAXHOST = cConfig.NI_MAXHOST or 1025
+cConfig.NI_MAXSERV = cConfig.NI_MAXSERV or 32
+cConfig.INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN or 16
+
for name in constant_names:
value = getattr(cConfig, name)
if value is not None:
@@ -184,7 +190,7 @@
O_NONBLOCK = cConfig.O_NONBLOCK
F_GETFL = cConfig.F_GETFL
F_SETFL = cConfig.F_SETFL
-INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN or 16
+INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN
INET6_ADDRSTRLEN = cConfig.INET6_ADDRSTRLEN
linux = cConfig.linux
@@ -374,7 +380,7 @@
gethostbyname.restype = POINTER(cConfig.hostent)
gethostbyaddr = socketdll.gethostbyaddr
-gethostbyaddr.argtypes = [c_char_p, c_int, c_int]
+gethostbyaddr.argtypes = [c_void_p, c_int, c_int]
gethostbyaddr.restype = POINTER(cConfig.hostent)
getservbyname = socketdll.getservbyname
Modified: pypy/dist/pypy/module/rsocket/interp_func.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/interp_func.py (original)
+++ pypy/dist/pypy/module/rsocket/interp_func.py Tue Oct 17 18:29:54 2006
@@ -1,7 +1,7 @@
from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
from pypy.module.rsocket.interp_socket import converted_error, W_RSocket
from pypy.module.rsocket import rsocket
-from pypy.module.rsocket.rsocket import _c
+from pypy.module.rsocket.rsocket import _c, SocketError
def gethostname(space):
@@ -13,62 +13,114 @@
res = rsocket.gethostname()
except SocketError, e:
raise converted_error(space, e)
- return space.wrap(namebuff.value)
+ return space.wrap(res)
gethostname.unwrap_spec = [ObjSpace]
-def gethostbyname(space, name):
+def gethostbyname(space, hostname):
"""gethostbyname(host) -> address
Return the IP address (a string of the form '255.255.255.255') for a host.
"""
try:
- addr = rsocket.gethostbyname(name)
- hostname = addr.get_host()
+ addr = rsocket.gethostbyname(hostname)
+ ip = addr.get_host()
except SocketError, e:
raise converted_error(space, e)
- return space.wrap(hostname)
+ return space.wrap(ip)
gethostbyname.unwrap_spec = [ObjSpace, str]
-##def gethostbyname_ex(space, name):
-## """gethostbyname_ex(host) -> (name, aliaslist, addresslist)
+def common_wrapgethost(space, (name, aliases, address_list)):
+ aliases = [space.wrap(alias) for alias in aliases]
+ address_list = [space.wrap(addr.get_host()) for addr in address_list]
+ return space.newtuple([space.wrap(name),
+ space.newlist(aliases),
+ space.newlist(address_list)])
+
+def gethostbyname_ex(space, host):
+ """gethostbyname_ex(host) -> (name, aliaslist, addresslist)
+
+ Return the true host name, a list of aliases, and a list of IP addresses,
+ for a host. The host argument is a string giving a host name or IP number.
+ """
+ try:
+ res = rsocket.gethostbyname_ex(host)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return common_wrapgethost(space, res)
+gethostbyname_ex.unwrap_spec = [ObjSpace, str]
+
+def gethostbyaddr(space, host):
+ """gethostbyaddr(host) -> (name, aliaslist, addresslist)
+
+ Return the true host name, a list of aliases, and a list of IP addresses,
+ for a host. The host argument is a string giving a host name or IP number.
+ """
+ try:
+ res = rsocket.gethostbyaddr(host)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return common_wrapgethost(space, res)
+gethostbyaddr.unwrap_spec = [ObjSpace, str]
+
+def getservbyname(space, name, w_proto=None):
+ """getservbyname(servicename[, protocolname]) -> integer
+
+ Return a port number from a service name and protocol name.
+ The optional protocol name, if given, should be 'tcp' or 'udp',
+ otherwise any protocol will match.
+ """
+ if space.is_w(w_proto, space.w_None):
+ proto = None
+ else:
+ proto = space.str_w(w_proto)
+ try:
+ port = rsocket.getservbyname(name, proto)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return space.wrap(port)
+getservbyname.unwrap_spec = [ObjSpace, str, W_Root]
+
+def getservbyport(space, port, w_proto=None):
+ """getservbyport(port[, protocolname]) -> string
+
+ Return the service name from a port number and protocol name.
+ The optional protocol name, if given, should be 'tcp' or 'udp',
+ otherwise any protocol will match.
+ """
+ if space.is_w(w_proto, space.w_None):
+ proto = None
+ else:
+ proto = space.str_w(w_proto)
+ try:
+ service = rsocket.getservbyport(port, proto)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return space.wrap(service)
+getservbyport.unwrap_spec = [ObjSpace, int, W_Root]
+
+def getprotobyname(space, name):
+ """getprotobyname(name) -> integer
+
+ Return the protocol number for the named protocol. (Rarely used.)
+ """
+ try:
+ proto = rsocket.getprotobyname(name)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return space.wrap(proto)
+getprotobyname.unwrap_spec = [ObjSpace, str]
+
+def getnameinfo(space, w_sockaddr, flags):
+ """getnameinfo(sockaddr, flags) --> (host, port)
-## Return the true host name, a list of aliases, and a list of IP addresses,
-## for a host. The host argument is a string giving a host name or IP number.
-## """
-##gethostbyname_ex.unwrap_spec = [ObjSpace, str]
-
-##def gethostbyaddr(space, name):
-## """gethostbyaddr(host) -> (name, aliaslist, addresslist)
-
-## Return the true host name, a list of aliases, and a list of IP addresses,
-## for a host. The host argument is a string giving a host name or IP number.
-## """
-##gethostbyaddr.unwrap_spec = [ObjSpace, str]
-
-##def getservbyname(space, name, w_proto=NoneNotWrapped):
-## """getservbyname(servicename[, protocolname]) -> integer
-
-## Return a port number from a service name and protocol name.
-## The optional protocol name, if given, should be 'tcp' or 'udp',
-## otherwise any protocol will match.
-## """
-##getservbyname.unwrap_spec = [ObjSpace, str, W_Root]
-
-##def getservbyport(space, port, w_proto=NoneNotWrapped):
-## """getservbyport(port[, protocolname]) -> string
-
-## Return the service name from a port number and protocol name.
-## The optional protocol name, if given, should be 'tcp' or 'udp',
-## otherwise any protocol will match.
-## """
-##getservbyport.unwrap_spec = [ObjSpace, int, W_Root]
-
-##def getprotobyname(space, name):
-## """getprotobyname(name) -> integer
-
-## Return the protocol number for the named protocol. (Rarely used.)
-## """
-##getprotobyname.unwrap_spec = [ObjSpace, str]
+ Get host and port for a sockaddr."""
+ try:
+ addr = rsocket.ipaddr_from_object(space, w_sockaddr)
+ host, servport = rsocket.getnameinfo(addr, flags)
+ except SocketError, e:
+ raise converted_error(space, e)
+ return space.newtuple([space.wrap(host), space.wrap(servport)])
+getnameinfo.unwrap_spec = [ObjSpace, W_Root, int]
def fromfd(space, fd, family, type, proto=0):
"""fromfd(fd, family, type[, proto]) -> socket object
@@ -200,9 +252,8 @@
return space.wrap(ip)
inet_ntop.unwrap_spec = [ObjSpace, int, str]
-MARKER MARKER
-
-def getaddrinfo(space, w_host, w_port, family=0, socktype=0, proto=0, flags=0):
+def getaddrinfo(space, w_host, w_port,
+ family=_c.AF_UNSPEC, socktype=0, proto=0, flags=0):
"""getaddrinfo(host, port [, family, socktype, proto, flags])
-> list of (family, socktype, proto, canonname, sockaddr)
@@ -231,657 +282,15 @@
else:
raise OperationError(space.w_TypeError,
space.wrap("Int or String expected"))
-
- res = _c.addrinfo_ptr()
- hints = _c.addrinfo()
- hints.ai_flags = flags
- hints.ai_family = family
- hints.ai_socktype = socktype
- hints.ai_protocol = proto
- retval = _c.getaddrinfo(host, port, _c.pointer(hints), _c.pointer(res))
- if retval != 0:
- raise w_get_socketgaierror(space, None, retval)
-
- result = []
- next = None
- if res:
- info = res.contents
- next = info.ai_next
- try:
- w_family = space.wrap(info.ai_family)
- w_socktype = space.wrap(info.ai_socktype)
- w_proto = space.wrap(info.ai_protocol)
- if info.ai_canonname:
- w_canonname = space.wrap(info.ai_canonname)
- else:
- w_canonname = space.wrap('')
- w_addr = w_makesockaddr(space,
- _c.cast(info.ai_addr, _c.sockaddr_ptr),
- info.ai_addrlen, info.ai_protocol)
- result.append(space.newtuple([w_family, w_socktype, w_proto,
- w_canonname, w_addr]))
- except:
- _c.freeaddrinfo(res)
- raise
- while next:
- info = next.contents
- next = info.ai_next
- try:
- w_family = space.wrap(info.ai_family)
- w_socktype = space.wrap(info.ai_socktype)
- w_proto = space.wrap(info.ai_protocol)
- if info.ai_canonname:
- w_canonname = space.wrap(info.ai_canonname)
- else:
- w_canonname = space.wrap('')
- w_addr = w_makesockaddr(space,
- _c.cast(info.ai_addr, _c.sockaddr_ptr),
- info.ai_addrlen, info.ai_protocol)
- result.append(space.newtuple([w_family, w_socktype, w_proto,
- w_canonname, w_addr]))
- except:
- _c.freeaddrinfo(res)
- raise
- result = space.newlist(result)
- _c.freeaddrinfo(res)
- return result
+ try:
+ lst = rsocket.getaddrinfo(host, port, family, socktype, proto, flags)
+ except SocketError, e:
+ raise converted_error(space, e)
+ lst1 = [space.newtuple([space.wrap(family),
+ space.wrap(socktype),
+ space.wrap(protocol),
+ space.wrap(canonname),
+ addr.as_object(space)])
+ for (family, socktype, protocol, canonname, addr) in lst]
+ return space.newlist(lst1)
getaddrinfo.unwrap_spec = [ObjSpace, W_Root, W_Root, int, int, int, int]
-
-def getnameinfo(space, w_sockaddr, flags):
- """getnameinfo(sockaddr, flags) --> (host, port)
-
- Get host and port for a sockaddr."""
- w_flowinfo = w_scope_id = space.wrap(0)
- sockaddr_len = space.int_w(space.len(w_sockaddr))
- if sockaddr_len == 2:
- w_host, w_port = space.unpackiterable(w_sockaddr, 2)
- elif sockaddr_len == 3:
- w_host, w_port, w_flowinfo = space.unpackiterable(w_sockaddr, 3)
- elif sockaddr_len == 4:
- w_host, w_port, w_flowinfo, w_scope_id = space.unpackiterable(w_sockaddr, 4)
- else:
- raise OperationError(space.w_TypeError,
- space.wrap('argument 1 should be 2-4 items (%d given)' % sockaddr_len))
- host = space.str_w(w_host)
- port = space.int_w(w_port)
- flowinfo = space.int_w(w_flowinfo)
- scope_id = space.int_w(w_scope_id)
-
- res = _c.addrinfo_ptr()
- hints = _c.addrinfo()
- hints.ai_family = _c.AF_UNSPEC
- hints.ai_socktype = _c.SOCK_DGRAM
- retval = _c.getaddrinfo(host, str(port), ctypes.pointer(hints), ctypes.pointer(res))
- if retval != 0:
- raise w_get_socketgaierror(space, None, retval)
- family = res.contents.ai_family
- if family == _c.AF_INET:
- if sockaddr_len != 2:
- if res:
- _c.freeaddrinfo(res)
- raise OperationError(space.w_TypeError,
- space.wrap('argument 1 should be 2 items (%d given)' % sockaddr_len))
-
- elif family == _c.AF_INET6:
- sin6_ptr = ctypes.cast(res.contents.ai_addr, ctypes.POINTER(_c.sockaddr_in6))
- sin6_ptr.contents.sin6_flowinfo = flowinfo
- sin6_ptr.contents.sin6_scope_id = scope_id
-
- hostbuf = ctypes.create_string_buffer(_c.NI_MAXHOST)
- portbuf = ctypes.create_string_buffer(_c.NI_MAXSERV)
- maxhost = _c.size_t(_c.NI_MAXHOST)
- error = _c.getnameinfo(res.contents.ai_addr, res.contents.ai_addrlen,
- hostbuf, maxhost,
- portbuf, _c.size_t(_c.NI_MAXSERV), flags)
-
- if res:
- _c.freeaddrinfo(res)
- if error:
- raise w_get_socketgaierror(space, None, error)
- return space.newtuple([space.wrap(hostbuf.value),
- space.wrap(portbuf.value)])
-getnameinfo.unwrap_spec = [ObjSpace, W_Root, int]
-
-# _____________________________________________________________
-#
-# Timeout management
-
-class State:
- def __init__(self, space):
- self.space = space
-
- self.defaulttimeout = -1 # Default timeout for new sockets
-
-def getstate(space):
- return space.fromcache(State)
-
-def setdefaulttimeout(space, w_timeout):
- if space.is_w(w_timeout, space.w_None):
- timeout = -1.0
- else:
- timeout = space.float_w(w_timeout)
- if timeout < 0.0:
- raise OperationError(space.w_ValueError,
- space.wrap("Timeout value out of range"))
-
- getstate(space).defaulttimeout = timeout
-setdefaulttimeout.unwrap_spec = [ObjSpace, W_Root]
-
-def getdefaulttimeout(space):
- timeout = getstate(space).defaulttimeout
-
- if timeout < 0.0:
- return space.wrap(None)
- else:
- return space.wrap(timeout)
-getdefaulttimeout.unwrap_spec = [ObjSpace]
-
-# _____________________________________________________________
-#
-# The socket type
-
-def newsocket(space, w_subtype, family=_c.AF_INET,
- type=_c.SOCK_STREAM, proto=0):
- fd = _c.socket(family, type, proto)
- if fd < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- # XXX If we want to support subclassing the socket type we will need
- # something along these lines. But allocate_instance is only defined
- # on the standard object space, so this is not really correct.
- #sock = space.allocate_instance(Socket, w_subtype)
- #Socket.__init__(sock, space, fd, family, type, proto)
- #return space.wrap(sock)
- return space.wrap(Socket(space, fd, family, type, proto))
-descr_socket_new = interp2app(newsocket,
- unwrap_spec=[ObjSpace, W_Root, int, int, int])
-
-def setblocking(fd, block):
- delay_flag = _c.fcntl(fd, _c.F_GETFL, 0)
- if block:
- delay_flag &= ~_c.O_NONBLOCK
- else:
- delay_flag |= _c.O_NONBLOCK
- _c.fcntl(fd, _c.F_SETFL, delay_flag)
-
-class Socket(Wrappable):
- "A wrappable box around an interp-level socket object."
-
- def __init__(self, space, fd, family, type, proto=0):
- self.fd = fd
- self.family = family
- self.type = type
- self.proto = proto
- self.closed = False
- self.timeout = getstate(space).defaulttimeout
- if self.timeout >= 0.0:
- setblocking(self.fd, False)
-
- def _getsockaddr(self, space, w_addr):
- """Returns a pointer to a sockaddr"""
- if self.family == _c.AF_INET:
- try:
- w_host, w_port = space.unpackiterable(w_addr, 2)
- except UnpackValueError:
- e_msg = space.wrap("getsockaddrarg: AF_INET address must be a tuple of two elements")
- raise OperationError(space.w_TypeError, e_msg)
-
- port = space.int_w(w_port)
- host = space.str_w(w_host)
- res = _c.addrinfo_ptr()
- hints = _c.addrinfo()
- hints.ai_family = self.family
- hints.ai_socktype = self.type
- hints.ai_protocol = self.proto
- retval = _c.getaddrinfo(host, str(port), ctypes.pointer(hints), ctypes.pointer(res))
- if retval != 0:
- raise w_get_socketgaierror(space, None, retval)
- addrinfo = res.contents
- addrlen = addrinfo.ai_addrlen
- caddr_buf = ctypes.create_string_buffer(intmask(addrlen)) # XXX forcing a long to an int
- _c.memcpy(caddr_buf, addrinfo.ai_addr, addrlen)
-
- sockaddr_ptr = ctypes.cast(caddr_buf, _c.sockaddr_ptr)
- return sockaddr_ptr, addrlen
-
- else:
- raise NotImplementedError('Unsupported address family') # XXX
-
- def accept(self, space):
- """accept() -> (socket object, address info)
-
- Wait for an incoming connection. Return a new socket representing the
- connection, and the address of the client. For IP sockets, the address
- info is a pair (hostaddr, port).
- """
- peeraddr = _c.pointer(_c.sockaddr())
- peeraddrlen = _c.socklen_t(_c.sockaddr_size)
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- newfd = _c.socketaccept(self.fd, peeraddr,
- _c.pointer(peeraddrlen))
- if GIL is not None: GIL.acquire(True)
-
- if newfd < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- newsocket = Socket(space, newfd, self.family, self.type, self.proto)
- return space.newtuple([newsocket, w_makesockaddr(space, peeraddr, peeraddrlen.value, self.proto)])
- accept.unwrap_spec = ['self', ObjSpace]
-
- def bind(self, space, w_addr):
- """bind(address)
-
- Bind the socket to a local address. For IP sockets, the address is a
- pair (host, port); the host must refer to the local host. For raw packet
- sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])
- """
- caddr_ptr, caddr_len = self._getsockaddr(space, w_addr)
- res = _c.socketbind(self.fd, caddr_ptr, caddr_len)
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- bind.unwrap_spec = ['self', ObjSpace, W_Root]
-
- def __del__(self):
- if not self.closed:
- _c.close(self.fd)
-
- def close(self, space):
- """close()
-
- Close the socket. It cannot be used after this call.
- """
- if not self.closed:
- res = _c.close(self.fd)
- if res < 0:
- errno = _c.geterrno()
- raise w_get_socketerror(space, None, errno)
- self.closed = True
- close.unwrap_spec = ['self', ObjSpace]
-
- def connect(self, space, w_addr):
- """connect(address)
-
- Connect the socket to a remote address. For IP sockets, the address
- is a pair (host, port).
- """
- errno = self._connect_ex(space, w_addr)
- if errno:
- raise w_get_socketerror(space, None, errno)
- connect.unwrap_spec = ['self', ObjSpace, W_Root]
-
- def _connect_ex(self, space, w_addr):
- """connect_ex(address) -> errno
-
- This is like connect(address), but returns an error code (the errno value)
- instead of raising an exception when an error occurs.
- """
- sockaddr_ptr, sockaddr_len = self._getsockaddr(space, w_addr)
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- err = _c.socketconnect(self.fd, sockaddr_ptr, sockaddr_len)
- if GIL is not None: GIL.acquire(True)
-
- if err:
- errno = _c.geterrno()
- if self.timeout > 0.0:
- # XXX timeout doesn't really work at the moment
- pass
- return errno
- return 0
-
- def connect_ex(self, space, w_addr):
- return space.wrap(self._connect_ex(space, w_addr))
- connect_ex.unwrap_spec = ['self', ObjSpace, W_Root]
-
- def dup(self, space):
- """dup() -> socket object
-
- Return a new socket object connected to the same system resource.
- """
- newfd = _c.dup(self.fd)
- if newfd < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return Socket(space, newfd, self.family, self.type, self.proto)
-
- dup.unwrap_spec = ['self', ObjSpace]
-
- def fileno(self, space):
- """fileno() -> integer
-
- Return the integer file descriptor of the socket.
- """
- if not self.closed:
- return space.wrap(self.fd)
- else:
- raise w_get_socketerror(space, "Bad file descriptor", errno.EBADF)
- fileno.unwrap_spec = ['self', ObjSpace]
-
- def getpeername(self, space):
- """getpeername() -> address info
-
- Return the address of the remote endpoint. For IP sockets, the address
- info is a pair (hostaddr, port).
- """
- def getpeername(self, space):
- peeraddr = ctypes.pointer(_c.sockaddr())
- peeraddrlen = _c.socklen_t(_c.sockaddr_size)
- res = _c.socketgetpeername(self.fd, peeraddr,
- ctypes.pointer(peeraddrlen))
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return w_makesockaddr(space, peeraddr, peeraddrlen.value, self.proto)
- getpeername.unwrap_spec = ['self', ObjSpace]
-
- def getsockname(self, space):
- """getsockname() -> address info
-
- Return the address of the local endpoint. For IP sockets, the address
- info is a pair (hostaddr, port).
- """
- peeraddr = ctypes.pointer(_c.sockaddr())
- peeraddrlen = _c.socklen_t(_c.sockaddr_size)
- res = _c.socketgetsockname(self.fd, peeraddr,
- ctypes.pointer(peeraddrlen))
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return w_makesockaddr(space, peeraddr, peeraddrlen.value, self.proto)
- getsockname.unwrap_spec = ['self', ObjSpace]
-
- def getsockopt(self, space, level, option, w_buffersize=NoneNotWrapped):
- """getsockopt(level, option[, buffersize]) -> value
-
- Get a socket option. See the Unix manual for level and option.
- If a nonzero buffersize argument is given, the return value is a
- string of that length; otherwise it is an integer.
- """
- if w_buffersize is not None:
- buffersize = space.int_w(w_buffersize)
- c_buffersize = _c.socklen_t(buffersize)
- buffer = ctypes.create_string_buffer(buffersize)
- err = _c.socketgetsockopt(self.fd, level, option, buffer,
- ctypes.pointer(c_buffersize))
- if err:
- raise w_get_socketerror(space, None, _c.geterrno())
- return space.wrap(buffer[:c_buffersize.value])
- # Assume integer option
- optval = _c.c_int()
- optlen = _c.socklen_t(_c.c_int_size)
- err = _c.socketgetsockopt(self.fd, level, option, _c.pointer(optval),
- ctypes.pointer(optlen))
- if err:
- raise w_get_socketerror(space, None, _c.geterrno())
- return space.wrap(optval.value)
- getsockopt.unwrap_spec = ['self', ObjSpace, int, int, W_Root]
-
- def listen(self, space, backlog):
- """listen(backlog)
-
- Enable a server to accept connections. The backlog argument must be at
- least 1; it specifies the number of unaccepted connection that the system
- will allow before refusing new connections.
- """
- if backlog < 1:
- backlog = 1
- res = _c.socketlisten(self.fd, backlog)
- if res == -1:
- raise w_get_socketerror(space, None, _c.geterrno())
- listen.unwrap_spec = ['self', ObjSpace, int]
-
- def makefile(self, space, w_mode='r', w_buffsize=-1):
- return app_makefile(space, self, w_mode, w_buffsize)
- makefile.unwrap_spec = ['self', ObjSpace, W_Root, W_Root]
-
- def recv(self, space, buffersize, flags=0):
- """recv(buffersize[, flags]) -> data
-
- Receive up to buffersize bytes from the socket. For the optional flags
- argument, see the Unix manual. When no data is available, block until
- at least one byte is available or until the remote end is closed. When
- the remote end is closed and all data is read, return the empty string.
- """
- buf = _c.create_string_buffer(buffersize)
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- read_bytes = _c.socketrecv(self.fd, buf, buffersize, flags)
- if GIL is not None: GIL.acquire(True)
-
- if read_bytes < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return space.wrap(buf[:read_bytes])
-
- recv.unwrap_spec = ['self', ObjSpace, int, int]
-
- def recvfrom(self, space, buffersize, flags=0):
- """recvfrom(buffersize[, flags]) -> (data, address info)
-
- Like recv(buffersize, flags) but also return the sender's address info.
- """
- buf = _c.create_string_buffer(buffersize)
- sockaddr = _c.sockaddr()
- sockaddr_size = _c.socklen_t(_c.sockaddr_size)
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- read_bytes = _c.recvfrom(self.fd, buf, buffersize, flags,
- _c.pointer(sockaddr), _c.pointer(sockaddr_size))
- if GIL is not None: GIL.acquire(True)
-
- if read_bytes < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- w_addr = w_makesockaddr(space, _c.pointer(sockaddr), sockaddr_size.value, self.proto)
- return space.newtuple([space.wrap(buf[:read_bytes]), w_addr])
- recvfrom.unwrap_spec = ['self', ObjSpace, int, int]
-
- def send(self, space, data, flags=0):
- """send(data[, flags]) -> count
-
- Send a data string to the socket. For the optional flags
- argument, see the Unix manual. Return the number of bytes
- sent; this may be less than len(data) if the network is busy.
- """
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- res = _c.send(self.fd, data, len(data), flags)
- if GIL is not None: GIL.acquire(True)
-
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return space.wrap(res)
- send.unwrap_spec = ['self', ObjSpace, str, int]
-
- def sendall(self, space, data, flags=0):
- """sendall(data[, flags])
-
- Send a data string to the socket. For the optional flags
- argument, see the Unix manual. This calls send() repeatedly
- until all data is sent. If an error occurs, it's impossible
- to tell how much data has been sent.
- """
- while data:
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- res = _c.send(self.fd, data, len(data), flags)
- if GIL is not None: GIL.acquire(True)
-
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- data = data[res:]
- sendall.unwrap_spec = ['self', ObjSpace, str, int]
-
- def sendto(self, space, data, w_param2, w_param3=NoneNotWrapped):
- """sendto(data[, flags], address) -> count
-
- Like send(data, flags) but allows specifying the destination address.
- For IP sockets, the address is a pair (hostaddr, port).
- """
- if w_param3 is None:
- # 2 args version
- flags = 0
- addr, addr_len = self._getsockaddr(space, w_param2)
- else:
- # 3 args version
- flags = space.int_w(w_param2)
- addr, addr_len = self._getsockaddr(space, w_param3)
-
- # XXX Temporary hack for releasing the GIL
- GIL = space.threadlocals.getGIL()
- if GIL is not None: GIL.release()
- res = _c.sendto(self.fd, data, len(data), flags, addr, addr_len)
- if GIL is not None: GIL.acquire(True)
-
- if res < 0:
- raise w_get_socketerror(space, None, _c.geterrno())
- return space.wrap(res)
- sendto.unwrap_spec = ['self', ObjSpace, str, W_Root, W_Root]
-
- def setblocking(self, space, flag):
- """setblocking(flag)
-
- Set the socket to blocking (flag is true) or non-blocking (false).
- setblocking(True) is equivalent to settimeout(None);
- setblocking(False) is equivalent to settimeout(0.0).
- """
- setblocking(self.fd, bool(flag))
- setblocking.unwrap_spec = ['self', ObjSpace, int]
-
- def setsockopt(self, space, level, option, w_value):
- """setsockopt(level, option, value)
-
- Set a socket option. See the Unix manual for level and option.
- The value argument can either be an integer or a string.
- """
- if space.is_true(space.isinstance(w_value, space.w_str)):
- strvalue = space.str_w(w_value)
- size = _c.socklen_t(len(strvalue))
- _c.socketsetsockopt(self.fd, level, option, strvalue,
- size)
- else:
- intvalue = ctypes.c_int(space.int_w(w_value))
- size = _c.socklen_t(_c.c_int_size)
- _c.socketsetsockopt(self.fd, level, option, _c.pointer(intvalue),
- size)
- setsockopt.unwrap_spec = ['self', ObjSpace, int, int, W_Root]
-
- def gettimeout(self, space):
- """gettimeout() -> timeout
-
- Returns the timeout in floating seconds associated with socket
- operations. A timeout of None indicates that timeouts on socket
- operations are disabled.
- """
- if self.timeout < 0.0:
- return space.w_None
- else:
- return space.wrap(self.timeout)
- gettimeout.unwrap_spec = ['self', ObjSpace]
-
- def settimeout(self, space, w_timeout):
- """settimeout(timeout)
-
- Set a timeout on socket operations. 'timeout' can be a float,
- giving in seconds, or None. Setting a timeout of None disables
- the timeout feature and is equivalent to setblocking(1).
- Setting a timeout of zero is the same as setblocking(0).
- """
- if space.is_w(w_timeout, space.w_None):
- timeout = -1.0
- else:
- timeout = space.float_w(w_timeout)
- if timeout < 0.0:
- raise OperationError(space.w_ValueError,
- space.wrap("Timeout value out of range"))
- self.timeout = timeout
- setblocking(self.fd, timeout < 0.0)
- settimeout.unwrap_spec = ['self', ObjSpace, W_Root]
-
- def shutdown(self, space, how):
- """shutdown(flag)
-
- Shut down the reading side of the socket (flag == SHUT_RD), the
- writing side of the socket (flag == SHUT_WR), or both ends
- (flag == SHUT_RDWR).
- """
- err = _c.shutdown(self.fd, how)
- if err:
- raise w_get_socketerror(space, None, _c.geterrno())
-
- shutdown.unwrap_spec = ['self', ObjSpace, int]
-
-
-
-app_makefile = gateway.applevel(r'''
-def makefile(self, mode="r", buffersize=-1):
- """makefile([mode[, buffersize]]) -> file object
-
- Return a regular file object corresponding to the socket.
- The mode and buffersize arguments are as for the built-in open() function.
- """
- import os
- newfd = os.dup(self.fileno())
- return os.fdopen(newfd, mode, buffersize)
-''', filename =__file__).interphook('makefile')
-
-socketmethodnames = """
-accept bind close connect connect_ex dup fileno
-getpeername getsockname getsockopt listen makefile recv
-recvfrom send sendall sendto setblocking setsockopt gettimeout
-settimeout shutdown
-""".split()
-socketmethods = {}
-for methodname in socketmethodnames:
- method = getattr(Socket, methodname)
- assert hasattr(method,'unwrap_spec'), methodname
- assert method.im_func.func_code.co_argcount == len(method.unwrap_spec), methodname
- socketmethods[methodname] = interp2app(method, unwrap_spec=method.unwrap_spec)
-
-Socket.typedef = TypeDef("_socket.socket",
- __doc__ = """\
-socket([family[, type[, proto]]]) -> socket object
-
-Open a socket of the given type. The family argument specifies the
-address family; it defaults to AF_INET. The type argument specifies
-whether this is a stream (SOCK_STREAM, this is the default)
-or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,
-specifying the default protocol. Keyword arguments are accepted.
-
-A socket object represents one endpoint of a network connection.
-
-Methods of socket objects (keyword arguments not allowed):
-
-accept() -- accept a connection, returning new socket and client address
-bind(addr) -- bind the socket to a local address
-close() -- close the socket
-connect(addr) -- connect the socket to a remote address
-connect_ex(addr) -- connect, return an error code instead of an exception
-dup() -- return a new socket object identical to the current one [*]
-fileno() -- return underlying file descriptor
-getpeername() -- return remote address [*]
-getsockname() -- return local address
-getsockopt(level, optname[, buflen]) -- get socket options
-gettimeout() -- return timeout or None
-listen(n) -- start listening for incoming connections
-makefile([mode, [bufsize]]) -- return a file object for the socket [*]
-recv(buflen[, flags]) -- receive data
-recvfrom(buflen[, flags]) -- receive data and sender's address
-sendall(data[, flags]) -- send all data
-send(data[, flags]) -- send data, may not send all of it
-sendto(data[, flags], addr) -- send data to a given address
-setblocking(0 | 1) -- set or clear the blocking I/O flag
-setsockopt(level, optname, value) -- set socket options
-settimeout(None | float) -- set or clear the timeout
-shutdown(how) -- shut down traffic in one or both directions
-
- [*] not available on all platforms!""",
- __new__ = descr_socket_new,
- ** socketmethods
- )
Modified: pypy/dist/pypy/module/rsocket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/interp_socket.py (original)
+++ pypy/dist/pypy/module/rsocket/interp_socket.py Tue Oct 17 18:29:54 2006
@@ -3,9 +3,7 @@
from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
from pypy.interpreter.gateway import interp2app
from pypy.module.rsocket.rsocket import RSocket, _c
-from pypy.module.rsocket.rsocket import SocketError, RSocketError
-from pypy.module.rsocket.rsocket import CSocketError, GAIError
-from pypy.module.rsocket.socketerror import socket_strerror
+from pypy.module.rsocket.rsocket import SocketError, SocketErrorWithErrno
class W_RSocket(Wrappable, RSocket):
@@ -237,25 +235,15 @@
# ____________________________________________________________
# Error handling
-def operror(space, classname, *args_w):
+def converted_error(space, e):
+ message = e.__str__()
w_module = space.getbuiltinmodule('_socket')
- w_exception_class = space.getattr(w_module, space.wrap(classname))
- w_exception = space.call_function(w_exception_class, *args_w)
+ w_exception_class = space.getattr(w_module, space.wrap(e.applevelerrcls))
+ w_exception = space.call_function(w_exception_class, space.wrap(message))
+ if isinstance(e, SocketErrorWithErrno):
+ space.setattr(w_exception, space.wrap('errno'), space.wrap(e.errno))
return OperationError(w_exception_class, w_exception)
-def converted_error(space, e):
- if isinstance(e, RSocketError):
- return operror(space, 'error', space.wrap(e.message))
- elif isinstance(e, CSocketError):
- message = socket_strerror(e.errno)
- return operror(space, 'error', space.wrap(message))
- elif isinstance(e, GAIError):
- message = _c.gai_strerror(e.errno)
- return operror(space, 'gaierror', space.wrap(message))
- else:
- # fall-back, should not occur
- return operror(space, 'error')
-
# ____________________________________________________________
socketmethodnames = """
Modified: pypy/dist/pypy/module/rsocket/rsocket.py
==============================================================================
--- pypy/dist/pypy/module/rsocket/rsocket.py (original)
+++ pypy/dist/pypy/module/rsocket/rsocket.py Tue Oct 17 18:29:54 2006
@@ -10,9 +10,7 @@
# - address families other than AF_INET, AF_INET6, AF_UNIX
# - methods dup(), getsockopt(), setsockopt(), makefile(),
# gettimeout(), settimeout()
-# - functions gethostbyaddr(), gethostbyname_ex(), getnameinfo(),
-# getprotobyname(), getservbyname(), getservbyport(),
-# getdefaulttimeout(), setdefaulttimeout()
+# - functions getnameinfo(), getdefaulttimeout(), setdefaulttimeout()
# - SSL
from pypy.rpython.objectmodel import instantiate
@@ -20,6 +18,7 @@
from ctypes import cast, POINTER, c_char, c_char_p, pointer, byref, c_void_p
from ctypes import create_string_buffer, sizeof
from pypy.rpython.rctypes.astruct import offsetof
+from pypy.module.rsocket.socketerror import socket_strerror
class Address(object):
@@ -173,6 +172,27 @@
return INETAddress(host, port)
from_object = staticmethod(from_object)
+ def fill_from_object(self, space, w_address):
+ # XXX a bit of code duplication
+ _, w_port = space.unpackiterable(w_address, 2)
+ port = space.int_w(w_port)
+ a = self.as_sockaddr_in()
+ a.sin_port = _c.htons(port)
+
+ def from_in_addr(in_addr):
+ sin = _c.sockaddr_in(sin_family = _c.AF_INET) # PLAT sin_len
+ sin.sin_addr = in_addr
+ paddr = cast(pointer(sin), _c.sockaddr_ptr)
+ result = instantiate(INETAddress)
+ result.addr = paddr.contents
+ result.addrlen = sizeof(_c.sockaddr_in)
+ return result
+ from_in_addr = staticmethod(from_in_addr)
+
+ def extract_in_addr(self):
+ p = cast(pointer(self.as_sockaddr_in().sin_addr), c_void_p)
+ return p, sizeof(_c.in_addr)
+
# ____________________________________________________________
class INET6Address(IPAddress):
@@ -240,6 +260,36 @@
return INET6Address(host, port, flowinfo, scope_id)
from_object = staticmethod(from_object)
+ def fill_from_object(self, space, w_address):
+ # XXX a bit of code duplication
+ pieces_w = space.unpackiterable(w_address)
+ if not (2 <= len(pieces_w) <= 4):
+ raise RSocketError("AF_INET6 address must be a tuple of length 2 "
+ "to 4, not %d" % len(pieces))
+ port = space.int_w(pieces_w[1])
+ if len(pieces_w) > 2: flowinfo = space.int_w(pieces_w[2])
+ else: flowinfo = 0
+ if len(pieces_w) > 3: scope_id = space.int_w(pieces_w[3])
+ else: scope_id = 0
+ a = self.as_sockaddr_in6()
+ a.sin6_port = _c.htons(port)
+ a.sin6_flowinfo = flowinfo
+ a.sin6_scope_id = scope_id
+
+ def from_in6_addr(in6_addr):
+ sin = _c.sockaddr_in6(sin6_family = _c.AF_INET) # PLAT sin_len
+ sin.sin6_addr = in6_addr
+ paddr = cast(pointer(sin), _c.sockaddr_ptr)
+ result = instantiate(INET6Address)
+ result.addr = paddr.contents
+ result.addrlen = sizeof(_c.sockaddr_in6)
+ return result
+ from_in6_addr = staticmethod(from_in6_addr)
+
+ def extract_in_addr(self):
+ p = cast(pointer(self.as_sockaddr_in6().sin6_addr), c_void_p)
+ return p, sizeof(_c.in6_addr)
+
# ____________________________________________________________
class UNIXAddress(Address):
@@ -345,6 +395,12 @@
buf[i] = ptr[i]
return buf
+def ipaddr_from_object(space, w_sockaddr):
+ host = space.str_w(space.getitem(w_sockaddr, space.wrap(0)))
+ addr = makeipaddr(host)
+ addr.fill_from_object(space, w_sockaddr)
+ return addr
+
# ____________________________________________________________
class RSocket(object):
@@ -538,30 +594,41 @@
return result
class SocketError(Exception):
+ applevelerrcls = 'error'
def __init__(self):
pass
+class SocketErrorWithErrno(SocketError):
+ def __init__(self, errno):
+ self.errno = errno
+
class RSocketError(SocketError):
def __init__(self, message):
self.message = message
def __str__(self):
return self.message
-class CSocketError(SocketError):
- def __init__(self, errno):
- self.errno = errno
+class CSocketError(SocketErrorWithErrno):
def __str__(self):
- return _c.socket_strerror(self.errno)
+ return socket_strerror(self.errno)
def last_error():
return CSocketError(_c.geterrno())
-class GAIError(SocketError):
- def __init__(self, errno):
- self.errno = errno
+class GAIError(SocketErrorWithErrno):
+ applevelerrcls = 'gaierror'
def __str__(self):
return _c.gai_strerror(self.errno)
+class HSocketError(SocketError):
+ applevelerrcls = 'herror'
+ def __init__(self, host):
+ self.host = host
+ # XXX h_errno is not easily available, and hstrerror() is
+ # marked as deprecated in the Linux man pages
+ def __str__(self):
+ return "host lookup failed: '%s'" % (self.host,)
+
# ____________________________________________________________
if _c.AF_UNIX is None:
@@ -607,6 +674,54 @@
makeipaddr(name, result)
return result
+def gethost_common(hostname, hostent, addr):
+ if not hostent:
+ raise HSocketError(hostname)
+ family = addr.family
+ if hostent.contents.h_addrtype != family:
+ raise CSocketError(errno.EAFNOSUPPORT)
+
+ aliases = []
+ h_aliases = hostent.contents.h_aliases
+ if h_aliases: # h_aliases can be NULL, according to SF #1511317
+ i = 0
+ alias = h_aliases[0]
+ while alias is not None:
+ aliases.append(alias)
+ i += 1
+ alias = h_aliases[i]
+
+ address_list = []
+ h_addr_list = hostent.contents.h_addr_list
+ i = 0
+ paddr = h_addr_list[0]
+ while paddr:
+ if family == _c.AF_INET:
+ p = cast(paddr, POINTER(_c.in_addr))
+ addr = INETAddress.from_in_addr(p.contents)
+ elif _c.AF_INET6 is not None and family == _c.AF_INET6:
+ p = cast(paddr, POINTER(_c.in6_addr))
+ addr = INET6Address.from_in6_addr(p.contents)
+ else:
+ raise RSocketError("unknown address family")
+ address_list.append(addr)
+ i += 1
+ paddr = h_addr_list[i]
+ return (hostent.contents.h_name, aliases, address_list)
+
+def gethostbyname_ex(name):
+ # XXX use gethostbyname_r() if available, and/or use locks if not
+ addr = gethostbyname(name)
+ hostent = _c.gethostbyname(name)
+ return gethost_common(name, hostent, addr)
+
+def gethostbyaddr(ip):
+ # XXX use gethostbyaddr_r() if available, and/or use locks if not
+ addr = makeipaddr(ip)
+ p, size = addr.extract_in_addr()
+ hostent =_c.gethostbyaddr(p, size, addr.family)
+ return gethost_common(ip, hostent, addr)
+
def getaddrinfo(host, port_or_service,
family=_c.AF_UNSPEC, socktype=0, proto=0, flags=0):
# port_or_service is a string, not an int (but try str(port_number)).
@@ -639,10 +754,38 @@
_c.freeaddrinfo(res)
return result
+def getservbyname(name, proto=None):
+ servent = _c.getservbyname(name, proto)
+ if not servent:
+ raise RSocketError("service/proto not found")
+ return _c.ntohs(servent.contents.s_port)
+
+def getservbyport(port, proto=None):
+ servent = _c.getservbyport(_c.htons(port), proto)
+ if not servent:
+ raise RSocketError("port/proto not found")
+ return servent.contents.s_name
+
+def getprotobyname(name):
+ protoent = _c.getprotobyname(name)
+ if not protoent:
+ raise RSocketError("protocol not found")
+ return protoent.contents.p_proto
+
+def getnameinfo(addr, flags):
+ host = create_string_buffer(_c.NI_MAXHOST)
+ serv = create_string_buffer(_c.NI_MAXSERV)
+ error =_c.getnameinfo(pointer(addr.addr), addr.addrlen,
+ host, len(host),
+ serv, len(serv), flags)
+ if error:
+ raise GAIError(error)
+ return host.value, serv.value
+
def inet_aton(ip):
"IPv4 dotted string -> packed 32-bits string"
buf = create_string_buffer(sizeof(_c.in_addr))
- if inet_aton(ip, cast(buf, POINTER(_c.in_addr))):
+ if _c.inet_aton(ip, cast(buf, POINTER(_c.in_addr))):
return buf.raw
else:
raise RSocketError("illegal IP address string passed to inet_aton")
@@ -653,7 +796,7 @@
raise RSocketError("packed IP wrong length for inet_ntoa")
buf = create_string_buffer(sizeof(_c.in_addr))
buf.raw = packed
- return inet_ntoa(cast(buf, POINTER(_c.in_addr)).contents)
+ return _c.inet_ntoa(cast(buf, POINTER(_c.in_addr)).contents)
def inet_pton(family, ip):
"human-readable string -> packed string"
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 Oct 17 18:29:54 2006
@@ -1,4 +1,3 @@
-import py; py.test.skip("in-progress")
from pypy.objspace.std import StdObjSpace
from pypy.interpreter.error import OperationError
from pypy.tool.udir import udir
@@ -32,7 +31,6 @@
assert space.unwrap(ip) == socket.gethostbyname_ex(host)
def test_gethostbyaddr():
- skip("XXX fix me")
host = "localhost"
ip = space.appexec([w_socket, space.wrap(host)],
"(_socket, host): return _socket.gethostbyaddr(host)")
@@ -155,14 +153,15 @@
tests = [
("\x00" * 16, "::"),
("\x01" * 16, ":".join(["101"] * 8)),
- ("\x00\x00\x10\x10" * 4, "::1010:" + ":".join(["0:1010"] * 3)),
+ ("\x00\x00\x10\x10" * 4, None), #"::1010:" + ":".join(["0:1010"] * 3)),
("\x00" * 12 + "\x01\x02\x03\x04", "::1.2.3.4"),
("\x00" * 10 + "\xff\xff\x01\x02\x03\x04", "::ffff:1.2.3.4"),
]
for packed, ip in tests:
w_ip = space.appexec([w_socket, space.wrap(packed)],
"(_socket, packed): return _socket.inet_ntop(_socket.AF_INET6, packed)")
- assert space.unwrap(w_ip) == ip
+ if ip is not None: # else don't check for the precise representation
+ assert space.unwrap(w_ip) == ip
w_packed = space.appexec([w_socket, w_ip],
"(_socket, ip): return _socket.inet_pton(_socket.AF_INET6, ip)")
assert space.unwrap(w_packed) == packed
@@ -263,6 +262,7 @@
assert space.unwrap(w_l) == info
def test_timeout():
+ skip("not implemented yet")
space.appexec([w_socket, space.wrap(25.4)],
"(_socket, timeout): _socket.setdefaulttimeout(timeout)")
w_t = space.appexec([w_socket],
@@ -362,6 +362,7 @@
assert False
def test_newsocket(self):
+ skip("in progress - importing socket doesn't work so far")
import socket
s = socket.socket()
More information about the Pypy-commit
mailing list