Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888...
authorGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 12:55:28 +0000 (12:55 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 12:55:28 +0000 (12:55 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines

  #2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade.

  This is a new feature, but Barry authorized adding it in the beta period.
........
  r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines

  Issue 3188: accept float('infinity') as well as float('inf').  This
  makes the float constructor behave in the same way as specified
  by various other language standards, including C99, IEEE 754r,
  and the IBM Decimal standard.
........
  r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines

  - Issue #2862: Make int and float freelist management consistent with other
    freelists.  Changes their CompactFreeList apis into ClearFreeList apis and
    calls them via gc.collect().
........
  r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line

  Issue 3301:  Bisect functions behaved badly when lo was negative.
........
  r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line

  Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments.
........
  r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line

  Wording changes
........
  r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line

  Add cautionary note on the use of PySequence_Fast_ITEMS.
........
  r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines

  #3317 in zipfile module, restore the previous names of global variables:
  some applications relied on them.

  Also remove duplicated lines.
........
  r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines

  #3342: In tracebacks, printed source lines were not indented since r62555.
  #3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
........
  r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines

  Fix for the AttributeError in test_asynchat.
........
  r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines

  Fixed test for asyncore.
........
  r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines

  - Fix bashisms in Tools/faqwiz/move-faqwiz.sh
........
  r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line

  fix various doc typos #3320
........
  r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines

  Fixed typo.
........
  r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line

  #1778443 robotparser fixes from Aristotelis Mikropoulos
........
  r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line

  Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute)
........
  r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines

  Add turtle into the module index.
........
  r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines

  Issue #3274: Use a less common identifier for the temporary variable
  in Py_CLEAR().
........
  r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line

  Re-word
........
  r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line

  Add various items; move ctypes items into a subsection of their own
........
  r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line

  Typo fixes
........
  r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line

  Typo fix
........
  r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line

  Typo fix
........
  r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line

  Expand the multiprocessing section
........
  r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines

  Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child
  process rather than both parent and child.

  Does anyone actually use fork1()?  It appears to be a Solaris thing
  but if Python is built with pthreads on Solaris, fork1() and fork()
  should be the same.
........
  r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line

  multiprocessing/connection.py patch to remove fqdn oddness for issue 3270
........
  r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line

  Add missing NEWS entry for r64962
........
  r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line

  Revert 3270 patch: self._address is in pretty widespread use, need to revisit
........

46 files changed:
Doc/c-api/conversion.rst
Doc/c-api/float.rst
Doc/c-api/sequence.rst
Doc/extending/windows.rst
Doc/library/__future__.rst
Doc/library/ctypes.rst
Doc/library/ftplib.rst
Doc/library/functions.rst
Doc/library/gc.rst
Doc/library/multiprocessing.rst
Doc/library/operator.rst
Doc/library/select.rst
Doc/library/stdtypes.rst
Doc/library/string.rst
Doc/library/sys.rst
Doc/library/tkinter.tix.rst
Doc/library/tkinter.turtle.rst
Doc/library/urllib.request.rst
Doc/library/wsgiref.rst
Doc/library/xmlrpc.client.rst
Doc/tutorial/stdlib2.rst
Doc/using/windows.rst
Doc/whatsnew/2.6.rst
Include/floatobject.h
Include/object.h
Include/traceback.h
Lib/bisect.py
Lib/fractions.py
Lib/multiprocessing/connection.py
Lib/shutil.py
Lib/test/test_bisect.py
Lib/test/test_float.py
Lib/test/test_fractions.py
Lib/test/test_import.py
Lib/test/test_shutil.py
Lib/zipfile.py
Misc/ACKS
Modules/_bisectmodule.c
Modules/gcmodule.c
Modules/posixmodule.c
Objects/floatobject.c
Python/_warnings.c
Python/import.c
Python/sysmodule.c
Python/traceback.c
Tools/faqwiz/move-faqwiz.sh

index f926094269e21bac90900d7b7384cd8ca9ac5fbf..b71283ba9e1145f86a8d9f79e0a8ffbd4728a009 100644 (file)
@@ -83,11 +83,11 @@ The following functions provide locale-independent string to number conversions.
    
 .. cfunction:: char * PyOS_stricmp(char *s1, char *s2)
 
-   Case insensitive comparison of strings. The functions works almost
-   identical to :cfunc:`strcmp` except that it ignores the case.
+   Case insensitive comparison of strings. The function works almost
+   identically to :cfunc:`strcmp` except that it ignores the case.
 
 
 .. cfunction:: char * PyOS_strnicmp(char *s1, char *s2, Py_ssize_t  size)
 
-   Case insensitive comparison of strings. The functions works almost
-   identical to :cfunc:`strncmp` except that it ignores the case.
+   Case insensitive comparison of strings. The function works almost
+   identically to :cfunc:`strncmp` except that it ignores the case.
index 8fff0d04e4c6d450c087933d418c3f3870358af7..77a8b83bc21828c3627f7528fc1c0ca582216a5e 100644 (file)
@@ -73,8 +73,7 @@ Floating Point Objects
 
    Return the minimum normalized positive float *DBL_MIN* as C :ctype:`double`.
 
-.. cfunction:: void PyFloat_CompactFreeList(size_t *bc, size_t *bf, size_t *sum)
+.. cfunction:: int PyFloat_ClearFreeList(void)
 
-   Compact the float free list. *bc* is the number of allocated blocks before
-   blocks are freed, *bf* is the number of freed blocks and *sum* is the number
-   of remaining objects in the blocks.
+   Clear the float free list. Return the number of items that could not
+   be freed.
index 6d3ef710836def3023627968a4b9e2f6d5738b7f..0ebc0f3f00a4f539e96db918e420450d2d22d32d 100644 (file)
@@ -143,6 +143,10 @@ Sequence Protocol
 
    Return the underlying array of PyObject pointers.  Assumes that *o* was returned
    by :cfunc:`PySequence_Fast` and *o* is not *NULL*.
+   
+   Note, if a list gets resized, the reallocation may relocate the items array.
+   So, only use the underlying array pointer in contexts where the sequence 
+   cannot change.
 
 
 .. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
index a0782a74842a3cab600013d12c71808e6be7ae03..1811277b88f8848ecaaa5eb7d614042d4c3c41a8 100644 (file)
@@ -23,7 +23,7 @@ C++.
 
    This chapter mentions a number of filenames that include an encoded Python
    version number.  These filenames are represented with the version number shown
-   as ``XY``; in practive, ``'X'`` will be the major version number and ``'Y'``
+   as ``XY``; in practice, ``'X'`` will be the major version number and ``'Y'``
    will be the minor version number of the Python release you're working with.  For
    example, if you are using Python 2.2.1, ``XY`` will actually be ``22``.
 
index e2349ccd58b2dc1134a9c4b63f522d7a93487967..d6f82a321707731d5da6b08d498b8904a6e8d45f 100644 (file)
@@ -16,7 +16,7 @@
 
 * To document when incompatible changes were introduced, and when they will be
   --- or were --- made mandatory.  This is a form of executable documentation, and
-  can be inspected programatically via importing :mod:`__future__` and examining
+  can be inspected programmatically via importing :mod:`__future__` and examining
   its contents.
 
 Each statement in :file:`__future__.py` is of the form::
index 939bf8f83b6b088cb92a9105bc2c01953c068e92..f422bf32980d354dcc8be206e409c3d0da394325 100644 (file)
@@ -1781,8 +1781,8 @@ Utility functions
 .. function:: byref(obj[, offset])
 
    Returns a light-weight pointer to ``obj``, which must be an
-   instance of a ctypes type.  ``offset`` defaults to zero, it must be
-   an integer which is added to the internal pointer value.
+   instance of a ctypes type.  ``offset`` defaults to zero, and must be
+   an integer that will be added to the internal pointer value.
 
    ``byref(obj, offset)`` corresponds to this C code::
 
index f360c60ccb42c6316b8bb64630ff8a1b7e4ce878..d4f8888ec712ccc44d67b652ad8f7e289dc505c5 100644 (file)
@@ -300,7 +300,7 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
 
    Send a ``QUIT`` command to the server and close the connection. This is the
    "polite" way to close a connection, but it may raise an exception of the server
-   reponds with an error to the ``QUIT`` command.  This implies a call to the
+   responds with an error to the ``QUIT`` command.  This implies a call to the
    :meth:`close` method which renders the :class:`FTP` instance useless for
    subsequent calls (see below).
 
index 4b1cbc661593eb898975973d40796e51a78d285b..ac40ce7011f7337b62b438ffc85a2d8b6bb7e365 100644 (file)
@@ -1186,6 +1186,7 @@ are always available.  They are listed here in alphabetical order.
    care about trailing, unmatched values from the longer iterables.  If those
    values are important, use :func:`itertools.zip_longest` instead.
 
+
 .. rubric:: Footnotes
 
 .. [#] Specifying a buffer size currently has no effect on systems that don't have
index 99504c651510bb23aca7d64419caea8d6fa68350..7c425e3ec62a8d01bb41c13cb95edca4aee27724 100644 (file)
@@ -44,6 +44,11 @@ The :mod:`gc` module provides the following functions:
    :exc:`ValueError` is raised if the generation number  is invalid. The number of
    unreachable objects found is returned.
 
+   The free lists maintained for a number of builtin types are cleared
+   whenever a full collection or collection of the highest generation (2)
+   is run.  Not all items in some free lists may be freed due to the
+   particular implementation, in particular :class:`float`.
+
 
 .. function:: set_debug(flags)
 
index be8777594f295e7631c1ad91b6b2ff92b2b27e7e..10ccb17f8d0aae9db4c5a575fb8978d4aadd7dfe 100644 (file)
@@ -158,7 +158,7 @@ However, if you really do need to use some shared data then
 
    The ``'d'`` and ``'i'`` arguments used when creating ``num`` and ``arr`` are
    typecodes of the kind used by the :mod:`array` module: ``'d'`` indicates a
-   double precision float and ``'i'`` inidicates a signed integer.  These shared
+   double precision float and ``'i'`` indicates a signed integer.  These shared
    objects will be process and thread safe.
 
    For more flexibility in using shared memory one can use the
@@ -168,7 +168,7 @@ However, if you really do need to use some shared data then
 **Server process**
 
    A manager object returned by :func:`Manager` controls a server process which
-   holds python objects and allows other processes to manipulate them using
+   holds Python objects and allows other processes to manipulate them using
    proxies.
 
    A manager returned by :func:`Manager` will support types :class:`list`,
@@ -451,7 +451,7 @@ Note that one can also create a shared queue by using a manager object -- see
    This means that if you try joining that process you may get a deadlock unless
    you are sure that all items which have been put on the queue have been
    consumed.  Similarly, if the child process is non-daemonic then the parent
-   process may hang on exit when it tries to join all it non-daemonic children.
+   process may hang on exit when it tries to join all its non-daemonic children.
 
    Note that a queue created using a manager does not have this issue.  See
    :ref:`multiprocessing-programming`.
@@ -532,7 +532,8 @@ For an example of the usage of queues for interprocess communication see
       Equivalent to ``get(False)``.
 
    :class:`multiprocessing.Queue` has a few additional methods not found in
-   :class:`queue.Queue` which are usually unnecessary:
+   :class:`queue.Queue`.  These methods are usually unnecessary for most
+   code:
 
    .. method:: close()
 
@@ -772,7 +773,7 @@ Synchronization primitives
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Generally synchronization primitives are not as necessary in a multiprocess
-program as they are in a mulithreaded program.  See the documentation for
+program as they are in a multithreaded program.  See the documentation for
 :mod:`threading` module.
 
 Note that one can also create synchronization primitives by using a manager
@@ -782,7 +783,7 @@ object -- see :ref:`multiprocessing-managers`.
 
    A bounded semaphore object: a clone of :class:`threading.BoundedSemaphore`.
 
-   (On Mac OSX this is indistiguishable from :class:`Semaphore` because
+   (On Mac OSX this is indistinguishable from :class:`Semaphore` because
    ``sem_getvalue()`` is not implemented on that platform).
 
 .. class:: Condition([lock])
@@ -891,8 +892,8 @@ processes.
 
 .. note::
 
-   Although it is posible to store a pointer in shared memory remember that this
-   will refer to a location in the address space of a specific process.
+   Although it is possible to store a pointer in shared memory remember that
+   this will refer to a location in the address space of a specific process.
    However, the pointer is quite likely to be invalid in the context of a second
    process and trying to dereference the pointer from the second process may
    cause a crash.
@@ -1081,7 +1082,7 @@ their parent process exits.  The manager classes are defined in the
 
       Start a subprocess to start the manager.
 
-   .. method:: server_forever()
+   .. method:: serve_forever()
 
       Run the server in the current process.
 
@@ -1774,7 +1775,7 @@ handler type) for messages from different processes to get mixed up.
    handler which sends output to :data:`sys.stderr` using format
    ``'[%(levelname)s/%(processName)s] %(message)s'``.  (The logger allows use of
    the non-standard ``'%(processName)s'`` format.)  Message sent to this logger
-   will not by default propogate to the root logger.
+   will not by default propagate to the root logger.
 
    Note that on Windows child processes will only inherit the level of the
    parent process's logger -- any other customization of the logger will not be
index 37996e01281a82ef6de799d4d10dc94afd211f50..a67c6d80b41b6c2b7f72b29b703511b5d1ce7a92 100644 (file)
@@ -513,7 +513,7 @@ Python syntax and the functions in the :mod:`operator` module.
 +-----------------------+-------------------------+---------------------------------+
 | Right Shift           | ``a >> b``              | ``rshift(a, b)``                |
 +-----------------------+-------------------------+---------------------------------+
-| Sequence Repitition   | ``seq * i``             | ``repeat(seq, i)``              |
+| Sequence Repetition   | ``seq * i``             | ``repeat(seq, i)``              |
 +-----------------------+-------------------------+---------------------------------+
 | String Formatting     | ``s % obj``             | ``mod(s, obj)``                 |
 +-----------------------+-------------------------+---------------------------------+
index 102d3eacf1a03d8e71d804ff3beacdb23d314fe3..f64d6dd4f784e866ac396eb144b8cf8d13633cab 100644 (file)
@@ -330,7 +330,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
    +---------------------------+---------------------------------------------+
    | :const:`KQ_EV_DISABLE`    | Disablesevent                               |
    +---------------------------+---------------------------------------------+
-   | :const:`KQ_EV_ONESHOT`    | Removes event after first occurence         |
+   | :const:`KQ_EV_ONESHOT`    | Removes event after first occurrence        |
    +---------------------------+---------------------------------------------+
    | :const:`KQ_EV_CLEAR`      | Reset the state after an event is retrieved |
    +---------------------------+---------------------------------------------+
@@ -365,7 +365,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
    +============================+============================================+
    | :const:`KQ_NOTE_DELETE`    | *unlink()* was called                      |
    +----------------------------+--------------------------------------------+
-   | :const:`KQ_NOTE_WRITE`     | a write occured                            |
+   | :const:`KQ_NOTE_WRITE`     | a write occurred                           |
    +----------------------------+--------------------------------------------+
    | :const:`KQ_NOTE_EXTEND`    | the file was extended                      |
    +----------------------------+--------------------------------------------+
index 586770ad3cbf4e5180d4fbe58ac6ba79ecbe784b..40417d85b06bdb4d935296681ec4b44a77a51f50 100644 (file)
@@ -1565,7 +1565,7 @@ The constructors for both classes work the same:
    .. method:: isdisjoint(other)
 
       Return True if the set has no elements in common with *other*.  Sets are
-      disjoint if and only if their interesection is the empty set.
+      disjoint if and only if their intersection is the empty set.
 
    .. method:: issubset(other)
                set <= other
index 662541ec494cd3ec899420ffabfb66c4d4db725e..07a2c4b6f2b14e58eff67064926e055bac571e8e 100644 (file)
@@ -266,7 +266,7 @@ Then the outer replacement field would be evaluated, producing::
 
    "noses     "
    
-Which is subsitituted into the string, yielding::
+Which is substituted into the string, yielding::
    
    "A man with two noses     "
    
index f92b1e4980aafbece141f0f4fe961b9f973d192f..3f73ec2127b3452fd5046d45493bb0af9fc09078 100644 (file)
@@ -54,19 +54,6 @@ always available.
    A string containing the copyright pertaining to the Python interpreter.
 
 
-.. function:: _compact_freelists()
-
-   Compact the free list of floats by deallocating unused blocks.
-   It can reduce the memory usage of the Python process several tenth of
-   thousands of integers or floats have been allocated at once.
-
-   The return value is a tuple of tuples each containing three elements,
-   amount of used objects, total block count before the blocks are deallocated
-   and amount of freed blocks. 
-
-   This function should be used for specialized purposes only.
-
-
 .. function:: _clear_type_cache()
 
    Clear the internal type cache. The type cache is used to speed up attribute
index a85aeb1567d6bbc6f233eb2e405ca2a6d4d45614..b555376eafee16c064477741808d15fc258328b5 100644 (file)
@@ -305,8 +305,8 @@ File Selectors
 .. \ulink{FileEntry}{http://tix.sourceforge.net/dist/current/demos/samples/FileEnt.tcl}
 
 
-Hierachical ListBox
-^^^^^^^^^^^^^^^^^^^
+Hierarchical ListBox
+^^^^^^^^^^^^^^^^^^^^
 
 
 .. class:: HList()
index 575c2fc736ad62f2d5329b7b08a3c2e0abaffadf..6bf9c109d1f625d89bdf2e16aa7605c4d7a9bb52 100644 (file)
@@ -2,6 +2,10 @@
 :mod:`turtle` --- Turtle graphics for Tk
 ========================================
 
+.. module:: tkinter.turtle
+   :synopsis: Turtle graphics for Tk
+.. sectionauthor:: Gregor Lingl <gregor.lingl@aon.at>
+
 Introduction
 ============
 
@@ -1251,7 +1255,7 @@ Window control
    ...     left(10)
    ...
    >>> for _ in range(8):
-   ...     left(45); fd(2)   # a regular octogon
+   ...     left(45); fd(2)   # a regular octagon
 
 
 Animation control
@@ -1262,7 +1266,7 @@ Animation control
    :param delay: positive integer
 
    Set or return the drawing *delay* in milliseconds.  (This is approximately
-   the time interval between two consecutived canvas updates.)  The longer the
+   the time interval between two consecutive canvas updates.)  The longer the
    drawing delay, the slower the animation.
 
    Optional argument:
index c506829ceaceb4fd5cacb3188feb395fb6bd3827..3038588de405c2bfd18a586edbafc8585c9a6167 100644 (file)
@@ -1062,7 +1062,7 @@ involved.  For example, the :envvar:`http_proxy` environment variable is read to
 obtain the HTTP proxy's URL.
 
 This example replaces the default :class:`ProxyHandler` with one that uses
-programatically-supplied proxy URLs, and adds proxy authorization support with
+programmatically-supplied proxy URLs, and adds proxy authorization support with
 :class:`ProxyBasicAuthHandler`. ::
 
    proxy_handler = urllib.request.ProxyHandler({'http': 'http://www.example.com:3128/'})
index 70064fcba1bbdfc03ecda0c2d1f539dedd0b97fb..fcfe7694f8d6ad4603051f6974565a068c539688 100644 (file)
@@ -413,7 +413,7 @@ Paste" library.
       from wsgiref.validate import validator
       from wsgiref.simple_server import make_server
 
-      # Our callable object which is intentionally not compilant to the 
+      # Our callable object which is intentionally not compliant to the 
       # standard, so the validator is going to break
       def simple_app(environ, start_response):
           status = '200 OK' # HTTP Status
index e249b12bf3718c3989de7616367c5509716612f4..1f188101a0054f68c56fc9a188061b126233a17c 100644 (file)
@@ -344,7 +344,7 @@ The client code for the preceding server::
    try:
        proxy.add(2, 5)
    except xmlrpc.client.Fault, err:
-       print("A fault occured")
+       print("A fault occurred")
        print("Fault code: %d" % err.faultCode)
        print("Fault string: %s" % err.faultString)
 
@@ -391,7 +391,7 @@ by providing an invalid URI::
    try:
        proxy.some_method()
    except xmlrpc.client.ProtocolError, err:
-       print("A protocol error occured")
+       print("A protocol error occurred")
        print("URL: %s" % err.url)
        print("HTTP/HTTPS headers: %s" % err.headers)
        print("Error code: %d" % err.errcode)
index 7d76363ee74487468e6861ac3f361ca158a502b4..84dfb613802744093c2e68f77df687e5f48c0e02 100644 (file)
@@ -286,7 +286,7 @@ sometimes there is a need for alternative implementations with different
 performance trade-offs.
 
 The :mod:`array` module provides an :class:`array()` object that is like a list
-that stores only homogenous data and stores it more compactly.  The following
+that stores only homogeneous data and stores it more compactly.  The following
 example shows an array of numbers stored as two byte unsigned binary numbers
 (typecode ``"H"``) rather than the usual 16 bytes per entry for regular lists of
 python int objects::
index 4064fa16b833956ea1aca2296ec4d5942d218646..2dd236ff0c6c43bc4d0fcccda3047217918760a1 100644 (file)
@@ -186,7 +186,7 @@ of your Python installation directory).  This suppresses the terminal window on
 startup.
 
 You can also make all ``.py`` scripts execute with :program:`pythonw.exe`,
-setting this through the usual facilites, for example (might require
+setting this through the usual facilities, for example (might require
 administrative rights):
 
 #. Launch a command prompt.
@@ -215,7 +215,7 @@ PyWin32
 
 The `PyWin32 <http://python.net/crew/mhammond/win32/>`_ module by Mark Hammond
 is a collection of modules for advanced Windows-specific support.  This includes
-utilites for:
+utilities for:
 
 * `Component Object Model <http://www.microsoft.com/com/>`_ (COM)
 * Win32 API calls
index 264ec2e62859766c6461ecabb24e2227a05ef9d5..5cf29cb69bcc7ba6a1d46a355bc39deba058b140 100644 (file)
@@ -51,7 +51,7 @@
 
 This article explains the new features in Python 2.6.  The release
 schedule is described in :pep:`361`; currently the final release is
-scheduled for September 3 2008.
+scheduled for October 1 2008.
 
 This article doesn't attempt to provide a complete specification of
 the new features, but instead provides a convenient overview.  For
@@ -526,28 +526,152 @@ environment variable.
 PEP 371: The ``multiprocessing`` Package
 =====================================================
 
-.. XXX I think this still needs help
+The new :mod:`multiprocessing` package lets Python programs create new
+processes that will perform a computation and return a result to the
+parent.  The parent and child processes can communicate using queues
+and pipes, synchronize their operations using locks and semaphores, 
+and can share simple arrays of data.  
+
+The :mod:`multiprocessing` module started out as an exact emulation of
+the :mod:`threading` module using processes instead of threads.  That
+goal was discarded along the path to Python 2.6, but the general
+approach of the module is still similar.  The fundamental class
+is the :class:`Process`, which is passed a callable object and 
+a collection of arguments.  The :meth:`start` method 
+sets the callable running in a subprocess, after which you can call
+the :meth:`is_alive` method to check whether the subprocess is still running
+and the :meth:`join` method to wait for the process to exit.
+
+Here's a simple example where the subprocess will calculate a
+factorial.  The function doing the calculation is a bit strange; it's
+written to take significantly longer when the input argument is a
+multiple of 4.
+
+::
+
+    import time
+    from multiprocessing import Process, Queue
+
+
+    def factorial(queue, N):
+       "Compute a factorial."
+       # If N is a multiple of 4, this function will take much longer.
+       if (N % 4) == 0:
+           time.sleep(.05 * N/4)
+
+       # Calculate the result
+       fact = 1L
+       for i in range(1, N+1):
+           fact = fact * i
+
+       # Put the result on the queue
+       queue.put(fact)
+
+    if __name__ == '__main__':
+       queue = Queue()
+
+       N = 5
+
+       p = Process(target=factorial, args=(queue, N))
+       p.start()
+       p.join()
+
+       result = queue.get()
+       print 'Factorial', N, '=', result
+
+A :class:`Queue` object is created and stored as a global.  The child
+process will use the value of the variable when the child was created;
+because it's a :class:`Queue`, parent and child can use the object to
+communicate.  (If the parent were to change the value of the global
+variable, the child's value would be unaffected, and vice versa.)
+
+Two other classes, :class:`Pool` and :class:`Manager`, provide
+higher-level interfaces.  :class:`Pool` will create a fixed number of
+worker processes, and requests can then be distributed to the workers
+by calling :meth:`apply` or `apply_async`, adding a single request,
+and :meth:`map` or :meth:`map_async` to distribute a number of
+requests.  The following code uses a :class:`Pool` to spread requests
+across 5 worker processes, receiving a list of results back.
+
+::
+
+   from multiprocessing import Pool
+
+    p = Pool(5)
+    result = p.map(factorial, range(1, 1000, 10))
+    for v in result:
+        print v
+
+This produces the following output::
+
+    1
+    39916800
+    51090942171709440000
+    8222838654177922817725562880000000
+    33452526613163807108170062053440751665152000000000
+    ...
+
+The :class:`Manager` class creates a separate server process that can
+hold master copies of Python data structures.  Other processes can
+then access and modify these data structures by using proxy objects.
+The following example creates a shared dictionary by calling the
+:meth:`dict` method; the worker processes then insert values into the
+dictionary.  (No locking is done automatically, which doesn't matter
+in this example.  :class:`Manager`'s methods also include
+:meth:`Lock`, :meth:`RLock`, and :meth:`Semaphore` to create shared locks.
+
+::
+
+    import time
+    from multiprocessing import Pool, Manager
+
+    def factorial(N, dictionary):
+       "Compute a factorial."
+       # Calculate the result
+       fact = 1L
+       for i in range(1, N+1):
+           fact = fact * i
+
+        # Store result in dictionary
+       dictionary[N] = fact
+
+    if __name__ == '__main__':
+       p = Pool(5)
+       mgr = Manager()
+       d = mgr.dict()         # Create shared dictionary
 
-:mod:`multiprocessing` makes it easy to distribute work over multiple processes.
-Its API is similiar to that of :mod:`threading`.  For example::
+       # Run tasks using the pool
+       for N in range(1, 1000, 10):
+           p.apply_async(factorial, (N, d))
 
-    from multiprocessing import Process
+       # Mark pool as closed -- no more tasks can be added.
+       p.close()
 
-    def long_hard_task(n):
-        print n * 43
+       # Wait for tasks to exit
+       p.join()
 
-    for i in range(10):
-        Process(target=long_hard_task, args=(i)).start()
+       # Output results
+       for k, v in sorted(d.items()):
+           print k, v
 
-will multiply the numbers between 0 and 10 times 43 and print out the result
-concurrently.
+This will produce the output::
+
+    1 1
+    11 39916800
+    21 51090942171709440000
+    31 8222838654177922817725562880000000
+    41 33452526613163807108170062053440751665152000000000
+    51 1551118753287382280224243016469303211063259720016986112000000000000
 
 .. seealso::
 
+   The documentation for the :mod:`multiprocessing` module.
+
    :pep:`371` - Addition of the multiprocessing package
      PEP written by Jesse Noller and Richard Oudkerk; 
      implemented by Richard Oudkerk and Jesse Noller.
 
+    
 .. ======================================================================
 
 .. _pep-3101:
@@ -1775,21 +1899,6 @@ details.
 
   (Contributed by Raymond Hettinger.)
 
-* XXX Describe the new ctypes calling convention that allows safe
-  access to errno.
-  (Implemented by Thomas Heller; :issue:`1798`.)
-
-* The :mod:`ctypes` module now supports a :class:`c_bool` datatype
-  that represents the C99 ``bool`` type.  (Contributed by David Remahl;
-  :issue:`1649190`.)
-
-  The :mod:`ctypes` string, buffer and array types also have improved
-  support for extended slicing syntax,
-  where various combinations of ``(start, stop, step)`` are supplied.
-  (Implemented by Thomas Wouters.)
-
-  .. Revision 57769
-
 * A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes
   the display characters for a  certain number of characters on a single line.
   (Contributed by Fabian Kreutz.)
@@ -2628,6 +2737,45 @@ Using the module is simple::
 
 .. ======================================================================
 
+ctypes Enhancements
+--------------------------------------------------
+
+Thomas Heller continued to maintain and enhance the 
+:mod:`ctypes` module.  
+
+:mod:`ctypes` now supports a :class:`c_bool` datatype
+that represents the C99 ``bool`` type.  (Contributed by David Remahl;
+:issue:`1649190`.)
+
+The :mod:`ctypes` string, buffer and array types have improved
+support for extended slicing syntax,
+where various combinations of ``(start, stop, step)`` are supplied.
+(Implemented by Thomas Wouters.)
+
+.. Revision 57769
+
+A new calling convention tells :mod:`ctypes` to clear the ``errno`` or
+Win32 LastError variables at the outset of each wrapped call.
+(Implemented by Thomas Heller; :issue:`1798`.)
+
+For the Unix ``errno`` variable: when creating a wrapped function,
+you can supply ``use_errno=True`` as a keyword parameter
+to the :func:`DLL` function
+and then call the module-level methods :meth:`set_errno`
+and :meth:`get_errno` to set and retrieve the error value.  
+
+The Win32 LastError variable is supported similarly by
+the :func:`DLL`, :func:`OleDLL`, and :func:`WinDLL` functions.
+You supply ``use_last_error=True`` as a keyword parameter
+and then call the module-level methods :meth:`set_last_error`
+and :meth:`get_last_error`.  
+
+The :func:`byref` function, used to retrieve a pointer to a ctypes
+instance, now has an optional **offset** parameter that is a byte
+count that will be added to the returned pointer.
+
+.. ======================================================================
+
 Improved SSL Support
 --------------------------------------------------
 
index 650d5448ac7246256d84db00c710ab4824506d70..364b913b47275631c5b79b91eca89baf02cb82a6 100644 (file)
@@ -103,7 +103,7 @@ PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
 PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);
 
 /* free list api */
-PyAPI_FUNC(void) PyFloat_CompactFreeList(size_t *, size_t *, size_t *);
+PyAPI_FUNC(int) PyFloat_ClearFreeList(void);
 
 /* Format the object based on the format_spec, as defined in PEP 3101
    (Advanced String Formatting). */
index 7f0e24a220622cad4ca474dfa7b6c7c7bf9fd665..07a4b2c89da58aa315dea2550f173425d84b7fa3 100644 (file)
@@ -695,9 +695,9 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
 #define Py_CLEAR(op)                           \
         do {                                   \
                 if (op) {                      \
-                        PyObject *tmp = (PyObject *)(op);      \
+                        PyObject *_py_tmp = (PyObject *)(op);  \
                         (op) = NULL;           \
-                        Py_DECREF(tmp);                \
+                        Py_DECREF(_py_tmp);    \
                 }                              \
         } while (0)
 
index 0be3ad53b603998c9bd778dd4a00f7a63ab8b059..e7943dae9698016009c45f38c3cb510afefd093c 100644 (file)
@@ -19,7 +19,7 @@ typedef struct _traceback {
 
 PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
 PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
-PyAPI_FUNC(int) Py_DisplaySourceLine(PyObject *, const char *, int, int);
+PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, const char *, int, int);
 
 /* Reveal traceback type so we can typecheck traceback objects */
 PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
index e4a21336f8173689b9e3bc5f0aebca988afaca5b..fe84255590a7b4c6f901749639d7ffd49a85a8e3 100644 (file)
@@ -9,6 +9,8 @@ def insort_right(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
+    if lo < 0:
+        raise ValueError('lo must be non-negative')
     if hi is None:
         hi = len(a)
     while lo < hi:
@@ -30,6 +32,8 @@ def bisect_right(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
+    if lo < 0:
+        raise ValueError('lo must be non-negative')
     if hi is None:
         hi = len(a)
     while lo < hi:
@@ -49,6 +53,8 @@ def insort_left(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
+    if lo < 0:
+        raise ValueError('lo must be non-negative')
     if hi is None:
         hi = len(a)
     while lo < hi:
@@ -69,6 +75,8 @@ def bisect_left(a, x, lo=0, hi=None):
     slice of a to be searched.
     """
 
+    if lo < 0:
+        raise ValueError('lo must be non-negative')
     if hi is None:
         hi = len(a)
     while lo < hi:
index 3df628adc0b98fadcc3e7b2c899e644ea588ad12..bc065243d418b56e8bfb32c456f15b48d089da0f 100755 (executable)
@@ -108,7 +108,9 @@ class Fraction(numbers.Rational):
         Beware that Fraction.from_float(0.3) != Fraction(3, 10).
 
         """
-        if not isinstance(f, float):
+        if isinstance(f, numbers.Integral):
+            f = float(f)
+        elif not isinstance(f, float):
             raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
                             (cls.__name__, f, type(f).__name__))
         if math.isnan(f) or math.isinf(f):
@@ -119,7 +121,9 @@ class Fraction(numbers.Rational):
     def from_decimal(cls, dec):
         """Converts a finite Decimal instance to a rational number, exactly."""
         from decimal import Decimal
-        if not isinstance(dec, Decimal):
+        if isinstance(dec, numbers.Integral):
+            dec = Decimal(int(dec))
+        elif not isinstance(dec, Decimal):
             raise TypeError(
                 "%s.from_decimal() only takes Decimals, not %r (%s)" %
                 (cls.__name__, dec, type(dec).__name__))
index 8493ac0ece67821ec12c25d099c00daff4cb4478..717e14e531edfd3357e7ea397d0864df2ea872d4 100644 (file)
@@ -222,11 +222,9 @@ class SocketListener(object):
         self._family = family
         self._last_accepted = None
 
-        sub_debug('listener bound to address %r', self._address)
-
         if family == 'AF_UNIX':
             self._unlink = Finalize(
-                self, os.unlink, args=(self._address,), exitpriority=0
+                self, os.unlink, args=(address,), exitpriority=0
                 )
         else:
             self._unlink = None
index e9cebae91ce85e63aaf6d7d300ec51b6deeca9d1..56ea7ec3edecee85b2a9718177295020ad28ee78 100644 (file)
@@ -8,6 +8,7 @@ import os
 import sys
 import stat
 from os.path import abspath
+import fnmatch
 
 __all__ = ["copyfileobj","copyfile","copymode","copystat","copy","copy2",
            "copytree","move","rmtree","Error"]
@@ -93,8 +94,19 @@ def copy2(src, dst):
     copyfile(src, dst)
     copystat(src, dst)
 
+def ignore_patterns(*patterns):
+    """Function that can be used as copytree() ignore parameter.
 
-def copytree(src, dst, symlinks=False):
+    Patterns is a sequence of glob-style patterns
+    that are used to exclude files"""
+    def _ignore_patterns(path, names):
+        ignored_names = []
+        for pattern in patterns:
+            ignored_names.extend(fnmatch.filter(names, pattern))
+        return set(ignored_names)
+    return _ignore_patterns
+
+def copytree(src, dst, symlinks=False, ignore=None):
     """Recursively copy a directory tree using copy2().
 
     The destination directory must not already exist.
@@ -105,13 +117,32 @@ def copytree(src, dst, symlinks=False):
     it is false, the contents of the files pointed to by symbolic
     links are copied.
 
+    The optional ignore argument is a callable. If given, it
+    is called with the `src` parameter, which is the directory
+    being visited by copytree(), and `names` which is the list of
+    `src` contents, as returned by os.listdir():
+
+        callable(src, names) -> ignored_names
+
+    Since copytree() is called recursively, the callable will be
+    called once for each directory that is copied. It returns a
+    list of names relative to the `src` directory that should
+    not be copied.
+
     XXX Consider this example code rather than the ultimate tool.
 
     """
     names = os.listdir(src)
+    if ignore is not None:
+        ignored_names = ignore(src, names)
+    else:
+        ignored_names = set()
+
     os.makedirs(dst)
     errors = []
     for name in names:
+        if name in ignored_names:
+            continue
         srcname = os.path.join(src, name)
         dstname = os.path.join(dst, name)
         try:
@@ -119,7 +150,7 @@ def copytree(src, dst, symlinks=False):
                 linkto = os.readlink(srcname)
                 os.symlink(linkto, dstname)
             elif os.path.isdir(srcname):
-                copytree(srcname, dstname, symlinks)
+                copytree(srcname, dstname, symlinks, ignore)
             else:
                 copy2(srcname, dstname)
             # XXX What about devices, sockets etc.?
index af9f1f7c6413241c230f55a77b2656afe379497c..987f33cb6135a930d0559c2caa20992dc4b7c22b 100644 (file)
@@ -114,6 +114,14 @@ class TestBisect(unittest.TestCase):
             self.assertEqual(func(data, elem), expected)
             self.assertEqual(func(UserList(data), elem), expected)
 
+    def test_negative_lo(self):
+        # Issue 3301
+        mod = self.module
+        self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3),
+        self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3),
+        self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3),
+        self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3),
+
     def test_random(self, n=25):
         from random import randrange
         for i in range(n):
index 7de53206af5b5420f735b3bad289b3b2347e87e9..db91e5e25ec3426cd8ba736c469970969c347e13 100644 (file)
@@ -284,24 +284,36 @@ class ReprTestCase(unittest.TestCase):
         floats_file.close()
 
 # Beginning with Python 2.6 float has cross platform compatible
-# ways to create and representate inf and nan
+# ways to create and represent inf and nan
 class InfNanTest(unittest.TestCase):
     def test_inf_from_str(self):
         self.assert_(isinf(float("inf")))
         self.assert_(isinf(float("+inf")))
         self.assert_(isinf(float("-inf")))
+        self.assert_(isinf(float("infinity")))
+        self.assert_(isinf(float("+infinity")))
+        self.assert_(isinf(float("-infinity")))
 
         self.assertEqual(repr(float("inf")), "inf")
         self.assertEqual(repr(float("+inf")), "inf")
         self.assertEqual(repr(float("-inf")), "-inf")
+        self.assertEqual(repr(float("infinity")), "inf")
+        self.assertEqual(repr(float("+infinity")), "inf")
+        self.assertEqual(repr(float("-infinity")), "-inf")
 
         self.assertEqual(repr(float("INF")), "inf")
         self.assertEqual(repr(float("+Inf")), "inf")
         self.assertEqual(repr(float("-iNF")), "-inf")
+        self.assertEqual(repr(float("Infinity")), "inf")
+        self.assertEqual(repr(float("+iNfInItY")), "inf")
+        self.assertEqual(repr(float("-INFINITY")), "-inf")
 
         self.assertEqual(str(float("inf")), "inf")
         self.assertEqual(str(float("+inf")), "inf")
         self.assertEqual(str(float("-inf")), "-inf")
+        self.assertEqual(str(float("infinity")), "inf")
+        self.assertEqual(str(float("+infinity")), "inf")
+        self.assertEqual(str(float("-infinity")), "-inf")
 
         self.assertRaises(ValueError, float, "info")
         self.assertRaises(ValueError, float, "+info")
@@ -309,6 +321,10 @@ class InfNanTest(unittest.TestCase):
         self.assertRaises(ValueError, float, "in")
         self.assertRaises(ValueError, float, "+in")
         self.assertRaises(ValueError, float, "-in")
+        self.assertRaises(ValueError, float, "infinit")
+        self.assertRaises(ValueError, float, "+Infin")
+        self.assertRaises(ValueError, float, "-INFI")
+        self.assertRaises(ValueError, float, "infinitys")
 
     def test_inf_as_str(self):
         self.assertEqual(repr(1e300 * 1e300), "inf")
index 4f8defb81ae09a34ee4ef22a16f7f2baa838a390..4fadf6caa49656394674a5203de0de0d00a92fca 100644 (file)
@@ -134,10 +134,8 @@ class FractionTest(unittest.TestCase):
         self.assertNotEquals(F(4, 2), r)
 
     def testFromFloat(self):
-        self.assertRaisesMessage(
-            TypeError, "Fraction.from_float() only takes floats, not 3 (int)",
-            F.from_float, 3)
-
+        self.assertRaises(TypeError, F.from_float, 3+4j)
+        self.assertEquals((10, 1), _components(F.from_float(10)))
         self.assertEquals((0, 1), _components(F.from_float(-0.0)))
         self.assertEquals((10, 1), _components(F.from_float(10.0)))
         self.assertEquals((-5, 2), _components(F.from_float(-2.5)))
@@ -161,10 +159,8 @@ class FractionTest(unittest.TestCase):
             F.from_float, nan)
 
     def testFromDecimal(self):
