[Python-3000-checkins] r58287 - in python/branches/py3k-importlib: Demo/classes/Rat.py Demo/classes/bitvec.py Doc/ACKS.txt Doc/c-api/newtypes.rst Doc/glossary.rst Doc/library/decimal.rst Doc/library/functions.rst Doc/library/stdtypes.rst Doc/tutorial/classes.rst Doc/tutorial/errors.rst Doc/tutorial/inputoutput.rst Doc/tutorial/interpreter.rst Doc/tutorial/introduction.rst Include/abstract.h Include/memoryobject.h Include/object.h Lib/distutils/fancy_getopt.py Lib/lib-tk/turtle.py Lib/test/string_tests.py Lib/test/test_descr.py Lib/test/test_unicode.py Modules/_bsddb.c Modules/_ctypes/_ctypes.c Modules/_hashopenssl.c Modules/_sre.c Modules/arraymodule.c Modules/datetimemodule.c Modules/mmapmodule.c Objects/abstract.c Objects/boolobject.c Objects/bufferobject.c Objects/bytesobject.c Objects/complexobject.c Objects/floatobject.c Objects/longobject.c Objects/memoryobject.c Objects/setobject.c Objects/stringobject.c Objects/unicodeobject.c Objects/weakrefobject.c PC/_winreg.c Parser/tokenizer.c Parser/tokenizer.h Python/getargs.c Python/marshal.c Tools/modulator/Templates/object_tp_as_number Tools/scripts/byext.py

brett.cannon python-3000-checkins at python.org
Sat Sep 29 22:20:35 CEST 2007


Author: brett.cannon
Date: Sat Sep 29 22:20:33 2007
New Revision: 58287

Modified:
   python/branches/py3k-importlib/   (props changed)
   python/branches/py3k-importlib/Demo/classes/Rat.py
   python/branches/py3k-importlib/Demo/classes/bitvec.py
   python/branches/py3k-importlib/Doc/ACKS.txt
   python/branches/py3k-importlib/Doc/c-api/newtypes.rst
   python/branches/py3k-importlib/Doc/glossary.rst
   python/branches/py3k-importlib/Doc/library/decimal.rst
   python/branches/py3k-importlib/Doc/library/functions.rst
   python/branches/py3k-importlib/Doc/library/stdtypes.rst
   python/branches/py3k-importlib/Doc/tutorial/classes.rst
   python/branches/py3k-importlib/Doc/tutorial/errors.rst
   python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst
   python/branches/py3k-importlib/Doc/tutorial/interpreter.rst
   python/branches/py3k-importlib/Doc/tutorial/introduction.rst
   python/branches/py3k-importlib/Include/abstract.h
   python/branches/py3k-importlib/Include/memoryobject.h
   python/branches/py3k-importlib/Include/object.h
   python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py
   python/branches/py3k-importlib/Lib/lib-tk/turtle.py
   python/branches/py3k-importlib/Lib/test/string_tests.py
   python/branches/py3k-importlib/Lib/test/test_descr.py
   python/branches/py3k-importlib/Lib/test/test_unicode.py
   python/branches/py3k-importlib/Modules/_bsddb.c
   python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c
   python/branches/py3k-importlib/Modules/_hashopenssl.c
   python/branches/py3k-importlib/Modules/_sre.c
   python/branches/py3k-importlib/Modules/arraymodule.c
   python/branches/py3k-importlib/Modules/datetimemodule.c
   python/branches/py3k-importlib/Modules/mmapmodule.c
   python/branches/py3k-importlib/Objects/abstract.c
   python/branches/py3k-importlib/Objects/boolobject.c
   python/branches/py3k-importlib/Objects/bufferobject.c
   python/branches/py3k-importlib/Objects/bytesobject.c
   python/branches/py3k-importlib/Objects/complexobject.c
   python/branches/py3k-importlib/Objects/floatobject.c
   python/branches/py3k-importlib/Objects/longobject.c
   python/branches/py3k-importlib/Objects/memoryobject.c
   python/branches/py3k-importlib/Objects/setobject.c
   python/branches/py3k-importlib/Objects/stringobject.c
   python/branches/py3k-importlib/Objects/unicodeobject.c
   python/branches/py3k-importlib/Objects/weakrefobject.c
   python/branches/py3k-importlib/PC/_winreg.c
   python/branches/py3k-importlib/Parser/tokenizer.c
   python/branches/py3k-importlib/Parser/tokenizer.h
   python/branches/py3k-importlib/Python/getargs.c
   python/branches/py3k-importlib/Python/marshal.c
   python/branches/py3k-importlib/Tools/modulator/Templates/object_tp_as_number
   python/branches/py3k-importlib/Tools/scripts/byext.py
Log:
Merged revisions 58223-58286 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k


Modified: python/branches/py3k-importlib/Demo/classes/Rat.py
==============================================================================
--- python/branches/py3k-importlib/Demo/classes/Rat.py	(original)
+++ python/branches/py3k-importlib/Demo/classes/Rat.py	Sat Sep 29 22:20:33 2007
@@ -226,10 +226,6 @@
     def __bool__(a):
         return a.__num != 0
 
