[pypy-svn] r33652 - pypy/dist/pypy/module/rsocket
ac at codespeak.net
ac at codespeak.net
Tue Oct 24 15:05:08 CEST 2006
Author: ac
Date: Tue Oct 24 15:05:07 2006
New Revision: 33652
Modified:
pypy/dist/pypy/module/rsocket/__init__.py
pypy/dist/pypy/module/rsocket/interp_func.py
pypy/dist/pypy/module/rsocket/interp_socket.py
pypy/dist/pypy/module/rsocket/rsocket.py
Log:
Move support for defaulttimeout into rsocket.
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 24 15:05:07 2006
@@ -25,12 +25,10 @@
fromfd socketpair
ntohs ntohl htons htonl inet_aton inet_ntoa inet_pton inet_ntop
getaddrinfo getnameinfo
+ getdefaulttimeout setdefaulttimeout
""".split():
Module.interpleveldefs[name] = 'interp_func.%s' % (name, )
- for name in """getdefaulttimeout setdefaulttimeout""".split():
- Module.interpleveldefs[name] = 'interp_socket.%s' % (name, )
-
for constant, value in _c.constants.iteritems():
Module.interpleveldefs[constant] = "space.wrap(%r)" % value
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 24 15:05:07 2006
@@ -298,3 +298,26 @@
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 getdefaulttimeout(space):
+ """getdefaulttimeout() -> timeout
+
+ Returns the default timeout in floating seconds for new socket objects.
+ A value of None indicates that new socket objects have no timeout.
+ When the socket module is first imported, the default is None.
+ """
+ timeout = rsocket.getdefaulttimeout()
+ if timeout < 0.0:
+ return space.w_None
+ return space.wrap(timeout)
+getdefaulttimeout.unwrap_spec = [ObjSpace]
+
+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'))
+ rsocket.setdefaulttimeout(timeout)
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 24 15:05:07 2006
@@ -8,10 +8,6 @@
class W_RSocket(Wrappable, RSocket):
- def __init__(self, space, family, type, proto):
- RSocket.__init__(self, family, type, proto)
- self.settimeout(space.fromcache(State).defaulttimeout)
-
def accept_w(self, space):
"""accept() -> (socket object, address info)
@@ -294,34 +290,6 @@
raise converted_error(space, e)
shutdown_w.unwrap_spec = ['self', ObjSpace, int]
-class State:
- defaulttimeout = -1.0 # Default is blocking
- def __init__(self, space):
- pass
-
-def getdefaulttimeout(space):
- """getdefaulttimeout() -> timeout
-
- Returns the default timeout in floating seconds for new socket objects.
- A value of None indicates that new socket objects have no timeout.
- When the socket module is first imported, the default is None.
- """
- timeout = space.fromcache(State).defaulttimeout
- if timeout < 0.0:
- return space.w_None
- return space.wrap(timeout)
-getdefaulttimeout.unwrap_spec = [ObjSpace]
-
-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'))
- space.fromcache(State).defaulttimeout = timeout
-
def newsocket(space, w_subtype, family=_c.AF_INET,
type=_c.SOCK_STREAM, proto=0):
# XXX If we want to support subclassing the socket type we will need
@@ -330,7 +298,7 @@
#sock = space.allocate_instance(W_RSocket, w_subtype)
#Socket.__init__(sock, space, fd, family, type, proto)
try:
- sock = W_RSocket(space, family, type, proto)
+ sock = W_RSocket(family, type, proto)
except SocketError, e:
raise converted_error(space, e)
return space.wrap(sock)
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 24 15:05:07 2006
@@ -410,7 +410,6 @@
"""
_mixin_ = True # for interp_socket.py
fd = _c.INVALID_SOCKET
- timeout = -1.0 # Default is blocking
def __init__(self, family=_c.AF_INET, type=_c.SOCK_STREAM, proto=0):
"""Create a new socket."""
fd = _c.socket(family, type, proto)
@@ -421,6 +420,7 @@
self.family = family
self.type = type
self.proto = proto
+ self.timeout = defaults.timeout
def __del__(self):
self.close()
@@ -713,6 +713,7 @@
result.family = family
result.type = type
result.proto = proto
+ result.timeout = defaults.timeout
return result
class SocketError(Exception):
@@ -755,6 +756,12 @@
applevelerrcls = 'timeout'
def __str__(self):
return 'timed out'
+
+class Defaults:
+ timeout = -1.0 # Blocking
+defaults = Defaults()
+
+
# ____________________________________________________________
if _c.AF_UNIX is None:
@@ -785,6 +792,9 @@
raise last_error()
return make_socket(fd, family, type, proto, SocketClass)
+def getdefaulttimeout():
+ return defaults.timeout
+
def gethostname():
buf = create_string_buffer(1024)
res = _c.gethostname(buf, sizeof(buf)-1)
@@ -960,3 +970,8 @@
if res is None:
raise last_error()
return res
+
+def setdefaulttimeout(timeout):
+ if timeout < 0.0:
+ timeout = -1.0
+ defaults.timeout = timeout
More information about the pypy-svn
mailing list