Skip to content

Commit 6c07b1e

Browse files
committed
don't add _get_timeout; update NEWS entry
1 parent 0f7dd2c commit 6c07b1e

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

Lib/socketserver.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,20 @@ def service_actions(self):
270270
# - finish_request() instantiates the request handler class; this
271271
# constructor will handle the request all by itself
272272

273-
def _get_timeout(self):
274-
"""Hook so child classes can support other sources of timeout."""
275-
return self.timeout
276-
277273
def handle_request(self):
278274
"""Handle one request, possibly blocking.
279275
280276
Respects self.timeout.
281277
"""
282-
timeout = self._get_timeout()
278+
# Support people who used socket.settimeout() to escape
279+
# handle_request before self.timeout was available.
280+
timeout = None
281+
if hasattr(self, "socket"):
282+
timeout = self.socket.gettimeout()
283+
if timeout is None:
284+
timeout = self.timeout
285+
elif self.timeout is not None:
286+
timeout = min(timeout, self.timeout)
283287
if timeout is not None:
284288
deadline = time() + timeout
285289

@@ -491,16 +495,6 @@ def server_close(self):
491495
"""
492496
self.socket.close()
493497

494-
def _get_timeout(self):
495-
# Support people who used socket.settimeout() to escape
496-
# handle_request before self.timeout was available.
497-
timeout = self.socket.gettimeout()
498-
if timeout is None:
499-
timeout = self.timeout
500-
elif self.timeout is not None:
501-
timeout = min(timeout, self.timeout)
502-
return timeout
503-
504498
def fileno(self):
505499
"""Return socket file number.
506500
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Updated documentation for :mod:`socketserver` to clarify the differences
22
between :class:`socketserver.BaseServer` and
3-
:class:`socketserver.TCPServer`.
3+
:class:`socketserver.TCPServer`. Additionally, :class:`socketserver.BaseServer`
4+
no longer assumes that all subclasses will add a ``socket`` attribute, and
5+
:method:`socketserver.BaseServer.get_request` now raises ``NotImplementedError``.
6+
It was previously absent and attempting to use it would generate an
7+
``AttributeError``.

0 commit comments

Comments
 (0)