-    # coercion
-    def __coerce__(a, b):
-        return a, Rat(b)
-
 def test():
     '''\
     Test function for rat module.

Modified: python/branches/py3k-importlib/Demo/classes/bitvec.py
==============================================================================
--- python/branches/py3k-importlib/Demo/classes/bitvec.py	(original)
+++ python/branches/py3k-importlib/Demo/classes/bitvec.py	Sat Sep 29 22:20:33 2007
@@ -311,13 +311,6 @@
         return BitVec(~self._data & ((1 << self._len) - 1), \
                   self._len)
 
-    def __coerce__(self, otherseq, *rest):
-        #needed for *some* of the arithmetic operations
-        #rprt('%r.__coerce__%r\n' % (self, (otherseq,) + rest))
-        if type(otherseq) != type(self):
-            otherseq = bitvec(otherseq, *rest)
-        return self, otherseq
-
     def __int__(self):
         return int(self._data)
 

Modified: python/branches/py3k-importlib/Doc/ACKS.txt
==============================================================================
--- python/branches/py3k-importlib/Doc/ACKS.txt	(original)
+++ python/branches/py3k-importlib/Doc/ACKS.txt	Sat Sep 29 22:20:33 2007
@@ -65,6 +65,7 @@
 * Harald Hanche-Olsen
 * Manus Hand
 * Gerhard Häring
+* Peter Harris
 * Travis B. Hartwell
 * Tim Hatch
 * Janko Hauser

Modified: python/branches/py3k-importlib/Doc/c-api/newtypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/newtypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/c-api/newtypes.rst	Sat Sep 29 22:20:33 2007
@@ -330,7 +330,7 @@
 section.  The fields will be described in the order in which they occur in the
 structure.
 
-Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc,
+Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, intargfunc,
 intintargfunc, intobjargproc, intintobjargproc, objobjargproc, destructor,
 freefunc, printfunc, getattrfunc, getattrofunc, setattrfunc, setattrofunc,
 cmpfunc, reprfunc, hashfunc
@@ -592,17 +592,34 @@
 
    This field is inherited by subtypes.
 
-.. cmember:: PyNumberMethods *tp_as_number;
+.. cmember:: PyNumberMethods* tp_as_number
 
-   XXX
+   Pointer to an additional structure that contains fields relevant only to
+   objects which implement the number protocol.  These fields are documented in
+   :ref:`number-structs`.
 
-.. cmember:: PySequenceMethods *tp_as_sequence;
+   The :attr:`tp_as_number` field is not inherited, but the contained fields are
+   inherited individually.
+
+
+.. cmember:: PySequenceMethods* tp_as_sequence
+
+   Pointer to an additional structure that contains fields relevant only to
+   objects which implement the sequence protocol.  These fields are documented
+   in :ref:`sequence-structs`.
 
-   XXX
+   The :attr:`tp_as_sequence` field is not inherited, but the contained fields
+   are inherited individually.
 
-.. cmember:: PyMappingMethods *tp_as_mapping;
 
-   XXX
+.. cmember:: PyMappingMethods* tp_as_mapping
+
+   Pointer to an additional structure that contains fields relevant only to
+   objects which implement the mapping protocol.  These fields are documented in
+   :ref:`mapping-structs`.
+
+   The :attr:`tp_as_mapping` field is not inherited, but the contained fields are
+   inherited individually.
 
 
 .. cmember:: hashfunc PyTypeObject.tp_hash
@@ -751,19 +768,6 @@
       :attr:`sq_inplace_repeat`.
 
 
-   .. data:: Py_TPFLAGS_CHECKTYPES
-
-      If this bit is set, the binary and ternary operations in the
-      :ctype:`PyNumberMethods` structure referenced by :attr:`tp_as_number` accept
-      arguments of arbitrary object types, and do their own type conversions if
-      needed.  If this bit is clear, those operations require that all arguments have
-      the current type as their type, and the caller is supposed to perform a coercion
-      operation first.  This applies to :attr:`nb_add`, :attr:`nb_subtract`,
-      :attr:`nb_multiply`, :attr:`nb_divide`, :attr:`nb_remainder`, :attr:`nb_divmod`,
-      :attr:`nb_power`, :attr:`nb_lshift`, :attr:`nb_rshift`, :attr:`nb_and`,
-      :attr:`nb_xor`, and :attr:`nb_or`.
-
-
    .. data:: Py_TPFLAGS_HAVE_RICHCOMPARE
 
       If this bit is set, the type object has the :attr:`tp_richcompare` field, as
@@ -1414,28 +1418,106 @@
 of the library.
 
 
+.. _number-structs:
+
+Number Object Structures
+========================
+
+.. sectionauthor:: Amaury Forgeot d'Arc
+
+
+.. ctype:: PyNumberMethods
+
+   This structure holds pointers to the functions which an object uses to
+   implement the number protocol.  Each function is used by the function of
+   similar name documented in the :ref:`number` section.
+
+   Here is the structure definition::
+
+       typedef struct {
+            binaryfunc nb_add;
+            binaryfunc nb_subtract;
+            binaryfunc nb_multiply;
+            binaryfunc nb_remainder;
+            binaryfunc nb_divmod;
+            ternaryfunc nb_power;
+            unaryfunc nb_negative;
+            unaryfunc nb_positive;
+            unaryfunc nb_absolute;
+            inquiry nb_bool;
+            unaryfunc nb_invert;
+            binaryfunc nb_lshift;
+            binaryfunc nb_rshift;
+            binaryfunc nb_and;
+            binaryfunc nb_xor;
+            binaryfunc nb_or;
+            int nb_reserved;  /* unused, must be zero */
+            unaryfunc nb_int;
+            unaryfunc nb_long;
+            unaryfunc nb_float;
+            
+            unaryfunc nb_oct; /* not used anymore, must be zero */
+            unaryfunc nb_hex; /* not used anymore, must be zero */
+
+            binaryfunc nb_inplace_add;
+            binaryfunc nb_inplace_subtract;
+            binaryfunc nb_inplace_multiply;
+            binaryfunc nb_inplace_remainder;
+            ternaryfunc nb_inplace_power;
+            binaryfunc nb_inplace_lshift;
+            binaryfunc nb_inplace_rshift;
+            binaryfunc nb_inplace_and;
+            binaryfunc nb_inplace_xor;
+            binaryfunc nb_inplace_or;
+
+            binaryfunc nb_floor_divide;
+            binaryfunc nb_true_divide;
+            binaryfunc nb_inplace_floor_divide;
+            binaryfunc nb_inplace_true_divide;
+
+            unaryfunc nb_index;
+       } PyNumberMethods;
+
+   .. note::
+
+      Binary and ternary functions must check the type of all their operands,
+      and implement the necessary conversions (at least one of the operands is
+      an instance of the defined type).  If the operation is not defined for the
+      given operands, binary and ternary functions must return
+      ``Py_NotImplemented``, if another error occurred they must return ``NULL``
+      and set an exception.
+
+
 .. _mapping-structs:
 
 Mapping Object Structures
 =========================
 
+.. sectionauthor:: Amaury Forgeot d'Arc
+
 
 .. ctype:: PyMappingMethods
 
-   Structure used to hold pointers to the functions used to implement the mapping
-   protocol for an extension type.
+   This structure holds pointers to the functions which an object uses to
+   implement the mapping protocol.  It has three members:
 
+.. cmember:: lenfunc PyMappingMethods.mp_length
 
-.. _number-structs:
+   This function is used by :cfunc:`PyMapping_Length` and
+   :cfunc:`PyObject_Size`, and has the same signature.  This slot may be set to
+   *NULL* if the object has no defined length.
 
-Number Object Structures
-========================
+.. cmember:: binaryfunc PyMappingMethods.mp_subscript
 
+   This function is used by :cfunc:`PyObject_GetItem` and has the same
+   signature.  This slot must be filled for the :cfunc:`PyMapping_Check`
+   function to return ``1``, it can be *NULL* otherwise.
 
-.. ctype:: PyNumberMethods
+.. cmember:: objobjargproc PyMappingMethods.mp_ass_subscript
 
-   Structure used to hold pointers to the functions an extension type uses to
-   implement the number protocol.
+   This function is used by :cfunc:`PyObject_SetItem` and has the same
+   signature.  If this slot is *NULL*, the object does not support item
+   assignment.
 
 
 .. _sequence-structs:
@@ -1443,12 +1525,68 @@
 Sequence Object Structures
 ==========================
 
+.. sectionauthor:: Amaury Forgeot d'Arc
+
 
 .. ctype:: PySequenceMethods
 
-   Structure used to hold pointers to the functions which an object uses to
+   This structure holds pointers to the functions which an object uses to
    implement the sequence protocol.
 
+.. cmember:: lenfunc PySequenceMethods.sq_length
+
+   This function is used by :cfunc:`PySequence_Size` and :cfunc:`PyObject_Size`,
+   and has the same signature.
+
+.. cmember:: binaryfunc PySequenceMethods.sq_concat
+
+   This function is used by :cfunc:`PySequence_Concat` and has the same
+   signature.  It is also used by the `+` operator, after trying the numeric
+   addition via the :attr:`tp_as_number.nb_add` slot.
+
+.. cmember:: ssizeargfunc PySequenceMethods.sq_repeat
+
+   This function is used by :cfunc:`PySequence_Repeat` and has the same
+   signature.  It is also used by the `*` operator, after trying numeric
+   multiplication via the :attr:`tp_as_number.nb_mul` slot.
+
+.. cmember:: ssizeargfunc PySequenceMethods.sq_item
+
+   This function is used by :cfunc:`PySequence_GetItem` and has the same
+   signature.  This slot must be filled for the :cfunc:`PySequence_Check`
+   function to return ``1``, it can be *NULL* otherwise.
+
+   Negative indexes are handled as follows: if the :attr:`sq_length` slot is
+   filled, it is called and the sequence length is used to compute a positive
+   index which is passed to :attr:`sq_item`.  If :attr:`sq_length` is *NULL*,
+   the index is passed as is to the function.
+
+.. cmember:: ssizeobjargproc PySequenceMethods.sq_ass_item
+
+   This function is used by :cfunc:`PySequence_SetItem` and has the same
+   signature.  This slot may be left to *NULL* if the object does not support
+   item assignment.
+
+.. cmember:: objobjproc PySequenceMethods.sq_contains
+
+   This function may be used by :cfunc:`PySequence_Contains` and has the same
+   signature.  This slot may be left to *NULL*, in this case
+   :cfunc:`PySequence_Contains` simply traverses the sequence until it finds a
+   match.
+
+.. cmember:: binaryfunc PySequenceMethods.sq_inplace_concat
+
+   This function is used by :cfunc:`PySequence_InPlaceConcat` and has the same
+   signature.  It should modify its first operand, and return it.
+
+.. cmember:: ssizeargfunc PySequenceMethods.sq_inplace_repeat
+
+   This function is used by :cfunc:`PySequence_InPlaceRepeat` and has the same
+   signature.  It should modify its first operand, and return it.
+
+.. XXX need to explain precedence between mapping and sequence
+.. XXX explains when to implement the sq_inplace_* slots
+
 
 .. _buffer-structs:
 

Modified: python/branches/py3k-importlib/Doc/glossary.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/glossary.rst	(original)
+++ python/branches/py3k-importlib/Doc/glossary.rst	Sat Sep 29 22:20:33 2007
@@ -32,19 +32,6 @@
       One of the two flavors of classes in earlier Python versions.  Since
       Python 3.0, there are no classic classes anymore.
     
-   coercion
-      The implicit conversion of an instance of one type to another during an
-      operation which involves two arguments of the same type.  For example,
-      ``int(3.15)`` converts the floating point number to the integer ``3``, but
-      in ``3+4.5``, each argument is of a different type (one int, one float),
-      and both must be converted to the same type before they can be added or it
-      will raise a ``TypeError``.  Coercion between two operands can be
-      performed with the ``coerce`` builtin function; thus, ``3+4.5`` is
-      equivalent to calling ``operator.add(*coerce(3, 4.5))`` and results in
-      ``operator.add(3.0, 4.5)``.  Without coercion, all arguments of even
-      compatible types would have to be normalized to the same value by the
-      programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
-    
    complex number
       An extension of the familiar real number system in which all numbers are
       expressed as a sum of a real part and an imaginary part.  Imaginary
@@ -168,14 +155,14 @@
    integer division
       Mathematical division discarding any remainder.  For example, the
       expression ``11/4`` currently evaluates to ``2`` in contrast to the
-      ``2.75`` returned by float division.  Also called *floor division*.
-      When dividing two integers the outcome will always be another integer
-      (having the floor function applied to it). However, if one of the operands
-      is another numeric type (such as a :class:`float`), the result will be
-      coerced (see :term:`coercion`) to a common type.  For example, an integer
-      divided by a float will result in a float value, possibly with a decimal
-      fraction.  Integer division can be forced by using the ``//`` operator
-      instead of the ``/`` operator.  See also :term:`__future__`.
+      ``2.75`` returned by float division.  Also called *floor division*.  When
+      dividing two integers the outcome will always be another integer (having
+      the floor function applied to it). However, if the operands types are
+      different, one of them will be converted to the other's type.  For
+      example, an integer divided by a float will result in a float value,
+      possibly with a decimal fraction.  Integer division can be forced by using
+      the ``//`` operator instead of the ``/`` operator.  See also
+      :term:`__future__`.
     
    interactive
       Python has an interactive interpreter which means that you can try out

Modified: python/branches/py3k-importlib/Doc/library/decimal.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/decimal.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/decimal.rst	Sat Sep 29 22:20:33 2007
@@ -312,7 +312,7 @@
 numeric types such as :class:`float` and :class:`int`.  All of the usual math
 operations and special methods apply.  Likewise, decimal objects can be copied,
 pickled, printed, used as dictionary keys, used as set elements, compared,
-sorted, and coerced to another type (such as :class:`float` or :class:`long`).
+sorted, and converted to another type (such as :class:`float` or :class:`int`).
 
 In addition to the standard numeric properties, decimal floating point objects
 also have a number of specialized methods:

Modified: python/branches/py3k-importlib/Doc/library/functions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/functions.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/functions.rst	Sat Sep 29 22:20:33 2007
@@ -701,53 +701,55 @@
    :func:`open` instead of invoking the :class:`file` constructor directly.
 
    The first two arguments are the same as for ``stdio``'s :cfunc:`fopen`:
-   *filename* is the file name to be opened, and *mode* is a string indicating how
-   the file is to be opened.
+   *filename* is the file name to be opened, and *mode* is a string
+   indicating how the file is to be opened.
 
-   The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'`` for
-   writing (truncating the file if it already exists), and ``'a'`` for appending
-   (which on *some* Unix systems means that *all* writes append to the end of the
-   file regardless of the current seek position).  If *mode* is omitted, it
-   defaults to ``'r'``.  When opening a binary file, you should append ``'b'`` to
-   the *mode* value to open the file in binary mode, which will improve
-   portability.  (Appending ``'b'`` is useful even on systems that don't treat
-   binary and text files differently, where it serves as documentation.)  See below
-   for more possible values of *mode*.
+   The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'``
+   for writing (truncating the file if it already exists), and ``'a'`` for
+   appending (which on *some* Unix systems means that *all* writes append to
+   the end of the file regardless of the current seek position).  If *mode*
+   is omitted, it defaults to ``'r'``.  See below for more possible values
+   of *mode*.
+
+   Python distinguishes between files opened in binary and text modes, even
+   when the underlying operating system doesn't.  Files opened in binary
+   mode (appending ``'b'`` to the *mode* argument to :func:``open``) return
+   contents as bytes objects without any decoding.  In text mode (the
+   default, or when ``'t'`` is appended to the *mode* argument) the contents
+   of the file are returned as strings, the bytes having been first decoded
+   using the encoding specified by :func:`sys.getfilesystemencoding`.
 
    .. index::
       single: line-buffered I/O
       single: unbuffered I/O
       single: buffer size, I/O
       single: I/O control; buffering
+      single: binary mode
+      single: text mode
+      module: sys
+
+   The optional *bufsize* argument specifies the file's desired buffer size:
+   0 means unbuffered, 1 means line buffered, any other positive value means
+   use a buffer of (approximately) that size.  A negative *bufsize* means to
+   use the system default, which is usually line buffered for tty devices
+   and fully buffered for other files.  If omitted, the system default is
+   used. [#]_
+
+   Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note
+   that ``'w+'`` truncates the file).
+
+   When a file is opened in text mode it is also opened in universal
+   newlines mode.  Unlike earlier versions of Python it's no longer
+   necessary to add a ``'U'`` value to the *mode* argument to enable this
+   mode.  Consequently, in files opened in text mode lines may be terminated
+   with ``'\n'``, ``'\r'``, or ``'\r\n'``. All three external
+   representations are seen as ``'\n'`` by the Python program.  File objects
+   opened in text mode also have a :attr:`newlines` attribute which has a
+   value of ``None`` (if no newlines have been seen yet), ``'\n'``,
+   ``'\r'``, ``'\r\n'``, or a tuple containing all the newline types seen.
 
-   The optional *bufsize* argument specifies the file's desired buffer size: 0
-   means unbuffered, 1 means line buffered, any other positive value means use a
-   buffer of (approximately) that size.  A negative *bufsize* means to use the
-   system default, which is usually line buffered for tty devices and fully
-   buffered for other files.  If omitted, the system default is used. [#]_
-
-   Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note that
-   ``'w+'`` truncates the file).  Append ``'b'`` to the mode to open the file in
-   binary mode, on systems that differentiate between binary and text files; on
-   systems that don't have this distinction, adding the ``'b'`` has no effect.
-
-   In addition to the standard :cfunc:`fopen` values *mode* may be ``'U'`` or
-   ``'rU'``.  Python is usually built with universal newline support; supplying
-   ``'U'`` opens the file as a text file, but lines may be terminated by any of the
-   following: the Unix end-of-line convention ``'\n'``,  the Macintosh convention
-   ``'\r'``, or the Windows convention ``'\r\n'``. All of these external
-   representations are seen as ``'\n'`` by the Python program. If Python is built
-   without universal newline support a *mode* with ``'U'`` is the same as normal
-   text mode.  Note that file objects so opened also have an attribute called
-   :attr:`newlines` which has a value of ``None`` (if no newlines have yet been
-   seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline
-   types seen.
-
-   Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``,
-   ``'w'`` or ``'a'``.
-
-   See also the :mod:`fileinput` module, the :mod:`os` module, and the
-   :mod:`os.path` module.
+   See also the :mod:`fileinput` module, the file-related functions in the
+   :mod:`os` module, and the :mod:`os.path` module.
 
 
 .. function:: ord(c)

Modified: python/branches/py3k-importlib/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/stdtypes.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/stdtypes.rst	Sat Sep 29 22:20:33 2007
@@ -10,13 +10,6 @@
 The following sections describe the standard types that are built into the
 interpreter.
 
-.. note::
-
-   Historically (until release 2.2), Python's built-in types have differed from
-   user-defined types because it was not possible to use the built-in types as the
-   basis for object-oriented inheritance. This limitation no longer
-   exists.
-
 .. index:: pair: built-in; types
 
 The principal built-in types are numerics, sequences, mappings, files, classes,
@@ -129,8 +122,8 @@
 
 .. index:: pair: chaining; comparisons
 
-Comparison operations are supported by all objects.  They all have the same
-priority (which is higher than that of the Boolean operations). Comparisons can
+There are eight comparison operations in Python.  They all have the same
+priority (which is higher than that of the Boolean operations).  Comparisons can
 be chained arbitrarily; for example, ``x < y <= z`` is equivalent to ``x < y and
 y <= z``, except that *y* is evaluated only once (but in both cases *z* is not
 evaluated at all when ``x < y`` is found to be false).
@@ -172,24 +165,35 @@
    pair: object; numeric
    pair: objects; comparing
 
-Objects of different types, except different numeric types and different string
-types, never compare equal; such objects are ordered consistently but
-arbitrarily (so that sorting a heterogeneous array yields a consistent result).
+Objects of different types, except different numeric types, never compare equal.
 Furthermore, some types (for example, file objects) support only a degenerate
-notion of comparison where any two objects of that type are unequal.  Again,
-such objects are ordered arbitrarily but consistently. The ``<``, ``<=``, ``>``
-and ``>=`` operators will raise a :exc:`TypeError` exception when any operand is
-a complex number.
-
-.. index:: single: __cmp__() (instance method)
+notion of comparison where any two objects of that type are unequal.  The ``<``,
+``<=``, ``>`` and ``>=`` operators will raise a :exc:`TypeError` exception when
+any operand is a complex number, the objects are of different types that cannot
+be compared, or other cases where there is no defined ordering.
+
+.. index:: 
+   single: __cmp__() (instance method)
+   single: __eq__() (instance method)
+   single: __ne__() (instance method)
+   single: __lt__() (instance method)
+   single: __le__() (instance method)
+   single: __gt__() (instance method)
+   single: __ge__() (instance method)
 
 Instances of a class normally compare as non-equal unless the class defines the
-:meth:`__cmp__` method.  Refer to :ref:`customization`) for information on the
-use of this method to effect object comparisons.
+:meth:`__eq__` or :meth:`__cmp__` method.
 
-**Implementation note:** Objects of different types except numbers are ordered
-by their type names; objects of the same types that don't support proper
-comparison are ordered by their address.
+Instances of a class cannot be ordered with respect to other instances of the
+same class, or other types of object, unless the class defines enough of the
+methods :meth:`__cmp__`, :meth:`__lt__`, :meth:`__le__`, :meth:`__gt__`, and
+:meth:`__ge__` (in general, either :meth:`__cmp__` or both :meth:`__lt__` and
+:meth:`__eq__` are sufficient, if you want the conventional meanings of the
+comparison operators).
+
+The behavior of the :keyword:`is` and :keyword:`is not` operators cannot be
+customized; also they can be applied to any two objects and never raise an
+exception.
 
 .. index::
    operator: in
@@ -201,27 +205,22 @@
 
 .. _typesnumeric:
 
-Numeric Types --- :class:`int`, :class:`float`, :class:`long`, :class:`complex`
-===============================================================================
+Numeric Types --- :class:`int`, :class:`float`, :class:`complex`
+================================================================
 
 .. index::
    object: numeric
    object: Boolean
    object: integer
-   object: long integer
    object: floating point
    object: complex number
    pair: C; language
 
-There are four distinct numeric types: :dfn:`plain integers`, :dfn:`long
-integers`,  :dfn:`floating point numbers`, and :dfn:`complex numbers`. In
-addition, Booleans are a subtype of plain integers. Plain integers (also just
-called :dfn:`integers`) are implemented using :ctype:`long` in C, which gives
-them at least 32 bits of precision (``sys.maxint`` is always set to the maximum
-plain integer value for the current platform, the minimum value is
-``-sys.maxint - 1``).  Long integers have unlimited precision. Floating point
-numbers are implemented using :ctype:`double` in C. All bets on their precision
-are off unless you happen to know the machine you are working with.
+There are three distinct numeric types: :dfn:`integers`, :dfn:`floating point
+numbers`, and :dfn:`complex numbers`.  In addition, Booleans are a subtype of
+plain integers.  Integers have unlimited precision.  loating point numbers are
+implemented using :ctype:`double` in C.  All bets on their precision are off
+unless you happen to know the machine you are working with.
 
 Complex numbers have a real and imaginary part, which are each implemented using
 :ctype:`double` in C.  To extract these parts from a complex number *z*, use
@@ -230,21 +229,19 @@
 .. index::
    pair: numeric; literals
    pair: integer; literals
-   triple: long; integer; literals
    pair: floating point; literals
    pair: complex number; literals
    pair: hexadecimal; literals
    pair: octal; literals
+   pair: binary: literals
 
 Numbers are created by numeric literals or as the result of built-in functions
-and operators.  Unadorned integer literals (including hex and octal numbers)
-yield plain integers unless the value they denote is too large to be represented
-as a plain integer, in which case they yield a long integer.  Integer literals
-with an ``'L'`` or ``'l'`` suffix yield long integers (``'L'`` is preferred
-because ``1l`` looks too much like eleven!).  Numeric literals containing a
-decimal point or an exponent sign yield floating point numbers.  Appending
-``'j'`` or ``'J'`` to a numeric literal yields a complex number with a zero real
-part. A complex numeric literal is the sum of a real and an imaginary part.
+and operators.  Unadorned integer literals (including hex, octal and binary
+numbers) yield integers.  Numeric literals containing a decimal point or an
+exponent sign yield floating point numbers.  Appending ``'j'`` or ``'J'`` to a
+numeric literal yields an imaginary number (a complex number with a zero real
+part) which you can add to an integer or float to get a complex number with real
+and imaginary parts.
 
 .. index::
    single: arithmetic
@@ -255,58 +252,55 @@
 
 Python fully supports mixed arithmetic: when a binary arithmetic operator has
 operands of different numeric types, the operand with the "narrower" type is
-widened to that of the other, where plain integer is narrower than long integer
-is narrower than floating point is narrower than complex. Comparisons between
-numbers of mixed type use the same rule. [#]_ The constructors :func:`int`,
-:func:`long`, :func:`float`, and :func:`complex` can be used to produce numbers
-of a specific type.
+widened to that of the other, where integer is narrower than floating point,
+which is narrower than complex.  Comparisons between numbers of mixed type use
+the same rule. [#]_ The constructors :func:`int`, :func:`float`, and
+:func:`complex` can be used to produce numbers of a specific type.
 
 All numeric types (except complex) support the following operations, sorted by
 ascending priority (operations in the same box have the same priority; all
 numeric operations have a higher priority than comparison operations):
 
-+--------------------+---------------------------------+--------+
-| Operation          | Result                          | Notes  |
-+====================+=================================+========+
-| ``x + y``          | sum of *x* and *y*              |        |
-+--------------------+---------------------------------+--------+
-| ``x - y``          | difference of *x* and *y*       |        |
-+--------------------+---------------------------------+--------+
-| ``x * y``          | product of *x* and *y*          |        |
-+--------------------+---------------------------------+--------+
-| ``x / y``          | quotient of *x* and *y*         | \(1)   |
-+--------------------+---------------------------------+--------+
-| ``x // y``         | (floored) quotient of *x* and   | \(5)   |
-|                    | *y*                             |        |
-+--------------------+---------------------------------+--------+
-| ``x % y``          | remainder of ``x / y``          | \(4)   |
-+--------------------+---------------------------------+--------+
-| ``-x``             | *x* negated                     |        |
-+--------------------+---------------------------------+--------+
-| ``+x``             | *x* unchanged                   |        |
-+--------------------+---------------------------------+--------+
-| ``abs(x)``         | absolute value or magnitude of  |        |
-|                    | *x*                             |        |
-+--------------------+---------------------------------+--------+
-| ``int(x)``         | *x* converted to integer        | \(2)   |
-+--------------------+---------------------------------+--------+
-| ``long(x)``        | *x* converted to long integer   | \(2)   |
-+--------------------+---------------------------------+--------+
-| ``float(x)``       | *x* converted to floating point |        |
-+--------------------+---------------------------------+--------+
-| ``complex(re,im)`` | a complex number with real part |        |
-|                    | *re*, imaginary part *im*.      |        |
-|                    | *im* defaults to zero.          |        |
-+--------------------+---------------------------------+--------+
-| ``c.conjugate()``  | conjugate of the complex number |        |
-|                    | *c*                             |        |
-+--------------------+---------------------------------+--------+
-| ``divmod(x, y)``   | the pair ``(x // y, x % y)``    | (3)(4) |
-+--------------------+---------------------------------+--------+
-| ``pow(x, y)``      | *x* to the power *y*            |        |
-+--------------------+---------------------------------+--------+
-| ``x ** y``         | *x* to the power *y*            |        |
-+--------------------+---------------------------------+--------+
++---------------------+---------------------------------+-------+--------------------+
+| Operation           | Result                          | Notes | Full documentation |
++==================== +=================================+=======+====================|
+| ``x + y``           | sum of *x* and *y*              |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``x - y``           | difference of *x* and *y*       |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``x * y``           | product of *x* and *y*          |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``x / y``           | quotient of *x* and *y*         |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``x // y``          | floored quotient of *x* and     | \(1)  |                    |
+|                     | *y*                             |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``x % y``           | remainder of ``x / y``          | \(2)  |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``-x``              | *x* negated                     |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``+x``              | *x* unchanged                   |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``abs(x)``          | absolute value or magnitude of  |       | :func:`abs`        |
+|                     | *x*                             |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``int(x)``          | *x* converted to integer        | \(3)  | :func:`int`        |
++---------------------+---------------------------------+-------+--------------------+
+| ``float(x)``        | *x* converted to floating point |       | :func:`float`      |
++---------------------+---------------------------------+-------+--------------------+
+| ``complex(re, im)`` | a complex number with real part |       | :func:`complex`    |
+|                     | *re*, imaginary part *im*.      |       |                    |
+|                     | *im* defaults to zero.          |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+|  ``c.conjugate()``  | conjugate of the complex number |       |                    |
+|                     | *c*                             |       |                    |
++---------------------+---------------------------------+-------+--------------------+
+| ``divmod(x, y)``    | the pair ``(x // y, x % y)``    | \(2)  | :func:`divmod`     |
++---------------------+---------------------------------+-------+--------------------+
+| ``pow(x, y)``       | *x* to the power *y*            |       | :func:`pow`        |
++---------------------+---------------------------------+-------+--------------------+
+| ``x ** y``          | *x* to the power *y*            |       |                    |
++---------------------+---------------------------------+-------+--------------------+
 
 .. index::
    triple: operations on; numeric; types
@@ -315,16 +309,16 @@
 Notes:
 
 (1)
-   .. index::
-      pair: integer; division
-      triple: long; integer; division
-
-   For (plain or long) integer division, the result is an integer. The result is
-   always rounded towards minus infinity: 1/2 is 0, (-1)/2 is -1, 1/(-2) is -1, and
-   (-1)/(-2) is 0.  Note that the result is a long integer if either operand is a
-   long integer, regardless of the numeric value.
+   Also referred to as integer division.  The resultant value is a whole
+   integer, though the result's type is not necessarily int.  The result is
+   always rounded towards minus infinity: ``1//2`` is ``0``, ``(-1)//2`` is
+   ``-1``, ``1//(-2)`` is ``-1``, and ``(-1)//(-2)`` is ``0``.
 
 (2)
+   Not for complex numbers.  Instead convert to floats using :func:`abs` if
+   appropriate.
+
+(3)
    .. index::
       module: math
       single: floor() (in module math)
@@ -336,19 +330,6 @@
    as in C; see functions :func:`floor` and :func:`ceil` in the :mod:`math` module
    for well-defined conversions.
 
-(3)
-   See :ref:`built-in-funcs` for a full description.
-
-(4)
-   Complex floor division operator, modulo operator, and :func:`divmod`.
-
-   .. deprecated:: 2.3
-      Instead convert to float using :func:`abs` if appropriate.
-
-(5)
-   Also referred to as integer division.  The resultant value is a whole integer,
-   though the result's type is not necessarily int.
-
 .. % XXXJH exceptions: overflow (when? what operations?) zerodivision
 
 
@@ -359,10 +340,9 @@
 
 .. _bit-string-operations:
 
-Plain and long integer types support additional operations that make sense only
-for bit-strings.  Negative numbers are treated as their 2's complement value
-(for long integers, this assumes a sufficiently large number of bits that no
-overflow occurs during the operation).
+Integers support additional operations that make sense only for bit-strings.
+Negative numbers are treated as their 2's complement value (this assumes a
+sufficiently large number of bits that no overflow occurs during the operation).
 
 The priorities of the binary bit-wise operations are all lower than the numeric
 operations and higher than the comparisons; the unary operation ``~`` has the
@@ -453,7 +433,7 @@
    Python objects in the Python/C API.
 
 
-.. method:: iterator.next()
+.. method:: iterator.__next__()
 
    Return the next item from the container.  If there are no further items, raise
    the :exc:`StopIteration` exception.  This method corresponds to the
@@ -465,11 +445,9 @@
 specific types are not important beyond their implementation of the iterator
 protocol.
 
-The intention of the protocol is that once an iterator's :meth:`__next__` method
-raises :exc:`StopIteration`, it will continue to do so on subsequent calls.
-Implementations that do not obey this property are deemed broken.  (This
-constraint was added in Python 2.3; in Python 2.2, various iterators are broken
-according to this rule.)
+Once an iterator's :meth:`__next__` method raises :exc:`StopIteration`, it must
+continue to do so on subsequent calls.  Implementations that do not obey this
+property are deemed broken.
 
 Python's generators provide a convenient way to implement the iterator protocol.
 If a container object's :meth:`__iter__` method is implemented as a generator,
@@ -789,8 +767,11 @@
 
 .. method:: str.join(seq)
 
-   Return a string which is the concatenation of the strings in the sequence *seq*.
-   The separator between elements is the string providing this method.
+   Return a string which is the concatenation of the values in the sequence
+   *seq*. Non-string values in *seq* will be converted to a string using their
+   respective ``str()`` value. If there are any :class:`bytes` objects in
+   *seq*, a :exc:`TypeError` will be raised. The separator between elements is
+   the string providing this method.
 
 
 .. method:: str.ljust(width[, fillchar])
@@ -1137,13 +1118,9 @@
    decimal point and defaults to 6.
 
 (5)
-   The ``%r`` conversion was added in Python 2.0.
-
    The precision determines the maximal number of characters used.
 
 
-   The precision determines the maximal number of characters used.
-
 Since Python strings have an explicit length, ``%s`` conversions do not assume
 that ``'\0'`` is the end of the string.
 
@@ -1161,8 +1138,8 @@
 
 .. _typesseq-range:
 
-XRange Type
------------
+Range Type
+----------
 
 .. index:: object: range
 
@@ -1171,7 +1148,7 @@
 object will always take the same amount of memory, no matter the size of the
 range it represents.  There are no consistent performance advantages.
 
-XRange objects have very little behavior: they only support indexing, iteration,
+Range objects have very little behavior: they only support indexing, iteration,
 and the :func:`len` function.
 
 

Modified: python/branches/py3k-importlib/Doc/tutorial/classes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/classes.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/classes.rst	Sat Sep 29 22:20:33 2007
@@ -473,8 +473,8 @@
 Multiple Inheritance
 --------------------
 
-Python supports a limited form of multiple inheritance as well.  A class
-definition with multiple base classes looks like this::
+Python supports a form of multiple inheritance as well.  A class definition with
+multiple base classes looks like this::
 
    class DerivedClassName(Base1, Base2, Base3):
        <statement-1>
@@ -483,15 +483,18 @@
        .
        <statement-N>
 
-Formerly, the only rule was depth-first, left-to-right.  Thus, if an attribute
-was not found in :class:`DerivedClassName`, it was searched in :class:`Base1`,
-then (recursively) in the base classes of :class:`Base1`, and only if it was not
-found there, it was searched in :class:`Base2`, and so on.
-
-In the meantime, the method resolution order changes dynamically to support
-cooperative calls to :func:`super`.  This approach is known in some other
-multiple-inheritance languages as call-next-method and is more powerful than the
-super call found in single-inheritance languages.
+For most purposes, in the simplest cases, you can think of the search for
+attributes inherited from a parent class as depth-first, left-to-right, not
+searching twice in the same class where there is an overlap in the hierarchy.
+Thus, if an attribute is not found in :class:`DerivedClassName`, it is searched
+for in :class:`Base1`, then (recursively) in the base classes of :class:`Base1`,
+and if it was not found there, it was searched for in :class:`Base2`, and so on.
+
+In fact, it is slightly more complex than that; the method resolution order
+changes dynamically to support cooperative calls to :func:`super`.  This
+approach is known in some other multiple-inheritance languages as
+call-next-method and is more powerful than the super call found in
+single-inheritance languages.
 
 Dynamic ordering is necessary because all cases of multiple inheritance exhibit
 one or more diamond relationships (where one at least one of the parent classes

Modified: python/branches/py3k-importlib/Doc/tutorial/errors.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/errors.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/errors.rst	Sat Sep 29 22:20:33 2007
@@ -115,9 +115,9 @@
 handlers for different exceptions.  At most one handler will be executed.
 Handlers only handle exceptions that occur in the corresponding try clause, not
 in other handlers of the same :keyword:`try` statement.  An except clause may
-name multiple exceptions as a tuple, for example::
+name multiple exceptions as a parenthesized tuple, for example::
 
-   ... except RuntimeError, TypeError, NameError:
+   ... except (RuntimeError, TypeError, NameError):
    ...     pass
 
 The last except clause may omit the exception name(s), to serve as a wildcard.

Modified: python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst	Sat Sep 29 22:20:33 2007
@@ -197,14 +197,20 @@
 writing. The *mode* argument is optional; ``'r'`` will be assumed if it's
 omitted.
 
-On Windows and the Macintosh, ``'b'`` appended to the mode opens the file in
-binary mode, so there are also modes like ``'rb'``, ``'wb'``, and ``'r+b'``.
-Windows makes a distinction between text and binary files; the end-of-line
-characters in text files are automatically altered slightly when data is read or
-written.  This behind-the-scenes modification to file data is fine for ASCII
-text files, but it'll corrupt binary data like that in :file:`JPEG` or
-:file:`EXE` files.  Be very careful to use binary mode when reading and writing
-such files.
+``'b'`` appended to the mode opens the file in binary mode, so there are
+also modes like ``'rb'``, ``'wb'``, and ``'r+b'``.  Python distinguishes
+between text and binary files.  Binary files are read and written without
+any data transformation.  In text mode, platform-specific newline
+representations are automatically converted to newlines when read and
+newline characters are automatically converted to the proper
+platform-specific representation when written.  This makes writing portable
+code which reads or writes text files easier.  In addition, when reading
+from or writing to text files, the data are automatically decoded or
+encoding, respectively, using the encoding associated with the file.
+
+This behind-the-scenes modification to file data is fine for text files, but
+will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files.  Be
+very careful to use binary mode when reading and writing such files.
 
 
 .. _tut-filemethods:

Modified: python/branches/py3k-importlib/Doc/tutorial/interpreter.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/interpreter.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/interpreter.rst	Sat Sep 29 22:20:33 2007
@@ -101,11 +101,14 @@
 prints a welcome message stating its version number and a copyright notice
 before printing the first prompt::
 
-   python
-   Python 1.5.2b2 (#1, Feb 28 1999, 00:02:06)  [GCC 2.8.1] on sunos5
-   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
+   $ python
+   Python 3.0a1 (py3k, Sep 12 2007, 12:21:02)
+   [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2
+   Type "help", "copyright", "credits" or "license" for more information.
    >>>
 
+.. XXX update for final release of Python 3.0
+
 Continuation lines are needed when entering a multi-line construct. As an
 example, take a look at this :keyword:`if` statement::
 
@@ -170,44 +173,32 @@
 Source Code Encoding
 --------------------
 
-.. XXX out of date!
-
-It is possible to use encodings different than ASCII in Python source files. The
-best way to do it is to put one more special comment line right after the ``#!``
-line to define the source file encoding::
+By default, Python source files are treated as encoded in UTF-8.  In that
+encoding, characters of most languages in the world can be used simultaneously
+in string literals, identifiers and comments --- although the standard library
+only uses ASCII characters for identifiers, a convention that any portable code
+should follow.  To display all these characters properly, your editor must
+recognize that the file is UTF-8, and it must use a font that supports all the
+characters in the file.
+
+It is also possible to specify a different encoding for source files.  In order
+to do this, put one more special comment line right after the ``#!`` line to
+define the source file encoding::
 
    # -*- coding: encoding -*- 
 
-
-With that declaration, all characters in the source file will be treated as
-having the encoding *encoding*, and it will be possible to directly write
-Unicode string literals in the selected encoding.  The list of possible
-encodings can be found in the Python Library Reference, in the section on
-:mod:`codecs`.
-
-For example, to write Unicode literals including the Euro currency symbol, the
-ISO-8859-15 encoding can be used, with the Euro symbol having the ordinal value
-164.  This script will print the value 8364 (the Unicode codepoint corresponding
-to the Euro symbol) and then exit::
-
-   # -*- coding: iso-8859-15 -*-
-
-   currency = u"€"
-   print(ord(currency))
-
-If your editor supports saving files as ``UTF-8`` with a UTF-8 *byte order mark*
-(aka BOM), you can use that instead of an encoding declaration. IDLE supports
-this capability if ``Options/General/Default Source Encoding/UTF-8`` is set.
-Notice that this signature is not understood in older Python releases (2.2 and
-earlier), and also not understood by the operating system for script files with
-``#!`` lines (only used on Unix systems).
-
-By using UTF-8 (either through the signature or an encoding declaration),
-characters of most languages in the world can be used simultaneously in string
-literals and comments.  Using non-ASCII characters in identifiers is not
-supported. To display all these characters properly, your editor must recognize
-that the file is UTF-8, and it must use a font that supports all the characters
-in the file.
+With that declaration, everything in the source file will be treated as having
+the encoding *encoding* instead of UTF-8.  The list of possible encodings can be
+found in the Python Library Reference, in the section on :mod:`codecs`.
+
+For example, if your editor of choice does not support UTF-8 encoded files and
+insists on using some other encoding, say Windows-1252, you can write::
+
+   # -*- coding: cp-1252 -*-
+
+and still use all characters in the Windows-1252 character set in the source
+files.  The special encoding comment must be in the *first or second* line
+within the file.
 
 
 .. _tut-startup:

Modified: python/branches/py3k-importlib/Doc/tutorial/introduction.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/introduction.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/introduction.rst	Sat Sep 29 22:20:33 2007
@@ -131,9 +131,9 @@
    0.5
 
 The conversion functions to floating point and integer (:func:`float`,
-:func:`int` and :func:`long`) don't work for complex numbers --- there is no one
-correct way to convert a complex number to a real number.  Use ``abs(z)`` to get
-its magnitude (as a float) or ``z.real`` to get its real part. ::
+:func:`int`) don't work for complex numbers --- there is not one correct way to
+convert a complex number to a real number.  Use ``abs(z)`` to get its magnitude
+(as a float) or ``z.real`` to get its real part::
 
    >>> a=3.0+4.0j
    >>> float(a)

Modified: python/branches/py3k-importlib/Include/abstract.h
==============================================================================
--- python/branches/py3k-importlib/Include/abstract.h	(original)
+++ python/branches/py3k-importlib/Include/abstract.h	Sat Sep 29 22:20:33 2007
@@ -542,7 +542,7 @@
 	/* Return 1 if the getbuffer function is available, otherwise 
 	   return 0 */
 
-     PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, PyBuffer *view, 
+     PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view, 
 					int flags);
 
 	/* This is a C-API version of the getbuffer function call.  It checks
@@ -552,7 +552,7 @@
         */
 
 
-     PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view);
+     PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view);
 
 
 	/* C-API version of the releasebuffer function call.  It
@@ -570,7 +570,7 @@
            buffer
         */
 
-     PyAPI_FUNC(void *) PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices);
+     PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
         
         /* Get the memory area pointed to by the indices for the buffer given. 
            Note that view->ndim is the assumed size of indices 
@@ -583,10 +583,10 @@
     
 
 	
-     PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, PyBuffer *view,
+     PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
     					   Py_ssize_t len, char fort);
 
-     PyAPI_FUNC(int) PyBuffer_FromContiguous(PyBuffer *view, void *buf, 
+     PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf, 
     					     Py_ssize_t len, char fort);
 
 
@@ -611,7 +611,7 @@
         /* Copy the data from the src buffer to the buffer of destination
          */
 
-     PyAPI_FUNC(int) PyBuffer_IsContiguous(PyBuffer *view, char fortran);
+     PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fortran);
 
 
      PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, 
@@ -626,7 +626,7 @@
             per element.
         */
 
-     PyAPI_FUNC(int) PyBuffer_FillInfo(PyBuffer *view, void *buf,
+     PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, void *buf,
 		             	       Py_ssize_t len, int readonly,
 				       int flags);
 

Modified: python/branches/py3k-importlib/Include/memoryobject.h
==============================================================================
--- python/branches/py3k-importlib/Include/memoryobject.h	(original)
+++ python/branches/py3k-importlib/Include/memoryobject.h	Sat Sep 29 22:20:33 2007
@@ -10,7 +10,7 @@
 typedef struct {
         PyObject_HEAD
         PyObject *base;
-        PyBuffer view;
+        Py_buffer view;
 } PyMemoryViewObject;
 
 
@@ -57,7 +57,7 @@
 
 PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
 
-PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(PyBuffer *info);
+PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(Py_buffer *info);
 	/* create new if bufptr is NULL 
 	    will be a new bytesobject in base */
 

Modified: python/branches/py3k-importlib/Include/object.h
==============================================================================
--- python/branches/py3k-importlib/Include/object.h	(original)
+++ python/branches/py3k-importlib/Include/object.h	Sat Sep 29 22:20:33 2007
@@ -133,7 +133,6 @@
 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
 typedef int (*inquiry)(PyObject *);
 typedef Py_ssize_t (*lenfunc)(PyObject *);
-typedef int (*coercion)(PyObject **, PyObject **);
 typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
 typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
 typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
@@ -154,10 +153,10 @@
         Py_ssize_t *strides;
         Py_ssize_t *suboffsets;
         void *internal;
-} PyBuffer;
+} Py_buffer;
 
-typedef int (*getbufferproc)(PyObject *, PyBuffer *, int);
-typedef void (*releasebufferproc)(PyObject *, PyBuffer *);
+typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
+typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
 
         /* Flags for getting buffers */
 #define PyBUF_SIMPLE 0
@@ -222,7 +221,7 @@
 	binaryfunc nb_and;
 	binaryfunc nb_xor;
 	binaryfunc nb_or;
-	coercion nb_coerce;
+	int nb_reserved; /* unused, used to be nb_coerce */
 	unaryfunc nb_int;
 	unaryfunc nb_long;
 	unaryfunc nb_float;

Modified: python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py	(original)
+++ python/branches/py3k-importlib/Lib/distutils/fancy_getopt.py	Sat Sep 29 22:20:33 2007
@@ -388,7 +388,7 @@
     text = text.expandtabs()
     text = text.translate(WS_TRANS)
     chunks = re.split(r'( +|-+)', text)
-    chunks = filter(None, chunks)      # ' - ' results in empty strings
+    chunks = [ch for ch in chunks if ch] # ' - ' results in empty strings
     lines = []
 
     while chunks:

Modified: python/branches/py3k-importlib/Lib/lib-tk/turtle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/lib-tk/turtle.py	(original)
+++ python/branches/py3k-importlib/Lib/lib-tk/turtle.py	Sat Sep 29 22:20:33 2007
@@ -531,7 +531,7 @@
 
     def _goto(self, x1, y1):
         x0, y0 = self._position
-        self._position = map(float, (x1, y1))
+        self._position = (float(x1), float(y1))
         if self._filling:
             self._path.append(self._position)
         if self._drawing:
@@ -749,25 +749,25 @@
     global _width, _height, _startx, _starty
 
     width = geometry.get('width',_width)
-    if width >= 0 or width == None:
+    if width is None or width >= 0:
         _width = width
     else:
         raise ValueError("width can not be less than 0")
 
     height = geometry.get('height',_height)
-    if height >= 0 or height == None:
+    if height is None or height >= 0:
         _height = height
     else:
         raise ValueError("height can not be less than 0")
 
     startx = geometry.get('startx', _startx)
-    if startx >= 0 or startx == None:
+    if startx is None or startx >= 0:
         _startx = _startx
     else:
         raise ValueError("startx can not be less than 0")
 
     starty = geometry.get('starty', _starty)
-    if starty >= 0 or starty == None:
+    if starty is None or starty >= 0:
         _starty = starty
     else:
         raise ValueError("startx can not be less than 0")

Modified: python/branches/py3k-importlib/Lib/test/string_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/string_tests.py	(original)
+++ python/branches/py3k-importlib/Lib/test/string_tests.py	Sat Sep 29 22:20:33 2007
@@ -13,6 +13,7 @@
 
 class BadSeq1(Sequence):
     def __init__(self): self.seq = [7, 'hello', 123]
+    def __str__(self): return '{0} {1} {2}'.format(*self.seq)
 
 class BadSeq2(Sequence):
     def __init__(self): self.seq = ['a', 'b', 'c']
@@ -987,19 +988,19 @@
         self.checkequal('abc', 'a', 'join', ('abc',))
         self.checkequal('z', 'a', 'join', UserList(['z']))
         self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
-        self.checkraises(TypeError, '.', 'join', ['a', 'b', 3])
+        self.checkequal('a.b.3', '.', 'join', ['a', 'b', 3])
         for i in [5, 25, 125]:
             self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
                  ['a' * i] * i)
             self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
                  ('a' * i,) * i)
 
-        self.checkraises(TypeError, ' ', 'join', BadSeq1())
+        self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
         self.checkequal('a b c', ' ', 'join', BadSeq2())
 
         self.checkraises(TypeError, ' ', 'join')
         self.checkraises(TypeError, ' ', 'join', 7)
-        self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123]))
+        self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
         try:
             def f():
                 yield 4 + ""

Modified: python/branches/py3k-importlib/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_descr.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_descr.py	Sat Sep 29 22:20:33 2007
@@ -3238,10 +3238,6 @@
     except ValueError: pass
     else: raise TestFailed("''.split('') doesn't raise ValueError")
 
-    try: ''.join([0])
-    except TypeError: pass
-    else: raise TestFailed("''.join([0]) doesn't raise TypeError")
-
     try: ''.rindex('5')
     except ValueError: pass
     else: raise TestFailed("''.rindex('5') doesn't raise ValueError")

Modified: python/branches/py3k-importlib/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_unicode.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_unicode.py	Sat Sep 29 22:20:33 2007
@@ -178,6 +178,10 @@
     def test_join(self):
         string_tests.MixinStrUnicodeUserStringTest.test_join(self)
 
+        class MyWrapper:
+            def __init__(self, sval): self.sval = sval
+            def __str__(self): return self.sval
+
         # mixed arguments
         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
         self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
@@ -186,6 +190,8 @@
         self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
         self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
         self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
+        self.checkequalnofix('1 2 foo', ' ', 'join', [1, 2, MyWrapper('foo')])
+        self.checkraises(TypeError, ' ', 'join', [1, 2, 3, bytes()])
 
     def test_replace(self):
         string_tests.CommonTest.test_replace(self)

Modified: python/branches/py3k-importlib/Modules/_bsddb.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_bsddb.c	(original)
+++ python/branches/py3k-importlib/Modules/_bsddb.c	Sat Sep 29 22:20:33 2007
@@ -382,7 +382,7 @@
 
 
 /* Cleanup a Python buffer API view created by make_dbt() */
-static void free_buf_view(PyObject *obj, PyBuffer *view)
+static void free_buf_view(PyObject *obj, Py_buffer *view)
 {
     if (view) {
         PyObject_ReleaseBuffer(obj, view);
@@ -400,13 +400,13 @@
             } while(0);
 
 
-static PyBuffer * _malloc_view(PyObject *obj)
+static Py_buffer * _malloc_view(PyObject *obj)
 {
-    PyBuffer *view;
+    Py_buffer *view;
 
-    if (!(view = PyMem_Malloc(sizeof(PyBuffer)))) {
+    if (!(view = PyMem_Malloc(sizeof(Py_buffer)))) {
         PyErr_SetString(PyExc_MemoryError,
-                        "PyBuffer malloc failed");
+                        "Py_buffer malloc failed");
         return NULL;
     }
     /* XXX(gps): PyBUF_LOCKDATA is desired to prevent other theads from
@@ -429,11 +429,11 @@
 
 /* Create a DBT structure (containing key and data values) from Python
    strings.  Returns >= 1 on success, 0 on an error.  The returned_view_p
-   may be filled with a newly allocated PyBuffer view on success.
-   The caller MUST call free_buf_view() on any returned PyBuffer. */
-static int make_dbt(PyObject* obj, DBT* dbt, PyBuffer** returned_view_p)
+   may be filled with a newly allocated Py_buffer view on success.
+   The caller MUST call free_buf_view() on any returned Py_buffer. */
+static int make_dbt(PyObject* obj, DBT* dbt, Py_buffer** returned_view_p)
 {
-    PyBuffer *view;
+    Py_buffer *view;
 
     /* simple way to ensure the caller can detect if we've returned a
        new buffer view or not: require their pointer to start out NULL. */
@@ -464,14 +464,14 @@
    what's been given, verifies that it's allowed, and then makes the DBT.
 
    Caller MUST call FREE_DBT_VIEW(keydbt, keyobj, key_view) with all
-   returned DBT and PyBuffer values when done. */
+   returned DBT and Py_buffer values when done. */
 static int
 make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags,
-             PyBuffer** returned_view_p)
+             Py_buffer** returned_view_p)
 {
     db_recno_t recno;
     int type;
-    PyBuffer *view;
+    Py_buffer *view;
 
     /* simple way to ensure the caller can detect if we've returned a
        new buffer view or not: require their pointer to start out NULL. */
@@ -1221,7 +1221,7 @@
 {
     PyObject* txnobj = NULL;
     PyObject* dataobj;
-    PyBuffer* data_buf_view = NULL;
+    Py_buffer* data_buf_view = NULL;
     db_recno_t recno;
     DBT key, data;
     DB_TXN *txn = NULL;
@@ -1534,7 +1534,7 @@
     PyObject* txnobj = NULL;
     int flags = 0;
     PyObject* keyobj;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key;
     DB_TXN *txn = NULL;
     static char* kwnames[] = { "key", "txn", "flags", NULL };
@@ -1585,7 +1585,7 @@
     PyObject* keyobj;
     PyObject* dfltobj = NULL;
     PyObject* retval = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     int dlen = -1;
     int doff = -1;
     DBT key, data;
@@ -1654,7 +1654,7 @@
     PyObject* keyobj;
     PyObject* dfltobj = NULL;
     PyObject* retval = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     int dlen = -1;
     int doff = -1;
     DBT key, pkey, data;
@@ -1758,7 +1758,7 @@
     PyObject* txnobj = NULL;
     PyObject* keyobj;
     PyObject* retval = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key, data;
     DB_TXN *txn = NULL;
     static char* kwnames[] = { "key", "txn", NULL };
@@ -1802,8 +1802,8 @@
     PyObject* keyobj;
     PyObject* dataobj;
     PyObject* retval = NULL;
-    PyBuffer* data_buf_view = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* data_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key, data;
     void *orig_data;
     DB_TXN *txn = NULL;
@@ -1969,7 +1969,7 @@
     int err, flags=0;
     PyObject* txnobj = NULL;
     PyObject* keyobj;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key;
     DB_TXN *txn = NULL;
     DB_KEY_RANGE range;
@@ -2100,8 +2100,8 @@
     int dlen = -1;
     int doff = -1;
     PyObject *keyobj, *dataobj, *retval;
-    PyBuffer *data_buf_view = NULL;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *data_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
     DBT key, data;
     DB_TXN *txn = NULL;
     static char* kwnames[] = { "key", "data", "txn", "flags", "dlen",
@@ -2881,7 +2881,7 @@
 {
     int err;
     PyObject* retval;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key;
     DBT data;
 
@@ -2920,8 +2920,8 @@
     DBT key, data;
     int retval;
     int flags = 0;
-    PyBuffer *data_buf_view = NULL;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *data_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
 
     if (self->db == NULL) {
         PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed");
@@ -2966,7 +2966,7 @@
 {
     int err;
     PyObject* keyobj;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     DBT key, data;
     PyObject* txnobj = NULL;
     DB_TXN *txn = NULL;
@@ -3263,8 +3263,8 @@
     PyObject* keyobj = NULL;
     PyObject* dataobj = NULL;
     PyObject* retval = NULL;
-    PyBuffer* data_buf_view = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* data_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     int dlen = -1;
     int doff = -1;
     DBT key, data;
@@ -3354,8 +3354,8 @@
     PyObject* keyobj = NULL;
     PyObject* dataobj = NULL;
     PyObject* retval = NULL;
-    PyBuffer* data_buf_view = NULL;
-    PyBuffer* key_buf_view = NULL;
+    Py_buffer* data_buf_view = NULL;
+    Py_buffer* key_buf_view = NULL;
     int dlen = -1;
     int doff = -1;
     DBT key, pkey, data;
@@ -3517,8 +3517,8 @@
 {
     int err, flags = 0;
     PyObject *keyobj, *dataobj;
-    PyBuffer *data_buf_view = NULL;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *data_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
     DBT key, data;
     static char* kwnames[] = { "key", "data", "flags", "dlen", "doff",
                                      NULL };
@@ -3558,7 +3558,7 @@
     int err, flags = 0;
     DBT key, data;
     PyObject *retval, *keyobj;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
     static char* kwnames[] = { "key", "flags", "dlen", "doff", NULL };
     int dlen = -1;
     int doff = -1;
@@ -3630,7 +3630,7 @@
     int err, flags = 0;
     DBT key, data;
     PyObject *retval, *keyobj;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
     static char* kwnames[] = { "key", "flags", "dlen", "doff", NULL };
     int dlen = -1;
     int doff = -1;
@@ -3705,8 +3705,8 @@
     int err;
     DBT key, data;
     PyObject *retval;
-    PyBuffer *data_buf_view = NULL;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *data_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
 
     /* the caller did this:  CHECK_CURSOR_NOT_CLOSED(self); */
     if (!make_key_dbt(self->mydb, keyobj, &key, NULL, &key_buf_view))
@@ -4480,7 +4480,7 @@
     int locker, lock_mode;
     DBT obj;
     PyObject *objobj, *retval;
-    PyBuffer *obj_buf_view = NULL;
+    Py_buffer *obj_buf_view = NULL;
 
     if (!PyArg_ParseTuple(args, "iOi|i:lock_get", &locker, &objobj, &lock_mode, &flags))
         return NULL;
@@ -5057,7 +5057,7 @@
 {
     int err, flags = 0;
     PyObject *keyobj;
-    PyBuffer *key_buf_view = NULL;
+    Py_buffer *key_buf_view = NULL;
     PyObject *txnobj = NULL;
     DB_TXN *txn = NULL;
     DBT key;

Modified: python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c	Sat Sep 29 22:20:33 2007
@@ -740,7 +740,7 @@
 	char *ptr;
 	Py_ssize_t size;
         int rel = 0;
-        PyBuffer view;
+        Py_buffer view;
 
 	if (PyBuffer_Check(value)) {
                 if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
@@ -2083,7 +2083,7 @@
 	{ NULL },
 };
 
-static int CData_GetBuffer(PyObject *_self, PyBuffer *view, int flags)
+static int CData_GetBuffer(PyObject *_self, Py_buffer *view, int flags)
 {
 	CDataObject *self = (CDataObject *)_self;
         return PyBuffer_FillInfo(view, self->b_ptr, self->b_size, 0, flags);
@@ -3833,48 +3833,6 @@
 }
 
 static int
-Array_ass_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *value)
-{
-	CDataObject *self = (CDataObject *)_self;
-	Py_ssize_t i, len;
-
-	if (value == NULL) {
-		PyErr_SetString(PyExc_TypeError,
-				"Array does not support item deletion");
-		return -1;
-	}
-
-	if (ilow < 0)
-		ilow = 0;
-	else if (ilow > self->b_length)
-		ilow = self->b_length;
-	if (ihigh < 0)
-		ihigh = 0;
-	if (ihigh < ilow)
-		ihigh = ilow;
-	else if (ihigh > self->b_length)
-		ihigh = self->b_length;
-
-	len = PySequence_Length(value);
-	if (len != ihigh - ilow) {
-		PyErr_SetString(PyExc_ValueError,
-				"Can only assign sequence of same size");
-		return -1;
-	}
-	for (i = 0; i < len; i++) {
-		PyObject *item = PySequence_GetItem(value, i);
-		int result;
-		if (item == NULL)
-			return -1;
-		result = Array_ass_item(_self, i+ilow, item);
-		Py_DECREF(item);
-		if (result == -1)
-			return -1;
-	}
-	return 0;
-}
-
-static int
 Array_ass_subscript(PyObject *_self, PyObject *item, PyObject *value)
 {
 	CDataObject *self = (CDataObject *)_self;

Modified: python/branches/py3k-importlib/Modules/_hashopenssl.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_hashopenssl.c	(original)
+++ python/branches/py3k-importlib/Modules/_hashopenssl.c	Sat Sep 29 22:20:33 2007
@@ -176,7 +176,7 @@
 EVP_update(EVPobject *self, PyObject *args)
 {
     PyObject *obj;
-    PyBuffer view;
+    Py_buffer view;
 
     if (!PyArg_ParseTuple(args, "O:update", &obj))
         return NULL;
@@ -252,7 +252,7 @@
     static char *kwlist[] = {"name", "string", NULL};
     PyObject *name_obj = NULL;
     PyObject *data_obj = NULL;
-    PyBuffer view;
+    Py_buffer view;
     char *nameStr;
     const EVP_MD *digest;
 
@@ -397,7 +397,7 @@
     static char *kwlist[] = {"name", "string", NULL};
     PyObject *name_obj = NULL;
     PyObject *data_obj = NULL;
-    PyBuffer view = { 0 };
+    Py_buffer view = { 0 };
     PyObject *ret_obj;
     char *name;
     const EVP_MD *digest;
@@ -437,7 +437,7 @@
     EVP_new_ ## NAME (PyObject *self, PyObject *args) \
     { \
         PyObject *data_obj = NULL; \
-        PyBuffer view = { 0 }; \
+        Py_buffer view = { 0 }; \
         PyObject *ret_obj; \
      \
         if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \

Modified: python/branches/py3k-importlib/Modules/_sre.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sre.c	(original)
+++ python/branches/py3k-importlib/Modules/_sre.c	Sat Sep 29 22:20:33 2007
@@ -1672,7 +1672,7 @@
     Py_ssize_t size, bytes;
     int charsize;
     void* ptr;
-    PyBuffer view;
+    Py_buffer view;
 
     /* get pointer to string buffer */
     view.len = -1;

Modified: python/branches/py3k-importlib/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/arraymodule.c	(original)
+++ python/branches/py3k-importlib/Modules/arraymodule.c	Sat Sep 29 22:20:33 2007
@@ -1784,7 +1784,7 @@
 
 
 static int
-array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
+array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
 {
         if ((flags & PyBUF_CHARACTER)) {
                 PyErr_SetString(PyExc_TypeError,
@@ -1825,7 +1825,7 @@
 }
 
 static void
-array_buffer_relbuf(arrayobject *self, PyBuffer *view)
+array_buffer_relbuf(arrayobject *self, Py_buffer *view)
 {
         self->ob_exports--;
 }

Modified: python/branches/py3k-importlib/Modules/datetimemodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/datetimemodule.c	(original)
+++ python/branches/py3k-importlib/Modules/datetimemodule.c	Sat Sep 29 22:20:33 2007
@@ -2082,7 +2082,7 @@
 	0,					/*nb_and*/
 	0,					/*nb_xor*/
 	0,					/*nb_or*/
-	0,					/*nb_coerce*/
+	0,					/*nb_reserved*/
 	0,					/*nb_int*/
 	0,					/*nb_long*/
 	0,					/*nb_float*/

Modified: python/branches/py3k-importlib/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k-importlib/Modules/mmapmodule.c	(original)
+++ python/branches/py3k-importlib/Modules/mmapmodule.c	Sat Sep 29 22:20:33 2007
@@ -601,7 +601,7 @@
 /* Functions for treating an mmap'ed file as a buffer */
 
 static int
-mmap_buffer_getbuf(mmap_object *self, PyBuffer *view, int flags) 
+mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags) 
 {
 	CHECK_VALID(-1);
         if (PyBuffer_FillInfo(view, self->data, self->size, 
@@ -612,7 +612,7 @@
 }
 
 static void
-mmap_buffer_releasebuf(mmap_object *self, PyBuffer *view)
+mmap_buffer_releasebuf(mmap_object *self, Py_buffer *view)
 {
         self->exports--;
 }

Modified: python/branches/py3k-importlib/Objects/abstract.c
==============================================================================
--- python/branches/py3k-importlib/Objects/abstract.c	(original)
+++ python/branches/py3k-importlib/Objects/abstract.c	Sat Sep 29 22:20:33 2007
@@ -224,7 +224,7 @@
                       Py_ssize_t *buffer_len)
 {
 	PyBufferProcs *pb;
-        PyBuffer view;
+        Py_buffer view;
 
 	if (obj == NULL || buffer == NULL || buffer_len == NULL) {
 		null_error();
@@ -267,7 +267,7 @@
 			  Py_ssize_t *buffer_len)
 {
 	PyBufferProcs *pb;
-        PyBuffer view;
+        Py_buffer view;
 
 	if (obj == NULL || buffer == NULL || buffer_len == NULL) {
 		null_error();
@@ -295,7 +295,7 @@
 			   Py_ssize_t *buffer_len)
 {
 	PyBufferProcs *pb;
-        PyBuffer view;
+        Py_buffer view;
 
 	if (obj == NULL || buffer == NULL || buffer_len == NULL) {
 		null_error();
@@ -320,7 +320,7 @@
 /* Buffer C-API for Python 3.0 */
 
 int
-PyObject_GetBuffer(PyObject *obj, PyBuffer *view, int flags)
+PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
 {
         if (!PyObject_CheckBuffer(obj)) {
                 PyErr_SetString(PyExc_TypeError,
@@ -331,7 +331,7 @@
 }
 
 void
-PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view)
+PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view)
 {
         if (obj->ob_type->tp_as_buffer != NULL && 
             obj->ob_type->tp_as_buffer->bf_releasebuffer != NULL) {
@@ -341,7 +341,7 @@
 
 
 static int
-_IsFortranContiguous(PyBuffer *view)
+_IsFortranContiguous(Py_buffer *view)
 {
         Py_ssize_t sd, dim;
         int i;
@@ -362,7 +362,7 @@
 }
 
 static int
-_IsCContiguous(PyBuffer *view)
+_IsCContiguous(Py_buffer *view)
 {
         Py_ssize_t sd, dim;
         int i;
@@ -383,7 +383,7 @@
 }
 
 int
-PyBuffer_IsContiguous(PyBuffer *view, char fort)
+PyBuffer_IsContiguous(Py_buffer *view, char fort)
 {
 
         if (view->suboffsets != NULL) return 0;
@@ -399,7 +399,7 @@
 
 
 void* 
-PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices)
+PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
 {
         char* pointer;
         int i;
@@ -452,7 +452,7 @@
   */
 
 int 
-PyBuffer_ToContiguous(void *buf, PyBuffer *view, Py_ssize_t len, char fort)
+PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
 {
         int k;
         void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
@@ -503,7 +503,7 @@
 }
 
 int
-PyBuffer_FromContiguous(PyBuffer *view, void *buf, Py_ssize_t len, char fort)
+PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
 {
         int k;
         void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
@@ -556,7 +556,7 @@
 
 int PyObject_CopyData(PyObject *dest, PyObject *src) 
 {
-        PyBuffer view_dest, view_src;
+        Py_buffer view_dest, view_src;
         int k;
         Py_ssize_t *indices, elements;
         char *dptr, *sptr;
@@ -649,7 +649,7 @@
 }
 
 int
-PyBuffer_FillInfo(PyBuffer *view, void *buf, Py_ssize_t len,
+PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len,
               int readonly, int flags)
 {        
         if (view == NULL) return 0;

Modified: python/branches/py3k-importlib/Objects/boolobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/boolobject.c	(original)
+++ python/branches/py3k-importlib/Objects/boolobject.c	Sat Sep 29 22:20:33 2007
@@ -108,7 +108,7 @@
 	bool_and,		/* nb_and */
 	bool_xor,		/* nb_xor */
 	bool_or,		/* nb_or */
-	0,			/* nb_coerce */
+	0,			/* nb_reserved */
 	0,			/* nb_int */
 	0,			/* nb_long */
 	0,			/* nb_float */

Modified: python/branches/py3k-importlib/Objects/bufferobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/bufferobject.c	(original)
+++ python/branches/py3k-importlib/Objects/bufferobject.c	Sat Sep 29 22:20:33 2007
@@ -16,11 +16,12 @@
 
 
 static int
-get_buf(PyBufferObject *self, PyBuffer *view, int flags)
+get_buf(PyBufferObject *self, Py_buffer *view, int flags)
 {
 	if (self->b_base == NULL) {
 		view->buf = self->b_ptr;
 		view->len = self->b_size;
+		view->readonly = 0;
 	}
 	else {
 		Py_ssize_t count, offset;
@@ -46,7 +47,7 @@
 
 
 static int
-buffer_getbuf(PyBufferObject *self, PyBuffer *view, int flags)
+buffer_getbuf(PyBufferObject *self, Py_buffer *view, int flags)
 {
         if (view == NULL) return 0;
         if (!get_buf(self, view, flags))
@@ -57,7 +58,7 @@
 
 
 static void
-buffer_releasebuf(PyBufferObject *self, PyBuffer *view) 
+buffer_releasebuf(PyBufferObject *self, Py_buffer *view) 
 {
         /* No-op if there is no self->b_base */
 	if (self->b_base != NULL) {
@@ -229,7 +230,7 @@
 }
 
 static int
-get_bufx(PyObject *obj, PyBuffer *view, int flags)
+get_bufx(PyObject *obj, Py_buffer *view, int flags)
 {
 	PyBufferProcs *bp;
 
@@ -256,7 +257,7 @@
 	void *p1, *p2;
 	Py_ssize_t len1, len2, min_len;
 	int cmp, ok;
-        PyBuffer v1, v2;
+        Py_buffer v1, v2;
 
 	ok = 1;
 	if (!get_bufx(self, &v1, PyBUF_SIMPLE))
@@ -318,7 +319,7 @@
 static long
 buffer_hash(PyBufferObject *self)
 {
-        PyBuffer view;
+        Py_buffer view;
 	register Py_ssize_t len;
 	register unsigned char *p;
 	register long x;
@@ -351,7 +352,7 @@
 static PyObject *
 buffer_str(PyBufferObject *self)
 {
-        PyBuffer view;
+        Py_buffer view;
         PyObject *res;
 
 	if (!get_buf(self, &view, PyBUF_SIMPLE))
@@ -366,7 +367,7 @@
 static Py_ssize_t
 buffer_length(PyBufferObject *self)
 {
-        PyBuffer view;
+        Py_buffer view;
 
 	if (!get_buf(self, &view, PyBUF_SIMPLE))
 		return -1;
@@ -380,7 +381,7 @@
 	PyBufferProcs *pb = other->ob_type->tp_as_buffer;
 	char *p;
 	PyObject *ob;
-        PyBuffer view, view2;
+        Py_buffer view, view2;
 
 	if (pb == NULL ||
             pb->bf_getbuffer == NULL)
@@ -426,7 +427,7 @@
 {
 	PyObject *ob;
 	register char *p;
-        PyBuffer view;
+        Py_buffer view;
 
 	if (count < 0)
 		count = 0;
@@ -450,7 +451,7 @@
 static PyObject *
 buffer_item(PyBufferObject *self, Py_ssize_t idx)
 {
-        PyBuffer view;
+        Py_buffer view;
         PyObject *ob;
 
 	if (!get_buf(self, &view, PyBUF_SIMPLE))
@@ -467,7 +468,7 @@
 static PyObject *
 buffer_subscript(PyBufferObject *self, PyObject *item)
 {
-	PyBuffer view;
+	Py_buffer view;
 	PyObject *ob;
 	
 	if (!get_buf(self, &view, PyBUF_SIMPLE))
@@ -537,7 +538,7 @@
 buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
 {
 	PyBufferProcs *pb;
-        PyBuffer view, view2;
+        Py_buffer view, view2;
 
 	if (!get_buf(self, &view, PyBUF_SIMPLE))
 		return -1;
@@ -585,7 +586,7 @@
 static int
 buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
 {
-	PyBuffer v1;
+	Py_buffer v1;
 
 	if (!get_buf(self, &v1, PyBUF_SIMPLE))
 		return -1;
@@ -606,7 +607,7 @@
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelength;
-		PyBuffer v2;
+		Py_buffer v2;
 		PyBufferProcs *pb;
 		
 		if (PySlice_GetIndicesEx((PySliceObject *)item, v1.len,

Modified: python/branches/py3k-importlib/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/bytesobject.c	(original)
+++ python/branches/py3k-importlib/Objects/bytesobject.c	Sat Sep 29 22:20:33 2007
@@ -50,7 +50,7 @@
 }
 
 static int
-bytes_getbuffer(PyBytesObject *obj, PyBuffer *view, int flags)
+bytes_getbuffer(PyBytesObject *obj, Py_buffer *view, int flags)
 {
         int ret;
         void *ptr;
@@ -70,13 +70,13 @@
 }
 
 static void
-bytes_releasebuffer(PyBytesObject *obj, PyBuffer *view)
+bytes_releasebuffer(PyBytesObject *obj, Py_buffer *view)
 {
         obj->ob_exports--;
 }
 
 static Py_ssize_t
-_getbuffer(PyObject *obj, PyBuffer *view)
+_getbuffer(PyObject *obj, Py_buffer *view)
 {
     PyBufferProcs *buffer = Py_Type(obj)->tp_as_buffer;
 
@@ -213,7 +213,7 @@
 PyBytes_Concat(PyObject *a, PyObject *b)
 {
     Py_ssize_t size;
-    PyBuffer va, vb;
+    Py_buffer va, vb;
     PyBytesObject *result;
 
     va.len = -1;
@@ -266,7 +266,7 @@
 {
     Py_ssize_t mysize;
     Py_ssize_t size;
-    PyBuffer vo;
+    Py_buffer vo;
 
     if (_getbuffer(other, &vo) < 0) {
         PyErr_Format(PyExc_TypeError, "can't concat bytes to %.100s",
@@ -462,7 +462,7 @@
 {
     Py_ssize_t avail, needed;
     void *bytes;
-    PyBuffer vbytes;
+    Py_buffer vbytes;
     int res = 0;
 
     vbytes.len = -1;
@@ -814,7 +814,7 @@
     /* Use the modern buffer interface */
     if (PyObject_CheckBuffer(arg)) {
         Py_ssize_t size;
-        PyBuffer view;
+        Py_buffer view;
         if (PyObject_GetBuffer(arg, &view, PyBUF_FULL_RO) < 0)
             return -1;
         size = view.len;
@@ -954,7 +954,7 @@
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
     Py_ssize_t self_size, other_size;
-    PyBuffer self_bytes, other_bytes;
+    Py_buffer self_bytes, other_bytes;
     PyObject *res;
     Py_ssize_t minsize;
     int cmp;
@@ -1067,7 +1067,7 @@
 bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
 {
     PyObject *subobj;
-    PyBuffer subbuf;
+    Py_buffer subbuf;
     Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
     Py_ssize_t res;
 
@@ -2033,7 +2033,7 @@
 {
     Py_ssize_t count = -1;
     PyObject *from, *to, *res;
-    PyBuffer vfrom, vto;
+    Py_buffer vfrom, vto;
 
     if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count))
         return NULL;
@@ -2187,7 +2187,7 @@
     Py_ssize_t maxsplit = -1, count = 0;
     const char *s = PyBytes_AS_STRING(self), *sub;
     PyObject *list, *str, *subobj = Py_None;
-    PyBuffer vsub;
+    Py_buffer vsub;
 #ifdef USE_FAST
     Py_ssize_t pos;
 #endif
@@ -2396,7 +2396,7 @@
     Py_ssize_t maxsplit = -1, count = 0;
     const char *s = PyBytes_AS_STRING(self), *sub;
     PyObject *list, *str, *subobj = Py_None;
-    PyBuffer vsub;
+    Py_buffer vsub;
 
     if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
         return NULL;
@@ -2647,7 +2647,7 @@
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
     PyObject *arg = Py_None;
-    PyBuffer varg;
+    Py_buffer varg;
     if (!PyArg_ParseTuple(args, "|O:strip", &arg))
         return NULL;
     if (arg == Py_None) {
@@ -2683,7 +2683,7 @@
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
     PyObject *arg = Py_None;
-    PyBuffer varg;
+    Py_buffer varg;
     if (!PyArg_ParseTuple(args, "|O:lstrip", &arg))
         return NULL;
     if (arg == Py_None) {
@@ -2716,7 +2716,7 @@
     Py_ssize_t left, right, mysize, argsize;
     void *myptr, *argptr;
     PyObject *arg = Py_None;
-    PyBuffer varg;
+    Py_buffer varg;
     if (!PyArg_ParseTuple(args, "|O:rstrip", &arg))
         return NULL;
     if (arg == Py_None) {

Modified: python/branches/py3k-importlib/Objects/complexobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/complexobject.c	(original)
+++ python/branches/py3k-importlib/Objects/complexobject.c	Sat Sep 29 22:20:33 2007
@@ -963,7 +963,7 @@
 	0,					/* nb_and */
 	0,					/* nb_xor */
 	0,					/* nb_or */
-	(coercion)0,				/* nb_coerce */
+	0,					/* nb_reserved */
 	complex_int,				/* nb_int */
 	complex_long,				/* nb_long */
 	complex_float,				/* nb_float */

Modified: python/branches/py3k-importlib/Objects/floatobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/floatobject.c	(original)
+++ python/branches/py3k-importlib/Objects/floatobject.c	Sat Sep 29 22:20:33 2007
@@ -235,8 +235,7 @@
 }
 
 /* Macro and helper that convert PyObject obj to a C double and store
-   the value in dbl; this replaces the functionality of the coercion
-   slot function.  If conversion to double raises an exception, obj is
+   the value in dbl.  If conversion to double raises an exception, obj is
    set to NULL, and the function invoking this macro returns NULL.  If
    obj is not of float, int or long type, Py_NotImplemented is incref'ed,
    stored in obj, and returned from the function invoking this macro.
@@ -1069,7 +1068,7 @@
 	0,		/*nb_and*/
 	0,		/*nb_xor*/
 	0,		/*nb_or*/
-	(coercion)0,	/*nb_coerce*/
+	0,		/*nb_reserved*/
 	float_trunc,	/*nb_int*/
 	float_trunc,	/*nb_long*/
 	float_float,	/*nb_float*/

Modified: python/branches/py3k-importlib/Objects/longobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/longobject.c	(original)
+++ python/branches/py3k-importlib/Objects/longobject.c	Sat Sep 29 22:20:33 2007
@@ -3631,7 +3631,7 @@
 			long_and,	/*nb_and*/
 			long_xor,	/*nb_xor*/
 			long_or,	/*nb_or*/
-			0,		/*nb_coerce*/
+			0,		/*nb_reserved*/
 			long_long,	/*nb_int*/
 			long_long,	/*nb_long*/
 			long_float,	/*nb_float*/

Modified: python/branches/py3k-importlib/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/memoryobject.c	(original)
+++ python/branches/py3k-importlib/Objects/memoryobject.c	Sat Sep 29 22:20:33 2007
@@ -4,16 +4,16 @@
 #include "Python.h"
 
 static int
-memory_getbuf(PyMemoryViewObject *self, PyBuffer *view, int flags)
+memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
 {
-        if (view != NULL) 
-                memcpy(view, &(self->view), sizeof(PyBuffer));
-        return self->base->ob_type->tp_as_buffer->bf_getbuffer(self->base, 
-                                                               NULL, PyBUF_FULL);
+        if (view != NULL)
+		*view = self->view;
+        return self->base->ob_type->tp_as_buffer->bf_getbuffer(self->base, NULL,
+                                                               PyBUF_FULL);
 }
 
 static void
-memory_releasebuf(PyMemoryViewObject *self, PyBuffer *view) 
+memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view)
 {
         PyObject_ReleaseBuffer(self->base, NULL);
 }
@@ -24,11 +24,16 @@
 Create a new memoryview object which references the given object.");
 
 PyObject *
-PyMemoryView_FromMemory(PyBuffer *info)
+PyMemoryView_FromMemory(Py_buffer *info)
 {
-	/* XXX(nnorwitz): need to implement something here? */
-        PyErr_SetString(PyExc_NotImplementedError, "need to implement");
-        return NULL;
+	PyMemoryViewObject *mview;
+
+	mview = (PyMemoryViewObject *)PyObject_New(PyMemoryViewObject,
+						   &PyMemoryView_Type);
+	if (mview == NULL) return NULL;
+	mview->base = NULL;
+	mview->view = *info;
+	return (PyObject *)mview;
 }
 
 PyObject *
@@ -37,16 +42,16 @@
         PyMemoryViewObject *mview;
 
         if (!PyObject_CheckBuffer(base)) {
-                PyErr_SetString(PyExc_TypeError, 
-                                "cannot make memory view because object does "\
+                PyErr_SetString(PyExc_TypeError,
+                                "cannot make memory view because object does "
                                 "not have the buffer interface");
-                return NULL;                               
+                return NULL;
         }
-        
-        mview = (PyMemoryViewObject *)PyObject_New(PyMemoryViewObject, 
+
+        mview = (PyMemoryViewObject *)PyObject_New(PyMemoryViewObject,
                                                    &PyMemoryView_Type);
         if (mview == NULL) return NULL;
-        
+
         mview->base = NULL;
         if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL) < 0) {
                 Py_DECREF(mview);
@@ -64,12 +69,12 @@
         PyObject *obj;
         if (!PyArg_UnpackTuple(args, "memoryview", 1, 1, &obj)) return NULL;
 
-        return PyMemoryView_FromObject(obj);        
+        return PyMemoryView_FromObject(obj);
 }
 
 
 static void
-_strided_copy_nd(char *dest, char *src, int nd, Py_ssize_t *shape, 
+_strided_copy_nd(char *dest, char *src, int nd, Py_ssize_t *shape,
                  Py_ssize_t *strides, int itemsize, char fort)
 {
         int k;
@@ -87,23 +92,23 @@
         }
         else {
                 if (fort == 'F') {
-                        /* Copy first dimension first, 
+                        /* Copy first dimension first,
                            second dimension second, etc...
                            Set up the recursive loop backwards so that final
-                           dimension is actually copied last. 
+                           dimension is actually copied last.
                         */
                         outstride = itemsize;
                         for (k=1; k<nd-1;k++) {
                                 outstride *= shape[k];
                         }
                         for (k=0; k<shape[nd-1]; k++) {
-                                _strided_copy_nd(dest, src, nd-1, shape, 
+                                _strided_copy_nd(dest, src, nd-1, shape,
                                                  strides, itemsize, fort);
                                 dest += outstride;
                                 src += strides[nd-1];
                         }
                 }
-                
+
                 else {
                         /* Copy last dimension first,
                            second-to-last dimension second, etc.
@@ -116,7 +121,7 @@
                         }
                         for (k=0; k<shape[0]; k++) {
                                 _strided_copy_nd(dest, src, nd-1, shape+1,
-                                                 strides+1, itemsize, 
+                                                 strides+1, itemsize,
                                                  fort);
                                 dest += outstride;
                                 src += strides[0];
@@ -130,15 +135,15 @@
 void _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape);
 
 static int
-_indirect_copy_nd(char *dest, PyBuffer *view, char fort)
+_indirect_copy_nd(char *dest, Py_buffer *view, char fort)
 {
         Py_ssize_t *indices;
         int k;
         Py_ssize_t elements;
         char *ptr;
         void (*func)(int, Py_ssize_t *, Py_ssize_t *);
-        
-        
+
+
         /* XXX(nnorwitz): need to check for overflow! */
         indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*view->ndim);
         if (indices == NULL) {
@@ -148,7 +153,7 @@
         for (k=0; k<view->ndim;k++) {
                 indices[k] = 0;
         }
-        
+
         elements = 1;
         for (k=0; k<view->ndim; k++) {
                 elements *= view->shape[k];
@@ -165,26 +170,26 @@
                 memcpy(dest, ptr, view->itemsize);
                 dest += view->itemsize;
         }
-                
+
         PyMem_Free(indices);
         return 0;
 }
 
-/* 
+/*
    Get a the data from an object as a contiguous chunk of memory (in
    either 'C' or 'F'ortran order) even if it means copying it into a
    separate memory area.
 
    Returns a new reference to a Memory view object.  If no copy is needed,
-   the memory view object points to the original memory and holds a 
+   the memory view object points to the original memory and holds a
    lock on the original.  If a copy is needed, then the memory view object
-   points to a brand-new Bytes object (and holds a memory lock on it). 
+   points to a brand-new Bytes object (and holds a memory lock on it).
 
    buffertype
 
    PyBUF_READ  buffer only needs to be read-only
    PyBUF_WRITE buffer needs to be writable (give error if not contiguous)
-   PyBUF_SHADOW buffer needs to be writable so shadow it with 
+   PyBUF_SHADOW buffer needs to be writable so shadow it with
                 a contiguous buffer if it is not. The view will point to
                 the shadow buffer which can be written to and then
                 will be copied back into the other buffer when the memory
@@ -196,7 +201,7 @@
 {
         PyMemoryViewObject *mem;
         PyObject *bytes;
-        PyBuffer *view;
+        Py_buffer *view;
         int flags;
         char *dest;
 
@@ -205,7 +210,7 @@
                                 "object does not have the buffer interface");
                 return NULL;
         }
-        
+
         mem = PyObject_New(PyMemoryViewObject, &PyMemoryView_Type);
         if (mem == NULL) return NULL;
 
@@ -235,8 +240,8 @@
         if (buffertype == PyBUF_WRITE) {
                 PyObject_DEL(mem);
                 PyErr_SetString(PyExc_BufferError,
-                                "writable contiguous buffer requested for a non-contiguous" \
-                                "object.");
+                                "writable contiguous buffer requested "
+                                "for a non-contiguousobject.");
                 return NULL;
         }
         bytes = PyBytes_FromStringAndSize(NULL, view->len);
@@ -250,22 +255,25 @@
         */
         /* strided or in-direct copy */
         if (view->suboffsets==NULL) {
-                _strided_copy_nd(dest, view->buf, view->ndim, view->shape, 
-                                 view->strides, view->itemsize, fort); 
+                _strided_copy_nd(dest, view->buf, view->ndim, view->shape,
+                                 view->strides, view->itemsize, fort);
         }
         else {
                 if (_indirect_copy_nd(dest, view, fort) < 0) {
                         Py_DECREF(bytes);
                         PyObject_ReleaseBuffer(obj, view);
                         return NULL;
-                }                 
+                }
         }
         if (buffertype == PyBUF_SHADOW) {
                 /* return a shadowed memory-view object */
                 view->buf = dest;
                 mem->base = PyTuple_Pack(2, obj, bytes);
-		/* XXX(nnorwitz): need to verify alloc was successful. */
                 Py_DECREF(bytes);
+		if (mem->base == NULL) {
+			PyObject_ReleaseBuffer(obj, view);
+			return NULL;
+		}
         }
         else {
                 PyObject_ReleaseBuffer(obj, view);
@@ -348,7 +356,7 @@
         return PyInt_FromLong(self->view.ndim);
 }
 
-static PyGetSetDef memory_getsetlist[] ={ 
+static PyGetSetDef memory_getsetlist[] ={
         {"format",	(getter)memory_format_get,	NULL, NULL},
         {"itemsize",	(getter)memory_itemsize_get,	NULL, NULL},
         {"shape",	(getter)memory_shape_get,	NULL, NULL},
@@ -364,13 +372,15 @@
 static PyObject *
 memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs)
 {
-        /* Create new Bytes object for data */
         return PyBytes_FromObject((PyObject *)mem);
 }
 
 static PyObject *
 memory_tolist(PyMemoryViewObject *mem, PyObject *noargs)
 {
+	/* This should construct a (nested) list of unpacked objects
+	   possibly using the struct module.
+	 */
         Py_INCREF(Py_NotImplemented);
         return Py_NotImplemented;
 }
@@ -393,16 +403,16 @@
                    with buffer interface and the second element is a
                    contiguous "shadow" that must be copied back into
                    the data areay of the first tuple element before
-                   releasing the buffer on the first element.  
+                   releasing the buffer on the first element.
                 */
-                
+
                 PyObject_CopyData(PyTuple_GET_ITEM(self->base,0),
                                   PyTuple_GET_ITEM(self->base,1));
 
                 /* The view member should have readonly == -1 in
                    this instance indicating that the memory can
                    be "locked" and was locked and will be unlocked
-                   again after this call. 
+                   again after this call.
                 */
                 PyObject_ReleaseBuffer(PyTuple_GET_ITEM(self->base,0),
                                        &(self->view));
@@ -429,12 +439,12 @@
 static PyObject *
 memory_str(PyMemoryViewObject *self)
 {
-        PyBuffer view;
+        Py_buffer view;
         PyObject *res;
 
         if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
                 return NULL;
-        
+
 	res = PyBytes_FromStringAndSize(NULL, view.len);
         PyBuffer_ToContiguous(PyBytes_AS_STRING(res), &view, view.len, 'C');
         PyObject_ReleaseBuffer((PyObject *)self, &view);
@@ -446,7 +456,7 @@
 static Py_ssize_t
 memory_length(PyMemoryViewObject *self)
 {
-        PyBuffer view;
+        Py_buffer view;
 
         if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
                 return -1;
@@ -454,9 +464,61 @@
 	return view.len;
 }
 
+/*
+  mem[obj] returns a bytes object holding the data for one element if
+           obj fully indexes the memory view or another memory-view object
+	   if it does not.
+
+	   0-d memory-view objects can be referenced using ... or () but
+	   not with anything else.
+ */
 static PyObject *
 memory_subscript(PyMemoryViewObject *self, PyObject *key)
 {
+	Py_buffer *view;
+	view = &(self->view);
+
+	if (view->ndim == 0) {
+		if (key == Py_Ellipsis ||
+		    (PyTuple_Check(key) && PyTuple_GET_SIZE(key)==0)) {
+			Py_INCREF(self);
+			return (PyObject *)self;
+		}
+		else {
+			PyErr_SetString(PyExc_IndexError,
+                                        "invalid indexing of 0-dim memory");
+			return NULL;
+		}
+	}
+	if (PyIndex_Check(key)) {
+		Py_ssize_t result;
+		result = PyNumber_AsSsize_t(key, NULL);
+		if (result == -1 && PyErr_Occurred())
+			return NULL;
+		if (view->ndim == 1) {
+			/* Return a bytes object */
+			char *ptr;
+			ptr = (char *)view->buf;
+			if (view->strides == NULL)
+				ptr += view->itemsize * result;
+			else
+				ptr += view->strides[0] * result;
+			if (view->suboffsets != NULL &&
+                            view->suboffsets[0] >= 0)
+                        {
+				ptr = *((char **)ptr) + view->suboffsets[0];
+			}
+			return PyBytes_FromStringAndSize(ptr, view->itemsize);
+		}
+		else {
+			/* Return a new memory-view object */
+			Py_buffer newview;
+			PyMemoryView_FromMemory(&newview);
+		}
+	}
+
+
+
         Py_INCREF(Py_NotImplemented);
         return Py_NotImplemented;
 }
@@ -511,7 +573,7 @@
 	0,					/* tp_weaklistoffset */
 	0,					/* tp_iter */
 	0,					/* tp_iternext */
-	memory_methods,	   		        /* tp_methods */	
+	memory_methods,	   		        /* tp_methods */
 	0,	      		                /* tp_members */
 	memory_getsetlist,  		        /* tp_getset */
 	0,					/* tp_base */

Modified: python/branches/py3k-importlib/Objects/setobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/setobject.c	(original)
+++ python/branches/py3k-importlib/Objects/setobject.c	Sat Sep 29 22:20:33 2007
@@ -1881,7 +1881,7 @@
 	(binaryfunc)set_and,		/*nb_and*/
 	(binaryfunc)set_xor,		/*nb_xor*/
 	(binaryfunc)set_or,		/*nb_or*/
-	0,				/*nb_coerce*/
+	0,				/*nb_reserved*/
 	0,				/*nb_int*/
 	0,				/*nb_long*/
 	0,				/*nb_float*/

Modified: python/branches/py3k-importlib/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/stringobject.c	(original)
+++ python/branches/py3k-importlib/Objects/stringobject.c	Sat Sep 29 22:20:33 2007
@@ -1160,7 +1160,7 @@
 }
 
 static int
-string_buffer_getbuffer(PyStringObject *self, PyBuffer *view, int flags)
+string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
 {
         return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self), 0, flags);
 }

Modified: python/branches/py3k-importlib/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/unicodeobject.c	Sat Sep 29 22:20:33 2007
@@ -5412,14 +5412,20 @@
 
 	item = PySequence_Fast_GET_ITEM(fseq, i);
 	/* Convert item to Unicode. */
-	if (! PyUnicode_Check(item) && ! PyString_Check(item)) {
-	    PyErr_Format(PyExc_TypeError,
-			 "sequence item %zd: expected string or Unicode,"
-			 " %.80s found",
-			 i, Py_Type(item)->tp_name);
-	    goto onError;
+	if (!PyString_Check(item) && !PyUnicode_Check(item))
+	{
+		if (PyBytes_Check(item))
+		{
+			PyErr_Format(PyExc_TypeError,
+                            "sequence item %d: join() will not operate on "
+                            "bytes objects", i);
+			goto onError;
+		}
+		item = PyObject_Unicode(item);
 	}
-	item = PyUnicode_FromObject(item);
+	else
+		item = PyUnicode_FromObject(item);
+
 	if (item == NULL)
 	    goto onError;
 	/* We own a reference to item from here on. */
@@ -8104,7 +8110,7 @@
 
 
 static int
-unicode_buffer_getbuffer(PyUnicodeObject *self, PyBuffer *view, int flags)
+unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
 {
 
     if (flags & PyBUF_CHARACTER) {

Modified: python/branches/py3k-importlib/Objects/weakrefobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/weakrefobject.c	(original)
+++ python/branches/py3k-importlib/Objects/weakrefobject.c	Sat Sep 29 22:20:33 2007
@@ -589,7 +589,7 @@
     proxy_and,              /*nb_and*/
     proxy_xor,              /*nb_xor*/
     proxy_or,               /*nb_or*/
-    0,                      /*nb_coerce*/
+    0,                      /*nb_reserved*/
     proxy_int,              /*nb_int*/
     proxy_long,             /*nb_long*/
     proxy_float,            /*nb_float*/

Modified: python/branches/py3k-importlib/PC/_winreg.c
==============================================================================
--- python/branches/py3k-importlib/PC/_winreg.c	(original)
+++ python/branches/py3k-importlib/PC/_winreg.c	Sat Sep 29 22:20:33 2007
@@ -430,7 +430,7 @@
 	PyHKEY_binaryFailureFunc,	/* nb_and */
 	PyHKEY_binaryFailureFunc,	/* nb_xor */
 	PyHKEY_binaryFailureFunc,	/* nb_or */
-	NULL,				/* nb_coerce */
+	0,				/* nb_reserved */
 	PyHKEY_intFunc,			/* nb_int */
 	PyHKEY_unaryFailureFunc,	/* nb_long */
 	PyHKEY_unaryFailureFunc,	/* nb_float */
@@ -773,7 +773,7 @@
 			if (value == Py_None)
 				*retDataSize = 0;
 			else {
-				PyBuffer view;
+				Py_buffer view;
 
 				if (!PyObject_CheckBuffer(value)) {
 					PyErr_Format(PyExc_TypeError,

Modified: python/branches/py3k-importlib/Parser/tokenizer.c
==============================================================================
--- python/branches/py3k-importlib/Parser/tokenizer.c	(original)
+++ python/branches/py3k-importlib/Parser/tokenizer.c	Sat Sep 29 22:20:33 2007
@@ -139,7 +139,7 @@
 	tok->alterror = 1;
 	tok->alttabsize = 1;
 	tok->altindstack[0] = 0;
-	tok->decoding_state = 0;
+	tok->decoding_state = STATE_INIT;
 	tok->decoding_erred = 0;
 	tok->read_coding_spec = 0;
 	tok->encoding = NULL;
@@ -280,7 +280,7 @@
 	if (cs != NULL) {
 		tok->read_coding_spec = 1;
 		if (tok->encoding == NULL) {
-			assert(tok->decoding_state == 1); /* raw */
+			assert(tok->decoding_state == STATE_RAW);
 			if (strcmp(cs, "utf-8") == 0 ||
 			    strcmp(cs, "iso-8859-1") == 0) {
 				tok->encoding = cs;
@@ -288,7 +288,7 @@
 				r = set_readline(tok, cs);
 				if (r) {
 					tok->encoding = cs;
-					tok->decoding_state = -1;
+					tok->decoding_state = STATE_NORMAL;
 				}
 				else
 					PyMem_FREE(cs);
@@ -318,7 +318,7 @@
 	  struct tok_state *tok)
 {
 	int ch = get_char(tok);
-	tok->decoding_state = 1;
+	tok->decoding_state = STATE_RAW;
 	if (ch == EOF) {
 		return 1;
 	} else if (ch == 0xEF) {
@@ -330,11 +330,11 @@
 	} else if (ch == 0xFE) {
 		ch = get_char(tok); if (ch != 0xFF) goto NON_BOM;
 		if (!set_readline(tok, "utf-16-be")) return 0;
-		tok->decoding_state = -1;
+		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;
-		tok->decoding_state = -1;
+		tok->decoding_state = STATE_NORMAL;
 #endif
 	} else {
 		unget_char(ch, tok);
@@ -494,12 +494,12 @@
 	char *line = NULL;
 	int badchar = 0;
 	for (;;) {
-		if (tok->decoding_state < 0) {
+		if (tok->decoding_state == STATE_NORMAL) {
 			/* We already have a codec associated with
 			   this input. */
 			line = fp_readl(s, size, tok);
 			break;
-		} else if (tok->decoding_state > 0) {
+		} else if (tok->decoding_state == STATE_RAW) {
 			/* We want a 'raw' read. */
 			line = Py_UniversalNewlineFgets(s, size,
 							tok->fp, NULL);
@@ -510,7 +510,7 @@
 			   reader functions from now on. */
 			if (!check_bom(fp_getc, fp_ungetc, fp_setreadl, tok))
 				return error_ret(tok);
-			assert(tok->decoding_state != 0);
+			assert(tok->decoding_state != STATE_INIT);
 		}
 	}
 	if (line != NULL && tok->lineno < 2 && !tok->read_coding_spec) {
@@ -550,7 +550,7 @@
 static int
 decoding_feof(struct tok_state *tok)
 {
-	if (tok->decoding_state >= 0) {
+	if (tok->decoding_state != STATE_NORMAL) {
 		return feof(tok->fp);
 	} else {
 		PyObject* buf = tok->decoding_buffer;
@@ -700,7 +700,7 @@
 			return NULL;
 		}
 		strcpy(tok->encoding, enc);
-		tok->decoding_state = -1;
+		tok->decoding_state = STATE_NORMAL;
 	}
 	return tok;
 }

Modified: python/branches/py3k-importlib/Parser/tokenizer.h
==============================================================================
--- python/branches/py3k-importlib/Parser/tokenizer.h	(original)
+++ python/branches/py3k-importlib/Parser/tokenizer.h	Sat Sep 29 22:20:33 2007
@@ -12,6 +12,12 @@
 
 #define MAXINDENT 100	/* Max indentation level */
 
+enum decoding_state {
+	STATE_INIT,
+	STATE_RAW,
+	STATE_NORMAL, /* have a codec associated with input */
+};
+
 /* Tokenizer state */
 struct tok_state {
 	/* Input state; buf <= cur <= inp <= end */
@@ -40,7 +46,7 @@
 	int alttabsize;	/* Alternate tab spacing */
 	int altindstack[MAXINDENT];	/* Stack of alternate indents */
 	/* Stuff for PEP 0263 */
-	int decoding_state;	/* -1:decoding, 0:init, 1:raw */
+	enum decoding_state decoding_state;
 	int decoding_erred;	/* whether erred in decoding  */
 	int read_coding_spec;	/* whether 'coding:...' has been read  */
 	char *encoding;

Modified: python/branches/py3k-importlib/Python/getargs.c
==============================================================================
--- python/branches/py3k-importlib/Python/getargs.c	(original)
+++ python/branches/py3k-importlib/Python/getargs.c	Sat Sep 29 22:20:33 2007
@@ -1211,7 +1211,7 @@
 		PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
 		int count;
                 int temp=-1;
-                PyBuffer view;
+                Py_buffer view;
 			
 		if (pb == NULL || 
 		    pb->bf_getbuffer == NULL ||
@@ -1242,7 +1242,7 @@
 		char **p = va_arg(*p_va, char **);
 		PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
 		int count;
-                PyBuffer view;
+                Py_buffer view;
 		
 		if (*format++ != '#')
 			return converterr(
@@ -1286,7 +1286,7 @@
 {
 	PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
 	Py_ssize_t count;
-        PyBuffer view;
+        Py_buffer view;
 
         *errmsg = NULL;
         *p = NULL;

Modified: python/branches/py3k-importlib/Python/marshal.c
==============================================================================
--- python/branches/py3k-importlib/Python/marshal.c	(original)
+++ python/branches/py3k-importlib/Python/marshal.c	Sat Sep 29 22:20:33 2007
@@ -367,7 +367,7 @@
 		/* Write unknown buffer-style objects as a string */
 		char *s;
 		PyBufferProcs *pb = v->ob_type->tp_as_buffer;
-                PyBuffer view;
+                Py_buffer view;
 		if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
                         w_byte(TYPE_UNKNOWN, p);
                         p->error = 1;

Modified: python/branches/py3k-importlib/Tools/modulator/Templates/object_tp_as_number
==============================================================================
--- python/branches/py3k-importlib/Tools/modulator/Templates/object_tp_as_number	(original)
+++ python/branches/py3k-importlib/Tools/modulator/Templates/object_tp_as_number	Sat Sep 29 22:20:33 2007
@@ -103,13 +103,6 @@
 	/* XXXX */
 }
 
-static int
-$abbrev$_coerce(PyObject **pv, PyObject **pw)
-{
-	/* XXXX I haven't a clue... */
-	return 1;
-}
-
 static PyObject *
 $abbrev$_int($abbrev$object *v)
 {

Modified: python/branches/py3k-importlib/Tools/scripts/byext.py
==============================================================================
--- python/branches/py3k-importlib/Tools/scripts/byext.py	(original)
+++ python/branches/py3k-importlib/Tools/scripts/byext.py	Sat Sep 29 22:20:33 2007
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3.0
 
 """Show file statistics by extension."""
 
@@ -60,13 +60,13 @@
         data = f.read()
         f.close()
         self.addstats(ext, "bytes", len(data))
-        if '\0' in data:
+        if b'\0' in data:
             self.addstats(ext, "binary", 1)
             return
         if not data:
             self.addstats(ext, "empty", 1)
         #self.addstats(ext, "chars", len(data))
-        lines = data.splitlines()
+        lines = str(data, "latin-1").splitlines()
         self.addstats(ext, "lines", len(lines))
         del lines
         words = data.split()
@@ -77,14 +77,12 @@
         d[key] = d.get(key, 0) + n
 
     def report(self):
-        exts = self.stats.keys()
-        exts.sort()
+        exts = sorted(self.stats)
         # Get the column keys
         columns = {}
         for ext in exts:
             columns.update(self.stats[ext])
-        cols = columns.keys()
-        cols.sort()
+        cols = sorted(columns)
         colwidth = {}
         colwidth["ext"] = max([len(ext) for ext in exts])
         minwidth = 6


More information about the Python-3000-checkins mailing list