cpython: e0fbd25f0b36 (original) (raw)
Mercurial > cpython
changeset 100259:e0fbd25f0b36 2.7
Issue #26309: Shut down SocketServer request if verify_request() is false Based on patch by Aviv Palivoda. [#26309]
Martin Panter vadmium+py@gmail.com | |
---|---|
date | Thu, 18 Feb 2016 10:43:55 +0000 |
parents | c272a1e53f5b |
children | cba717fa8e10 |
files | Lib/SocketServer.py Lib/test/test_socketserver.py Misc/NEWS |
diffstat | 3 files changed, 29 insertions(+), 0 deletions(-)[+] [-] Lib/SocketServer.py 2 Lib/test/test_socketserver.py 23 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -296,6 +296,8 @@ class BaseServer: except: self.handle_error(request, client_address) self.shutdown_request(request)
else:[](#l1.7)
self.shutdown_request(request)[](#l1.8)
def handle_timeout(self): """Called if no new request arrives within self.timeout.
--- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -326,6 +326,29 @@ class SocketServerTest(unittest.TestCase SocketServer.TCPServer((HOST, -1), SocketServer.StreamRequestHandler)
- def test_shutdown_request_called_if_verify_request_false(self):
# Issue #26309: BaseServer should call shutdown_request even if[](#l2.8)
# verify_request is False[](#l2.9)
result = {"shutdown_called": False}[](#l2.10)
class MyServer(SocketServer.TCPServer):[](#l2.12)
def verify_request(self, request, client_address):[](#l2.13)
return False[](#l2.14)
def shutdown_request(self, request):[](#l2.16)
result["shutdown_called"] = True[](#l2.17)
SocketServer.TCPServer.shutdown_request(self, request)[](#l2.18)
def connect_to_server(proto, addr):[](#l2.20)
s = socket.socket(proto, socket.SOCK_STREAM)[](#l2.21)
s.connect(addr)[](#l2.22)
s.close()[](#l2.23)
self.run_server(MyServer,[](#l2.25)
SocketServer.StreamRequestHandler,[](#l2.26)
connect_to_server)[](#l2.27)
self.assertEqual(result["shutdown_called"], True)[](#l2.28)
+ def test_main(): if imp.lock_held():
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -50,6 +50,10 @@ Core and Builtins Library ------- +- Issue #26309: In the "socketserver" module, shut down the request (closing