Merged revisions 80524 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r80524 | antoine.pitrou | 2010-04-27 10:53:36 +0200 (mar., 27 avril 2010) | 9 lines Merged revisions 80522 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80522 | antoine.pitrou | 2010-04-27 10:40:51 +0200 (mar., 27 avril 2010) | 3 lines Remove uses of find_unused_port() in test_ssl, and small cleanups ........ ................
This commit is contained in:
parent
f07d5589c0
commit
0fb2e54c87
|
@ -551,9 +551,9 @@ else:
|
||||||
self.flag = None
|
self.flag = None
|
||||||
self.active = False
|
self.active = False
|
||||||
self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0]
|
self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0]
|
||||||
self.port = support.find_unused_port()
|
|
||||||
self.server = self.HTTPSServer(
|
self.server = self.HTTPSServer(
|
||||||
(HOST, self.port), self.RootedHTTPRequestHandler, certfile)
|
(HOST, 0), self.RootedHTTPRequestHandler, certfile)
|
||||||
|
self.port = self.server.server_port
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
|
|
||||||
|
@ -634,12 +634,11 @@ else:
|
||||||
def handle_error(self):
|
def handle_error(self):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def __init__(self, port, certfile):
|
def __init__(self, certfile):
|
||||||
self.port = port
|
|
||||||
self.certfile = certfile
|
self.certfile = certfile
|
||||||
asyncore.dispatcher.__init__(self)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.port = support.bind_port(sock, '')
|
||||||
self.bind(('', port))
|
asyncore.dispatcher.__init__(self, sock)
|
||||||
self.listen(5)
|
self.listen(5)
|
||||||
|
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
|
@ -654,8 +653,8 @@ else:
|
||||||
def __init__(self, certfile):
|
def __init__(self, certfile):
|
||||||
self.flag = None
|
self.flag = None
|
||||||
self.active = False
|
self.active = False
|
||||||
self.port = support.find_unused_port()
|
self.server = self.EchoServer(certfile)
|
||||||
self.server = self.EchoServer(self.port, certfile)
|
self.port = self.server.port
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
|
|
||||||
|
@ -881,37 +880,38 @@ else:
|
||||||
|
|
||||||
listener_ready = threading.Event()
|
listener_ready = threading.Event()
|
||||||
listener_gone = threading.Event()
|
listener_gone = threading.Event()
|
||||||
port = support.find_unused_port()
|
|
||||||
|
|
||||||
# `listener` runs in a thread. It opens a socket listening on
|
|
||||||
# PORT, and sits in an accept() until the main thread connects.
|
|
||||||
# Then it rudely closes the socket, and sets Event `listener_gone`
|
|
||||||
# to let the main thread know the socket is gone.
|
|
||||||
def listener():
|
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.bind((HOST, port))
|
port = support.bind_port(s, HOST)
|
||||||
|
|
||||||
|
# `listener` runs in a thread. It sits in an accept() until
|
||||||
|
# the main thread connects. Then it rudely closes the socket,
|
||||||
|
# and sets Event `listener_gone` to let the main thread know
|
||||||
|
# the socket is gone.
|
||||||
|
def listener():
|
||||||
s.listen(5)
|
s.listen(5)
|
||||||
listener_ready.set()
|
listener_ready.set()
|
||||||
s.accept()
|
s.accept()
|
||||||
s = None # reclaim the socket object, which also closes it
|
s.close()
|
||||||
listener_gone.set()
|
listener_gone.set()
|
||||||
|
|
||||||
def connector():
|
def connector():
|
||||||
listener_ready.wait()
|
listener_ready.wait()
|
||||||
s = socket.socket()
|
c = socket.socket()
|
||||||
s.connect((HOST, port))
|
c.connect((HOST, port))
|
||||||
listener_gone.wait()
|
listener_gone.wait()
|
||||||
try:
|
try:
|
||||||
ssl_sock = ssl.wrap_socket(s)
|
ssl_sock = ssl.wrap_socket(c)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise support.TestFailed(
|
raise test_support.TestFailed(
|
||||||
'connecting to closed SSL socket should have failed')
|
'connecting to closed SSL socket should have failed')
|
||||||
|
|
||||||
t = threading.Thread(target=listener)
|
t = threading.Thread(target=listener)
|
||||||
t.start()
|
t.start()
|
||||||
|
try:
|
||||||
connector()
|
connector()
|
||||||
|
finally:
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
def testProtocolSSL2(self):
|
def testProtocolSSL2(self):
|
||||||
|
|
Loading…
Reference in New Issue