-        self.assertRaisesMessage(
-            TypeError,
-            "Fraction.from_decimal() only takes Decimals, not 3 (int)",
-            F.from_decimal, 3)
+        self.assertRaises(TypeError, F.from_decimal, 3+4j)
+        self.assertEquals(F(10, 1), F.from_decimal(10))
         self.assertEquals(F(0), F.from_decimal(Decimal("-0")))
         self.assertEquals(F(5, 10), F.from_decimal(Decimal("0.5")))
         self.assertEquals(F(5, 1000), F.from_decimal(Decimal("5e-3")))
index 81e221dd7350528ca3d93d550d46680fd01d0e2a..aa65c7a419b44d171f32b3e899217a20e9bb1aa2 100644 (file)
@@ -1,5 +1,3 @@
-from test.support import TESTFN, run_unittest, catch_warning
-
 import unittest
 import os
 import random
@@ -8,7 +6,7 @@ import sys
 import py_compile
 import warnings
 import imp
-from test.support import unlink, TESTFN, unload
+from test.support import unlink, TESTFN, unload, run_unittest, catch_warning
 
 
 def remove_files(name):
@@ -267,6 +265,25 @@ class RelativeImport(unittest.TestCase):
         from . import relimport
         self.assertTrue(hasattr(relimport, "RelativeImport"))
 
