[Python-checkins] cpython (3.3): Close #19339: telnetlib module is now using time.monotonic() when available to

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


http://hg.python.org/cpython/rev/ea3deb022890
changeset:   86646:ea3deb022890
branch:      3.3
parent:      86641:e62a64507913
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Sat Oct 26 09:16:29 2013 +0200
summary:
  Close #19339: telnetlib module is now using time.monotonic() when available to
compute timeout.

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


diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py
--- a/Lib/telnetlib.py
+++ b/Lib/telnetlib.py
@@ -38,6 +38,10 @@
 import sys
 import socket
 import select
+try:
+    from time import monotonic as _time
+except ImportError:
+    from time import time as _time
 
 __all__ = ["Telnet"]
 
@@ -302,8 +306,7 @@
         n = len(match)
         call_timeout = timeout
         if timeout is not None:
-            from time import time
-            time_start = time()
+            time_start = _time()
         self.process_rawq()
         i = self.cookedq.find(match)
         if i < 0:
@@ -316,7 +319,7 @@
                 except select.error as e:
                     if e.errno == errno.EINTR:
                         if timeout is not None:
-                            elapsed = time() - time_start
+                            elapsed = _time() - time_start
                             call_timeout = timeout-elapsed
                         continue
                     raise
@@ -327,7 +330,7 @@
                         self.process_rawq()
                         i = self.cookedq.find(match, i)
                 if timeout is not None:
-                    elapsed = time() - time_start
+                    elapsed = _time() - time_start
                     if elapsed >= timeout:
                         break
                     call_timeout = timeout-elapsed
@@ -356,8 +359,7 @@
         s_args = s_reply
         if timeout is not None:
             s_args = s_args + (timeout,)
-            from time import time
-            time_start = time()
+            time_start = _time()
         while not self.eof and select.select(*s_args) == s_reply:
             i = max(0, len(self.cookedq)-n)
             self.fill_rawq()
@@ -369,7 +371,7 @@
                 self.cookedq = self.cookedq[i:]
                 return buf
             if timeout is not None:
-                elapsed = time() - time_start
+                elapsed = _time() - time_start
                 if elapsed >= timeout:
                     break
                 s_args = s_reply + (timeout-elapsed,)
@@ -665,8 +667,7 @@
                 expect_list[i] = re.compile(expect_list[i])
         call_timeout = timeout
         if timeout is not None:
-            from time import time
-            time_start = time()
+            time_start = _time()
         self.process_rawq()
         m = None
         for i in indices:
@@ -686,7 +687,7 @@
                 except select.error as e:
                     if e.errno == errno.EINTR:
                         if timeout is not None:
-                            elapsed = time() - time_start
+                            elapsed = _time() - time_start
                             call_timeout = timeout-elapsed
                         continue
                     raise
@@ -702,7 +703,7 @@
                                 self.cookedq = self.cookedq[e:]
                                 break
                 if timeout is not None:
-                    elapsed = time() - time_start
+                    elapsed = _time() - time_start
                     if elapsed >= timeout:
                         break
                     call_timeout = timeout-elapsed
@@ -727,8 +728,7 @@
                 if not re: import re
                 list[i] = re.compile(list[i])
         if timeout is not None:
-            from time import time
-            time_start = time()
+            time_start = _time()
         while 1:
             self.process_rawq()
             for i in indices:
@@ -741,7 +741,7 @@
             if self.eof:
                 break
             if timeout is not None:
-                elapsed = time() - time_start
+                elapsed = _time() - time_start
                 if elapsed >= timeout:
                     break
                 s_args = ([self.fileno()], [], [], timeout-elapsed)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,9 @@
 Library
 -------
 
+- Issue #19339: telnetlib module is now using time.monotonic() when available
+  to compute timeout.
+
 - Issue #19288: Fixed the "in" operator of dbm.gnu databases for string
   argument.  Original patch by Arfrever Frehtes Taifersar Arahesis.
 

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


More information about the Python-checkins mailing list