summaryrefslogtreecommitdiffstats
path: root/Lib/ssl.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-16 01:24:05 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-16 01:24:05 (GMT)
commit39eb8fa0dbbcd6568fceb7ca59220aa3281e0cc4 (patch)
tree5fa187d82123d1055401cb9ae8a4dcd16928bfde /Lib/ssl.py
parentdd9e3b8736fae1f730d027d5383a2b17c661ce82 (diff)
downloadcpython-39eb8fa0dbbcd6568fceb7ca59220aa3281e0cc4.zip
cpython-39eb8fa0dbbcd6568fceb7ca59220aa3281e0cc4.tar.gz
cpython-39eb8fa0dbbcd6568fceb7ca59220aa3281e0cc4.tar.bz2
This is roughly socket2.diff from issue 1378, with a few changes applied
to ssl.py (no need to test whether we can dup any more). Regular sockets no longer have a _base, but we still have explicit reference counting of socket objects for the benefit of makefile(); using duplicate sockets won't work for SSLSocket.
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r--Lib/ssl.py21
1 files changed, 6 insertions, 15 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index c2cfa31..9d63d12 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -78,8 +78,8 @@ from _ssl import (
from socket import socket, AF_INET, SOCK_STREAM, error
from socket import getnameinfo as _getnameinfo
from socket import error as socket_error
+from socket import dup as _dup
import base64 # for DER-to-PEM translation
-_can_dup_socket = hasattr(socket, "dup")
class SSLSocket(socket):
@@ -99,20 +99,11 @@ class SSLSocket(socket):
if sock is not None:
# copied this code from socket.accept()
fd = sock.fileno()
- nfd = fd
- if _can_dup_socket:
- nfd = os.dup(fd)
- try:
- socket.__init__(self, family=sock.family, type=sock.type,
- proto=sock.proto, fileno=nfd)
- except:
- if nfd != fd:
- os.close(nfd)
- else:
- if fd != nfd:
- sock.close()
- sock = None
-
+ nfd = _dup(fd)
+ socket.__init__(self, family=sock.family, type=sock.type,
+ proto=sock.proto, fileno=nfd)
+ sock.close()
+ sock = None
elif fileno is not None:
socket.__init__(self, fileno=fileno)
else: