]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 70507-70508 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 21 Mar 2009 17:44:10 +0000 (17:44 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 21 Mar 2009 17:44:10 +0000 (17:44 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r70507 | benjamin.peterson | 2009-03-21 12:31:58 -0500 (Sat, 21 Mar 2009) | 75 lines

  Merged revisions 70342,70385-70387,70389-70390,70392-70393,70395,70400,70405-70406,70418,70438,70464,70468 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r70342 | georg.brandl | 2009-03-13 14:03:58 -0500 (Fri, 13 Mar 2009) | 1 line

    #5486: typos.
  ........
    r70385 | benjamin.peterson | 2009-03-15 09:38:55 -0500 (Sun, 15 Mar 2009) | 1 line

    fix tuple.index() error message #5495
  ........
    r70386 | georg.brandl | 2009-03-15 16:32:06 -0500 (Sun, 15 Mar 2009) | 1 line

    #5496: fix docstring of lookup().
  ........
    r70387 | georg.brandl | 2009-03-15 16:37:16 -0500 (Sun, 15 Mar 2009) | 1 line

    #5493: clarify __nonzero__ docs.
  ........
    r70389 | georg.brandl | 2009-03-15 16:43:38 -0500 (Sun, 15 Mar 2009) | 1 line

    Fix a small nit in the error message if bool() falls back on __len__ and it returns the wrong type: it would tell the user that __nonzero__ should return bool or int.
  ........
    r70390 | georg.brandl | 2009-03-15 16:44:43 -0500 (Sun, 15 Mar 2009) | 1 line

    #5491: clarify nested() semantics.
  ........
    r70392 | georg.brandl | 2009-03-15 16:46:00 -0500 (Sun, 15 Mar 2009) | 1 line

    #5488: add missing struct member.
  ........
    r70393 | georg.brandl | 2009-03-15 16:47:42 -0500 (Sun, 15 Mar 2009) | 1 line

    #5478: fix copy-paste oversight in function signature.
  ........
    r70395 | georg.brandl | 2009-03-15 16:51:48 -0500 (Sun, 15 Mar 2009) | 1 line

    #5276: document IDLESTARTUP and .Idle.py.
  ........
    r70400 | georg.brandl | 2009-03-15 16:59:37 -0500 (Sun, 15 Mar 2009) | 3 lines

    Fix markup in re docs and give a mail address in regex howto, so that
    the recommendation to send suggestions to the author can be followed.
  ........
    r70405 | georg.brandl | 2009-03-15 17:11:07 -0500 (Sun, 15 Mar 2009) | 7 lines

    Move the previously local import of threading to module level.

    This is cleaner and avoids lockups in obscure cases where a Queue
    is instantiated while the import lock is already held by another thread.

    OKed by Tim Peters.
  ........
    r70406 | hirokazu.yamamoto | 2009-03-15 17:43:14 -0500 (Sun, 15 Mar 2009) | 1 line

    Added skip for old MSVC.
  ........
    r70418 | georg.brandl | 2009-03-16 14:42:03 -0500 (Mon, 16 Mar 2009) | 1 line

    Add token markup.
  ........
    r70438 | benjamin.peterson | 2009-03-17 15:29:51 -0500 (Tue, 17 Mar 2009) | 1 line

    I thought this was begging for an example
  ........
    r70464 | benjamin.peterson | 2009-03-18 15:58:09 -0500 (Wed, 18 Mar 2009) | 1 line

    a much better example
  ........
    r70468 | benjamin.peterson | 2009-03-18 22:04:31 -0500 (Wed, 18 Mar 2009) | 1 line

    close files after comparing them
  ........
................
  r70508 | benjamin.peterson | 2009-03-21 12:36:10 -0500 (Sat, 21 Mar 2009) | 1 line

  port the queue change r70405
................

14 files changed:
Doc/c-api/typeobj.rst
Doc/howto/regex.rst
Doc/library/contextlib.rst
Doc/library/functions.rst
Doc/library/idle.rst
Doc/library/re.rst
Doc/library/string.rst
Doc/library/xml.dom.rst
Doc/reference/datamodel.rst
Lib/filecmp.py
Lib/queue.py
Modules/_codecsmodule.c
Objects/tupleobject.c
Objects/typeobject.c

index 7dd576e7bbaec58f03837bfc8744efbca69b6a42..8f6a012f0d70a3fd176c922f2248060e6c2fdd5a 100644 (file)
@@ -1052,6 +1052,7 @@ Number Object Structures
             binaryfunc nb_inplace_add;
             binaryfunc nb_inplace_subtract;
             binaryfunc nb_inplace_multiply;
+            binaryfunc nb_inplace_divide;
             binaryfunc nb_inplace_remainder;
             ternaryfunc nb_inplace_power;
             binaryfunc nb_inplace_lshift;
index c74fd3984fa1cee5b7e5b816d684aa9e778afd18..3ed53686d36e3eb1aa0015fd6eb715f7995babd0 100644 (file)
@@ -4,7 +4,7 @@
   Regular Expression HOWTO
 ****************************
 
-:Author: A.M. Kuchling
+:Author: A.M. Kuchling <amk@amk.ca>
 :Release: 0.05
 
 .. TODO:
index 74a68cfc82fde5be33ef44cab0346d7fd29cef43..e2ca6a1a8efd09eff6edf67b0e3984f7492761a8 100644 (file)
@@ -61,14 +61,15 @@ Functions provided:
 
       from contextlib import nested
 
-      with nested(A, B, C) as (X, Y, Z):
+      with nested(A(), B(), C()) as (X, Y, Z):
           do_something()
 
    is equivalent to this::
 
-      with A as X:
-          with B as Y:
-              with C as Z:
+      m1, m2, m3 = A(), B(), C()
+      with m1 as X:
+          with m2 as Y:
+              with m3 as Z:
                   do_something()
 
    Note that if the :meth:`__exit__` method of one of the nested context managers
index 9057a7a0443787d938b5e3ab6e2dc4a275011073..e2562ea43137d28b83a37e3ae01c9a16084cc1bc 100644 (file)
@@ -560,6 +560,14 @@ are always available.  They are listed here in alphabetical order.
    its :meth:`__next__` method; if the value returned is equal to *sentinel*,
    :exc:`StopIteration` will be raised, otherwise the value will be returned.
 
+   One useful application of the second form of :func:`iter` is to read lines of
+   a file until a certain line is reached.  The following example reads a file
+   until ``"STOP"`` is reached: ::
+
+      with open("mydata.txt") as fp:
+          for line in iter(fp.readline, "STOP"):
+              process_line(line)
+
 
 .. function:: len(s)
 
index 413750fda54e0bd9a1e751c2242f2916400f0899..1b78fb9bc1bb50e6b1db03a62cbbb3df02e2e1bd 100644 (file)
@@ -253,6 +253,24 @@ Shell colors:
       black
 
 
+Startup
+-------
+
+Upon startup with the ``-s`` option, IDLE will execute the file referenced by
+the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
+Idle first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
+referenced is run.  If ``IDLESTARTUP`` is not present, Idle checks for
+``PYTHONSTARTUP``.  Files referenced by these environment variables are
+convenient places to store functions that are used frequently from the Idle
+shell, or for executing import statements to import common modules.
+
+In addition, ``Tk`` also loads a startup file if it is present.  Note that the
+Tk file is loaded unconditionally.  This additional file is ``.Idle.py`` and is
+looked for in the user's home directory.  Statements in this file will be
+executed in the Tk namespace, so this file is not useful for importing functions
+to be used from Idle's Python shell.
+
+
 Command line usage
 ^^^^^^^^^^^^^^^^^^
 
index 9399a49e148630ed5a1bbd24c864a4c11eba348d..4232ccc711e476d7e6e5de83406075889b8fd53b 100644 (file)
@@ -1114,7 +1114,7 @@ For example:
    string)`` or ``re.search(pattern, string)``.
 
 :func:`match` has an optional second parameter that gives an index in the string
-where the search is to start:
+where the search is to start::
 
    >>> pattern = re.compile("o")
    >>> pattern.match("dog")      # No match as "o" is not at the start of "dog."
index 98c705129856da0d75d06b37e3dd5bebf5515570..2e444adf3430a6253f02755fa39ad616227c8b8e 100644 (file)
@@ -196,7 +196,7 @@ The grammar for a replacement field is as follows:
 
    .. productionlist:: sf
       replacement_field: "{" `field_name` ["!" `conversion`] [":" `format_spec`] "}"
-      field_name: (`identifier` | `integer`) ("." `attribute_name` | "[" element_index "]")*
+      field_name: (`identifier` | `integer`) ("." `attribute_name` | "[" `element_index` "]")*
       attribute_name: `identifier`
       element_index: `integer`
       conversion: "r" | "s" | "a"
index 2a0c788abb9a001993e4e20763edfa7a3a633415..bf1b1513852a8da618db404d0d48f4fcac281256 100644 (file)
@@ -600,7 +600,7 @@ of that class.
    Same as equivalent method in the :class:`Document` class.
 
 
-.. method:: Element.getElementsByTagNameNS(tagName)
+.. method:: Element.getElementsByTagNameNS(namespaceURI, localName)
 
    Same as equivalent method in the :class:`Document` class.
 
index 3fda6a4a68fd4bd46388224f020b0af99de40ba4..b38e9d7637aec2c4e25600a03584c03879c3480b 100644 (file)
@@ -1248,11 +1248,12 @@ Basic customization
 
    .. index:: single: __len__() (mapping object method)
 
-   Called to implement truth value testing, and the built-in operation ``bool()``;
-   should return ``False`` or ``True``. When this method is not defined,
-   :meth:`__len__` is called, if it is defined (see below) and ``True`` is returned
-   when the length is not zero.  If a class defines neither :meth:`__len__` nor
-   :meth:`__bool__`, all its instances are considered true.
+   Called to implement truth value testing and the built-in operation
+   ``bool()``; should return ``False`` or ``True``, or their integer equivalents
+   ``0`` or ``1``.  When this method is not defined, :meth:`__len__` is called,
+   if it is defined, and the object is considered true if its result is nonzero.
+   If a class defines neither :meth:`__len__` nor :meth:`__bool__`, all its
+   instances are considered true.
 
 
 .. _attribute-access:
index 6dcebaa23dfc75f9a8645b7f3c9cf63edbe413a8..4cbb0d682b9af4af3331a1efbb2d808caaa5c729 100644 (file)
@@ -11,6 +11,7 @@ Functions:
 
 import os
 import stat
+import contextlib
 from itertools import filterfalse
 
 __all__ = ["cmp","dircmp","cmpfiles"]
@@ -62,15 +63,14 @@ def _sig(st):
 
 def _do_cmp(f1, f2):
     bufsize = BUFSIZE
-    fp1 = open(f1, 'rb')
-    fp2 = open(f2, 'rb')
-    while True:
-        b1 = fp1.read(bufsize)
-        b2 = fp2.read(bufsize)
-        if b1 != b2:
-            return False
-        if not b1:
-            return True
+    with contextlib.nested(open(f1, 'rb'), open(f2, 'rb')) as (fp1, fp2):
+        while True:
+            b1 = fp1.read(bufsize)
+            b2 = fp2.read(bufsize)
+            if b1 != b2:
+                return False
+            if not b1:
+                return True
 
 # Directory comparison class.
 #
index 7cb297c9167e1c5564ca3d5634cc806c4d910859..29292223d7db9125c14d4d861ab408b77861210c 100644 (file)
@@ -1,6 +1,10 @@
 """A multi-producer, multi-consumer queue."""
 
 from time import time as _time
+try:
+    import threading as _threading
+except ImportError:
+    import dummy_threading as _threading
 from collections import deque
 import heapq
 
@@ -20,26 +24,22 @@ class Queue:
     If maxsize is <= 0, the queue size is infinite.
     """
     def __init__(self, maxsize=0):
-        try:
-            import threading
-        except ImportError:
-            import dummy_threading as threading
         self.maxsize = maxsize
         self._init(maxsize)
         # mutex must be held whenever the queue is mutating.  All methods
         # that acquire mutex must release it before returning.  mutex
         # is shared between the three conditions, so acquiring and
         # releasing the conditions also acquires and releases mutex.
-        self.mutex = threading.Lock()
+        self.mutex = _threading.Lock()
         # Notify not_empty whenever an item is added to the queue; a
         # thread waiting to get is notified then.
-        self.not_empty = threading.Condition(self.mutex)
+        self.not_empty = _threading.Condition(self.mutex)
         # Notify not_full whenever an item is removed from the queue;
         # a thread waiting to put is notified then.
-        self.not_full = threading.Condition(self.mutex)
+        self.not_full = _threading.Condition(self.mutex)
         # Notify all_tasks_done whenever the number of unfinished tasks
         # drops to zero; thread waiting to join() is notified to resume
-        self.all_tasks_done = threading.Condition(self.mutex)
+        self.all_tasks_done = _threading.Condition(self.mutex)
         self.unfinished_tasks = 0
 
     def task_done(self):
index e7dbf89499ee96c41884ea5ed6b5989dfb9a9a32..cbcf84dd07d953d8aee07e5e520e851529093644 100644 (file)
@@ -61,7 +61,7 @@ PyDoc_STRVAR(lookup__doc__,
 "lookup(encoding) -> CodecInfo\n\
 \n\
 Looks up a codec tuple in the Python codec registry and returns\n\
-a tuple of function (or a CodecInfo object).");
+a CodecInfo object.");
 
 static
 PyObject *codec_lookup(PyObject *self, PyObject *args)
index d3a8a8abdd76f947d26d6ff32b5162f646160ec2..42758084f8266e9f8c30b87dcad8cc498a16bcb7 100644 (file)
@@ -458,7 +458,7 @@ tupleindex(PyTupleObject *self, PyObject *args)
                else if (cmp < 0)
                        return NULL;
        }
-       PyErr_SetString(PyExc_ValueError, "tuple.index(x): x not in list");
+       PyErr_SetString(PyExc_ValueError, "tuple.index(x): x not in tuple");
        return NULL;
 }
 
index da5df518a6c34b8fe8bd71cc9eb0be95ec328c5b..e7f68d693ede144bc056ca35e65d2a66c88cfadc 100644 (file)
@@ -4785,7 +4785,7 @@ slot_nb_bool(PyObject *self)
        PyObject *func, *args;
        static PyObject *bool_str, *len_str;
        int result = -1;
-       int from_len = 0;
+       int using_len = 0;
 
        func = lookup_maybe(self, "__bool__", &bool_str);
        if (func == NULL) {
@@ -4794,14 +4794,14 @@ slot_nb_bool(PyObject *self)
                func = lookup_maybe(self, "__len__", &len_str);
                if (func == NULL)
                        return PyErr_Occurred() ? -1 : 1;
-               from_len = 1;
-       }
+               using_len = 1;
+       }
        args = PyTuple_New(0);
        if (args != NULL) {
                PyObject *temp = PyObject_Call(func, args, NULL);
                Py_DECREF(args);
                if (temp != NULL) {
-                       if (from_len) {
+                       if (using_len) {
                                /* enforced by slot_nb_len */
                                result = PyObject_IsTrue(temp);
                        }
@@ -4810,9 +4810,11 @@ slot_nb_bool(PyObject *self)
                        }
                        else {
                                PyErr_Format(PyExc_TypeError,
-                                        "__bool__ should return "
-                                        "bool, returned %s",
-                                        Py_TYPE(temp)->tp_name);
+                                            "%s should return "
+                                            "bool or int, returned %s",
+                                            (using_len ? "__len__"
+                                                       : "__bool__"),
+                                            Py_TYPE(temp)->tp_name);
                                result = -1;
                        }
                        Py_DECREF(temp);