From: Victor Stinner Date: Sat, 26 Oct 2013 07:20:38 +0000 (+0200) Subject: (Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when X-Git-Tag: v3.4.0b1~530 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ebca392a6cb2aa7369e18ad29b31a712f861fa2a;p=thirdparty%2FPython%2Fcpython.git (Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when available to compute timeout. --- ebca392a6cb2aa7369e18ad29b31a712f861fa2a diff --cc Lib/telnetlib.py index fa23be07e991,14ca1b19041d..0cacac85fa0e --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@@ -33,9 -34,14 +33,13 @@@ To do # Imported modules -import errno import sys import socket -import select +import selectors + try: + from time import monotonic as _time + except ImportError: + from time import time as _time __all__ = ["Telnet"] @@@ -303,26 -355,26 +307,25 @@@ class Telnet buf = self.cookedq[:i] self.cookedq = self.cookedq[i:] return buf - s_reply = ([self], [], []) - s_args = s_reply if timeout is not None: - from time import time - deadline = time() + timeout - s_args = s_args + (timeout,) - time_start = _time() - while not self.eof and select.select(*s_args) == s_reply: - i = max(0, len(self.cookedq)-n) - self.fill_rawq() - self.process_rawq() - i = self.cookedq.find(match, i) - if i >= 0: - i = i+n - buf = self.cookedq[:i] - self.cookedq = self.cookedq[i:] - return buf - if timeout is not None: - elapsed = _time() - time_start - if elapsed >= timeout: - break - s_args = s_reply + (timeout-elapsed,) ++ deadline = _time() + timeout + with _TelnetSelector() as selector: + selector.register(self, selectors.EVENT_READ) + while not self.eof: + if selector.select(timeout): + i = max(0, len(self.cookedq)-n) + self.fill_rawq() + self.process_rawq() + i = self.cookedq.find(match, i) + if i >= 0: + i = i+n + buf = self.cookedq[:i] + 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() def read_all(self): @@@ -610,28 -728,27 +613,27 @@@ if not re: import re list[i] = re.compile(list[i]) if timeout is not None: - from time import time - deadline = time() + timeout - time_start = _time() - while 1: - self.process_rawq() - for i in indices: - m = list[i].search(self.cookedq) - if m: - e = m.end() - text = self.cookedq[:e] - self.cookedq = self.cookedq[e:] - return (i, m, text) - if self.eof: - break - if timeout is not None: - elapsed = _time() - time_start - if elapsed >= timeout: - break - s_args = ([self.fileno()], [], [], timeout-elapsed) - r, w, x = select.select(*s_args) - if not r: - break - self.fill_rawq() ++ deadline = _time() + timeout + with _TelnetSelector() as selector: + selector.register(self, selectors.EVENT_READ) + while not self.eof: + self.process_rawq() + for i in indices: + m = list[i].search(self.cookedq) + if m: + e = m.end() + text = self.cookedq[:e] + self.cookedq = self.cookedq[e:] + 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 + else: + continue + self.fill_rawq() text = self.read_very_lazy() if not text and self.eof: raise EOFError diff --cc Misc/NEWS index e7899fdc473b,7e0291a363d0..f95ec0c0ee73 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -21,138 -15,98 +21,141 @@@ Core and Builtin - Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the Python executable and not removed by the linker's optimizer. -- Issue #19279: UTF-7 decoder no more produces illegal strings. +- Issue #19306: Add extra hints to the faulthandler module's stack + dumps that these are "upside down". -- Fix macro expansion of _PyErr_OCCURRED(), and make sure to use it in at - least one place so as to avoid regressions. +Library +------- -- Issue #19014: memoryview.cast() is now allowed on zero-length views. ++- Issue #19339: telnetlib module is now using time.monotonic() when available ++ to compute timeout. + -- Issue #19098: Prevent overflow in the compiler when the recursion limit is set - absurdly high. +- Issue #19399: fix sporadic test_subprocess failure. -- Issue #18942: sys._debugmallocstats() output was damaged on Windows. +- Issue #13234: Fix os.listdir to work with extended paths on Windows. + Patch by Santoso Wijaya. -- Issue #18667: Add missing "HAVE_FCHOWNAT" symbol to posix._have_functions. +- Issue #19375: The site module adding a "site-python" directory to sys.path, + if it exists, is now deprecated. -- Issue #18368: PyOS_StdioReadline() no longer leaks memory when realloc() - fails. +- Issue #19379: Lazily import linecache in the warnings module, to make + startup with warnings faster until a warning gets printed. -- Issue #16741: Fix an error reporting in int(). +- Issue #19327: Fixed the working of regular expressions with too big charset. -- Issue #17899: Fix rare file descriptor leak in os.listdir(). +- Issue #17400: New 'is_global' attribute for ipaddress to tell if an address + is allocated by IANA for global or private networks. -- Issue #18552: Check return value of PyArena_AddPyObject() in - obj2ast_object(). +- Issue #19350: Increasing the test coverage of macurl2path. Patch by Colin + Williams. -- Issue #18560: Fix potential NULL pointer dereference in sum(). +- Issue #19365: Optimized the parsing of long replacement string in re.sub*() + functions. -- Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0], - prefix and exec_prefix if the operation system does not obey MAXPATHLEN. +- Issue #19352: Fix unittest discovery when a module can be reached + through several paths (e.g. under Debian/Ubuntu with virtualenv). -- Issue #18344: Fix potential ref-leaks in _bufferedreader_read_all(). +- Issue #15207: Fix mimetypes to read from correct part of Windows registry + Original patch by Dave Chambers -- Issue #17872: Fix a segfault in marshal.load() when input stream returns - more bytes than requested. +- Issue #16595: Add prlimit() to resource module. -- Issue #18426: Fix NULL pointer dereference in C extension import when - PyModule_GetDef() returns an error. +- Issue #19324: Expose Linux-specific constants in resource module. -- Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the - tstate is first removed from TLS and then deallocated. +- Issue #17400: ipaddress should make it easy to identify rfc6598 addresses. -- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise - OverflowError when an argument of %c format is out of range. +- Load SSL's error strings in hashlib. -- Issue #18137: Detect integer overflow on precision in float.__format__() - and complex.__format__(). +- Issue #18527: Upgrade internal copy of zlib to 1.2.8. -- Issue #18183: Fix various unicode operations on strings with large unicode - codepoints. +- Issue #19274: Add a filterfunc parameter to PyZipFile.writepy. -- Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows(). +- Issue #8964: fix platform._sys_version to handle IronPython 2.6+. + Patch by Martin Matusiak. -- Issue #18038: SyntaxError raised during compilation sources with illegal - encoding now always contains an encoding name. +- Issue #18958: Improve error message for json.load(s) while passing a string + that starts with a UTF-8 BOM. -- Issue #17644: Fix a crash in str.format when curly braces are used in square - brackets. +- Issue #19307: Improve error message for json.load(s) while passing objects + of the wrong type. -- Issue #17983: Raise a SyntaxError for a ``global __class__`` statement in a - class body. +- Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by + limiting the call to readline(). Original patch by Michał + Jastrzębski and Giampaolo Rodola. -- Issue #17927: Frame objects kept arguments alive if they had been copied into - a cell, even if the cell was cleared. +- Issue #17087: Improved the repr for regular expression match objects. -Library -------- +Tests +----- -- Issue #19339: telnetlib module is now using time.monotonic() when available - to compute timeout. +- Issue 19384: Fix test_py_compile for root user, patch by Claudiu Popa. -- Issue #19288: Fixed the "in" operator of dbm.gnu databases for string - argument. Original patch by Arfrever Frehtes Taifersar Arahesis. +Build +----- -- Issue #19287: Fixed the "in" operator of dbm.ndbm databases for string - argument. Original patch by Arfrever Frehtes Taifersar Arahesis. +- Issue #19356: Avoid using a C variabled named "_self", it's a reserved + word in some C compilers. -- Issue #19327: Fixed the working of regular expressions with too big charset. -- Issue #19350: Increasing the test coverage of macurl2path. Patch by Colin - Williams. +What's New in Python 3.4.0 Alpha 4? +=================================== -- Issue #19352: Fix unittest discovery when a module can be reached - through several paths (e.g. under Debian/Ubuntu with virtualenv). +Release date: 2013-10-20 -- Issue #15207: Fix mimetypes to read from correct part of Windows registry - Original patch by Dave Chambers +Core and Builtins +----------------- -- Issue #8964: fix platform._sys_version to handle IronPython 2.6+. - Patch by Martin Matusiak. +- Issue #19301: Give classes and functions that are explicitly marked global a + global qualname. -- Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by - limiting the call to readline(). Original patch by Michał - Jastrzębski and Giampaolo Rodola. +- Issue #19279: UTF-7 decoder no longer produces illegal strings. + +- Issue #16612: Add "Argument Clinic", a compile-time preprocessor for + C files to generate argument parsing code. (See PEP 436.) + +- Issue #18810: Shift stat calls in importlib.machinery.FileFinder such that + the code is optimistic that if something exists in a directory named exactly + like the possible package being searched for that it's in actuality a + directory. + +- Issue #18416: importlib.machinery.PathFinder now treats '' as the cwd and + importlib.machinery.FileFinder no longer special-cases '' to '.'. This leads + to modules imported from cwd to now possess an absolute file path for + __file__ (this does not affect modules specified by path on the CLI but it + does affect -m/runpy). It also allows FileFinder to be more consistent by not + having an edge case. + +- Issue #4555: All exported C symbols are now prefixed with either + "Py" or "_Py". + +- Issue #19219: Speed up marshal.loads(), and make pyc files slightly + (5% to 10%) smaller. + +- Issue #19221: Upgrade Unicode database to version 6.3.0. + +- Issue #16742: The result of the C callback PyOS_ReadlineFunctionPointer must + now be a string allocated by PyMem_RawMalloc() or PyMem_RawRealloc() (or NULL + if an error occurred), instead of a string allocated by PyMem_Malloc() or + PyMem_Realloc(). + +- Issue #19199: Remove ``PyThreadState.tick_counter`` field + +- Fix macro expansion of _PyErr_OCCURRED(), and make sure to use it in at + least one place so as to avoid regressions. + +- Issue #19087: Improve bytearray allocation in order to allow cheap popping + of data at the front (slice deletion). + +- Issue #19014: memoryview.cast() is now allowed on zero-length views. + +- Issue #18690: memoryview is now automatically registered with + collections.abc.Sequence + +- Issue #19078: memoryview now correctly supports the reversed builtin + (Patch by Claudiu Popa) + +Library +------- - Issue #18235: Fix the sysconfig variables LDSHARED and BLDSHARED under AIX. Patch by David Edelsohn.