[Python-checkins] cpython (merge 3.3 -> default): (Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when

victor.stinner python-checkins at python.org
Sat Oct 26 09:21:01 CEST 2013


http://hg.python.org/cpython/rev/d0f90d3f6203
changeset:   86647:d0f90d3f6203
parent:      86645:2b904290b3b9
parent:      86646:ea3deb022890
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Oct 26 09:20:38 2013 +0200
summary:
  (Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when
available to compute timeout.

files:
  Lib/telnetlib.py |  14 ++++++++------
  Misc/NEWS        |   3 +++
  2 files changed, 11 insertions(+), 6 deletions(-)


diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py
--- a/Lib/telnetlib.py
+++ b/Lib/telnetlib.py
@@ -36,6 +36,10 @@
 import sys
 import socket
 import selectors
+try:
+    from time import monotonic as _time
+except ImportError:
+    from time import time as _time
 
 __all__ = ["Telnet"]
 
@@ -304,8 +308,7 @@
             self.cookedq = self.cookedq[i:]
             return buf
         if timeout is not None:
-            from time import time
-            deadline = time() + timeout
+            deadline = _time() + timeout
         with _TelnetSelector() as selector:
             selector.register(self, selectors.EVENT_READ)
             while not self.eof:
@@ -320,7 +323,7 @@
                         self.cookedq = self.cookedq[i:]
                         return buf
                 if timeout is not None:
-                    timeout = deadline - time()
+                    timeout = deadline - _time()
                     if timeout < 0:
                         break
         return self.read_very_lazy()
@@ -610,8 +613,7 @@
                 if not re: import re
                 list[i] = re.compile(list[i])
         if timeout is not None:
-            from time import time
-            deadline = time() + timeout
+            deadline = _time() + timeout
         with _TelnetSelector() as selector:
             selector.register(self, selectors.EVENT_READ)
             while not self.eof:
@@ -625,7 +627,7 @@
                         return (i, m, text)
                 if timeout is not None:
                     ready = selector.select(timeout)
-                    timeout = deadline - time()
+                    timeout = deadline - _time()
                     if not ready:
                         if timeout < 0:
                             break
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@
 Library
 -------
 
+- Issue #19339: telnetlib module is now using time.monotonic() when available
+  to compute timeout.
+
 - Issue #19399: fix sporadic test_subprocess failure.
 
 - Issue #13234: Fix os.listdir to work with extended paths on Windows.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list