Remove unused code

As of python 3.5 socket_pair is supported on windows as well
This commit is contained in:
Kovid Goyal 2020-12-08 09:37:57 +05:30
parent 2375f1c295
commit e5a5065934
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -5,8 +5,7 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import errno, socket, select, os, time import errno, socket, os, time
from contextlib import closing
from email.utils import formatdate from email.utils import formatdate
from operator import itemgetter from operator import itemgetter
@ -146,43 +145,12 @@ def stop_cork(sock):
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 0) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 0)
def create_sock_pair(port=0): def create_sock_pair():
'''Create socket pair. Works also on windows by using an ephemeral TCP port.''' '''Create socket pair. Works also on windows by using an ephemeral TCP port.'''
if hasattr(socket, 'socketpair'):
client_sock, srv_sock = socket.socketpair() client_sock, srv_sock = socket.socketpair()
set_socket_inherit(client_sock, False), set_socket_inherit(srv_sock, False) set_socket_inherit(client_sock, False), set_socket_inherit(srv_sock, False)
return client_sock, srv_sock return client_sock, srv_sock
# Create a non-blocking temporary server socket
temp_srv_sock = socket.socket()
set_socket_inherit(temp_srv_sock, False)
temp_srv_sock.setblocking(False)
temp_srv_sock.bind(('127.0.0.1', port))
port = temp_srv_sock.getsockname()[1]
temp_srv_sock.listen(1)
with closing(temp_srv_sock):
# Create non-blocking client socket
client_sock = socket.socket()
client_sock.setblocking(False)
set_socket_inherit(client_sock, False)
try:
client_sock.connect(('127.0.0.1', port))
except socket.error as err:
# EWOULDBLOCK is not an error, as the socket is non-blocking
if err.errno not in socket_errors_nonblocking:
raise
# Use select to wait for connect() to succeed.
timeout = 1
readable = select.select([temp_srv_sock], [], [], timeout)[0]
if temp_srv_sock not in readable:
raise Exception('Client socket not connected in {} second(s)'.format(timeout))
srv_sock = temp_srv_sock.accept()[0]
set_socket_inherit(srv_sock, False)
client_sock.setblocking(True)
return client_sock, srv_sock
def parse_http_list(header_val): def parse_http_list(header_val):
"""Parse lists as described by RFC 2068 Section 2. """Parse lists as described by RFC 2068 Section 2.