+    def test_issue3221(self):
+        def check_relative():
+            exec("from . import relimport", ns)
+        # Check both OK with __package__ and __name__ correct
+        ns = dict(__package__='test', __name__='test.notarealmodule')
+        check_relative()
+        # Check both OK with only __name__ wrong
+        ns = dict(__package__='test', __name__='notarealpkg.notarealmodule')
+        check_relative()
+        # Check relative fails with only __package__ wrong
+        ns = dict(__package__='foo', __name__='test.notarealmodule')
+        self.assertRaises(SystemError, check_relative)
+        # Check relative fails with __package__ and __name__ wrong
+        ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule')
+        self.assertRaises(SystemError, check_relative)
+        # Check both fail with package set to a non-string
+        ns = dict(__package__=object())
+        self.assertRaises(ValueError, check_relative)
+
 def test_main(verbose=None):
     run_unittest(ImportTest, PathsTests, RelativeImport)
 
index 2e680a90d354200d98c43261a9ca9a0e296dec41..ad60a44bb32ba91fb60ce5483bcf6f32637c679c 100644 (file)
@@ -108,6 +108,82 @@ class TestShutil(unittest.TestCase):
                 if os.path.exists(path):
                     shutil.rmtree(path)
 
+    def test_copytree_with_exclude(self):
+
+        def write_data(path, data):
+            f = open(path, "w")
+            f.write(data)
+            f.close()
+
+        def read_data(path):
+            f = open(path)
+            data = f.read()
+            f.close()
+            return data
+
+        # creating data
+        join = os.path.join
+        exists = os.path.exists
+        src_dir = tempfile.mkdtemp()
+        dst_dir = join(tempfile.mkdtemp(), 'destination')
+        write_data(join(src_dir, 'test.txt'), '123')
+        write_data(join(src_dir, 'test.tmp'), '123')
+        os.mkdir(join(src_dir, 'test_dir'))
+        write_data(join(src_dir, 'test_dir', 'test.txt'), '456')
+        os.mkdir(join(src_dir, 'test_dir2'))
+        write_data(join(src_dir, 'test_dir2', 'test.txt'), '456')
+        os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
+        os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
+        write_data(join(src_dir, 'test_dir2', 'subdir', 'test.txt'), '456')
+        write_data(join(src_dir, 'test_dir2', 'subdir2', 'test.py'), '456')
+
+
+        # testing glob-like patterns
+        try:
+            patterns = shutil.ignore_patterns('*.tmp', 'test_dir2')
+            shutil.copytree(src_dir, dst_dir, ignore=patterns)
+            # checking the result: some elements should not be copied
+            self.assert_(exists(join(dst_dir, 'test.txt')))
+            self.assert_(not exists(join(dst_dir, 'test.tmp')))
+            self.assert_(not exists(join(dst_dir, 'test_dir2')))
+        finally:
+            if os.path.exists(dst_dir):
+                shutil.rmtree(dst_dir)
+        try:
+            patterns = shutil.ignore_patterns('*.tmp', 'subdir*')
+            shutil.copytree(src_dir, dst_dir, ignore=patterns)
+            # checking the result: some elements should not be copied
+            self.assert_(not exists(join(dst_dir, 'test.tmp')))
+            self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
+            self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir')))
+        finally:
+            if os.path.exists(dst_dir):
+                shutil.rmtree(dst_dir)
+
+        # testing callable-style
+        try:
+            def _filter(src, names):
+                res = []
+                for name in names:
+                    path = os.path.join(src, name)
+
+                    if (os.path.isdir(path) and
+                        path.split()[-1] == 'subdir'):
+                        res.append(name)
+                    elif os.path.splitext(path)[-1] in ('.py'):
+                        res.append(name)
+                return res
+
+            shutil.copytree(src_dir, dst_dir, ignore=_filter)
+
+            # checking the result: some elements should not be copied
+            self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir2',
+                                    'test.py')))
+            self.assert_(not exists(join(dst_dir, 'test_dir2', 'subdir')))
+
+        finally:
+            if os.path.exists(dst_dir):
+                shutil.rmtree(dst_dir)
 
     if hasattr(os, "symlink"):
         def test_dont_copy_file_onto_link_to_itself(self):
index 59a86e2415f12d073c3680746b56ca16f37e8312..fda990385d0ec2aae59211ed121321776d9fc643 100644 (file)
@@ -45,9 +45,9 @@ ZIP_DEFLATED = 8
 
 # The "end of central directory" structure, magic number, size, and indices
 # (section V.I in the format document)
-structEndCentDir = b"<4s4H2LH"
-magicEndCentDir = b"PK\005\006"
-sizeEndCentDir = struct.calcsize(structEndCentDir)
+structEndArchive = b"<4s4H2LH"
+stringEndArchive = b"PK\005\006"
+sizeEndCentDir = struct.calcsize(structEndArchive)
 
 _ECD_SIGNATURE = 0
 _ECD_DISK_NUMBER = 1
@@ -65,37 +65,9 @@ _ECD_LOCATION = 9
 # The "central directory" structure, magic number, size, and indices
 # of entries in the structure (section V.F in the format document)
 structCentralDir = "<4s4B4HL2L5H2L"
-magicCentralDir = b"PK\001\002"
+stringCentralDir = b"PK\001\002"
 sizeCentralDir = struct.calcsize(structCentralDir)
 
-# The "local file header" structure, magic number, size, and indices
-# (section V.A in the format document)
-structFileHeader = "<4s2B4HL2L2H"
-magicFileHeader = b"PK\003\004"
-sizeFileHeader = struct.calcsize(structFileHeader)
-
-# The "Zip64 end of central directory locator" structure, magic number, and size
-structEndCentDir64Locator = "<4sLQL"
-magicEndCentDir64Locator = b"PK\x06\x07"
-sizeEndCentDir64Locator = struct.calcsize(structEndCentDir64Locator)
-
-# The "Zip64 end of central directory" record, magic number, size, and indices
-# (section V.G in the format document)
-structEndCentDir64 = "<4sQ2H2L4Q"
-magicEndCentDir64 = b"PK\x06\x06"
-sizeEndCentDir64 = struct.calcsize(structEndCentDir64)
-
-_CD64_SIGNATURE = 0
-_CD64_DIRECTORY_RECSIZE = 1
-_CD64_CREATE_VERSION = 2
-_CD64_EXTRACT_VERSION = 3
-_CD64_DISK_NUMBER = 4
-_CD64_DISK_NUMBER_START = 5
-_CD64_NUMBER_ENTRIES_THIS_DISK = 6
-_CD64_NUMBER_ENTRIES_TOTAL = 7
-_CD64_DIRECTORY_SIZE = 8
-_CD64_OFFSET_START_CENTDIR = 9
-
 # indexes of entries in the central directory structure
 _CD_SIGNATURE = 0
 _CD_CREATE_VERSION = 1
@@ -120,7 +92,7 @@ _CD_LOCAL_HEADER_OFFSET = 18
 # The "local file header" structure, magic number, size, and indices
 # (section V.A in the format document)
 structFileHeader = "<4s2B4HL2L2H"
-magicFileHeader = b"PK\003\004"
+stringFileHeader = b"PK\003\004"
 sizeFileHeader = struct.calcsize(structFileHeader)
 
 _FH_SIGNATURE = 0
@@ -137,15 +109,15 @@ _FH_FILENAME_LENGTH = 10
 _FH_EXTRA_FIELD_LENGTH = 11
 
 # The "Zip64 end of central directory locator" structure, magic number, and size
-structEndCentDir64Locator = "<4sLQL"
-magicEndCentDir64Locator = b"PK\x06\x07"
-sizeEndCentDir64Locator = struct.calcsize(structEndCentDir64Locator)
+structEndArchive64Locator = "<4sLQL"
+stringEndArchive64Locator = b"PK\x06\x07"
+sizeEndCentDir64Locator = struct.calcsize(structEndArchive64Locator)
 
 # The "Zip64 end of central directory" record, magic number, size, and indices
 # (section V.G in the format document)
-structEndCentDir64 = "<4sQ2H2L4Q"
-magicEndCentDir64 = b"PK\x06\x06"
-sizeEndCentDir64 = struct.calcsize(structEndCentDir64)
+structEndArchive64 = "<4sQ2H2L4Q"
+stringEndArchive64 = b"PK\x06\x06"
+sizeEndCentDir64 = struct.calcsize(structEndArchive64)
 
 _CD64_SIGNATURE = 0
 _CD64_DIRECTORY_RECSIZE = 1
