Author: Armin Rigo <[email protected]>
Branch: py3k
Changeset: r86577:4c74988264fd
Date: 2016-08-26 19:10 +0200
http://bitbucket.org/pypy/pypy/changeset/4c74988264fd/
Log: test and fix for _socket.dup()
diff --git a/pypy/module/_socket/interp_func.py
b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -142,7 +142,10 @@
@unwrap_spec(fd=int)
def dup(space, fd):
- newfd = rsocket.dup(fd)
+ try:
+ newfd = rsocket.dup(fd)
+ except SocketError as e:
+ raise converted_error(space, e)
return space.wrap(newfd)
@unwrap_spec(fd=int, family=int, type=int, proto=int)
diff --git a/pypy/module/_socket/test/test_sock_app.py
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -552,6 +552,10 @@
fd = socket.dup(s.fileno())
assert s.fileno() != fd
+ def test_dup_error(self):
+ import _socket
+ raises(_socket.error, _socket.dup, 123456)
+
def test_buffer(self):
# Test that send/sendall/sendto accept a buffer as arg
import _socket, os
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -1121,14 +1121,14 @@
return result
else:
def dup(fd):
- return _c.dup(fd)
-
- def fromfd(fd, family, type, proto=0, SocketClass=RSocket):
- # Dup the fd so it and the socket can be closed independently
fd = _c.dup(fd)
if fd < 0:
raise last_error()
- return make_socket(fd, family, type, proto, SocketClass)
+ return fd
+
+def fromfd(fd, family, type, proto=0, SocketClass=RSocket):
+ # Dup the fd so it and the socket can be closed independently
+ return make_socket(dup(fd), family, type, proto, SocketClass)
def getdefaulttimeout():
return defaults.timeout
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit