diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst index cdb32d3eac7..69ec0de99be 100644 --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -1952,7 +1952,7 @@ This is described in more detail in :pep:`301`. The ``check`` command performs some tests on the meta-data of a package. -It makes sure for example that all required meta-data are provided through +For example, it verifies that all required meta-data are provided as the arguments passed to the :func:`setup` function. .. % todo diff --git a/Doc/distutils/examples.rst b/Doc/distutils/examples.rst index d5918a5eb26..648063b2176 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -236,10 +236,10 @@ With exactly the same source tree layout, this extension can be put in the Checking a package ================== -The ``check`` command allows you to verify if your package meta-data are -meeting the minimum requirements to build a distribution. +The ``check`` command allows you to verify if your package meta-data +meet the minimum requirements to build a distribution. -To run it, just call it over your :file:`setup.py` script. If something is +To run it, just call it using your :file:`setup.py` script. If something is missing, ``check`` will display a warning. Let's take an example with a simple script:: @@ -252,7 +252,7 @@ Running the ``check`` command will display some warnings:: $ python setup.py check running check - warning: check: missing required meta-data: version ,url + warning: check: missing required meta-data: version, url warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst index f37bb05565e..d9eb00c277f 100644 --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -86,6 +86,14 @@ document could also be refactored with this option. The :option:`-v` option enables output of more information on the translation process. +Since some print statements can be parsed as function calls or statements, 2to3 +cannot always read files containing the print function. When 2to3 detects the +presence of the ``from __future__ import print_function`` compiler directive, it +modifies its internal grammar to interpert :func:`print` as a function. This +change can also be enabled manually with the :option:`-p` flag. Use +:option:`-p` to run fixers on code that already has had its print statements +converted. + .. _2to3-fixers: diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst index 3e5fcd67f62..d6d4ae2ec0d 100644 --- a/Doc/library/bdb.rst +++ b/Doc/library/bdb.rst @@ -62,14 +62,22 @@ The :mod:`bdb` module also defines two classes: * The breakpoint hit count. -.. class:: Bdb() +.. class:: Bdb(skip=None) - The :class:`Bdb` acts as a generic Python debugger base class. + The :class:`Bdb` class acts as a generic Python debugger base class. This class takes care of the details of the trace facility; a derived class should implement user interaction. The standard debugger class (:class:`pdb.Pdb`) is an example. + The *skip* argument, if given, must be an iterable of glob-style + module name patterns. The debugger will not step into frames that + originate in a module that matches one of these patterns. Whether a + frame is considered to originate in a certain module is determined + by the ``__name__`` in the frame globals. + + .. versionadded:: 2.7 + The *skip* argument. The following methods of :class:`Bdb` normally don't need to be overridden. diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 5188b51b6ad..8fb984ed8bd 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -98,8 +98,8 @@ Module Interface *buffering* is an optional integer used to set the buffering policy. By default full buffering is on. Pass 0 to switch buffering off (only allowed - in binary mode), 1 to set line buffering, and an integer > 1 for full - buffering. + in binary mode), 1 to set line buffering, and an integer > 1 to indicate the + size of the buffer. *encoding* is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 24ace8bbf6f..175314ee641 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -104,6 +104,14 @@ The mathematical and bitwise operations are the most numerous: Return ``a // b``. +.. function:: index(a) + __index__(a) + + Return *a* converted to an integer. Equivalent to ``a.__index__()``. + + .. versionadded:: 2.5 + + .. function:: inv(obj) invert(obj) __inv__(obj) @@ -133,7 +141,7 @@ The mathematical and bitwise operations are the most numerous: .. function:: neg(obj) __neg__(obj) - Return *obj* negated. + Return *obj* negated (``-obj``). .. function:: or_(a, b) @@ -145,7 +153,7 @@ The mathematical and bitwise operations are the most numerous: .. function:: pos(obj) __pos__(obj) - Return *obj* positive. + Return *obj* positive (``+obj``). .. function:: pow(a, b) @@ -179,13 +187,7 @@ The mathematical and bitwise operations are the most numerous: Return the bitwise exclusive or of *a* and *b*. -.. function:: index(a) - __index__(a) - - Return *a* converted to an integer. Equivalent to ``a.__index__()``. - - -Operations which work with sequences include: +Operations which work with sequences (some of them with mappings too) include: .. function:: concat(a, b) __concat__(a, b) @@ -394,67 +396,77 @@ Mapping Operators to Functions This table shows how abstract operations correspond to operator symbols in the Python syntax and the functions in the :mod:`operator` module. -+-----------------------+-------------------------+---------------------------------+ -| Operation | Syntax | Function | -+=======================+=========================+=================================+ -| Addition | ``a + b`` | ``add(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | -+-----------------------+-------------------------+---------------------------------+ -| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Division | ``a / b`` | ``truediv(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Division | ``a // b`` | ``floordiv(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise And | ``a & b`` | ``and_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Inversion | ``~ a`` | ``invert(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Or | ``a | b`` | ``or_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Exponentiation | ``a ** b`` | ``pow(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Identity | ``a is b`` | ``is_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Identity | ``a is not b`` | ``is_not(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexing | ``obj[k]`` | ``getitem(obj, k)`` | -+-----------------------+-------------------------+---------------------------------+ -| Left Shift | ``a << b`` | ``lshift(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Modulo | ``a % b`` | ``mod(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Multiplication | ``a * b`` | ``mul(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Negation (Arithmetic) | ``- a`` | ``neg(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Negation (Logical) | ``not a`` | ``not_(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Right Shift | ``a >> b`` | ``rshift(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| String Formatting | ``s % obj`` | ``mod(s, obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Subtraction | ``a - b`` | ``sub(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Truth Test | ``obj`` | ``truth(obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a < b`` | ``lt(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a <= b`` | ``le(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Equality | ``a == b`` | ``eq(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Difference | ``a != b`` | ``ne(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a >= b`` | ``ge(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a > b`` | ``gt(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ ++-----------------------+-------------------------+---------------------------------------+ +| Operation | Syntax | Function | ++=======================+=========================+=======================================+ +| Addition | ``a + b`` | ``add(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Division | ``a / b`` | ``div(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Division | ``a // b`` | ``floordiv(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise And | ``a & b`` | ``and_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Inversion | ``~ a`` | ``invert(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Or | ``a | b`` | ``or_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Exponentiation | ``a ** b`` | ``pow(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Identity | ``a is b`` | ``is_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Identity | ``a is not b`` | ``is_not(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexing | ``obj[k]`` | ``getitem(obj, k)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Left Shift | ``a << b`` | ``lshift(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Modulo | ``a % b`` | ``mod(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Multiplication | ``a * b`` | ``mul(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Negation (Arithmetic) | ``- a`` | ``neg(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Negation (Logical) | ``not a`` | ``not_(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Positive | ``+ a`` | ``pos(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Right Shift | ``a >> b`` | ``rshift(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` | ++-----------------------+-------------------------+---------------------------------------+ +| String Formatting | ``s % obj`` | ``mod(s, obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Subtraction | ``a - b`` | ``sub(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Truth Test | ``obj`` | ``truth(obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a < b`` | ``lt(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a <= b`` | ``le(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Equality | ``a == b`` | ``eq(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Difference | ``a != b`` | ``ne(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a >= b`` | ``ge(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a > b`` | ``gt(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 96b524daf10..9a0c00ef811 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -55,7 +55,7 @@ insert :: import pdb; pdb.set_trace() at the location you want to break into the debugger. You can then step through -the code following this statement, and continue running without debugger using +the code following this statement, and continue running without the debugger using the ``c`` command. The typical usage to inspect a crashed program is:: diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index e465b566f59..f7df0b58ed7 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -6,6 +6,8 @@ The Python Profilers .. sectionauthor:: James Roskind +.. module:: profile + :synopsis: Python source profiler. .. index:: single: InfoSeek Corporation diff --git a/Doc/library/pty.rst b/Doc/library/pty.rst index ac965ffce28..d039fdf4fed 100644 --- a/Doc/library/pty.rst +++ b/Doc/library/pty.rst @@ -2,8 +2,8 @@ ======================================== .. module:: pty - :platform: IRIX, Linux - :synopsis: Pseudo-Terminal Handling for SGI and Linux. + :platform: Linux + :synopsis: Pseudo-Terminal Handling for Linux. .. moduleauthor:: Steen Lumholt .. sectionauthor:: Moshe Zadka @@ -13,8 +13,8 @@ concept: starting another process and being able to write to and read from its controlling terminal programmatically. Because pseudo-terminal handling is highly platform dependent, there is code to -do it only for SGI and Linux. (The Linux code is supposed to work on other -platforms, but hasn't been tested yet.) +do it only for Linux. (The Linux code is supposed to work on other platforms, +but hasn't been tested yet.) The :mod:`pty` module defines the following functions: @@ -31,8 +31,8 @@ The :mod:`pty` module defines the following functions: .. function:: openpty() Open a new pseudo-terminal pair, using :func:`os.openpty` if possible, or - emulation code for SGI and generic Unix systems. Return a pair of file - descriptors ``(master, slave)``, for the master and the slave end, respectively. + emulation code for generic Unix systems. Return a pair of file descriptors + ``(master, slave)``, for the master and the slave end, respectively. .. function:: spawn(argv[, master_read[, stdin_read]]) diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index 1f53037c570..4d0a99527aa 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -365,7 +365,7 @@ object, see :ref:`tarinfo-objects` for details. value. Depending on this value the respective file is either excluded (:const:`True`) or added (:const:`False`). If *filter* is specified it must be a function that takes a :class:`TarInfo` object argument and returns the - changed TarInfo object. If it instead returns :const:`None` the TarInfo + changed :class:`TarInfo` object. If it instead returns :const:`None` the :class:`TarInfo` object will be excluded from the archive. See :ref:`tar-examples` for an example. diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index d70550a57f2..d9471869cbb 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -2023,7 +2023,7 @@ The public classes of the module :mod:`turtle` Subclass of TurtleScreen, with :ref:`four methods added `. -.. class:: ScrolledCavas(master) +.. class:: ScrolledCanvas(master) :param master: some Tkinter widget to contain the ScrolledCanvas, i.e. a Tkinter-canvas with scrollbars added diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 685d2079eb7..2aa49e3d5cd 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -72,10 +72,9 @@ support weak references but can add support through subclassing:: obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable -.. impl-detail:: - - Other built-in types such as :class:`tuple` and :class:`long` do not support - weak references even when subclassed. +Other built-in types such as :class:`tuple` and :class:`long` do not support +weak references even when subclassed (This is an implementation detail and may +be different across various Python implementations.). Extension types can easily be made to support weak references; see :ref:`weakref-support`. diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index a7fb8427a6f..ae8751e60ae 100644 --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -197,6 +197,13 @@ ZipFile Objects be a subset of the list returned by :meth:`namelist`. *pwd* is the password used for encrypted files. + .. warning:: + + Never extract archives from untrusted sources without prior inspection. + It is possible that files are created outside of *path*, e.g. members + that have absolute filenames starting with ``"/"`` or filenames with two + dots ``".."``. + .. method:: ZipFile.printdir() diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 27d8e5cccd7..8b71153d887 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -2416,9 +2416,13 @@ changes, or look through the Subversion logs for all the details. environments. TIPC addresses are 4- or 5-tuples. (Contributed by Alberto Bertogli; :issue:`1646`.) - A new function, :func:`create_connection`, takes an address - and connects to it using an optional timeout value, returning - the connected socket object. + A new function, :func:`create_connection`, takes an address and + connects to it using an optional timeout value, returning the + connected socket object. This function also looks up the address's + type and connects to it using IPv4 or IPv6 as appropriate. Changing + your code to use :func:`create_connection` instead of + ``socket(socket.AF_INET, ...)`` may be all that's required to make + your code work with IPv6. * The base classes in the :mod:`SocketServer` module now support calling a :meth:`handle_timeout` method after a span of inactivity diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 9a8fca1d5f2..12844cbf9fa 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -92,7 +92,7 @@ class check(Command): missing.append(attr) if missing: - self.warn("missing required meta-data: %s" % ' ,'.join(missing)) + self.warn("missing required meta-data: %s" % ', '.join(missing)) if metadata.author: if not metadata.author_email: self.warn("missing meta-data: if 'author' supplied, " + diff --git a/Lib/inspect.py b/Lib/inspect.py index 1f1b7f90540..c4895023689 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -238,7 +238,7 @@ def isroutine(object): def isabstract(object): """Return true if the object is an abstract base class (ABC).""" - return isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT + return bool(isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT) def getmembers(object, predicate=None): """Return all members of an object as (name, value) pairs sorted by name. diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 75a74fa50f2..9fb0692702c 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -193,6 +193,14 @@ if sys.platform == 'darwin': newsoft = min(hard, max(soft, 1024*2048)) resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard)) +# Test result constants. +PASSED = 1 +FAILED = 0 +ENV_CHANGED = -1 +SKIPPED = -2 +RESOURCE_DENIED = -3 +INTERRUPTED = -4 + from test import support RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', @@ -352,7 +360,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(*args, **kwargs) except BaseException as e: - result = -4, e.__class__.__name__ + result = INTERRUPTED, e.__class__.__name__ sys.stdout.flush() print() # Force a newline (just in case) print(json.dumps(result)) @@ -443,19 +451,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, def accumulate_result(test, result): ok, test_time = result test_times.append((test_time, test)) - if ok > 0: + if ok == PASSED: good.append(test) - return 'good' - elif -2 < ok <= 0: + elif ok == FAILED: bad.append(test) - if ok == -1: - environment_changed.append(test) - return 'bad' - else: + elif ok == ENV_CHANGED: + bad.append(test) + environment_changed.append(test) + elif ok == SKIPPED: skipped.append(test) - if ok == -3: - resource_denieds.append(test) - return 'skipped' + elif ok == RESOURCE_DENIED: + skipped.append(test) + resource_denieds.append(test) if use_mp: from threading import Thread @@ -511,7 +518,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print(stdout) if stderr: print(stderr, file=sys.stderr) - if result[0] == -4: + if result[0] == INTERRUPTED: assert result[1] == 'KeyboardInterrupt' pending.clear() raise KeyboardInterrupt # What else? @@ -532,8 +539,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(test, verbose, quiet, testdir, huntrleaks, debug) - which = accumulate_result(test, result) - if verbose3 and which == 'bad': + accumulate_result(test, result) + if verbose3 and result[0] == FAILED: print("Re-running test {} in verbose mode".format(test)) runtest(test, True, quiet, testdir, huntrleaks, debug) except KeyboardInterrupt: @@ -679,15 +686,14 @@ def runtest(test, verbose, quiet, testdir -- test directory huntrleaks -- run multiple times to test for leaks; requires a debug build; a triple corresponding to -R's three arguments - debug -- if true, print tracebacks for failed tests regardless of - verbose setting - Return: - -4 KeyboardInterrupt when run under -j - -3 test skipped because resource denied - -2 test skipped for some other reason - -1 test failed because it changed the execution environment - 0 test failed - 1 test passed + + Returns one of the test result constants: + INTERRUPTED KeyboardInterrupt when run under -j + RESOURCE_DENIED test skipped because resource denied + SKIPPED test skipped for some other reason + ENV_CHANGED test failed because it changed the execution environment + FAILED test failed + PASSED test passed """ support.verbose = verbose # Tell tests to be moderately quiet @@ -843,18 +849,18 @@ def runtest_inner(test, verbose, quiet, if not quiet: print(test, "skipped --", msg) sys.stdout.flush() - return -3, test_time + return RESOURCE_DENIED, test_time except unittest.SkipTest as msg: if not quiet: print(test, "skipped --", msg) sys.stdout.flush() - return -2, test_time + return SKIPPED, test_time except KeyboardInterrupt: raise except support.TestFailed as msg: print("test", test, "failed --", msg) sys.stdout.flush() - return 0, test_time + return FAILED, test_time except: type, value = sys.exc_info()[:2] print("test", test, "crashed --", str(type) + ":", value) @@ -862,13 +868,13 @@ def runtest_inner(test, verbose, quiet, if verbose or debug: traceback.print_exc(file=sys.stdout) sys.stdout.flush() - return 0, test_time + return FAILED, test_time else: if refleak: - return 0, test_time + return FAILED, test_time if environment.changed: - return -1, test_time - return 1, test_time + return ENV_CHANGED, test_time + return PASSED, test_time def cleanup_test_droppings(testname, verbose): import shutil diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 0a832c43720..07697acbf22 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -154,6 +154,14 @@ class AST_Tests(unittest.TestCase): im = ast.parse("from . import y").body[0] self.assertIsNone(im.module) + def test_base_classes(self): + self.assertTrue(issubclass(ast.For, ast.stmt)) + self.assertTrue(issubclass(ast.Name, ast.expr)) + self.assertTrue(issubclass(ast.stmt, ast.AST)) + self.assertTrue(issubclass(ast.expr, ast.AST)) + self.assertTrue(issubclass(ast.comprehension, ast.AST)) + self.assertTrue(issubclass(ast.Gt, ast.AST)) + def test_nodeclasses(self): x = ast.BinOp(1, 2, 3, lineno=0) self.assertEquals(x.left, 1) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index c1df23e851b..9dba30db530 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -120,6 +120,28 @@ class TestPredicates(IsTestBase): self.assertTrue('a' in members) self.assertTrue('b' not in members) + def test_isabstract(self): + from abc import ABCMeta, abstractmethod + + class AbstractClassExample(metaclass=ABCMeta): + + @abstractmethod + def foo(self): + pass + + class ClassExample(AbstractClassExample): + def foo(self): + pass + + a = ClassExample() + + # Test general behaviour. + self.assertTrue(inspect.isabstract(AbstractClassExample)) + self.assertFalse(inspect.isabstract(ClassExample)) + self.assertFalse(inspect.isabstract(a)) + self.assertFalse(inspect.isabstract(int)) + self.assertFalse(inspect.isabstract(5)) + class TestInterpreterStack(IsTestBase): def __init__(self, *args, **kwargs): diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index 0e562906551..21ddc9af6fe 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -55,6 +55,14 @@ class ModuleTests(unittest.TestCase): {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) self.assertTrue(foo.__dict__ is d) + def test_dont_clear_dict(self): + # See issue 7140. + def f(): + foo = ModuleType("foo") + foo.bar = 4 + return foo + self.assertEqual(f().__dict__["bar"], 4) + def test_main(): run_unittest(ModuleTests) diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index fb60ee46468..9008717b907 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -493,9 +493,9 @@ class CacheTests(unittest.TestCase): _strptime._strptime_time("10", "%d") _strptime._strptime_time("2005", "%Y") _strptime._TimeRE_cache.locale_time.lang = "Ni" - original_time_re = id(_strptime._TimeRE_cache) + original_time_re = _strptime._TimeRE_cache _strptime._strptime_time("10", "%d") - self.assertNotEqual(original_time_re, id(_strptime._TimeRE_cache)) + self.assertIsNot(original_time_re, _strptime._TimeRE_cache) self.assertEqual(len(_strptime._regex_cache), 1) def test_regex_cleanup(self): @@ -514,11 +514,10 @@ class CacheTests(unittest.TestCase): def test_new_localetime(self): # A new LocaleTime instance should be created when a new TimeRE object # is created. - locale_time_id = id(_strptime._TimeRE_cache.locale_time) + locale_time_id = _strptime._TimeRE_cache.locale_time _strptime._TimeRE_cache.locale_time.lang = "Ni" _strptime._strptime_time("10", "%d") - self.assertNotEqual(locale_time_id, - id(_strptime._TimeRE_cache.locale_time)) + self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time) def test_TimeRE_recreation(self): # The TimeRE instance should be recreated upon changing the locale. @@ -530,15 +529,15 @@ class CacheTests(unittest.TestCase): try: _strptime._strptime_time('10', '%d') # Get id of current cache object. - first_time_re_id = id(_strptime._TimeRE_cache) + first_time_re = _strptime._TimeRE_cache try: # Change the locale and force a recreation of the cache. locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8')) _strptime._strptime_time('10', '%d') # Get the new cache object's id. - second_time_re_id = id(_strptime._TimeRE_cache) + second_time_re = _strptime._TimeRE_cache # They should not be equal. - self.assertNotEqual(first_time_re_id, second_time_re_id) + self.assertIsNot(first_time_re, second_time_re) # Possible test locale is not supported while initial locale is. # If this is the case just suppress the exception and fall-through # to the reseting to the original locale. diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 330a2c5d562..c5d8d79e354 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -185,11 +185,13 @@ class ThreadTests(BaseTestCase): except AsyncExc: pass else: + # This code is unreachable but it reflects the intent. If we wanted + # to be smarter the above loop wouldn't be infinite. self.fail("AsyncExc not raised") try: self.assertEqual(result, 1) # one thread state modified except UnboundLocalError: - # The exception was raised to quickly for us to get the result. + # The exception was raised too quickly for us to get the result. pass # `worker_started` is set by the thread when it's inside a try/except diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index ba705bac7ac..7b91ab2dbd3 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -531,6 +531,24 @@ pass the '-ucompiler' option to process the full directory. ... break ... else: True True + +Evil tabs + >>> dump_tokens("def f():\\n\\tif x\\n \\tpass") + ENCODING 'utf-8' (0, 0) (0, 0) + NAME 'def' (1, 0) (1, 3) + NAME 'f' (1, 4) (1, 5) + OP '(' (1, 5) (1, 6) + OP ')' (1, 6) (1, 7) + OP ':' (1, 7) (1, 8) + NEWLINE '\\n' (1, 8) (1, 9) + INDENT '\\t' (2, 0) (2, 1) + NAME 'if' (2, 1) (2, 3) + NAME 'x' (2, 4) (2, 5) + NEWLINE '\\n' (2, 5) (2, 6) + INDENT ' \\t' (3, 0) (3, 9) + NAME 'pass' (3, 9) (3, 13) + DEDENT '' (4, 0) (4, 0) + DEDENT '' (4, 0) (4, 0) """ from test import support diff --git a/Lib/tokenize.py b/Lib/tokenize.py index fb58c6b77a0..9d2a6bb88b4 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -23,15 +23,15 @@ __author__ = 'Ka-Ping Yee ' __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' 'Skip Montanaro, Raymond Hettinger, Trent Nelson, ' 'Michael Foord') - import re, string, sys from token import * from codecs import lookup, BOM_UTF8 cookie_re = re.compile("coding[:=]\s*([-\w.]+)") import token -__all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize", - "detect_encoding", "NL", "untokenize", "ENCODING", "TokenInfo"] +__all__ = [x for x in dir(token) if not x.startswith("_")] +__all__.extend(["COMMENT", "tokenize", "detect_encoding", "NL", "untokenize", + "ENCODING", "TokenInfo"]) del token COMMENT = N_TOKENS @@ -407,7 +407,7 @@ def _tokenize(readline, encoding): if encoding is not None: line = line.decode(encoding) - lnum = lnum + 1 + lnum += 1 pos, max = 0, len(line) if contstr: # continued string @@ -435,12 +435,17 @@ def _tokenize(readline, encoding): if not line: break column = 0 while pos < max: # measure leading whitespace - if line[pos] == ' ': column = column + 1 - elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize - elif line[pos] == '\f': column = 0 - else: break - pos = pos + 1 - if pos == max: break + if line[pos] == ' ': + column += 1 + elif line[pos] == '\t': + column = (column//tabsize + 1)*tabsize + elif line[pos] == '\f': + column = 0 + else: + break + pos += 1 + if pos == max: + break if line[pos] in '#\r\n': # skip comments or blank lines if line[pos] == '#': @@ -516,13 +521,15 @@ def _tokenize(readline, encoding): elif initial == '\\': # continued stmt continued = 1 else: - if initial in '([{': parenlev = parenlev + 1 - elif initial in ')]}': parenlev = parenlev - 1 + if initial in '([{': + parenlev += 1 + elif initial in ')]}': + parenlev -= 1 yield TokenInfo(OP, token, spos, epos, line) else: yield TokenInfo(ERRORTOKEN, line[pos], (lnum, pos), (lnum, pos+1), line) - pos = pos + 1 + pos += 1 for indent in indents[1:]: # pop remaining indent levels yield TokenInfo(DEDENT, '', (lnum, 0), (lnum, 0), '') diff --git a/Lib/xml/__init__.py b/Lib/xml/__init__.py index fa5e8cd4999..deed983d976 100644 --- a/Lib/xml/__init__.py +++ b/Lib/xml/__init__.py @@ -19,12 +19,6 @@ etree -- The ElementTree XML library. This is a subset of the full __all__ = ["dom", "parsers", "sax", "etree"] -# When being checked-out without options, this has the form -# "Revision: x.y " -# When exported using -kv, it is "x.y". -__version__ = "$Revision$".split()[-2:][0] - - _MINIMUM_XMLPLUS_VERSION = (0, 8, 4) diff --git a/Misc/Porting b/Misc/Porting index 1b94f141e9f..ec9cf1f4411 100644 --- a/Misc/Porting +++ b/Misc/Porting @@ -31,8 +31,7 @@ target platform. Forget about the posix module for now -- simply take it out of the config.c file. Bang on it until you get a >>> prompt. (You may have to disable the -importing of "site.py" and "exceptions.py" by passing -X and -S -options. +importing of "site.py" by passing the -S options.) Then bang on it until it executes very simple Python statements. diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index ad9730d67ae..c19c4c08ae6 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -597,9 +597,6 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds) Py_CLEAR(self->writenl); Py_CLEAR(self->decoder); - assert((newline != NULL && newline_obj != Py_None) || - (newline == NULL && newline_obj == Py_None)); - assert((newline != NULL && newline_obj != Py_None) || (newline == NULL && newline_obj == Py_None)); diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 249c22765e8..052fca1be31 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -661,7 +661,7 @@ PyDoc_STRVAR(math_ceil_doc, "This is the smallest integral value >= x."); FUNC2(copysign, copysign, - "copysign(x,y)\n\nReturn x with the sign of y.") + "copysign(x, y)\n\nReturn x with the sign of y.") FUNC1(cos, cos, 0, "cos(x)\n\nReturn the cosine of x (measured in radians).") FUNC1(cosh, cosh, 1, @@ -695,8 +695,8 @@ PyDoc_STRVAR(math_floor_doc, FUNC1A(gamma, m_tgamma, "gamma(x)\n\nGamma function at x.") FUNC1(log1p, log1p, 1, - "log1p(x)\n\nReturn the natural logarithm of 1+x (base e).\n\ - The result is computed in a way which is accurate for x near zero.") + "log1p(x)\n\nReturn the natural logarithm of 1+x (base e).\n" + "The result is computed in a way which is accurate for x near zero.") FUNC1(sin, sin, 0, "sin(x)\n\nReturn the sine of x (measured in radians).") FUNC1(sinh, sinh, 1, @@ -925,7 +925,7 @@ _fsum_error: #undef NUM_PARTIALS PyDoc_STRVAR(math_fsum_doc, -"sum(iterable)\n\n\ +"fsum(iterable)\n\n\ Return an accurate floating point sum of values in the iterable.\n\ Assumes IEEE-754 floating point arithmetic."); @@ -1101,7 +1101,8 @@ math_ldexp(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_ldexp_doc, -"ldexp(x, i) -> x * (2**i)"); +"ldexp(x, i)\n\n\ +Return x * (2**i)."); static PyObject * math_modf(PyObject *self, PyObject *arg) @@ -1192,7 +1193,8 @@ math_log(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_log_doc, -"log(x[, base]) -> the logarithm of x to the given base.\n\ +"log(x[, base])\n\n\ +Return the logarithm of x to the given base.\n\ If the base not specified, returns the natural logarithm (base e) of x."); static PyObject * @@ -1202,7 +1204,7 @@ math_log10(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_log10_doc, -"log10(x) -> the base 10 logarithm of x."); +"log10(x)\n\nReturn the base 10 logarithm of x."); static PyObject * math_fmod(PyObject *self, PyObject *args) @@ -1235,7 +1237,7 @@ math_fmod(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_fmod_doc, -"fmod(x,y)\n\nReturn fmod(x, y), according to platform C." +"fmod(x, y)\n\nReturn fmod(x, y), according to platform C." " x % y may differ."); static PyObject * @@ -1277,7 +1279,7 @@ math_hypot(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_hypot_doc, -"hypot(x,y)\n\nReturn the Euclidean distance, sqrt(x*x + y*y)."); +"hypot(x, y)\n\nReturn the Euclidean distance, sqrt(x*x + y*y)."); /* pow can't use math_2, but needs its own wrapper: the problem is that an infinite result can arise either as a result of overflow @@ -1364,7 +1366,7 @@ math_pow(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_pow_doc, -"pow(x,y)\n\nReturn x**y (x to the power of y)."); +"pow(x, y)\n\nReturn x**y (x to the power of y)."); static const double degToRad = Py_MATH_PI / 180.0; static const double radToDeg = 180.0 / Py_MATH_PI; @@ -1379,7 +1381,8 @@ math_degrees(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_degrees_doc, -"degrees(x) -> converts angle x from radians to degrees"); +"degrees(x)\n\n\ +Convert angle x from radians to degrees."); static PyObject * math_radians(PyObject *self, PyObject *arg) @@ -1391,7 +1394,8 @@ math_radians(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_radians_doc, -"radians(x) -> converts angle x from degrees to radians"); +"radians(x)\n\n\ +Convert angle x from degrees to radians."); static PyObject * math_isnan(PyObject *self, PyObject *arg) @@ -1403,8 +1407,8 @@ math_isnan(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_isnan_doc, -"isnan(x) -> bool\n\ -Checks if float x is not a number (NaN)"); +"isnan(x) -> bool\n\n\ +Check if float x is not a number (NaN)."); static PyObject * math_isinf(PyObject *self, PyObject *arg) @@ -1416,8 +1420,8 @@ math_isinf(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_isinf_doc, -"isinf(x) -> bool\n\ -Checks if float x is infinite (positive or negative)"); +"isinf(x) -> bool\n\n\ +Check if float x is infinite (positive or negative)."); static PyMethodDef math_methods[] = { {"acos", math_acos, METH_O, math_acos_doc}, diff --git a/Modules/operator.c b/Modules/operator.c index 0ba8b09941f..85d662d9591 100644 --- a/Modules/operator.c +++ b/Modules/operator.c @@ -7,7 +7,7 @@ PyDoc_STRVAR(operator_doc, This module exports a set of functions implemented in C corresponding\n\ to the intrinsic operators of Python. For example, operator.add(x, y)\n\ is equivalent to the expression x+y. The function names are those\n\ -used for special class methods; variants without leading and trailing\n\ +used for special methods; variants without leading and trailing\n\ '__' are also provided for convenience."); #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ @@ -197,21 +197,21 @@ spam2o(not_,__not__, "not_(a) -- Same as not a.") spam2(and_,__and__, "and_(a, b) -- Same as a & b.") spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") spam2(or_,__or__, "or_(a, b) -- Same as a | b.") -spam2(iadd,__iadd__, "iadd(a, b) -- Same as a += b.") -spam2(isub,__isub__, "isub(a, b) -- Same as a -= b.") -spam2(imul,__imul__, "imul(a, b) -- Same as a *= b.") -spam2(ifloordiv,__ifloordiv__, "ifloordiv(a, b) -- Same as a //= b.") -spam2(itruediv,__itruediv__, "itruediv(a, b) -- Same as a /= b.") -spam2(imod,__imod__, "imod(a, b) -- Same as a %= b.") -spam2(ilshift,__ilshift__, "ilshift(a, b) -- Same as a <<= b.") -spam2(irshift,__irshift__, "irshift(a, b) -- Same as a >>= b.") -spam2(iand,__iand__, "iand(a, b) -- Same as a &= b.") -spam2(ixor,__ixor__, "ixor(a, b) -- Same as a ^= b.") -spam2(ior,__ior__, "ior(a, b) -- Same as a |= b.") +spam2(iadd,__iadd__, "a = iadd(a, b) -- Same as a += b.") +spam2(isub,__isub__, "a = isub(a, b) -- Same as a -= b.") +spam2(imul,__imul__, "a = imul(a, b) -- Same as a *= b.") +spam2(ifloordiv,__ifloordiv__, "a = ifloordiv(a, b) -- Same as a //= b.") +spam2(itruediv,__itruediv__, "a = itruediv(a, b) -- Same as a /= b") +spam2(imod,__imod__, "a = imod(a, b) -- Same as a %= b.") +spam2(ilshift,__ilshift__, "a = ilshift(a, b) -- Same as a <<= b.") +spam2(irshift,__irshift__, "a = irshift(a, b) -- Same as a >>= b.") +spam2(iand,__iand__, "a = iand(a, b) -- Same as a &= b.") +spam2(ixor,__ixor__, "a = ixor(a, b) -- Same as a ^= b.") +spam2(ior,__ior__, "a = ior(a, b) -- Same as a |= b.") spam2(concat,__concat__, "concat(a, b) -- Same as a + b, for a and b sequences.") spam2(iconcat,__iconcat__, - "iconcat(a, b) -- Same as a += b, for a and b sequences.") + "a = iconcat(a, b) -- Same as a += b, for a and b sequences.") spam2(getitem,__getitem__, "getitem(a, b) -- Same as a[b].") spam2(setitem,__setitem__, @@ -219,7 +219,7 @@ spam2(setitem,__setitem__, spam2(delitem,__delitem__, "delitem(a, b) -- Same as del a[b].") spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.") -spam2(ipow,__ipow__, "ipow(a, b) -- Same as a **= b.") +spam2(ipow,__ipow__, "a = ipow(a, b) -- Same as a **= b.") spam2(lt,__lt__, "lt(a, b) -- Same as aprop_doc); prop->prop_doc = get_doc; - } else { - /* Put __doc__ in dict of the subclass instance instead, - otherwise it gets shadowed by class's __doc__. */ - if (PyObject_SetAttrString(self, "__doc__", get_doc) != 0) - { - /* DECREF for props handled by _dealloc */ - Py_DECREF(get_doc); + } + else { + /* If this is a property subclass, put __doc__ + in dict of the subclass instance instead, + otherwise it gets shadowed by __doc__ in the + class's dict. */ + int err = PyObject_SetAttrString(self, "__doc__", get_doc); + Py_DECREF(get_doc); + if (err < 0) return -1; - } - Py_DECREF(get_doc); } prop->getter_doc = 1; - } else { + } + else if (PyErr_ExceptionMatches(PyExc_Exception)) { PyErr_Clear(); } + else { + return -1; + } } return 0; diff --git a/Objects/listobject.c b/Objects/listobject.c index 2bab4ef26b3..09fba48f6dc 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -183,9 +183,12 @@ PyList_GetItem(PyObject *op, Py_ssize_t i) return NULL; } if (i < 0 || i >= Py_SIZE(op)) { - if (indexerr == NULL) + if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); + if (indexerr == NULL) + return NULL; + } PyErr_SetObject(PyExc_IndexError, indexerr); return NULL; } @@ -406,9 +409,12 @@ static PyObject * list_item(PyListObject *a, Py_ssize_t i) { if (i < 0 || i >= Py_SIZE(a)) { - if (indexerr == NULL) + if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); + if (indexerr == NULL) + return NULL; + } PyErr_SetObject(PyExc_IndexError, indexerr); return NULL; } diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 11dd43d23c8..c1dd228abf4 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -312,7 +312,10 @@ module_dealloc(PyModuleObject *m) if (m->md_def && m->md_def->m_free) m->md_def->m_free(m); if (m->md_dict != NULL) { - _PyModule_Clear((PyObject *)m); + /* If we are the only ones holding a reference, we can clear + the dictionary. */ + if (Py_REFCNT(m->md_dict) == 1) + _PyModule_Clear((PyObject *)m); Py_DECREF(m->md_dict); } if (m->md_state != NULL) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index e637cb37e5b..f3ef1cbc6c1 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -197,20 +197,26 @@ get_normal_name(char *s) /* for utf-8 and latin-1 */ int i; for (i = 0; i < 12; i++) { int c = s[i]; - if (c == '\0') break; - else if (c == '_') buf[i] = '-'; - else buf[i] = tolower(c); + if (c == '\0') + break; + else if (c == '_') + buf[i] = '-'; + else + buf[i] = tolower(c); } buf[i] = '\0'; if (strcmp(buf, "utf-8") == 0 || - strncmp(buf, "utf-8-", 6) == 0) return "utf-8"; + strncmp(buf, "utf-8-", 6) == 0) + return "utf-8"; else if (strcmp(buf, "latin-1") == 0 || strcmp(buf, "iso-8859-1") == 0 || strcmp(buf, "iso-latin-1") == 0 || strncmp(buf, "latin-1-", 8) == 0 || strncmp(buf, "iso-8859-1-", 11) == 0 || - strncmp(buf, "iso-latin-1-", 12) == 0) return "iso-8859-1"; - else return s; + strncmp(buf, "iso-latin-1-", 12) == 0) + return "iso-8859-1"; + else + return s; } /* Return the coding spec in S, or NULL if none is found. */ @@ -336,12 +342,18 @@ check_bom(int get_char(struct tok_state *), /* Disable support for UTF-16 BOMs until a decision is made whether this needs to be supported. */ } else if (ch == 0xFE) { - ch = get_char(tok); if (ch != 0xFF) goto NON_BOM; - if (!set_readline(tok, "utf-16-be")) return 0; + ch = get_char(tok); + if (ch != 0xFF) + goto NON_BOM; + if (!set_readline(tok, "utf-16-be")) + return 0; tok->decoding_state = STATE_NORMAL; } else if (ch == 0xFF) { - ch = get_char(tok); if (ch != 0xFE) goto NON_BOM; - if (!set_readline(tok, "utf-16-le")) return 0; + ch = get_char(tok); + if (ch != 0xFE) + goto NON_BOM; + if (!set_readline(tok, "utf-16-le")) + return 0; tok->decoding_state = STATE_NORMAL; #endif } else { @@ -1036,7 +1048,7 @@ tok_backup(register struct tok_state *tok, register int c) { if (c != EOF) { if (--tok->cur < tok->buf) - Py_FatalError("tok_backup: begin of buffer"); + Py_FatalError("tok_backup: beginning of buffer"); if (*tok->cur != c) *tok->cur = c; }