@@ -176,8 +148,8 @@ def _EndRecData64(fpin, offset, endrec):
     """
     fpin.seek(offset - sizeEndCentDir64Locator, 2)
     data = fpin.read(sizeEndCentDir64Locator)
-    sig, diskno, reloff, disks = struct.unpack(structEndCentDir64Locator, data)
-    if sig != magicEndCentDir64Locator:
+    sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data)
+    if sig != stringEndArchive64Locator:
         return endrec
 
     if diskno != 0 or disks != 1:
@@ -188,8 +160,8 @@ def _EndRecData64(fpin, offset, endrec):
     data = fpin.read(sizeEndCentDir64)
     sig, sz, create_version, read_version, disk_num, disk_dir, \
             dircount, dircount2, dirsize, diroffset = \
-            struct.unpack(structEndCentDir64, data)
-    if sig != magicEndCentDir64:
+            struct.unpack(structEndArchive64, data)
+    if sig != stringEndArchive64:
         return endrec
 
     # Update the original endrec using data from the ZIP64 record
@@ -217,9 +189,9 @@ def _EndRecData(fpin):
     # file if this is the case).
     fpin.seek(-sizeEndCentDir, 2)
     data = fpin.read()
-    if data[0:4] == magicEndCentDir and data[-2:] == b"\000\000":
+    if data[0:4] == stringEndArchive and data[-2:] == b"\000\000":
         # the signature is correct and there's no comment, unpack structure
-        endrec = struct.unpack(structEndCentDir, data)
+        endrec = struct.unpack(structEndArchive, data)
         endrec=list(endrec)
 
         # Append a blank comment and record start offset
@@ -241,11 +213,11 @@ def _EndRecData(fpin):
     maxCommentStart = max(filesize - (1 << 16) - sizeEndCentDir, 0)
     fpin.seek(maxCommentStart, 0)
     data = fpin.read()
-    start = data.rfind(magicEndCentDir)
+    start = data.rfind(stringEndArchive)
     if start >= 0:
         # found the magic number; attempt to unpack and interpret
         recData = data[start:start+sizeEndCentDir]
-        endrec = list(struct.unpack(structEndCentDir, recData))
+        endrec = list(struct.unpack(structEndArchive, recData))
         comment = data[start+sizeEndCentDir:]
         # check that comment length is correct
         if endrec[_ECD_COMMENT_SIZE] == len(comment):
@@ -352,7 +324,7 @@ class ZipInfo (object):
             self.create_version = max(45, self.extract_version)
 
         filename, flag_bits = self._encodeFilenameFlags()
-        header = struct.pack(structFileHeader, magicFileHeader,
+        header = struct.pack(structFileHeader, stringFileHeader,
                  self.extract_version, self.reserved, flag_bits,
                  self.compress_type, dostime, dosdate, CRC,
                  compress_size, file_size,
@@ -777,7 +749,7 @@ class ZipFile:
         total = 0
         while total < size_cd:
             centdir = fp.read(sizeCentralDir)
-            if centdir[0:4] != magicCentralDir:
+            if centdir[0:4] != stringCentralDir:
                 raise BadZipfile("Bad magic number for central directory")
             centdir = struct.unpack(structCentralDir, centdir)
             if self.debug > 2:
@@ -892,7 +864,7 @@ class ZipFile:
 
         # Skip the file header:
         fheader = zef_file.read(sizeFileHeader)
-        if fheader[0:4] != magicFileHeader:
+        if fheader[0:4] != stringFileHeader:
             raise BadZipfile("Bad magic number for file header")
 
         fheader = struct.unpack(structFileHeader, fheader)
@@ -1184,7 +1156,7 @@ class ZipFile:
                 try:
                     filename, flag_bits = zinfo._encodeFilenameFlags()
                     centdir = struct.pack(structCentralDir,
-                     magicCentralDir, create_version,
+                     stringCentralDir, create_version,
                      zinfo.create_system, extract_version, zinfo.reserved,
                      flag_bits, zinfo.compress_type, dostime, dosdate,
                      zinfo.CRC, compress_size, file_size,
@@ -1212,13 +1184,13 @@ class ZipFile:
             if pos1 > ZIP64_LIMIT:
                 # Need to write the ZIP64 end-of-archive records
                 zip64endrec = struct.pack(
-                        structEndCentDir64, magicEndCentDir64,
+                        structEndArchive64, stringEndArchive64,
                         44, 45, 45, 0, 0, count, count, pos2 - pos1, pos1)
                 self.fp.write(zip64endrec)
 
                 zip64locrec = struct.pack(
-                        structEndCentDir64Locator,
-                        magicEndCentDir64Locator, 0, pos2, 1)
+                        structEndArchive64Locator,
+                        stringEndArchive64Locator, 0, pos2, 1)
                 self.fp.write(zip64locrec)
                 centDirOffset = 0xFFFFFFFF
 
@@ -1229,7 +1201,7 @@ class ZipFile:
                           % ZIP_MAX_COMMENT
                 self.comment = self.comment[:ZIP_MAX_COMMENT]
 
-            endrec = struct.pack(structEndCentDir, magicEndCentDir,
+            endrec = struct.pack(structEndArchive, stringEndArchive,
                                  0, 0, count % ZIP_FILECOUNT_LIMIT,
                                  count % ZIP_FILECOUNT_LIMIT, pos2 - pos1,
                                  centDirOffset, len(self.comment))
index 7ce335ef50dd74ec5cde85beaba40d83c1168665..0a411e76583aef962c14ff4428ffbf1b202dcaca 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -460,6 +460,7 @@ Luke Mewburn
 Mike Meyer
 Steven Miale
 Trent Mick
+Aristotelis Mikropoulos
 Damien Miller
 Chad Miller
 Jay T. Miller
index 1280b04af30b9e7174f2dfb89cb44ac51a127960..bf47feb5869183f923aada682cdb1d4cbc8ad248 100644 (file)
@@ -11,6 +11,10 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
        PyObject *litem;
        Py_ssize_t mid, res;
 
+       if (lo < 0) {
+               PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
+               return -1;
+       }
        if (hi == -1) {
                hi = PySequence_Size(list);
                if (hi < 0)
@@ -108,6 +112,10 @@ internal_bisect_left(PyObject *list, PyObject *item, int lo, int hi)
        PyObject *litem;
        int mid, res;
 
+       if (lo < 0) {
+               PyErr_SetString(PyExc_ValueError, "lo must be non-negative");
+               return -1;
+       }
        if (hi == -1) {
                hi = PySequence_Size(list);
                if (hi < 0)
index 8b505c82667ff677daf86346362754e6986f8664..51bcd79f922bf56ae10e8c11bc132cd6ce034334 100644 (file)
@@ -706,6 +706,7 @@ clear_freelists(void)
        (void)PyCFunction_ClearFreeList();
        (void)PyTuple_ClearFreeList();
        (void)PyUnicode_ClearFreeList();
+       (void)PyFloat_ClearFreeList();
 }
 
 /* This is the main function.  Read this to understand how the
index 82821343760e551e1cf37acfb16571171f4e51d4..a6a19c10a48ada68a12b229115f4fdd7ede4ba1b 100644 (file)
@@ -3638,7 +3638,8 @@ posix_fork1(PyObject *self, PyObject *noargs)
        pid_t pid = fork1();
        if (pid == -1)
                return posix_error();
-       PyOS_AfterFork();
+       if (pid == 0)
+               PyOS_AfterFork();
        return PyLong_FromLong(pid);
 }
 #endif
index f18e7dd85e4260e8a3861a685b357d3af2a58994..daf7ee807ee91f564495b11d7b5a66f5ddeffe84 100644 (file)
@@ -225,6 +225,9 @@ PyFloat_FromString(PyObject *v)
                if (PyOS_strnicmp(p, "inf", 4) == 0) {
                        Py_RETURN_INF(sign);
                }
+               if (PyOS_strnicmp(p, "infinity", 9) == 0) {
+                       Py_RETURN_INF(sign);
+               }
 #ifdef Py_NAN
                if(PyOS_strnicmp(p, "nan", 4) == 0) {
                        Py_RETURN_NAN;
@@ -1903,30 +1906,28 @@ _PyFloat_Init(void)
                PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc);
 }
 
-void
-PyFloat_CompactFreeList(size_t *pbc, size_t *pbf, size_t *bsum)
+int
+PyFloat_ClearFreeList(void)
 {
        PyFloatObject *p;
        PyFloatBlock *list, *next;
-       unsigned i;
-       size_t bc = 0, bf = 0;  /* block count, number of freed blocks */
-       size_t fsum = 0;        /* total unfreed ints */
-       int frem;               /* remaining unfreed ints per block */
+       int i;
+       int u;                  /* remaining unfreed ints per block */
+       int freelist_size = 0;
 
        list = block_list;
        block_list = NULL;
        free_list = NULL;
        while (list != NULL) {
-               bc++;
-               frem = 0;
+               u = 0;
                for (i = 0, p = &list->objects[0];
                     i < N_FLOATOBJECTS;
                     i++, p++) {
                        if (PyFloat_CheckExact(p) && Py_REFCNT(p) != 0)
-                               frem++;
+                               u++;
                }
                next = list->next;
-               if (frem) {
+               if (u) {
                        list->next = block_list;
                        block_list = list;
                        for (i = 0, p = &list->objects[0];
@@ -1941,15 +1942,12 @@ PyFloat_CompactFreeList(size_t *pbc, size_t *pbf, size_t *bsum)
                        }
                }
                else {
-                       PyMem_FREE(list); /* XXX PyObject_FREE ??? */
-                       bf++;
+                       PyMem_FREE(list);
                }
-               fsum += frem;
+               freelist_size += u;
                list = next;
        }
-       *pbc = bc;
-       *pbf = bf;
-       *bsum = fsum;
+       return freelist_size;
 }
 
 void
@@ -1957,25 +1955,21 @@ PyFloat_Fini(void)
 {
        PyFloatObject *p;
        PyFloatBlock *list;
-       unsigned i;
-       size_t bc, bf;  /* block count, number of freed blocks */
-       size_t fsum;    /* total unfreed floats per block */
+       int i;
+       int u;                  /* total unfreed floats per block */
 
-       PyFloat_CompactFreeList(&bc, &bf, &fsum);
+       u = PyFloat_ClearFreeList();
 
        if (!Py_VerboseFlag)
                return;
        fprintf(stderr, "# cleanup floats");
-       if (!fsum) {
+       if (!u) {
                fprintf(stderr, "\n");
        }
        else {
                fprintf(stderr,
-                       ": %" PY_FORMAT_SIZE_T "d unfreed float%s in %"
-                       PY_FORMAT_SIZE_T "d out of %"
-                       PY_FORMAT_SIZE_T "d block%s\n",
-                       fsum, fsum == 1 ? "" : "s",
-                       bc - bf, bc, bc == 1 ? "" : "s");
+                       ": %d unfreed float%s\n",
+                       u, u == 1 ? "" : "s");
        }
        if (Py_VerboseFlag > 1) {
                list = block_list;
index e9384ca1f9cf935665bf436d39154b2a4d0db8ea..cb81b07925204a37eef70b7e5a0e2a36b9ada7d8 100644 (file)
@@ -266,7 +266,8 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
         PyFile_WriteString("\n", f_stderr);
     }
     else
-        Py_DisplaySourceLine(f_stderr, PyUnicode_AsString(filename), lineno, 2);
+        _Py_DisplaySourceLine(f_stderr, PyUnicode_AsString(filename),
+                              lineno, 2);
     PyErr_Clear();
 }
 
index 14cda6e2728ce6d98ebc2cc707227b91a3d64741..7ad3bf9bcb03386c8d1a3f3262ac549dd58618a6 100644 (file)
@@ -2162,6 +2162,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
        static PyObject *pathstr = NULL;
        static PyObject *pkgstr = NULL;
        PyObject *pkgname, *modname, *modpath, *modules, *parent;
+       int orig_level = level;
 
        if (globals == NULL || !PyDict_Check(globals) || !level)
                return Py_None;
@@ -2292,9 +2293,27 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
 
        modules = PyImport_GetModuleDict();
        parent = PyDict_GetItemString(modules, buf);
-       if (parent == NULL)
-               PyErr_Format(PyExc_SystemError,
-                               "Parent module '%.200s' not loaded", buf);
+       if (parent == NULL) {
+               if (orig_level < 1) {
+                       PyObject *err_msg = PyBytes_FromFormat(
+                               "Parent module '%.200s' not found "
+                               "while handling absolute import", buf);
+                       if (err_msg == NULL) {
+                               return NULL;
+                       }
+                       if (!PyErr_WarnEx(PyExc_RuntimeWarning,
+                                         PyBytes_AsString(err_msg), 1)) {
+                               *buf = '\0';
+                               *p_buflen = 0;
+                               parent = Py_None;
+                       }
+                       Py_DECREF(err_msg);
+               } else {
+                       PyErr_Format(PyExc_SystemError,
+                               "Parent module '%.200s' not loaded, "
+                               "cannot perform relative import", buf);
+               }
+       }
        return parent;
        /* We expect, but can't guarantee, if parent != None, that:
           - parent.__name__ == buf
index 4017ac2fa8e25be738c0d0c45fe9f364d4f189f7..f4118d6899ed98751720e95a76bcde1947e5656d 100644 (file)
@@ -824,29 +824,12 @@ PyDoc_STRVAR(sys_clear_type_cache__doc__,
 Clear the internal type lookup cache.");
 
 
-static PyObject *
-sys_compact_freelists(PyObject* self, PyObject* args)
-{
-       size_t fsum, fbc, fbf;
-
-       PyFloat_CompactFreeList(&fbc, &fbf, &fsum);
-
-       return Py_BuildValue("((kkk))", fsum, fbc, fbf);
-
-}
-
-PyDoc_STRVAR(sys_compact_freelists__doc__,
-"_compact_freelists() -> ((remaing_objects, total_blocks, freed_blocks),)\n\
-Compact the free lists of floats.");
-
 static PyMethodDef sys_methods[] = {
        /* Might as well keep this in alphabetic order */
        {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
         callstats_doc},
        {"_clear_type_cache",   sys_clear_type_cache,     METH_NOARGS,
         sys_clear_type_cache__doc__},
-       {"_compact_freelists",  sys_compact_freelists,    METH_NOARGS,
-        sys_compact_freelists__doc__},
        {"_current_frames", sys_current_frames, METH_NOARGS,
         current_frames_doc},
        {"displayhook", sys_displayhook, METH_O, displayhook_doc},
index 55300fc505eaef9a1f0f4447c0e3bc47efc552a4..d569a18de352153a1b1bacf177a7523f99a2ec75 100644 (file)
@@ -129,7 +129,7 @@ PyTraceBack_Here(PyFrameObject *frame)
 }
 
 int
-Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)
+_Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)
 {
        int err = 0;
        FILE *xfp = NULL;
@@ -241,7 +241,7 @@ tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)
        err = PyFile_WriteString(linebuf, f);
        if (err != 0)
                return err;
-        return Py_DisplaySourceLine(f, filename, lineno, 4);
+        return _Py_DisplaySourceLine(f, filename, lineno, 4);
 }
 
 static int
index 6a708aa25ce755f5fe063a0153864f203b207368..b3bcc9245cfc94e8ae949667ca2918c755c52cc3 100755 (executable)
@@ -9,7 +9,7 @@
 #   blackjesus:~> ./move-faqwiz.sh 2\.1 3\.2
 #   Moving FAQ question 02.001 to 03.002
 
-if [ x$2 == x ]; then
+if [ x$2 = x ]; then
     echo "Need 2 args: original_version final_version."
     exit 2
 fi
@@ -19,7 +19,7 @@ if [ ! -d data -o ! -d data/RCS ]; then
     exit 2
 fi
 
-function cut_n_pad() {
+cut_n_pad() {
     t=`echo $1 | cut -d. -f $2`
     export $3=`echo $t | awk "{ tmp = \\$0; l = length(tmp); for (i = 0; i < $2-l+1; i++) { tmp = "0".tmp } print tmp  }"`
 }
@@ -28,7 +28,13 @@ cut_n_pad $1 1 prefix1
 cut_n_pad $1 2 suffix1
 cut_n_pad $2 1 prefix2
 cut_n_pad $2 2 suffix2
-tmpfile=tmp$RANDOM.tmp
+if which tempfile >/dev/null; then
+    tmpfile=$(tempfile -d .)
+elif [ -n "$RANDOM" ]; then
+    tmpfile=tmp$RANDOM.tmp
+else
+    tmpfile=tmp$$.tmp
+fi
 file1=faq$prefix1.$suffix1.htp
 file2=faq$prefix2.$suffix2.htp