diff options
-rw-r--r-- | Doc/distutils/apiref.rst | 2 | ||||
-rw-r--r-- | Doc/distutils/examples.rst | 8 | ||||
-rw-r--r-- | Doc/library/2to3.rst | 8 | ||||
-rw-r--r-- | Doc/library/bdb.rst | 12 | ||||
-rw-r--r-- | Doc/library/io.rst | 4 | ||||
-rw-r--r-- | Doc/library/operator.rst | 156 | ||||
-rw-r--r-- | Doc/library/pdb.rst | 2 | ||||
-rw-r--r-- | Doc/library/profile.rst | 2 | ||||
-rw-r--r-- | Doc/library/pty.rst | 12 | ||||
-rw-r--r-- | Doc/library/turtle.rst | 2 | ||||
-rw-r--r-- | Doc/library/weakref.rst | 7 | ||||
-rw-r--r-- | Doc/library/zipfile.rst | 7 | ||||
-rw-r--r-- | Doc/whatsnew/2.6.rst | 10 | ||||
-rw-r--r-- | Lib/distutils/command/check.py | 2 | ||||
-rw-r--r-- | Lib/inspect.py | 2 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 8 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 22 | ||||
-rw-r--r-- | Lib/test/test_module.py | 8 | ||||
-rw-r--r-- | Lib/test/test_strptime.py | 15 | ||||
-rw-r--r-- | Lib/test/test_tokenize.py | 18 | ||||
-rw-r--r-- | Lib/tokenize.py | 33 | ||||
-rw-r--r-- | Lib/xml/__init__.py | 6 | ||||
-rw-r--r-- | Misc/Porting | 3 | ||||
-rw-r--r-- | Modules/mathmodule.c | 36 | ||||
-rw-r--r-- | Modules/operator.c | 28 | ||||
-rw-r--r-- | Objects/descrobject.c | 29 | ||||
-rw-r--r-- | Objects/listobject.c | 10 | ||||
-rw-r--r-- | Objects/moduleobject.c | 5 | ||||
-rw-r--r-- | Parser/tokenizer.c | 34 |
29 files changed, 307 insertions, 184 deletions
diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst index cdb32d3..69ec0de 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 d5918a5..648063b 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 f37bb05..d9eb00c 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 3e5fcd6..d6d4ae2 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 5188b51..8fb984e 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 24ace8b..175314e 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 95e17b2..b48f842 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 132365a..d676671 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -7,6 +7,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 6579ef0..be879f2 100644 --- a/Doc/library/pty.rst +++ b/Doc/library/pty.rst @@ -3,8 +3,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 <moshez@zadka.site.co.il> @@ -14,8 +14,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: @@ -32,8 +32,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/turtle.rst b/Doc/library/turtle.rst index d70550a..d947186 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 <screenspecific>`. -.. 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 d462f6e..639d8d0 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -69,10 +69,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 a7fb842..ae8751e 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 27d8e5c..8b71153 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 9a8fca1..12844cb 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 1f1b7f9..c489502 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/test_ast.py b/Lib/test/test_ast.py index c22d0d4..7ee16bf 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -140,6 +140,14 @@ class AST_Tests(unittest.TestCase): self.assertEquals(to_tuple(ast_tree), o) self._assertTrueorder(ast_tree, (0, 0)) + 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 c1df23e..9dba30d 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 0e56290..21ddc9a 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 fb60ee4..9008717 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_tokenize.py b/Lib/test/test_tokenize.py index ba705ba..7b91ab2 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 fb58c6b..9d2a6bb 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -23,15 +23,15 @@ __author__ = 'Ka-Ping Yee <ping@lfw.org>' __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 fa5e8cd..deed983 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 -# "<dollar>Revision: x.y </dollar>" -# 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 1b94f14..ec9cf1f 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/mathmodule.c b/Modules/mathmodule.c index 38d214a..27ffcfc 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -374,7 +374,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, @@ -406,8 +406,8 @@ PyDoc_STRVAR(math_floor_doc, "This is the largest integral value <= 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, @@ -636,7 +636,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."); @@ -812,7 +812,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) @@ -903,7 +904,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 * @@ -913,7 +915,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) @@ -946,7 +948,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 * @@ -988,7 +990,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 @@ -1075,7 +1077,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; @@ -1090,7 +1092,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) @@ -1102,7 +1105,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) @@ -1114,8 +1118,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) @@ -1127,8 +1131,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 0ba8b09..85d662d 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 a<b.") spam2(le,__le__, "le(a, b) -- Same as a<=b.") spam2(eq,__eq__, "eq(a, b) -- Same as a==b.") diff --git a/Objects/descrobject.c b/Objects/descrobject.c index d658151..81e6be9 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1293,26 +1293,29 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds) /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && get != NULL) { PyObject *get_doc = PyObject_GetAttrString(get, "__doc__"); - if (get_doc != NULL) { - /* get_doc already INCREF'd by GetAttr */ - if (Py_TYPE(self)==&PyProperty_Type) { + if (get_doc) { + if (Py_TYPE(self) == &PyProperty_Type) { Py_XDECREF(prop->prop_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 2bab4ef..09fba48 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 11dd43d..c1dd228 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 cc142a7..c1a6014 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -195,20 +195,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. */ @@ -334,12 +340,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 { @@ -980,7 +992,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; } |