[Python-3000-checkins] r58416 - in python/branches/py3k-importlib: Doc/library/debug.rst Doc/library/functions.rst Doc/library/hotshot.rst Doc/library/profile.rst Doc/tutorial/datastructures.rst Include/Python.h Include/bufferobject.h Lib/_abcoll.py Lib/ctypes/test/test_array_in_pointer.py Lib/ctypes/test/test_byteswap.py Lib/ctypes/test/test_strings.py Lib/ftplib.py Lib/hotshot Lib/idlelib/IOBinding.py Lib/idlelib/NEWS.txt Lib/pickle.py Lib/sqlite3/dbapi2.py Lib/sqlite3/test/dbapi.py Lib/sqlite3/test/types.py Lib/sqlite3/test/userfunctions.py Lib/subprocess.py Lib/test/test_array.py Lib/test/test_buffer.py Lib/test/test_bytes.py Lib/test/test_hotshot.py Lib/test/test_io.py Lib/test/test_marshal.py Lib/test/test_multibytecodec_support.py Lib/test/test_repr.py Lib/test/test_socket_ssl.py Lib/test/test_struct.py Lib/test/test_types.py Lib/test/test_unicode.py Lib/test/test_xml_etree.py Lib/test/test_xml_etree_c.py Lib/types.py Makefile.pre.in Misc/NEWS Modules/_ctypes/_ctypes.c Modules/_hotshot.c Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sqlite/statement.c Objects/bufferobject.c Objects/bytesobject.c Objects/fileobject.c Objects/memoryobject.c Objects/stringobject.c Objects/unicodeobject.c PC/VC6/pythoncore.dsp PC/config.c PC/os2emx/Makefile PC/os2emx/python25.def PCbuild/python.iss PCbuild/python20.wse PCbuild/pythoncore.vcproj PCbuild8/pythoncore/pythoncore.vcproj Parser/tokenizer.c Python/errors.c Python/pythonrun.c Tools/scripts/hotshotmain.py Tools/scripts/make_ctype.py setup.py

brett.cannon python-3000-checkins at python.org
Thu Oct 11 23:44:16 CEST 2007


Author: brett.cannon
Date: Thu Oct 11 23:44:13 2007
New Revision: 58416

Added:
   python/branches/py3k-importlib/Tools/scripts/make_ctype.py
      - copied unchanged from r58414, python/branches/py3k/Tools/scripts/make_ctype.py
Removed:
   python/branches/py3k-importlib/Doc/library/hotshot.rst
   python/branches/py3k-importlib/Include/bufferobject.h
   python/branches/py3k-importlib/Lib/hotshot/
   python/branches/py3k-importlib/Lib/test/test_buffer.py
   python/branches/py3k-importlib/Lib/test/test_hotshot.py
   python/branches/py3k-importlib/Modules/_hotshot.c
   python/branches/py3k-importlib/Objects/bufferobject.c
   python/branches/py3k-importlib/Tools/scripts/hotshotmain.py
Modified:
   python/branches/py3k-importlib/   (props changed)
   python/branches/py3k-importlib/Doc/library/debug.rst
   python/branches/py3k-importlib/Doc/library/functions.rst
   python/branches/py3k-importlib/Doc/library/profile.rst
   python/branches/py3k-importlib/Doc/tutorial/datastructures.rst
   python/branches/py3k-importlib/Include/Python.h
   python/branches/py3k-importlib/Lib/_abcoll.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py
   python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py
   python/branches/py3k-importlib/Lib/ftplib.py
   python/branches/py3k-importlib/Lib/idlelib/IOBinding.py
   python/branches/py3k-importlib/Lib/idlelib/NEWS.txt
   python/branches/py3k-importlib/Lib/pickle.py
   python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py
   python/branches/py3k-importlib/Lib/sqlite3/test/dbapi.py
   python/branches/py3k-importlib/Lib/sqlite3/test/types.py
   python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py
   python/branches/py3k-importlib/Lib/subprocess.py
   python/branches/py3k-importlib/Lib/test/test_array.py
   python/branches/py3k-importlib/Lib/test/test_bytes.py
   python/branches/py3k-importlib/Lib/test/test_io.py
   python/branches/py3k-importlib/Lib/test/test_marshal.py
   python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py
   python/branches/py3k-importlib/Lib/test/test_repr.py
   python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
   python/branches/py3k-importlib/Lib/test/test_struct.py
   python/branches/py3k-importlib/Lib/test/test_types.py
   python/branches/py3k-importlib/Lib/test/test_unicode.py
   python/branches/py3k-importlib/Lib/test/test_xml_etree.py
   python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py
   python/branches/py3k-importlib/Lib/types.py
   python/branches/py3k-importlib/Makefile.pre.in
   python/branches/py3k-importlib/Misc/NEWS
   python/branches/py3k-importlib/Modules/_ctypes/_ctypes.c
   python/branches/py3k-importlib/Modules/_sqlite/connection.c
   python/branches/py3k-importlib/Modules/_sqlite/cursor.c
   python/branches/py3k-importlib/Modules/_sqlite/statement.c
   python/branches/py3k-importlib/Objects/bytesobject.c
   python/branches/py3k-importlib/Objects/fileobject.c
   python/branches/py3k-importlib/Objects/memoryobject.c
   python/branches/py3k-importlib/Objects/stringobject.c
   python/branches/py3k-importlib/Objects/unicodeobject.c
   python/branches/py3k-importlib/PC/VC6/pythoncore.dsp
   python/branches/py3k-importlib/PC/config.c
   python/branches/py3k-importlib/PC/os2emx/Makefile
   python/branches/py3k-importlib/PC/os2emx/python25.def
   python/branches/py3k-importlib/PCbuild/python.iss
   python/branches/py3k-importlib/PCbuild/python20.wse
   python/branches/py3k-importlib/PCbuild/pythoncore.vcproj
   python/branches/py3k-importlib/PCbuild8/pythoncore/pythoncore.vcproj
   python/branches/py3k-importlib/Parser/tokenizer.c
   python/branches/py3k-importlib/Python/errors.c
   python/branches/py3k-importlib/Python/pythonrun.c
   python/branches/py3k-importlib/setup.py
Log:
Merged revisions 58355-58415 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k



Modified: python/branches/py3k-importlib/Doc/library/debug.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/debug.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/debug.rst	Thu Oct 11 23:44:13 2007
@@ -12,6 +12,5 @@
    bdb.rst
    pdb.rst
    profile.rst
-   hotshot.rst
    timeit.rst
    trace.rst
\ No newline at end of file

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	Thu Oct 11 23:44:13 2007
@@ -1079,34 +1079,6 @@
    returns an empty iterator.
 
 
-.. % ---------------------------------------------------------------------------
-
-
-.. _non-essential-built-in-funcs:
-
-Non-essential Built-in Functions
-================================
-
-There are several built-in functions that are no longer essential to learn, know
-or use in modern Python programming.  They have been kept here to maintain
-backwards compatibility with programs written for older versions of Python.
-
-Python programmers, trainers, students and bookwriters should feel free to
-bypass these functions without concerns about missing something important.
-
-
-.. XXX does this go away?
-.. function:: buffer(object[, offset[, size]])
-
-   The *object* argument must be an object that supports the buffer call interface
-   (such as strings, arrays, and buffers).  A new buffer object will be created
-   which references the *object* argument. The buffer object will be a slice from
-   the beginning of *object* (or from the specified *offset*). The slice will
-   extend to the end of *object* (or will have a length given by the *size*
-   argument).
-
-
-
 .. rubric:: Footnotes
 
 .. [#] Specifying a buffer size currently has no effect on systems that don't have

Deleted: /python/branches/py3k-importlib/Doc/library/hotshot.rst
==============================================================================
--- /python/branches/py3k-importlib/Doc/library/hotshot.rst	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,144 +0,0 @@
-
-:mod:`hotshot` --- High performance logging profiler
-====================================================
-
-.. module:: hotshot
-   :synopsis: High performance logging profiler, mostly written in C.
-.. moduleauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-.. sectionauthor:: Anthony Baxter <anthony at interlink.com.au>
-
-
-This module provides a nicer interface to the :mod:`_hotshot` C module. Hotshot
-is a replacement for the existing :mod:`profile` module. As it's written mostly
-in C, it should result in a much smaller performance impact than the existing
-:mod:`profile` module.
-
-.. note::
-
-   The :mod:`hotshot` module focuses on minimizing the overhead while profiling, at
-   the expense of long data post-processing times. For common usages it is
-   recommended to use :mod:`cProfile` instead. :mod:`hotshot` is not maintained and
-   might be removed from the standard library in the future.
-
-.. warning::
-
-   The :mod:`hotshot` profiler does not yet work well with threads. It is useful to
-   use an unthreaded script to run the profiler over the code you're interested in
-   measuring if at all possible.
-
-
-.. class:: Profile(logfile[, lineevents[, linetimings]])
-
-   The profiler object. The argument *logfile* is the name of a log file to use for
-   logged profile data. The argument *lineevents* specifies whether to generate
-   events for every source line, or just on function call/return. It defaults to
-   ``0`` (only log function call/return). The argument *linetimings* specifies
-   whether to record timing information. It defaults to ``1`` (store timing
-   information).
-
-
-.. _hotshot-objects:
-
-Profile Objects
----------------
-
-Profile objects have the following methods:
-
-
-.. method:: Profile.addinfo(key, value)
-
-   Add an arbitrary labelled value to the profile output.
-
-
-.. method:: Profile.close()
-
-   Close the logfile and terminate the profiler.
-
-
-.. method:: Profile.fileno()
-
-   Return the file descriptor of the profiler's log file.
-
-
-.. method:: Profile.run(cmd)
-
-   Profile an :func:`exec`\ -compatible string in the script environment. The
-   globals from the :mod:`__main__` module are used as both the globals and locals
-   for the script.
-
-
-.. method:: Profile.runcall(func, *args, **keywords)
-
-   Profile a single call of a callable. Additional positional and keyword arguments
-   may be passed along; the result of the call is returned, and exceptions are
-   allowed to propagate cleanly, while ensuring that profiling is disabled on the
-   way out.
-
-
-.. method:: Profile.runctx(cmd, globals, locals)
-
-   Profile an :func:`exec`\ -compatible string in a specific environment. The
-   string is compiled before profiling begins.
-
-
-.. method:: Profile.start()
-
-   Start the profiler.
-
-
-.. method:: Profile.stop()
-
-   Stop the profiler.
-
-
-Using hotshot data
-------------------
-
-.. module:: hotshot.stats
-   :synopsis: Statistical analysis for Hotshot
-
-
-This module loads hotshot profiling data into the standard :mod:`pstats` Stats
-objects.
-
-
-.. function:: load(filename)
-
-   Load hotshot data from *filename*. Returns an instance of the
-   :class:`pstats.Stats` class.
-
-
-.. seealso::
-
-   Module :mod:`profile`
-      The :mod:`profile` module's :class:`Stats` class
-
-
-.. _hotshot-example:
-
-Example Usage
--------------
-
-Note that this example runs the python "benchmark" pystones.  It can take some
-time to run, and will produce large output files. ::
-
-   >>> import hotshot, hotshot.stats, test.pystone
-   >>> prof = hotshot.Profile("stones.prof")
-   >>> benchtime, stones = prof.runcall(test.pystone.pystones)
-   >>> prof.close()
-   >>> stats = hotshot.stats.load("stones.prof")
-   >>> stats.strip_dirs()
-   >>> stats.sort_stats('time', 'calls')
-   >>> stats.print_stats(20)
-            850004 function calls in 10.090 CPU seconds
-
-      Ordered by: internal time, call count
-
-      ncalls  tottime  percall  cumtime  percall filename:lineno(function)
-           1    3.295    3.295   10.090   10.090 pystone.py:79(Proc0)
-      150000    1.315    0.000    1.315    0.000 pystone.py:203(Proc7)
-       50000    1.313    0.000    1.463    0.000 pystone.py:229(Func2)
-    .
-    .
-    .
-

Modified: python/branches/py3k-importlib/Doc/library/profile.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/profile.rst	(original)
+++ python/branches/py3k-importlib/Doc/library/profile.rst	Thu Oct 11 23:44:13 2007
@@ -57,7 +57,7 @@
 It also provides a series of report generation tools to allow users to rapidly
 examine the results of a profile operation.
 
-The Python standard library provides three different profilers:
+The Python standard library provides two different profilers:
 
 #. :mod:`profile`, a pure Python module, described in the sequel. Copyright ©
    1994, by InfoSeek Corporation.
@@ -66,15 +66,11 @@
    it suitable for profiling long-running programs. Based on :mod:`lsprof`,
    contributed by Brett Rosen and Ted Czotter.
 
-#. :mod:`hotshot`, a C module focusing on minimizing the overhead while
-   profiling, at the expense of long data post-processing times.
-
 The :mod:`profile` and :mod:`cProfile` modules export the same interface, so
 they are mostly interchangeables; :mod:`cProfile` has a much lower overhead but
 is not so far as well-tested and might not be available on all systems.
 :mod:`cProfile` is really a compatibility layer on top of the internal
-:mod:`_lsprof` module.  The :mod:`hotshot` module is reserved to specialized
-usages.
+:mod:`_lsprof` module.
 
 .. % \section{How Is This Profiler Different From The Old Profiler?}
 .. % \nodename{Profiler Changes}

Modified: python/branches/py3k-importlib/Doc/tutorial/datastructures.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/datastructures.rst	(original)
+++ python/branches/py3k-importlib/Doc/tutorial/datastructures.rst	Thu Oct 11 23:44:13 2007
@@ -560,15 +560,8 @@
    (1, 2, 3)             == (1.0, 2.0, 3.0)
    (1, 2, ('aa', 'ab'))   < (1, 2, ('abc', 'a'), 4)
 
-Note that comparing objects of different types is legal.  The outcome is
-deterministic but arbitrary: the types are ordered by their name. Thus, a list
-is always smaller than a string, a string is always smaller than a tuple, etc.
-[#]_ Mixed numeric types are compared according to their numeric value, so 0
-equals 0.0, etc.
-
-
-.. rubric:: Footnotes
-
-.. [#] The rules for comparing objects of different types should not be relied upon;
-   they may change in a future version of the language.
-
+Note that comparing objects of different types with ``<`` or ``>`` is legal
+provided that the objects have appropriate comparison methods.  For example,
+mixed numeric types are compared according to their numeric value, so 0 equals
+0.0, etc.  Otherwise, rather than providing an arbitrary ordering, the
+interpreter will raise a :exc:`TypeError` exception.

Modified: python/branches/py3k-importlib/Include/Python.h
==============================================================================
--- python/branches/py3k-importlib/Include/Python.h	(original)
+++ python/branches/py3k-importlib/Include/Python.h	Thu Oct 11 23:44:13 2007
@@ -76,7 +76,6 @@
 #endif
 #include "rangeobject.h"
 #include "stringobject.h"
-#include "bufferobject.h"
 #include "memoryobject.h"
 #include "tupleobject.h"
 #include "listobject.h"

Deleted: /python/branches/py3k-importlib/Include/bufferobject.h
==============================================================================
--- /python/branches/py3k-importlib/Include/bufferobject.h	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,33 +0,0 @@
-
-/* Buffer object interface */
-
-/* Note: the object's structure is private */
-
-#ifndef Py_BUFFEROBJECT_H
-#define Py_BUFFEROBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-PyAPI_DATA(PyTypeObject) PyBuffer_Type;
-
-#define PyBuffer_Check(op) (Py_Type(op) == &PyBuffer_Type)
-
-#define Py_END_OF_BUFFER	(-1)
-
-PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,
-                                           Py_ssize_t offset, Py_ssize_t size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,
-                                                    Py_ssize_t offset,
-                                                    Py_ssize_t size);
-
-PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
-
-PyAPI_FUNC(PyObject *) PyBuffer_New(Py_ssize_t size);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_BUFFEROBJECT_H */

Modified: python/branches/py3k-importlib/Lib/_abcoll.py
==============================================================================
--- python/branches/py3k-importlib/Lib/_abcoll.py	(original)
+++ python/branches/py3k-importlib/Lib/_abcoll.py	Thu Oct 11 23:44:13 2007
@@ -491,7 +491,7 @@
 
 Sequence.register(tuple)
 Sequence.register(basestring)
-Sequence.register(buffer)
+Sequence.register(memoryview)
 
 
 class MutableSequence(Sequence):

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_array_in_pointer.py	Thu Oct 11 23:44:13 2007
@@ -6,7 +6,7 @@
 def dump(obj):
     # helper function to dump memory contents in hex, with a hyphen
     # between the bytes.
-    h = str(hexlify(buffer(obj)))
+    h = str(hexlify(memoryview(obj)))
     return re.sub(r"(..)", r"\1-", h)[:-1]
 
 

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_byteswap.py	Thu Oct 11 23:44:13 2007
@@ -4,7 +4,7 @@
 from ctypes import *
 
 def bin(s):
-    return str(hexlify(buffer(s))).upper()
+    return str(hexlify(memoryview(s))).upper()
 
 # Each *simple* type that supports different byte orders has an
 # __ctype_be__ attribute that specifies the same type in BIG ENDIAN

Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py	(original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_strings.py	Thu Oct 11 23:44:13 2007
@@ -30,17 +30,17 @@
         buf.value = "Hello, World"
         self.failUnlessEqual(buf.value, "Hello, World")
 
-        self.failUnlessRaises(TypeError, setattr, buf, "value", buffer("Hello, World"))
-        self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
-        self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
+        self.failUnlessRaises(TypeError, setattr, buf, "value", memoryview(b"Hello, World"))
+        self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
+        self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
 
     def test_c_buffer_raw(self):
         buf = c_buffer(32)
 
-        buf.raw = buffer(b"Hello, World")
+        buf.raw = memoryview(b"Hello, World")
         self.failUnlessEqual(buf.value, "Hello, World")
-        self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
-        self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
+        self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
+        self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
 
     def test_param_1(self):
         BUF = c_char * 4

Modified: python/branches/py3k-importlib/Lib/ftplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ftplib.py	(original)
+++ python/branches/py3k-importlib/Lib/ftplib.py	Thu Oct 11 23:44:13 2007
@@ -103,7 +103,7 @@
     file = None
     welcome = None
     passiveserver = 1
-    encoding = "ASCII"
+    encoding = "latin1"
 
     # Initialization method (called by class instantiation).
     # Initialize host to localhost, port to standard ftp port

Modified: python/branches/py3k-importlib/Lib/idlelib/IOBinding.py
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/IOBinding.py	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/IOBinding.py	Thu Oct 11 23:44:13 2007
@@ -242,7 +242,7 @@
 
     eol = r"(\r\n)|\n|\r"  # \r\n (Windows), \n (UNIX), or \r (Mac)
     eol_re = re.compile(eol)
-    eol_convention = os.linesep # Default
+    eol_convention = os.linesep  # default
 
     def loadfile(self, filename):
         try:
@@ -389,9 +389,10 @@
 
     def writefile(self, filename):
         self.fixlastline()
-        chars = self.encode(self.text.get("1.0", "end-1c"))
+        text = self.text.get("1.0", "end-1c")
         if self.eol_convention != "\n":
-            chars = chars.replace("\n", self.eol_convention)
+            text = text.replace("\n", self.eol_convention)
+        chars = self.encode(self.text.get("1.0", "end-1c"))
         try:
             f = open(filename, "wb")
             f.write(chars)

Modified: python/branches/py3k-importlib/Lib/idlelib/NEWS.txt
==============================================================================
--- python/branches/py3k-importlib/Lib/idlelib/NEWS.txt	(original)
+++ python/branches/py3k-importlib/Lib/idlelib/NEWS.txt	Thu Oct 11 23:44:13 2007
@@ -1,3 +1,12 @@
+What's New in IDLE 3.0a2?
+=========================
+
+*Release date: XX-XXX-2007*
+
+- Windows EOL sequence not converted correctly, encoding error.
+  Caused file save to fail. Bug 1130.
+
+
 What's New in IDLE 3.0a1?
 =========================
 
@@ -19,7 +28,7 @@
 What's New in IDLE 2.6a1?
 =========================
 
-*Release date: XX-XXX-200X*  UNRELEASED
+*Release date: XX-XXX-200X*  UNRELEASED, but merged into 3.0a1
 
 - Corrected some bugs in AutoComplete.  Also, Page Up/Down in ACW implemented;
   mouse and cursor selection in ACWindow implemented; double Tab inserts

Modified: python/branches/py3k-importlib/Lib/pickle.py
==============================================================================
--- python/branches/py3k-importlib/Lib/pickle.py	(original)
+++ python/branches/py3k-importlib/Lib/pickle.py	Thu Oct 11 23:44:13 2007
@@ -778,31 +778,17 @@
         The protocol version of the pickle is detected automatically, so no
         proto argument is needed.
 
-        The file-like object must have two methods, a read() method that
-        takes an integer argument, and a readline() method that requires no
-        arguments.  Both methods should return a string.  Thus file-like
-        object can be a file object opened for reading, a StringIO object,
-        or any other custom object that meets this interface.
+        The file-like object must have two methods, a read() method
+        that takes an integer argument, and a readline() method that
+        requires no arguments.  Both methods should return bytes.
+        Thus file-like object can be a binary file object opened for
+        reading, a BytesIO object, or any other custom object that
+        meets this interface.
         """
-        try:
-            self.readline = file.readline
-        except AttributeError:
-            self.file = file
+        self.readline = file.readline
         self.read = file.read
         self.memo = {}
 
-    def readline(self):
-        # XXX Slow but at least correct
-        b = bytes()
-        while True:
-            c = self.file.read(1)
-            if not c:
-                break
-            b += c
-            if c == b'\n':
-                break
-        return b
-
     def load(self):
         """Read a pickled object representation from the open file.
 
@@ -895,7 +881,8 @@
     dispatch[BININT2[0]] = load_binint2
 
     def load_long(self):
-        self.append(int(str(self.readline()[:-1]), 0))
+        val = self.readline()[:-1].decode("ascii")
+        self.append(int(val, 0))
     dispatch[LONG[0]] = load_long
 
     def load_long1(self):
@@ -1076,8 +1063,10 @@
 
     def find_class(self, module, name):
         # Subclasses may override this
-        module = str(module)
-        name = str(name)
+        if isinstance(module, bytes):
+            module = module.decode("utf-8")
+        if isinstance(name, bytes):
+            name = name.decode("utf-8")
         __import__(module)
         mod = sys.modules[module]
         klass = getattr(mod, name)
@@ -1110,7 +1099,7 @@
     dispatch[DUP[0]] = load_dup
 
     def load_get(self):
-        self.append(self.memo[str8(self.readline())[:-1]])
+        self.append(self.memo[str(self.readline())[:-1]])
     dispatch[GET[0]] = load_get
 
     def load_binget(self):

Modified: python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/dbapi2.py	Thu Oct 11 23:44:13 2007
@@ -50,7 +50,7 @@
 version_info = tuple([int(x) for x in version.split(".")])
 sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
 
-Binary = buffer
+Binary = memoryview
 
 def register_adapters_and_converters():
     def adapt_date(val):

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/dbapi.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/dbapi.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/dbapi.py	Thu Oct 11 23:44:13 2007
@@ -593,7 +593,7 @@
         ts = sqlite.TimestampFromTicks(42)
 
     def CheckBinary(self):
-        b = sqlite.Binary(chr(0) + "'")
+        b = sqlite.Binary(b"\0'")
 
 class ExtensionTests(unittest.TestCase):
     def CheckScriptStringSql(self):

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/types.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/types.py	Thu Oct 11 23:44:13 2007
@@ -62,7 +62,7 @@
         self.failUnlessEqual(row[0], val)
 
     def CheckBlob(self):
-        val = buffer(b"Guglhupf")
+        val = memoryview(b"Guglhupf")
         self.cur.execute("insert into test(b) values (?)", (val,))
         self.cur.execute("select b from test")
         row = self.cur.fetchone()
@@ -203,7 +203,7 @@
 
     def CheckBlob(self):
         # default
-        val = buffer(b"Guglhupf")
+        val = memoryview(b"Guglhupf")
         self.cur.execute("insert into test(bin) values (?)", (val,))
         self.cur.execute("select bin from test")
         row = self.cur.fetchone()
@@ -305,7 +305,7 @@
 
     def CheckBinaryInputForConverter(self):
         testdata = b"abcdefg" * 10
-        result = self.con.execute('select ? as "x [bin]"', (buffer(bz2.compress(testdata)),)).fetchone()[0]
+        result = self.con.execute('select ? as "x [bin]"', (memoryview(bz2.compress(testdata)),)).fetchone()[0]
         self.failUnlessEqual(testdata, result)
 
 class DateTimeTests(unittest.TestCase):

Modified: python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py	(original)
+++ python/branches/py3k-importlib/Lib/sqlite3/test/userfunctions.py	Thu Oct 11 23:44:13 2007
@@ -36,7 +36,7 @@
 def func_returnnull():
     return None
 def func_returnblob():
-    return buffer(b"blob")
+    return b"blob"
 def func_raiseexception():
     5/0
 
@@ -49,7 +49,7 @@
 def func_isnone(v):
     return type(v) is type(None)
 def func_isblob(v):
-    return type(v) is buffer
+    return isinstance(v, (bytes, memoryview))
 
 class AggrNoStep:
     def __init__(self):
@@ -100,7 +100,8 @@
         self.val = None
 
     def step(self, whichType, val):
-        theType = {"str": str, "int": int, "float": float, "None": type(None), "blob": buffer}
+        theType = {"str": str, "int": int, "float": float, "None": type(None),
+                   "blob": bytes}
         self.val = int(theType[whichType] is type(val))
 
     def finalize(self):
@@ -196,8 +197,8 @@
         cur = self.con.cursor()
         cur.execute("select returnblob()")
         val = cur.fetchone()[0]
-        self.failUnlessEqual(type(val), buffer)
-        self.failUnlessEqual(val, buffer(b"blob"))
+        self.failUnlessEqual(type(val), bytes)
+        self.failUnlessEqual(val, memoryview(b"blob"))
 
     def CheckFuncException(self):
         cur = self.con.cursor()
@@ -234,7 +235,7 @@
 
     def CheckParamBlob(self):
         cur = self.con.cursor()
-        cur.execute("select isblob(?)", (buffer(b"blob"),))
+        cur.execute("select isblob(?)", (memoryview(b"blob"),))
         val = cur.fetchone()[0]
         self.failUnlessEqual(val, 1)
 
@@ -252,7 +253,7 @@
                 )
             """)
         cur.execute("insert into test(t, i, f, n, b) values (?, ?, ?, ?, ?)",
-            ("foo", 5, 3.14, None, buffer(b"blob"),))
+            ("foo", 5, 3.14, None, memoryview(b"blob"),))
 
         self.con.create_aggregate("nostep", 1, AggrNoStep)
         self.con.create_aggregate("nofinalize", 1, AggrNoFinalize)
@@ -344,7 +345,7 @@
 
     def CheckAggrCheckParamBlob(self):
         cur = self.con.cursor()
-        cur.execute("select checkType('blob', ?)", (buffer(b"blob"),))
+        cur.execute("select checkType('blob', ?)", (memoryview(b"blob"),))
         val = cur.fetchone()[0]
         self.failUnlessEqual(val, 1)
 

Modified: python/branches/py3k-importlib/Lib/subprocess.py
==============================================================================
--- python/branches/py3k-importlib/Lib/subprocess.py	(original)
+++ python/branches/py3k-importlib/Lib/subprocess.py	Thu Oct 11 23:44:13 2007
@@ -1041,8 +1041,11 @@
 
 
         def _communicate(self, input):
-            if isinstance(input, str): # Unicode
-                input = input.encode("utf-8") # XXX What else?
+            if self.stdin:
+                if isinstance(input, str): # Unicode
+                    input = input.encode("utf-8") # XXX What else?
+                if not isinstance(input, (bytes, str8)):
+                    input = bytes(input)
             read_set = []
             write_set = []
             stdout = None # Return
@@ -1071,7 +1074,8 @@
                     # When select has indicated that the file is writable,
                     # we can write up to PIPE_BUF bytes without risk
                     # blocking.  POSIX defines PIPE_BUF >= 512
-                    bytes_written = os.write(self.stdin.fileno(), buffer(input, input_offset, 512))
+                    chunk = input[input_offset : input_offset + 512]
+                    bytes_written = os.write(self.stdin.fileno(), chunk)
                     input_offset += bytes_written
                     if input_offset >= len(input):
                         self.stdin.close()

Modified: python/branches/py3k-importlib/Lib/test/test_array.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_array.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_array.py	Thu Oct 11 23:44:13 2007
@@ -708,7 +708,7 @@
 
     def test_buffer(self):
         a = array.array(self.typecode, self.example)
-        b = bytes(buffer(a))
+        b = bytes(memoryview(a))
         self.assertEqual(b[0], a.tostring()[0])
 
     def test_weakref(self):

Deleted: /python/branches/py3k-importlib/Lib/test/test_buffer.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_buffer.py	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,56 +0,0 @@
-"""Unit tests for buffer objects.
-
-For now, we just test (the brand new) rich comparison.
-
-"""
-
-import unittest
-from test import test_support
-
-class BufferTests(unittest.TestCase):
-
-    def test_comparison(self):
-        a = buffer("a.b.c")
-        b = buffer("a.b" + ".c")
-        self.assert_(a == b)
-        self.assert_(a <= b)
-        self.assert_(a >= b)
-        self.assert_(a == "a.b.c")
-        self.assert_(a <= "a.b.c")
-        self.assert_(a >= "a.b.c")
-        b = buffer("a.b.c.d")
-        self.assert_(a != b)
-        self.assert_(a <= b)
-        self.assert_(a < b)
-        self.assert_(a != "a.b.c.d")
-        self.assert_(a < "a.b.c.d")
-        self.assert_(a <= "a.b.c.d")
-        b = buffer("a.b")
-        self.assert_(a != b)
-        self.assert_(a >= b)
-        self.assert_(a > b)
-        self.assert_(a != "a.b")
-        self.assert_(a > "a.b")
-        self.assert_(a >= "a.b")
-        b = object()
-        self.assert_(a != b)
-        self.failIf(a == b)
-        self.assertRaises(TypeError, lambda: a < b)
-
-    def test_extended_getslice(self):
-        # Test extended slicing by comparing with list slicing.
-        s = bytes(range(255, -1, -1))
-        b = buffer(s)
-        indices = (0, None, 1, 3, 19, 300, -1, -2, -31, -300)
-        for start in indices:
-            for stop in indices:
-                # Skip step 0 (invalid)
-                for step in indices[1:]:
-                    self.assertEqual(b[start:stop:step],
-                                     s[start:stop:step])
-
-def test_main():
-    test_support.run_unittest(BufferTests)
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_bytes.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_bytes.py	Thu Oct 11 23:44:13 2007
@@ -130,12 +130,14 @@
         self.assertEqual(str8("abc") < b"ab", False)
         self.assertEqual(str8("abc") <= b"ab", False)
 
-        # Bytes can't be compared to Unicode!
+        # Byte comparisons with unicode should always fail!
         # Test this for all expected byte orders and Unicode character sizes
-        self.assertRaises(TypeError, lambda: b"\0a\0b\0c" == "abc")
-        self.assertRaises(TypeError, lambda: b"\0\0\0a\0\0\0b\0\0\0c" == "abc")
-        self.assertRaises(TypeError, lambda: b"a\0b\0c\0" == "abc")
-        self.assertRaises(TypeError, lambda: b"a\0\0\0b\0\0\0c\0\0\0" == "abc")
+        self.assertEqual(b"\0a\0b\0c" == "abc", False)
+        self.assertEqual(b"\0\0\0a\0\0\0b\0\0\0c" == "abc", False)
+        self.assertEqual(b"a\0b\0c\0" == "abc", False)
+        self.assertEqual(b"a\0\0\0b\0\0\0c\0\0\0" == "abc", False)
+        self.assertEqual(bytes() == str(), False)
+        self.assertEqual(bytes() != str(), True)
 
     def test_nohash(self):
         self.assertRaises(TypeError, hash, bytes())
@@ -343,7 +345,7 @@
 
     def test_from_buffer(self):
         sample = str8("Hello world\n\x80\x81\xfe\xff")
-        buf = buffer(sample)
+        buf = memoryview(sample)
         b = bytes(buf)
         self.assertEqual(b, bytes(map(ord, sample)))
 
@@ -456,8 +458,8 @@
         b = bytes([0x1a, 0x2b, 0x30])
         self.assertEquals(bytes.fromhex('1a2B30'), b)
         self.assertEquals(bytes.fromhex('  1A 2B  30   '), b)
-        self.assertEquals(bytes.fromhex(buffer(b'')), bytes())
-        self.assertEquals(bytes.fromhex(buffer(b'0000')), bytes([0, 0]))
+        self.assertEquals(bytes.fromhex(memoryview(b'')), bytes())
+        self.assertEquals(bytes.fromhex(memoryview(b'0000')), bytes([0, 0]))
         self.assertRaises(ValueError, bytes.fromhex, 'a')
         self.assertRaises(ValueError, bytes.fromhex, 'rt')
         self.assertRaises(ValueError, bytes.fromhex, '1a b cd')
@@ -630,7 +632,7 @@
         self.assertEqual(b'  a  bb  c  '.split(None, 3), [b'a', b'bb', b'c'])
 
     def test_split_buffer(self):
-        self.assertEqual(b'a b'.split(buffer(b' ')), [b'a', b'b'])
+        self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
 
     def test_split_string_error(self):
         self.assertRaises(TypeError, b'a b'.split, ' ')
@@ -653,7 +655,7 @@
         self.assertEqual(b'  a  bb  c  '.rsplit(None, 3), [b'a', b'bb', b'c'])
 
     def test_rplit_buffer(self):
-        self.assertEqual(b'a b'.rsplit(buffer(b' ')), [b'a', b'b'])
+        self.assertEqual(b'a b'.rsplit(memoryview(b' ')), [b'a', b'b'])
 
     def test_rplit_string_error(self):
         self.assertRaises(TypeError, b'a b'.rsplit, ' ')
@@ -707,9 +709,9 @@
         self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
 
     def test_strip_buffer(self):
-        self.assertEqual(b'abc'.strip(buffer(b'ac')), b'b')
-        self.assertEqual(b'abc'.lstrip(buffer(b'ac')), b'bc')
-        self.assertEqual(b'abc'.rstrip(buffer(b'ac')), b'ab')
+        self.assertEqual(b'abc'.strip(memoryview(b'ac')), b'b')
+        self.assertEqual(b'abc'.lstrip(memoryview(b'ac')), b'bc')
+        self.assertEqual(b'abc'.rstrip(memoryview(b'ac')), b'ab')
 
     def test_strip_string_error(self):
         self.assertRaises(TypeError, b'abc'.strip, 'b')

Deleted: /python/branches/py3k-importlib/Lib/test/test_hotshot.py
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/test_hotshot.py	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,132 +0,0 @@
-import hotshot
-import hotshot.log
-import os
-import pprint
-import unittest
-
-from test import test_support
-
-from hotshot.log import ENTER, EXIT, LINE
-
-
-def shortfilename(fn):
-    # We use a really shortened filename since an exact match is made,
-    # and the source may be either a Python source file or a
-    # pre-compiled bytecode file.
-    if fn:
-        return os.path.splitext(os.path.basename(fn))[0]
-    else:
-        return fn
-
-
-class UnlinkingLogReader(hotshot.log.LogReader):
-    """Extend the LogReader so the log file is unlinked when we're
-    done with it."""
-
-    def __init__(self, logfn):
-        self.__logfn = logfn
-        hotshot.log.LogReader.__init__(self, logfn)
-
-    def next(self, index=None):
-        try:
-            return hotshot.log.LogReader.next(self)
-        except StopIteration:
-            self.close()
-            os.unlink(self.__logfn)
-            raise
-
-
-class HotShotTestCase(unittest.TestCase):
-    def new_profiler(self, lineevents=0, linetimings=1):
-        self.logfn = test_support.TESTFN
-        return hotshot.Profile(self.logfn, lineevents, linetimings)
-
-    def get_logreader(self):
-        return UnlinkingLogReader(self.logfn)
-
-    def get_events_wotime(self):
-        L = []
-        for event in self.get_logreader():
-            what, (filename, lineno, funcname), tdelta = event
-            L.append((what, (shortfilename(filename), lineno, funcname)))
-        return L
-
-    def check_events(self, expected):
-        events = self.get_events_wotime()
-        if events != expected:
-            self.fail(
-                "events did not match expectation; got:\n%s\nexpected:\n%s"
-                % (pprint.pformat(events), pprint.pformat(expected)))
-
-    def run_test(self, callable, events, profiler=None):
-        if profiler is None:
-            profiler = self.new_profiler()
-        self.failUnless(not profiler._prof.closed)
-        profiler.runcall(callable)
-        self.failUnless(not profiler._prof.closed)
-        profiler.close()
-        self.failUnless(profiler._prof.closed)
-        self.check_events(events)
-
-    def test_addinfo(self):
-        def f(p):
-            p.addinfo("test-key", "test-value")
-        profiler = self.new_profiler()
-        profiler.runcall(f, profiler)
-        profiler.close()
-        log = self.get_logreader()
-        info = log._info
-        list(log)
-        self.assertEqual(info["test-key"], ["test-value"])
-
-    def test_line_numbers(self):
-        def f():
-            y = 2
-            x = 1
-        def g():
-            f()
-        f_lineno = f.__code__.co_firstlineno
-        g_lineno = g.__code__.co_firstlineno
-        events = [(ENTER, ("test_hotshot", g_lineno, "g")),
-                  (LINE,  ("test_hotshot", g_lineno+1, "g")),
-                  (ENTER, ("test_hotshot", f_lineno, "f")),
-                  (LINE,  ("test_hotshot", f_lineno+1, "f")),
-                  (LINE,  ("test_hotshot", f_lineno+2, "f")),
-                  (EXIT,  ("test_hotshot", f_lineno, "f")),
-                  (EXIT,  ("test_hotshot", g_lineno, "g")),
-                  ]
-        self.run_test(g, events, self.new_profiler(lineevents=1))
-
-    def test_start_stop(self):
-        # Make sure we don't return NULL in the start() and stop()
-        # methods when there isn't an error.  Bug in 2.2 noted by
-        # Anthony Baxter.
-        profiler = self.new_profiler()
-        profiler.start()
-        profiler.stop()
-        profiler.close()
-        os.unlink(self.logfn)
-
-    def test_bad_sys_path(self):
-        import sys
-        import os
-        orig_path = sys.path
-        coverage = hotshot._hotshot.coverage
-        try:
-            # verify we require a list for sys.path
-            sys.path = 'abc'
-            self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
-            # verify that we require sys.path exists
-            del sys.path
-            self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
-        finally:
-            sys.path = orig_path
-            if os.path.exists(test_support.TESTFN):
-                os.remove(test_support.TESTFN)
-
-def test_main():
-    test_support.run_unittest(HotShotTestCase)
-
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/py3k-importlib/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_io.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_io.py	Thu Oct 11 23:44:13 2007
@@ -251,7 +251,7 @@
 
     def test_array_writes(self):
         a = array.array('i', range(10))
-        n = len(buffer(a))
+        n = len(memoryview(a))
         f = io.open(test_support.TESTFN, "wb", 0)
         self.assertEqual(f.write(a), n)
         f.close()

Modified: python/branches/py3k-importlib/Lib/test/test_marshal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_marshal.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_marshal.py	Thu Oct 11 23:44:13 2007
@@ -98,9 +98,9 @@
         for s in ["", "Andr\xe8 Previn", "abc", " "*10000]:
             self.helper(s)
 
-    def test_buffer(self):
+    def test_bytes(self):
         for s in [b"", b"Andr\xe8 Previn", b"abc", b" "*10000]:
-            self.helper(buffer(s))
+            self.helper(s)
 
 class ExceptionTestCase(unittest.TestCase):
     def test_exceptions(self):

Modified: python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_multibytecodec_support.py	Thu Oct 11 23:44:13 2007
@@ -31,8 +31,14 @@
         self.incrementaldecoder = self.codec.incrementaldecoder
 
     def test_chunkcoding(self):
-        for native, utf8 in zip(*[map(bytes, str8(f).splitlines(1))
-                                  for f in self.tstring]):
+        tstring_lines = []
+        for b in self.tstring:
+            lines = b.split(b"\n")
+            last = lines.pop()
+            assert last == b""
+            lines = [line + b"\n" for line in lines]
+            tstring_lines.append(lines)
+        for native, utf8 in zip(*tstring_lines):
             u = self.decode(native)[0]
             self.assertEqual(u, utf8.decode('utf-8'))
             if self.roundtriptest:

Modified: python/branches/py3k-importlib/Lib/test/test_repr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_repr.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_repr.py	Thu Oct 11 23:44:13 2007
@@ -163,12 +163,6 @@
         eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
         eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
 
-    def test_buffer(self):
-        # XXX doesn't test buffers with no b_base or read-write buffers (see
-        # bufferobject.c).  The test is fairly incomplete too.  Sigh.
-        x = buffer('foo')
-        self.failUnless(repr(x).startswith('<read-only buffer for 0x'))
-
     def test_cell(self):
         # XXX Hmm? How to get at a cell object?
         pass

Modified: python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_socket_ssl.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_socket_ssl.py	Thu Oct 11 23:44:13 2007
@@ -41,10 +41,7 @@
 
         # A service which issues a welcome banner (without need to write
         # anything).
-        # XXX ("gmail.org", 995) has been unreliable so far, from time to
-        # XXX time non-responsive for hours on end (& across all buildbot
-        # XXX slaves, so that's not just a local thing).
-        ADDR = "gmail.org", 995
+        ADDR = "pop.gmail.com", 995
 
         s = socket.socket()
         s.settimeout(30.0)

Modified: python/branches/py3k-importlib/Lib/test/test_struct.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_struct.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_struct.py	Thu Oct 11 23:44:13 2007
@@ -541,7 +541,7 @@
 test_1530559()
 
 ###########################################################################
-# Packing and unpacking to/from buffers.
+# Packing and unpacking to/from memory views.
 
 # Copied and modified from unittest.
 def assertRaises(excClass, callableObj, *args, **kwargs):
@@ -556,7 +556,7 @@
     test_string = b'abcd01234'
     fmt = '4s'
     s = struct.Struct(fmt)
-    for cls in (str, str8, buffer, bytes):
+    for cls in (str, str8, bytes): # XXX + memoryview
         if verbose:
             print("test_unpack_from using", cls.__name__)
         data = cls(test_string)
@@ -567,7 +567,7 @@
             vereq(s.unpack_from(data, i), (data[i:i+4],))
         for i in range(6, len(test_string) + 1):
             simple_err(s.unpack_from, data, i)
-    for cls in (str, buffer):
+    for cls in (str, str8, bytes): # XXX + memoryview
         data = cls(test_string)
         vereq(struct.unpack_from(fmt, data), ('abcd',))
         vereq(struct.unpack_from(fmt, data, 2), ('cd01',))
@@ -619,19 +619,19 @@
     assertRaises(struct.error, pack_into, small_buf, 0, test_string)
     assertRaises(struct.error, pack_into, small_buf, 2, test_string)
 
-def test_unpack_with_buffer():
+def test_unpack_with_memoryview():
     # SF bug 1563759: struct.unpack doens't support buffer protocol objects
     data1 = array.array('B', b'\x12\x34\x56\x78')
-    data2 = buffer(b'......\x12\x34\x56\x78......', 6, 4)
+    data2 = memoryview(b'\x12\x34\x56\x78') # XXX b'......XXXX......', 6, 4
     for data in [data1, data2]:
         value, = struct.unpack('>I', data)
         vereq(value, 0x12345678)
 
-# Test methods to pack and unpack from buffers rather than strings.
+# Test methods to pack and unpack from memoryviews rather than strings.
 test_unpack_from()
 test_pack_into()
 test_pack_into_fn()
-test_unpack_with_buffer()
+test_unpack_with_memoryview()
 
 def test_bool():
     for prefix in tuple("<>!=")+('',):

Modified: python/branches/py3k-importlib/Lib/test/test_types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_types.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_types.py	Thu Oct 11 23:44:13 2007
@@ -203,54 +203,6 @@
         self.assertRaises(TypeError, type, 1, 2)
         self.assertRaises(TypeError, type, 1, 2, 3, 4)
 
-    def test_buffers(self):
-        self.assertRaises(ValueError, buffer, 'asdf', -1)
-        self.assertRaises(TypeError, buffer, None)
-
-        a = buffer(b'asdf')
-        hash(a)
-        b = a * 5
-        if a == b:
-            self.fail('buffers should not be equal')
-        if str(b) != ('asdf' * 5):
-            self.fail('repeated buffer has wrong content')
-        if str(a * 0) != '':
-            self.fail('repeated buffer zero times has wrong content')
-        if str(a + buffer(b'def')) != 'asdfdef':
-            self.fail('concatenation of buffers yields wrong content')
-        if str(buffer(a)) != 'asdf':
-            self.fail('composing buffers failed')
-        if str(buffer(a, 2)) != 'df':
-            self.fail('specifying buffer offset failed')
-        if str(buffer(a, 0, 2)) != 'as':
-            self.fail('specifying buffer size failed')
-        if str(buffer(a, 1, 2)) != 'sd':
-            self.fail('specifying buffer offset and size failed')
-        self.assertRaises(ValueError, buffer, buffer(b'asdf', 1), -1)
-        if str(buffer(buffer(b'asdf', 0, 2), 0)) != 'as':
-            self.fail('composing length-specified buffer failed')
-        if str(buffer(buffer(b'asdf', 0, 2), 0, 5000)) != 'as':
-            self.fail('composing length-specified buffer failed')
-        if str(buffer(buffer(b'asdf', 0, 2), 0, -1)) != 'as':
-            self.fail('composing length-specified buffer failed')
-        if str(buffer(buffer(b'asdf', 0, 2), 1, 2)) != 's':
-            self.fail('composing length-specified buffer failed')
-
-        try: a[1] = 'g'
-        except TypeError: pass
-        else: self.fail("buffer assignment should raise TypeError")
-
-        try: a[0:1] = 'g'
-        except TypeError: pass
-        else: self.fail("buffer slice assignment should raise TypeError")
-
-        # array.array() returns an object that does not implement a char buffer,
-        # something which int() uses for conversion.
-        import array
-        try: int(buffer(array.array('b')))
-        except TypeError: pass
-        else: self.fail("char buffer (at C level) not working")
-
 def test_main():
     run_unittest(TypesTests)
 

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	Thu Oct 11 23:44:13 2007
@@ -713,7 +713,7 @@
         if not sys.platform.startswith('java'):
             self.assertEqual(
                 str(
-                    buffer(b'character buffers are decoded to unicode'),
+                    memoryview(b'character buffers are decoded to unicode'),
                     'utf-8',
                     'strict'
                 ),

Modified: python/branches/py3k-importlib/Lib/test/test_xml_etree.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_xml_etree.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_xml_etree.py	Thu Oct 11 23:44:13 2007
@@ -183,9 +183,8 @@
     <html><body>text</body></html>
     >>> print(ET.tostring(element))
     <html><body>text</body></html>
-    >>> print(ET.tostring(element, "ascii"))
-    <?xml version='1.0' encoding='ascii'?>
-    <html><body>text</body></html>
+    >>> print(repr(ET.tostring(element, "ascii")))
+    b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<html><body>text</body></html>'
     >>> _, ids = ET.XMLID("<html><body>text</body></html>")
     >>> len(ids)
     0

Modified: python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py	(original)
+++ python/branches/py3k-importlib/Lib/test/test_xml_etree_c.py	Thu Oct 11 23:44:13 2007
@@ -175,9 +175,8 @@
     <html><body>text</body></html>
     >>> print(ET.tostring(element))
     <html><body>text</body></html>
-    >>> print(ET.tostring(element, "ascii"))
-    <?xml version='1.0' encoding='ascii'?>
-    <html><body>text</body></html>
+    >>> print(repr(ET.tostring(element, "ascii")))
+    b'<?xml version=\'1.0\' encoding=\'ascii\'?>\n<html><body>text</body></html>'
     >>> _, ids = ET.XMLID("<html><body>text</body></html>")
     >>> len(ids)
     0

Modified: python/branches/py3k-importlib/Lib/types.py
==============================================================================
--- python/branches/py3k-importlib/Lib/types.py	(original)
+++ python/branches/py3k-importlib/Lib/types.py	Thu Oct 11 23:44:13 2007
@@ -22,8 +22,6 @@
 except NameError:
     pass
 
-BufferType = buffer
-
 TupleType = tuple
 ListType = list
 DictType = DictionaryType = dict

Modified: python/branches/py3k-importlib/Makefile.pre.in
==============================================================================
--- python/branches/py3k-importlib/Makefile.pre.in	(original)
+++ python/branches/py3k-importlib/Makefile.pre.in	Thu Oct 11 23:44:13 2007
@@ -285,7 +285,6 @@
 OBJECT_OBJS=	\
 		Objects/abstract.o \
 		Objects/boolobject.o \
-		Objects/bufferobject.o \
 		Objects/bytesobject.o \
 		Objects/cellobject.o \
 		Objects/classobject.o \
@@ -530,7 +529,6 @@
 		Include/asdl.h \
 		Include/abstract.h \
 		Include/boolobject.h \
-		Include/bufferobject.h \
 		Include/bytesobject.h \
 		Include/ceval.h \
 		Include/classobject.h \
@@ -739,7 +737,7 @@
 PLATMACPATH=:plat-mac:plat-mac/lib-scriptpackages
 LIBSUBDIRS=	lib-tk site-packages test test/output test/data \
 		test/decimaltestdata \
-		encodings hotshot \
+		encodings \
 		email email/mime email/test email/test/data \
 		sqlite3 sqlite3/test \
 		logging bsddb bsddb/test csv wsgiref \

Modified: python/branches/py3k-importlib/Misc/NEWS
==============================================================================
--- python/branches/py3k-importlib/Misc/NEWS	(original)
+++ python/branches/py3k-importlib/Misc/NEWS	Thu Oct 11 23:44:13 2007
@@ -4,6 +4,16 @@
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's New in Python 3.0a2?
+
+*Unreleased*
+
+Extension Modules
+-----------------
+
+- The `hotshot` profiler has been removed; use `cProfile` instead.
+
+
 What's New in Python 3.0a1?
 ==========================
 

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	Thu Oct 11 23:44:13 2007
@@ -739,18 +739,12 @@
 {
 	char *ptr;
 	Py_ssize_t size;
-        int rel = 0;
         Py_buffer view;
 
-	if (PyBuffer_Check(value)) {
-                if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
-                        return -1;
-                size = view.len;
-                ptr = view.buf;
-                rel = 1;
-	} else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) {
+        if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
 		return -1;
-	}
+        size = view.len;
+	ptr = view.buf;
 	if (size > self->b_size) {
 		PyErr_SetString(PyExc_ValueError,
 				"string too long");
@@ -759,12 +753,10 @@
 
 	memcpy(self->b_ptr, ptr, size);
 
-        if (rel)
-                PyObject_ReleaseBuffer(value, &view);
+	PyObject_ReleaseBuffer(value, &view);
 	return 0;
  fail:
-        if (rel) 
-                PyObject_ReleaseBuffer(value, &view);
+	PyObject_ReleaseBuffer(value, &view);
         return -1;
 }
 

Deleted: /python/branches/py3k-importlib/Modules/_hotshot.c
==============================================================================
--- /python/branches/py3k-importlib/Modules/_hotshot.c	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,1645 +0,0 @@
-/*
- * This is the High Performance Python Profiler portion of HotShot.
- */
-
-#include "Python.h"
-#include "code.h"
-#include "eval.h"
-#include "frameobject.h"
-#include "structmember.h"
-
-/*
- * Which timer to use should be made more configurable, but that should not
- * be difficult.  This will do for now.
- */
-#ifdef MS_WINDOWS
-#include <windows.h>
-
-#ifdef HAVE_DIRECT_H
-#include <direct.h>    /* for getcwd() */
-#endif
-
-typedef __int64 hs_time;
-#define GETTIMEOFDAY(P_HS_TIME) \
-	{ LARGE_INTEGER _temp; \
-	  QueryPerformanceCounter(&_temp); \
-	  *(P_HS_TIME) = _temp.QuadPart; }
-	  
-
-#else
-#ifndef HAVE_GETTIMEOFDAY
-#error "This module requires gettimeofday() on non-Windows platforms!"
-#endif
-#if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__QNX__)
-#include <sys/time.h>
-#else
-#include <sys/resource.h>
-#include <sys/times.h>
-#endif
-typedef struct timeval hs_time;
-#endif
-
-#if !defined(__cplusplus) && !defined(inline)
-#ifdef __GNUC__
-#define inline __inline
-#endif
-#endif
-
-#ifndef inline
-#define inline
-#endif
-
-#define BUFFERSIZE 10240
-
-#if defined(PYOS_OS2) && defined(PYCC_GCC)
-#define PATH_MAX 260
-#endif
-
-#if defined(__sgi) && _COMPILER_VERSION>700 && !defined(PATH_MAX)
-/* fix PATH_MAX not being defined with MIPSPro 7.x
-   if mode is ANSI C (default) */
-#define PATH_MAX 1024
-#endif
-
-#ifndef PATH_MAX
-#   ifdef MAX_PATH
-#       define PATH_MAX MAX_PATH
-#   elif defined (_POSIX_PATH_MAX)
-#       define PATH_MAX _POSIX_PATH_MAX
-#   else
-#       error "Need a defn. for PATH_MAX in _hotshot.c"
-#   endif
-#endif
-
-typedef struct {
-    PyObject_HEAD
-    PyObject *filemap;
-    PyObject *logfilename;
-    Py_ssize_t index;
-    unsigned char buffer[BUFFERSIZE];
-    FILE *logfp;
-    int lineevents;
-    int linetimings;
-    int frametimings;
-    /* size_t filled; */
-    int active;
-    int next_fileno;
-    hs_time prev_timeofday;
-} ProfilerObject;
-
-typedef struct {
-    PyObject_HEAD
-    PyObject *info;
-    FILE *logfp;
-    int linetimings;
-    int frametimings;
-} LogReaderObject;
-
-static PyObject * ProfilerError = NULL;
-
-
-#ifndef MS_WINDOWS
-#ifdef GETTIMEOFDAY_NO_TZ
-#define GETTIMEOFDAY(ptv) gettimeofday((ptv))
-#else
-#define GETTIMEOFDAY(ptv) gettimeofday((ptv), (struct timezone *)NULL)
-#endif
-#endif
-
-
-/* The log reader... */
-
-PyDoc_STRVAR(logreader_close__doc__,
-"close()\n"
-"Close the log file, preventing additional records from being read.");
-
-static PyObject *
-logreader_close(LogReaderObject *self, PyObject *args)
-{
-    if (self->logfp != NULL) {
-        fclose(self->logfp);
-        self->logfp = NULL;
-    }
-    Py_INCREF(Py_None);
-
-    return Py_None;
-}
-
-PyDoc_STRVAR(logreader_fileno__doc__,
-"fileno() -> file descriptor\n"
-"Returns the file descriptor for the log file, if open.\n"
-"Raises ValueError if the log file is closed.");
-
-static PyObject *
-logreader_fileno(LogReaderObject *self)
-{
-    if (self->logfp == NULL) {
-        PyErr_SetString(PyExc_ValueError,
-                        "logreader's file object already closed");
-        return NULL;
-    }
-    return PyInt_FromLong(fileno(self->logfp));
-}
-
-
-/* Log File Format
- * ---------------
- *
- * The log file consists of a sequence of variable-length records.
- * Each record is identified with a record type identifier in two
- * bits of the first byte.  The two bits are the "least significant"
- * bits of the byte.
- *
- * Low bits:    Opcode:        Meaning:
- *       0x00         ENTER     enter a frame
- *       0x01          EXIT     exit a frame
- *       0x02        LINENO     execution moved onto a different line
- *       0x03         OTHER     more bits are needed to deecode
- *
- * If the type is OTHER, the record is not packed so tightly, and the
- * remaining bits are used to disambiguate the record type.  These
- * records are not used as frequently so compaction is not an issue.
- * Each of the first three record types has a highly tailored
- * structure that allows it to be packed tightly.
- *
- * The OTHER records have the following identifiers:
- *
- * First byte:  Opcode:        Meaning:
- *       0x13      ADD_INFO     define a key/value pair
- *       0x23   DEFINE_FILE     define an int->filename mapping
- *       0x33    LINE_TIMES     indicates if LINENO events have tdeltas
- *       0x43   DEFINE_FUNC     define a (fileno,lineno)->funcname mapping
- *       0x53   FRAME_TIMES     indicates if ENTER/EXIT events have tdeltas
- *
- * Packed Integers
- *
- * "Packed integers" are non-negative integer values encoded as a
- * sequence of bytes.  Each byte is encoded such that the most
- * significant bit is set if the next byte is also part of the
- * integer.  Each byte provides bits to the least-significant end of
- * the result; the accumulated value must be shifted up to place the
- * new bits into the result.
- *
- * "Modified packed integers" are packed integers where only a portion
- * of the first byte is used.  In the rest of the specification, these
- * are referred to as "MPI(n,name)", where "n" is the number of bits
- * discarded from the least-signicant positions of the byte, and
- * "name" is a name being given to those "discarded" bits, since they
- * are a field themselves.
- *
- * ENTER records:
- *
- *      MPI(2,type)  fileno          -- type is 0x00
- *      PI           lineno
- *      PI           tdelta          -- iff frame times are enabled
- *
- * EXIT records
- *
- *      MPI(2,type)  tdelta          -- type is 0x01; tdelta will be 0
- *                                      if frame times are disabled
- *
- * LINENO records
- *
- *      MPI(2,type)  lineno          -- type is 0x02
- *      PI           tdelta          -- iff LINENO includes it
- *
- * ADD_INFO records
- *
- *      BYTE         type            -- always 0x13
- *      PI           len1            -- length of first string
- *      BYTE         string1[len1]   -- len1 bytes of string data
- *      PI           len2            -- length of second string
- *      BYTE         string2[len2]   -- len2 bytes of string data
- *
- * DEFINE_FILE records
- *
- *      BYTE         type            -- always 0x23
- *      PI           fileno
- *      PI           len             -- length of filename
- *      BYTE         filename[len]   -- len bytes of string data
- *
- * DEFINE_FUNC records
- *
- *      BYTE         type            -- always 0x43
- *      PI           fileno
- *      PI           lineno
- *      PI           len             -- length of funcname
- *      BYTE         funcname[len]   -- len bytes of string data
- *
- * LINE_TIMES records
- *
- * This record can be used only before the start of ENTER/EXIT/LINENO
- * records.  If have_tdelta is true, LINENO records will include the
- * tdelta field, otherwise it will be omitted.  If this record is not
- * given, LINENO records will not contain the tdelta field.
- *
- *      BYTE         type            -- always 0x33
- *      BYTE         have_tdelta     -- 0 if LINENO does *not* have
- *                                      timing information
- * FRAME_TIMES records
- *
- * This record can be used only before the start of ENTER/EXIT/LINENO
- * records.  If have_tdelta is true, ENTER and EXIT records will
- * include the tdelta field, otherwise it will be omitted.  If this
- * record is not given, ENTER and EXIT records will contain the tdelta
- * field.
- *
- *      BYTE         type            -- always 0x53
- *      BYTE         have_tdelta     -- 0 if ENTER/EXIT do *not* have
- *                                      timing information
- */
-
-#define WHAT_ENTER        0x00
-#define WHAT_EXIT         0x01
-#define WHAT_LINENO       0x02
-#define WHAT_OTHER        0x03  /* only used in decoding */
-#define WHAT_ADD_INFO     0x13
-#define WHAT_DEFINE_FILE  0x23
-#define WHAT_LINE_TIMES   0x33
-#define WHAT_DEFINE_FUNC  0x43
-#define WHAT_FRAME_TIMES  0x53
-
-#define ERR_NONE          0
-#define ERR_EOF          -1
-#define ERR_EXCEPTION    -2
-#define ERR_BAD_RECTYPE  -3
-
-#define PISIZE            (sizeof(int) + 1)
-#define MPISIZE           (PISIZE + 1)
-
-/* Maximum size of "normal" events -- nothing that contains string data */
-#define MAXEVENTSIZE      (MPISIZE + PISIZE*2)
-
-
-/* Unpack a packed integer; if "discard" is non-zero, unpack a modified
- * packed integer with "discard" discarded bits.
- */
-static int
-unpack_packed_int(LogReaderObject *self, int *pvalue, int discard)
-{
-    int c;
-    int accum = 0;
-    int bits = 0;
-    int cont;
-
-    do {
-        /* read byte */
-	if ((c = fgetc(self->logfp)) == EOF)
-            return ERR_EOF;
-        accum |= ((c & 0x7F) >> discard) << bits;
-        bits += (7 - discard);
-        cont = c & 0x80;
-        discard = 0;
-    } while (cont);
-
-    *pvalue = accum;
-
-    return 0;
-}
-
-/* Unpack a string, which is encoded as a packed integer giving the
- * length of the string, followed by the string data.
- */
-static int
-unpack_string(LogReaderObject *self, PyObject **pvalue)
-{
-    int i;
-    int len;
-    int err;
-    int ch;
-    char *buf;
-    
-    if ((err = unpack_packed_int(self, &len, 0)))
-        return err;
-
-    buf = (char *)malloc(len);
-    if (!buf) {
-	PyErr_NoMemory();
-	return ERR_EXCEPTION;
-    }
-
-    for (i=0; i < len; i++) {
-        ch = fgetc(self->logfp);
-	buf[i] = ch;
-        if (ch == EOF) {
-            free(buf);
-            return ERR_EOF;
-        }
-    }
-    *pvalue = PyString_FromStringAndSize(buf, len);
-    free(buf);
-    if (*pvalue == NULL) {
-        return ERR_EXCEPTION;
-    }
-    return 0;
-}
-
-
-static int
-unpack_add_info(LogReaderObject *self)
-{
-    PyObject *key;
-    PyObject *value = NULL;
-    int err;
-
-    err = unpack_string(self, &key);
-    if (!err) {
-        err = unpack_string(self, &value);
-        if (err)
-            Py_DECREF(key);
-        else {
-            PyObject *list = PyDict_GetItem(self->info, key);
-            if (list == NULL) {
-                list = PyList_New(0);
-                if (list == NULL) {
-                    err = ERR_EXCEPTION;
-                    goto finally;
-                }
-                if (PyDict_SetItem(self->info, key, list)) {
-                    Py_DECREF(list);
-                    err = ERR_EXCEPTION;
-                    goto finally;
-                }
-                Py_DECREF(list);
-            }
-            if (PyList_Append(list, value))
-                err = ERR_EXCEPTION;
-        }
-    }
- finally:
-    Py_XDECREF(key);
-    Py_XDECREF(value);
-    return err;
-}
-
-
-static void
-eof_error(LogReaderObject *self)
-{
-    fclose(self->logfp);
-    self->logfp = NULL;
-    PyErr_SetString(PyExc_EOFError,
-                    "end of file with incomplete profile record");
-}
-
-static PyObject *
-logreader_tp_iternext(LogReaderObject *self)
-{
-    int c;
-    int what;
-    int err = ERR_NONE;
-    int lineno = -1;
-    int fileno = -1;
-    int tdelta = -1;
-    PyObject *s1 = NULL, *s2 = NULL;
-    PyObject *result = NULL;
-#if 0
-    unsigned char b0, b1;
-#endif
-
-    if (self->logfp == NULL) {
-        PyErr_SetString(ProfilerError,
-                        "cannot iterate over closed LogReader object");
-        return NULL;
-    }
-
-restart:
-    /* decode the record type */
-    if ((c = fgetc(self->logfp)) == EOF) {
-        fclose(self->logfp);
-        self->logfp = NULL;
-        return NULL;
-    }
-    what = c & WHAT_OTHER;
-    if (what == WHAT_OTHER)
-        what = c; /* need all the bits for type */
-    else
-        ungetc(c, self->logfp); /* type byte includes packed int */
-
-    switch (what) {
-    case WHAT_ENTER:
-        err = unpack_packed_int(self, &fileno, 2);
-        if (!err) {
-            err = unpack_packed_int(self, &lineno, 0);
-            if (self->frametimings && !err)
-                err = unpack_packed_int(self, &tdelta, 0);
-        }
-        break;
-    case WHAT_EXIT:
-        err = unpack_packed_int(self, &tdelta, 2);
-        break;
-    case WHAT_LINENO:
-        err = unpack_packed_int(self, &lineno, 2);
-        if (self->linetimings && !err)
-            err = unpack_packed_int(self, &tdelta, 0);
-        break;
-    case WHAT_ADD_INFO:
-        err = unpack_add_info(self);
-        break;
-    case WHAT_DEFINE_FILE:
-        err = unpack_packed_int(self, &fileno, 0);
-        if (!err) {
-            err = unpack_string(self, &s1);
-            if (!err) {
-                Py_INCREF(Py_None);
-                s2 = Py_None;
-            }
-        }
-        break;
-    case WHAT_DEFINE_FUNC:
-        err = unpack_packed_int(self, &fileno, 0);
-        if (!err) {
-            err = unpack_packed_int(self, &lineno, 0);
-            if (!err)
-                err = unpack_string(self, &s1);
-        }
-        break;
-    case WHAT_LINE_TIMES:
-        if ((c = fgetc(self->logfp)) == EOF)
-            err = ERR_EOF;
-        else {
-            self->linetimings = c ? 1 : 0;
-	    goto restart;
-	}
-        break;
-    case WHAT_FRAME_TIMES:
-        if ((c = fgetc(self->logfp)) == EOF)
-            err = ERR_EOF;
-        else {
-            self->frametimings = c ? 1 : 0;
-	    goto restart;
-	}
-        break;
-    default:
-        err = ERR_BAD_RECTYPE;
-    }
-    if (err == ERR_BAD_RECTYPE) {
-        PyErr_SetString(PyExc_ValueError,
-                        "unknown record type in log file");
-    }
-    else if (err == ERR_EOF) {
-        eof_error(self);
-    }
-    else if (!err) {
-        result = PyTuple_New(4);
-        if (result == NULL)
-            return NULL;
-        PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
-        PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
-        if (s1 == NULL)
-            PyTuple_SET_ITEM(result, 1, PyInt_FromLong(tdelta));
-        else
-            PyTuple_SET_ITEM(result, 1, s1);
-        if (s2 == NULL)
-            PyTuple_SET_ITEM(result, 3, PyInt_FromLong(lineno));
-        else
-            PyTuple_SET_ITEM(result, 3, s2);
-    }
-    /* The only other case is err == ERR_EXCEPTION, in which case the
-     * exception is already set.
-     */
-#if 0
-    b0 = self->buffer[self->index];
-    b1 = self->buffer[self->index + 1];
-    if (b0 & 1) {
-        /* This is a line-number event. */
-        what = PyTrace_LINE;
-        lineno = ((b0 & ~1) << 7) + b1;
-        self->index += 2;
-    }
-    else {
-        what = (b0 & 0x0E) >> 1;
-        tdelta = ((b0 & 0xF0) << 4) + b1;
-        if (what == PyTrace_CALL) {
-            /* we know there's a 2-byte file ID & 2-byte line number */
-            fileno = ((self->buffer[self->index + 2] << 8)
-                      + self->buffer[self->index + 3]);
-            lineno = ((self->buffer[self->index + 4] << 8)
-                      + self->buffer[self->index + 5]);
-            self->index += 6;
-        }
-        else
-            self->index += 2;
-    }
-#endif
-    return result;
-}
-
-static void
-logreader_dealloc(LogReaderObject *self)
-{
-    if (self->logfp != NULL) {
-        fclose(self->logfp);
-        self->logfp = NULL;
-    }
-    Py_XDECREF(self->info);
-    PyObject_Del(self);
-}
-
-static PyObject *
-logreader_sq_item(LogReaderObject *self, Py_ssize_t index)
-{
-    PyObject *result = logreader_tp_iternext(self);
-    if (result == NULL && !PyErr_Occurred()) {
-        PyErr_SetString(PyExc_IndexError, "no more events in log");
-        return NULL;
-    }
-    return result;
-}
-
-static void
-do_stop(ProfilerObject *self);
-
-static int
-flush_data(ProfilerObject *self)
-{
-    /* Need to dump data to the log file... */
-    size_t written = fwrite(self->buffer, 1, self->index, self->logfp);
-    if (written == (size_t)self->index)
-        self->index = 0;
-    else {
-        memmove(self->buffer, &self->buffer[written],
-                self->index - written);
-        self->index -= written;
-        if (written == 0) {
-            char *s = PyString_AsString(self->logfilename);
-            PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
-            do_stop(self);
-            return -1;
-        }
-    }
-    if (written > 0) {
-        if (fflush(self->logfp)) {
-            char *s = PyString_AsString(self->logfilename);
-            PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
-            do_stop(self);
-            return -1;
-        }
-    }
-    return 0;
-}
-
-static inline int
-pack_packed_int(ProfilerObject *self, int value)
-{
-    unsigned char partial;
-
-    do {
-        partial = value & 0x7F;
-        value >>= 7;
-        if (value)
-            partial |= 0x80;
-        self->buffer[self->index] = partial;
-        self->index++;
-    } while (value);
-    return 0;
-}
-
-/* Encode a modified packed integer, with a subfield of modsize bits
- * containing the value "subfield".  The value of subfield is not
- * checked to ensure it actually fits in modsize bits.
- */
-static inline int
-pack_modified_packed_int(ProfilerObject *self, int value,
-                         int modsize, int subfield)
-{
-    const int maxvalues[] = {-1, 1, 3, 7, 15, 31, 63, 127};
-
-    int bits = 7 - modsize;
-    int partial = value & maxvalues[bits];
-    unsigned char b = subfield | (partial << modsize);
-
-    if (partial != value) {
-        b |= 0x80;
-        self->buffer[self->index] = b;
-        self->index++;
-        return pack_packed_int(self, value >> bits);
-    }
-    self->buffer[self->index] = b;
-    self->index++;
-    return 0;
-}
-
-static int
-pack_string(ProfilerObject *self, const char *s, Py_ssize_t len)
-{
-    if (len + PISIZE + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    assert(len < INT_MAX);
-    if (pack_packed_int(self, (int)len) < 0)
-        return -1;
-    memcpy(self->buffer + self->index, s, len);
-    self->index += len;
-    return 0;
-}
-
-static int
-pack_add_info(ProfilerObject *self, const char *s1, const char *s2)
-{
-    Py_ssize_t len1 = strlen(s1);
-    Py_ssize_t len2 = strlen(s2);
-
-    if (len1 + len2 + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    self->buffer[self->index] = WHAT_ADD_INFO;
-    self->index++;
-    if (pack_string(self, s1, len1) < 0)
-        return -1;
-    return pack_string(self, s2, len2);
-}
-
-static int
-pack_define_file(ProfilerObject *self, int fileno, const char *filename)
-{
-    Py_ssize_t len = strlen(filename);
-
-    if (len + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    self->buffer[self->index] = WHAT_DEFINE_FILE;
-    self->index++;
-    if (pack_packed_int(self, fileno) < 0)
-        return -1;
-    return pack_string(self, filename, len);
-}
-
-static int
-pack_define_func(ProfilerObject *self, int fileno, int lineno,
-                 const char *funcname)
-{
-    Py_ssize_t len = strlen(funcname);
-
-    if (len + PISIZE*3 + 1 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    self->buffer[self->index] = WHAT_DEFINE_FUNC;
-    self->index++;
-    if (pack_packed_int(self, fileno) < 0)
-        return -1;
-    if (pack_packed_int(self, lineno) < 0)
-        return -1;
-    return pack_string(self, funcname, len);
-}
-
-static int
-pack_line_times(ProfilerObject *self)
-{
-    if (2 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    self->buffer[self->index] = WHAT_LINE_TIMES;
-    self->buffer[self->index + 1] = self->linetimings ? 1 : 0;
-    self->index += 2;
-    return 0;
-}
-
-static int
-pack_frame_times(ProfilerObject *self)
-{
-    if (2 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    self->buffer[self->index] = WHAT_FRAME_TIMES;
-    self->buffer[self->index + 1] = self->frametimings ? 1 : 0;
-    self->index += 2;
-    return 0;
-}
-
-static inline int
-pack_enter(ProfilerObject *self, int fileno, int tdelta, int lineno)
-{
-    if (MPISIZE + PISIZE*2 + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    pack_modified_packed_int(self, fileno, 2, WHAT_ENTER);
-    pack_packed_int(self, lineno);
-    if (self->frametimings)
-        return pack_packed_int(self, tdelta);
-    else
-        return 0;
-}
-
-static inline int
-pack_exit(ProfilerObject *self, int tdelta)
-{
-    if (MPISIZE + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    if (self->frametimings)
-        return pack_modified_packed_int(self, tdelta, 2, WHAT_EXIT);
-    self->buffer[self->index] = WHAT_EXIT;
-    self->index++;
-    return 0;
-}
-
-static inline int
-pack_lineno(ProfilerObject *self, int lineno)
-{
-    if (MPISIZE + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return -1;
-    }
-    return pack_modified_packed_int(self, lineno, 2, WHAT_LINENO);
-}
-
-static inline int
-pack_lineno_tdelta(ProfilerObject *self, int lineno, int tdelta)
-{
-    if (MPISIZE + PISIZE + self->index >= BUFFERSIZE) {
-        if (flush_data(self) < 0)
-            return 0;
-    }
-    if (pack_modified_packed_int(self, lineno, 2, WHAT_LINENO) < 0)
-        return -1;
-    return pack_packed_int(self, tdelta);
-}
-
-static inline int
-get_fileno(ProfilerObject *self, PyCodeObject *fcode)
-{
-    /* This is only used for ENTER events. */
-
-    PyObject *obj;
-    PyObject *dict;
-    int fileno;
-
-    obj = PyDict_GetItem(self->filemap, fcode->co_filename);
-    if (obj == NULL) {
-        /* first sighting of this file */
-        dict = PyDict_New();
-        if (dict == NULL) {
-            return -1;
-        }
-        fileno = self->next_fileno;
-        obj = Py_BuildValue("iN", fileno, dict);
-        if (obj == NULL) {
-            return -1;
-        }
-        if (PyDict_SetItem(self->filemap, fcode->co_filename, obj)) {
-            Py_DECREF(obj);
-            return -1;
-        }
-        self->next_fileno++;
-        Py_DECREF(obj);
-        if (pack_define_file(self, fileno,
-                             PyString_AS_STRING(fcode->co_filename)) < 0)
-            return -1;
-    }
-    else {
-        /* already know this ID */
-        fileno = PyInt_AS_LONG(PyTuple_GET_ITEM(obj, 0));
-        dict = PyTuple_GET_ITEM(obj, 1);
-    }
-    /* make sure we save a function name for this (fileno, lineno) */
-    obj = PyInt_FromLong(fcode->co_firstlineno);
-    if (obj == NULL) {
-        /* We just won't have it saved; too bad. */
-        PyErr_Clear();
-    }
-    else {
-        PyObject *name = PyDict_GetItem(dict, obj);
-        if (name == NULL) {
-            if (pack_define_func(self, fileno, fcode->co_firstlineno,
-                                 PyUnicode_AsString(fcode->co_name)) < 0) {
-                Py_DECREF(obj);
-                return -1;
-            }
-            if (PyDict_SetItem(dict, obj, fcode->co_name)) {
-                Py_DECREF(obj);
-                return -1;
-            }
-        }
-        Py_DECREF(obj);
-    }
-    return fileno;
-}
-
-static inline int
-get_tdelta(ProfilerObject *self)
-{
-    int tdelta;
-#ifdef MS_WINDOWS
-    hs_time tv;
-    hs_time diff;
-
-    GETTIMEOFDAY(&tv);
-    diff = tv - self->prev_timeofday;
-    tdelta = (int)diff;
-#else
-    struct timeval tv;
-
-    GETTIMEOFDAY(&tv);
-
-    tdelta = tv.tv_usec - self->prev_timeofday.tv_usec;
-    if (tv.tv_sec != self->prev_timeofday.tv_sec)
-        tdelta += (tv.tv_sec - self->prev_timeofday.tv_sec) * 1000000;
-#endif
-    /* time can go backwards on some multiprocessor systems or by NTP */
-    if (tdelta < 0)
-        return 0;
-
-    self->prev_timeofday = tv;
-    return tdelta;
-}
-
-
-/* The workhorse:  the profiler callback function. */
-
-static int
-tracer_callback(ProfilerObject *self, PyFrameObject *frame, int what,
-                PyObject *arg)
-{
-    int fileno;
-
-    switch (what) {
-    case PyTrace_CALL:
-        fileno = get_fileno(self, frame->f_code);
-        if (fileno < 0)
-            return -1;
-        return pack_enter(self, fileno,
-                          self->frametimings ? get_tdelta(self) : -1,
-                          frame->f_code->co_firstlineno);
-
-    case PyTrace_RETURN:
-        return pack_exit(self, get_tdelta(self));
-
-    case PyTrace_LINE:  /* we only get these events if we asked for them */
-        if (self->linetimings)
-            return pack_lineno_tdelta(self, frame->f_lineno,
-				      get_tdelta(self));
-        else
-            return pack_lineno(self, frame->f_lineno);
-
-    default:
-        /* ignore PyTrace_EXCEPTION */
-        break;
-    }
-    return 0;
-}
-
-
-/* A couple of useful helper functions. */
-
-#ifdef MS_WINDOWS
-static LARGE_INTEGER frequency = {0, 0};
-#endif
-
-static unsigned long timeofday_diff = 0;
-static unsigned long rusage_diff = 0;
-
-static void
-calibrate(void)
-{
-    hs_time tv1, tv2;
-
-#ifdef MS_WINDOWS
-    hs_time diff;
-    QueryPerformanceFrequency(&frequency);
-#endif
-
-    GETTIMEOFDAY(&tv1);
-    while (1) {
-        GETTIMEOFDAY(&tv2);
-#ifdef MS_WINDOWS
-        diff = tv2 - tv1;
-        if (diff != 0) {
-            timeofday_diff = (unsigned long)diff;
-            break;
-        }
-#else
-        if (tv1.tv_sec != tv2.tv_sec || tv1.tv_usec != tv2.tv_usec) {
-            if (tv1.tv_sec == tv2.tv_sec)
-                timeofday_diff = tv2.tv_usec - tv1.tv_usec;
-            else
-                timeofday_diff = (1000000 - tv1.tv_usec) + tv2.tv_usec;
-            break;
-        }
-#endif
-    }
-#if defined(MS_WINDOWS) || defined(PYOS_OS2) || \
-    defined(__VMS) || defined (__QNX__)
-    rusage_diff = -1;
-#else
-    {
-        struct rusage ru1, ru2;
-
-        getrusage(RUSAGE_SELF, &ru1);
-        while (1) {
-            getrusage(RUSAGE_SELF, &ru2);
-            if (ru1.ru_utime.tv_sec != ru2.ru_utime.tv_sec) {
-                rusage_diff = ((1000000 - ru1.ru_utime.tv_usec)
-                               + ru2.ru_utime.tv_usec);
-                break;
-            }
-            else if (ru1.ru_utime.tv_usec != ru2.ru_utime.tv_usec) {
-                rusage_diff = ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec;
-                break;
-            }
-            else if (ru1.ru_stime.tv_sec != ru2.ru_stime.tv_sec) {
-                rusage_diff = ((1000000 - ru1.ru_stime.tv_usec)
-                               + ru2.ru_stime.tv_usec);
-                break;
-            }
-            else if (ru1.ru_stime.tv_usec != ru2.ru_stime.tv_usec) {
-                rusage_diff = ru2.ru_stime.tv_usec - ru1.ru_stime.tv_usec;
-                break;
-            }
-        }
-    }
-#endif
-}
-
-static void
-do_start(ProfilerObject *self)
-{
-    self->active = 1;
-    GETTIMEOFDAY(&self->prev_timeofday);
-    if (self->lineevents)
-        PyEval_SetTrace((Py_tracefunc) tracer_callback, (PyObject *)self);
-    else
-        PyEval_SetProfile((Py_tracefunc) tracer_callback, (PyObject *)self);
-}
-
-static void
-do_stop(ProfilerObject *self)
-{
-    if (self->active) {
-        self->active = 0;
-        if (self->lineevents)
-            PyEval_SetTrace(NULL, NULL);
-        else
-            PyEval_SetProfile(NULL, NULL);
-    }
-    if (self->index > 0) {
-        /* Best effort to dump out any remaining data. */
-        flush_data(self);
-    }
-}
-
-static int
-is_available(ProfilerObject *self)
-{
-    if (self->active) {
-        PyErr_SetString(ProfilerError, "profiler already active");
-        return 0;
-    }
-    if (self->logfp == NULL) {
-        PyErr_SetString(ProfilerError, "profiler already closed");
-        return 0;
-    }
-    return 1;
-}
-
-
-/* Profiler object interface methods. */
-
-PyDoc_STRVAR(addinfo__doc__,
-"addinfo(key, value)\n"
-"Insert an ADD_INFO record into the log.");
-
-static PyObject *
-profiler_addinfo(ProfilerObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-    char *key, *value;
-
-    if (PyArg_ParseTuple(args, "ss:addinfo", &key, &value)) {
-        if (self->logfp == NULL)
-            PyErr_SetString(ProfilerError, "profiler already closed");
-        else {
-            if (pack_add_info(self, key, value) == 0) {
-                result = Py_None;
-                Py_INCREF(result);
-            }
-        }
-    }
-    return result;
-}
-
-PyDoc_STRVAR(close__doc__,
-"close()\n"
-"Shut down this profiler and close the log files, even if its active.");
-
-static PyObject *
-profiler_close(ProfilerObject *self)
-{
-    do_stop(self);
-    if (self->logfp != NULL) {
-        fclose(self->logfp);
-        self->logfp = NULL;
-    }
-    Py_INCREF(Py_None);
-    return Py_None;
-}
-
-#define fileno__doc__ logreader_fileno__doc__
-
-static PyObject *
-profiler_fileno(ProfilerObject *self)
-{
-    if (self->logfp == NULL) {
-        PyErr_SetString(PyExc_ValueError,
-                        "profiler's file object already closed");
-        return NULL;
-    }
-    return PyInt_FromLong(fileno(self->logfp));
-}
-
-PyDoc_STRVAR(runcall__doc__,
-"runcall(callable[, args[, kw]]) -> callable()\n"
-"Profile a specific function call, returning the result of that call.");
-
-static PyObject *
-profiler_runcall(ProfilerObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-    PyObject *callargs = NULL;
-    PyObject *callkw = NULL;
-    PyObject *callable;
-
-    if (PyArg_UnpackTuple(args, "runcall", 1, 3,
-                         &callable, &callargs, &callkw)) {
-        if (is_available(self)) {
-            do_start(self);
-            result = PyEval_CallObjectWithKeywords(callable, callargs, callkw);
-            do_stop(self);
-        }
-    }
-    return result;
-}
-
-PyDoc_STRVAR(runcode__doc__,
-"runcode(code, globals[, locals])\n"
-"Execute a code object while collecting profile data.  If locals is\n"
-"omitted, globals is used for the locals as well.");
-
-static PyObject *
-profiler_runcode(ProfilerObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-    PyCodeObject *code;
-    PyObject *globals;
-    PyObject *locals = NULL;
-
-    if (PyArg_ParseTuple(args, "O!O!|O:runcode",
-                         &PyCode_Type, &code,
-                         &PyDict_Type, &globals,
-                         &locals)) {
-        if (is_available(self)) {
-            if (locals == NULL || locals == Py_None)
-                locals = globals;
-            else if (!PyDict_Check(locals)) {
-                PyErr_SetString(PyExc_TypeError,
-                                "locals must be a dictionary or None");
-                return NULL;
-            }
-            do_start(self);
-            result = PyEval_EvalCode(code, globals, locals);
-            do_stop(self);
-#if 0
-            if (!PyErr_Occurred()) {
-                result = Py_None;
-                Py_INCREF(result);
-            }
-#endif
-        }
-    }
-    return result;
-}
-
-PyDoc_STRVAR(start__doc__,
-"start()\n"
-"Install this profiler for the current thread.");
-
-static PyObject *
-profiler_start(ProfilerObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-
-    if (is_available(self)) {
-        do_start(self);
-        result = Py_None;
-        Py_INCREF(result);
-    }
-    return result;
-}
-
-PyDoc_STRVAR(stop__doc__,
-"stop()\n"
-"Remove this profiler from the current thread.");
-
-static PyObject *
-profiler_stop(ProfilerObject *self, PyObject *args)
-{
-    PyObject *result = NULL;
-
-    if (!self->active)
-        PyErr_SetString(ProfilerError, "profiler not active");
-    else {
-        do_stop(self);
-        result = Py_None;
-        Py_INCREF(result);
-    }
-    return result;
-}
-
-
-/* Python API support. */
-
-static void
-profiler_dealloc(ProfilerObject *self)
-{
-    do_stop(self);
-    if (self->logfp != NULL)
-        fclose(self->logfp);
-    Py_XDECREF(self->filemap);
-    Py_XDECREF(self->logfilename);
-    PyObject_Del((PyObject *)self);
-}
-
-static PyMethodDef profiler_methods[] = {
-    {"addinfo", (PyCFunction)profiler_addinfo, METH_VARARGS, addinfo__doc__},
-    {"close",   (PyCFunction)profiler_close,   METH_NOARGS,  close__doc__},
-    {"fileno",  (PyCFunction)profiler_fileno,  METH_NOARGS,  fileno__doc__},
-    {"runcall", (PyCFunction)profiler_runcall, METH_VARARGS, runcall__doc__},
-    {"runcode", (PyCFunction)profiler_runcode, METH_VARARGS, runcode__doc__},
-    {"start",   (PyCFunction)profiler_start,   METH_NOARGS,  start__doc__},
-    {"stop",    (PyCFunction)profiler_stop,    METH_NOARGS,  stop__doc__},
-    {NULL, NULL}
-};
-
-static PyMemberDef profiler_members[] = {
-    {"frametimings", T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
-    {"lineevents",   T_LONG, offsetof(ProfilerObject, lineevents), READONLY},
-    {"linetimings",  T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
-    {NULL}
-};
-
-static PyObject *
-profiler_get_closed(ProfilerObject *self, void *closure)
-{
-    PyObject *result = (self->logfp == NULL) ? Py_True : Py_False;
-    Py_INCREF(result);
-    return result;
-}
-
-static PyGetSetDef profiler_getsets[] = {
-    {"closed", (getter)profiler_get_closed, NULL,
-     PyDoc_STR("True if the profiler's output file has already been closed.")},
-    {NULL}
-};
-
-
-PyDoc_STRVAR(profiler_object__doc__,
-"High-performance profiler object.\n"
-"\n"
-"Methods:\n"
-"\n"
-"close():      Stop the profiler and close the log files.\n"
-"fileno():     Returns the file descriptor of the log file.\n"
-"runcall():    Run a single function call with profiling enabled.\n"
-"runcode():    Execute a code object with profiling enabled.\n"
-"start():      Install the profiler and return.\n"
-"stop():       Remove the profiler.\n"
-"\n"
-"Attributes (read-only):\n"
-"\n"
-"closed:       True if the profiler has already been closed.\n"
-"frametimings: True if ENTER/EXIT events collect timing information.\n"
-"lineevents:   True if line events are reported to the profiler.\n"
-"linetimings:  True if line events collect timing information.");
-
-static PyTypeObject ProfilerType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "_hotshot.ProfilerType",		/* tp_name		*/
-    (int) sizeof(ProfilerObject),	/* tp_basicsize		*/
-    0,					/* tp_itemsize		*/
-    (destructor)profiler_dealloc,	/* tp_dealloc		*/
-    0,					/* tp_print		*/
-    0,					/* tp_getattr		*/
-    0,					/* tp_setattr		*/
-    0,					/* tp_compare		*/
-    0,					/* tp_repr		*/
-    0,					/* tp_as_number		*/
-    0,					/* tp_as_sequence	*/
-    0,					/* tp_as_mapping	*/
-    0,					/* tp_hash		*/
-    0,					/* tp_call		*/
-    0,					/* tp_str		*/
-    PyObject_GenericGetAttr,		/* tp_getattro		*/
-    0,					/* tp_setattro		*/
-    0,					/* tp_as_buffer		*/
-    Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
-    profiler_object__doc__,		/* tp_doc		*/
-    0,					/* tp_traverse		*/
-    0,					/* tp_clear		*/
-    0,					/* tp_richcompare	*/
-    0,					/* tp_weaklistoffset	*/
-    0,					/* tp_iter		*/
-    0,					/* tp_iternext		*/
-    profiler_methods,			/* tp_methods		*/
-    profiler_members,			/* tp_members		*/
-    profiler_getsets,			/* tp_getset		*/
-    0,					/* tp_base		*/
-    0,					/* tp_dict		*/
-    0,					/* tp_descr_get		*/
-    0,					/* tp_descr_set		*/
-};
-
-
-static PyMethodDef logreader_methods[] = {
-    {"close",   (PyCFunction)logreader_close,  METH_NOARGS,
-     logreader_close__doc__},
-    {"fileno",  (PyCFunction)logreader_fileno, METH_NOARGS,
-     logreader_fileno__doc__},
-    {NULL, NULL}
-};
-
-static PyMemberDef logreader_members[] = {
-    {"info", T_OBJECT, offsetof(LogReaderObject, info), READONLY,
-     PyDoc_STR("Dictionary mapping informational keys to lists of values.")},
-    {NULL}
-};
-
-
-PyDoc_STRVAR(logreader__doc__,
-"logreader(filename) --> log-iterator\n\
-Create a log-reader for the timing information file.");
-
-static PySequenceMethods logreader_as_sequence = {
-    0,					/* sq_length */
-    0,					/* sq_concat */
-    0,					/* sq_repeat */
-    (ssizeargfunc)logreader_sq_item,	/* sq_item */
-    0,					/* sq_slice */
-    0,					/* sq_ass_item */
-    0,					/* sq_ass_slice */
-    0,					/* sq_contains */
-    0,					/* sq_inplace_concat */
-    0,					/* sq_inplace_repeat */
-};
-
-static PyObject *
-logreader_get_closed(LogReaderObject *self, void *closure)
-{
-    PyObject *result = (self->logfp == NULL) ? Py_True : Py_False;
-    Py_INCREF(result);
-    return result;
-}
-
-static PyGetSetDef logreader_getsets[] = {
-    {"closed", (getter)logreader_get_closed, NULL,
-     PyDoc_STR("True if the logreader's input file has already been closed.")},
-    {NULL}
-};
-
-static PyTypeObject LogReaderType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "_hotshot.LogReaderType",		/* tp_name		*/
-    (int) sizeof(LogReaderObject),	/* tp_basicsize		*/
-    0,					/* tp_itemsize		*/
-    (destructor)logreader_dealloc,	/* tp_dealloc		*/
-    0,					/* tp_print		*/
-    0,					/* tp_getattr		*/
-    0,					/* tp_setattr		*/
-    0,					/* tp_compare		*/
-    0,					/* tp_repr		*/
-    0,					/* tp_as_number		*/
-    &logreader_as_sequence,		/* tp_as_sequence	*/
-    0,					/* tp_as_mapping	*/
-    0,					/* tp_hash		*/
-    0,					/* tp_call		*/
-    0,					/* tp_str		*/
-    PyObject_GenericGetAttr,		/* tp_getattro		*/
-    0,					/* tp_setattro		*/
-    0,					/* tp_as_buffer		*/
-    Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
-    logreader__doc__,			/* tp_doc		*/
-    0,					/* tp_traverse		*/
-    0,					/* tp_clear		*/
-    0,					/* tp_richcompare	*/
-    0,					/* tp_weaklistoffset	*/
-    PyObject_SelfIter,			/* tp_iter		*/
-    (iternextfunc)logreader_tp_iternext,/* tp_iternext		*/
-    logreader_methods,			/* tp_methods		*/
-    logreader_members,			/* tp_members		*/
-    logreader_getsets,			/* tp_getset		*/
-    0,					/* tp_base		*/
-    0,					/* tp_dict		*/
-    0,					/* tp_descr_get		*/
-    0,					/* tp_descr_set		*/
-};
-
-static PyObject *
-hotshot_logreader(PyObject *unused, PyObject *args)
-{
-    LogReaderObject *self = NULL;
-    char *filename;
-    int c;
-    int err = 0;
-
-    if (PyArg_ParseTuple(args, "s:logreader", &filename)) {
-        self = PyObject_New(LogReaderObject, &LogReaderType);
-        if (self != NULL) {
-            self->frametimings = 1;
-            self->linetimings = 0;
-            self->info = NULL;
-            self->logfp = fopen(filename, "rb");
-            if (self->logfp == NULL) {
-                PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
-                Py_DECREF(self);
-                self = NULL;
-                goto finally;
-            }
-            self->info = PyDict_New();
-            if (self->info == NULL) {
-                Py_DECREF(self);
-                goto finally;
-            }
-            /* read initial info */
-            for (;;) {
-                if ((c = fgetc(self->logfp)) == EOF) {
-                    eof_error(self);
-                    break;
-                }
-                if (c != WHAT_ADD_INFO) {
-                    ungetc(c, self->logfp);
-                    break;
-                }
-                err = unpack_add_info(self);
-                if (err) {
-                    if (err == ERR_EOF)
-                        eof_error(self);
-                    else
-                        PyErr_SetString(PyExc_RuntimeError,
-                                        "unexpected error");
-                    break;
-                }
-            }
-        }
-    }
- finally:
-    return (PyObject *) self;
-}
-
-
-/* Return a Python string that represents the version number without the
- * extra cruft added by revision control, even if the right options were
- * given to the "cvs export" command to make it not include the extra
- * cruft.
- */
-static char *
-get_version_string(void)
-{
-    static char *rcsid = "$Revision$";
-    char *rev = rcsid;
-    char *buffer;
-    int i = 0;
-
-    while (*rev && !isdigit(Py_CHARMASK(*rev)))
-        ++rev;
-    while (rev[i] != ' ' && rev[i] != '\0')
-        ++i;
-    buffer = (char *)malloc(i + 1);
-    if (buffer != NULL) {
-        memmove(buffer, rev, i);
-        buffer[i] = '\0';
-    }
-    return buffer;
-}
-
-/* Write out a RFC 822-style header with various useful bits of
- * information to make the output easier to manage.
- */
-static int
-write_header(ProfilerObject *self)
-{
-    char *buffer;
-    char cwdbuffer[PATH_MAX];
-    PyObject *temp;
-    Py_ssize_t i, len;
-
-    buffer = get_version_string();
-    if (buffer == NULL) {
-        PyErr_NoMemory();
-        return -1;
-    }
-    pack_add_info(self, "hotshot-version", buffer);
-    pack_add_info(self, "requested-frame-timings",
-                  (self->frametimings ? "yes" : "no"));
-    pack_add_info(self, "requested-line-events",
-                  (self->lineevents ? "yes" : "no"));
-    pack_add_info(self, "requested-line-timings",
-                  (self->linetimings ? "yes" : "no"));
-    pack_add_info(self, "platform", Py_GetPlatform());
-    pack_add_info(self, "executable", Py_GetProgramFullPath());
-    free(buffer);
-    buffer = (char *) Py_GetVersion();
-    if (buffer == NULL)
-        PyErr_Clear();
-    else
-        pack_add_info(self, "executable-version", buffer);
-
-#ifdef MS_WINDOWS
-    PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%I64d", frequency.QuadPart);
-    pack_add_info(self, "reported-performance-frequency", cwdbuffer);
-#else
-    PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", rusage_diff);
-    pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
-    PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", timeofday_diff);
-    pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
-#endif
-
-    pack_add_info(self, "current-directory",
-                  getcwd(cwdbuffer, sizeof cwdbuffer));
-
-    temp = PySys_GetObject("path");
-    if (temp == NULL || !PyList_Check(temp)) {
-	PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list");
-    	return -1;
-    }
-    len = PyList_GET_SIZE(temp);
-    for (i = 0; i < len; ++i) {
-        PyObject *item = PyList_GET_ITEM(temp, i);
-        buffer = PyString_AsString(item);
-        if (buffer == NULL) {
-            pack_add_info(self, "sys-path-entry", "<non-string-path-entry>");
-            PyErr_Clear();
-        }
-        else {
-            pack_add_info(self, "sys-path-entry", buffer);
-        }
-    }
-    pack_frame_times(self);
-    pack_line_times(self);
-
-    return 0;
-}
-
-PyDoc_STRVAR(profiler__doc__,
-"profiler(logfilename[, lineevents[, linetimes]]) -> profiler\n\
-Create a new profiler object.");
-
-static PyObject *
-hotshot_profiler(PyObject *unused, PyObject *args)
-{
-    char *logfilename;
-    ProfilerObject *self = NULL;
-    int lineevents = 0;
-    int linetimings = 1;
-
-    if (PyArg_ParseTuple(args, "s|ii:profiler", &logfilename,
-                         &lineevents, &linetimings)) {
-        self = PyObject_New(ProfilerObject, &ProfilerType);
-        if (self == NULL)
-            return NULL;
-        self->frametimings = 1;
-        self->lineevents = lineevents ? 1 : 0;
-        self->linetimings = (lineevents && linetimings) ? 1 : 0;
-        self->index = 0;
-        self->active = 0;
-        self->next_fileno = 0;
-        self->logfp = NULL;
-        self->logfilename = PyTuple_GET_ITEM(args, 0);
-        Py_INCREF(self->logfilename);
-        self->filemap = PyDict_New();
-        if (self->filemap == NULL) {
-            Py_DECREF(self);
-            return NULL;
-        }
-        self->logfp = fopen(logfilename, "wb");
-        if (self->logfp == NULL) {
-            Py_DECREF(self);
-            PyErr_SetFromErrnoWithFilename(PyExc_IOError, logfilename);
-            return NULL;
-        }
-        if (timeofday_diff == 0) {
-            /* Run this several times since sometimes the first
-             * doesn't give the lowest values, and we're really trying
-             * to determine the lowest.
-             */
-            calibrate();
-            calibrate();
-            calibrate();
-        }
-        if (write_header(self)) {
-            /* some error occurred, exception has been set */
-            Py_DECREF(self);
-            self = NULL;
-        }
-    }
-    return (PyObject *) self;
-}
-
-PyDoc_STRVAR(coverage__doc__,
-"coverage(logfilename) -> profiler\n\
-Returns a profiler that doesn't collect any timing information, which is\n\
-useful in building a coverage analysis tool.");
-
-static PyObject *
-hotshot_coverage(PyObject *unused, PyObject *args)
-{
-    char *logfilename;
-    PyObject *result = NULL;
-
-    if (PyArg_ParseTuple(args, "s:coverage", &logfilename)) {
-        result = hotshot_profiler(unused, args);
-        if (result != NULL) {
-            ProfilerObject *self = (ProfilerObject *) result;
-            self->frametimings = 0;
-            self->linetimings = 0;
-            self->lineevents = 1;
-        }
-    }
-    return result;
-}
-
-PyDoc_VAR(resolution__doc__) = 
-#ifdef MS_WINDOWS
-PyDoc_STR(
-"resolution() -> (performance-counter-ticks, update-frequency)\n"
-"Return the resolution of the timer provided by the QueryPerformanceCounter()\n"
-"function.  The first value is the smallest observed change, and the second\n"
-"is the result of QueryPerformanceFrequency()."
-)
-#else
-PyDoc_STR(
-"resolution() -> (gettimeofday-usecs, getrusage-usecs)\n"
-"Return the resolution of the timers provided by the gettimeofday() and\n"
-"getrusage() system calls, or -1 if the call is not supported."
-)
-#endif
-;
-
-static PyObject *
-hotshot_resolution(PyObject *self, PyObject *unused)
-{
-    if (timeofday_diff == 0) {
-        calibrate();
-        calibrate();
-        calibrate();
-    }
-#ifdef MS_WINDOWS
-    return Py_BuildValue("ii", timeofday_diff, frequency.LowPart);
-#else
-    return Py_BuildValue("ii", timeofday_diff, rusage_diff);
-#endif
-}
-
-
-static PyMethodDef functions[] = {
-    {"coverage",   hotshot_coverage,   METH_VARARGS, coverage__doc__},
-    {"profiler",   hotshot_profiler,   METH_VARARGS, profiler__doc__},
-    {"logreader",  hotshot_logreader,  METH_VARARGS, logreader__doc__},
-    {"resolution", hotshot_resolution, METH_NOARGS,  resolution__doc__},
-    {NULL, NULL}
-};
-
-
-void
-init_hotshot(void)
-{
-    PyObject *module;
-
-    Py_Type(&LogReaderType) = &PyType_Type;
-    Py_Type(&ProfilerType) = &PyType_Type;
-    module = Py_InitModule("_hotshot", functions);
-    if (module != NULL) {
-        char *s = get_version_string();
-
-        PyModule_AddStringConstant(module, "__version__", s);
-        free(s);
-        Py_INCREF(&LogReaderType);
-        PyModule_AddObject(module, "LogReaderType",
-                           (PyObject *)&LogReaderType);
-        Py_INCREF(&ProfilerType);
-        PyModule_AddObject(module, "ProfilerType",
-                           (PyObject *)&ProfilerType);
-
-        if (ProfilerError == NULL)
-            ProfilerError = PyErr_NewException("hotshot.ProfilerError",
-                                               NULL, NULL);
-        if (ProfilerError != NULL) {
-            Py_INCREF(ProfilerError);
-            PyModule_AddObject(module, "ProfilerError", ProfilerError);
-        }
-        PyModule_AddIntConstant(module, "WHAT_ENTER", WHAT_ENTER);
-        PyModule_AddIntConstant(module, "WHAT_EXIT", WHAT_EXIT);
-        PyModule_AddIntConstant(module, "WHAT_LINENO", WHAT_LINENO);
-        PyModule_AddIntConstant(module, "WHAT_OTHER", WHAT_OTHER);
-        PyModule_AddIntConstant(module, "WHAT_ADD_INFO", WHAT_ADD_INFO);
-        PyModule_AddIntConstant(module, "WHAT_DEFINE_FILE", WHAT_DEFINE_FILE);
-        PyModule_AddIntConstant(module, "WHAT_DEFINE_FUNC", WHAT_DEFINE_FUNC);
-        PyModule_AddIntConstant(module, "WHAT_LINE_TIMES", WHAT_LINE_TIMES);
-    }
-}

Modified: python/branches/py3k-importlib/Modules/_sqlite/connection.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/connection.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/connection.c	Thu Oct 11 23:44:13 2007
@@ -425,16 +425,16 @@
         sqlite3_result_int64(context, (PY_LONG_LONG)longval);
     } else if (PyFloat_Check(py_val)) {
         sqlite3_result_double(context, PyFloat_AsDouble(py_val));
-    } else if (PyBuffer_Check(py_val)) {
+    } else if (PyString_Check(py_val)) {
+        sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
+    } else if (PyUnicode_Check(py_val)) {
+        sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
+    } else if (PyObject_CheckBuffer(py_val)) {
         if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
             PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
         } else {
             sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
         }
-    } else if (PyString_Check(py_val)) {
-        sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
-    } else if (PyUnicode_Check(py_val)) {
-        sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
     } else {
         /* TODO: raise error */
     }
@@ -449,7 +449,6 @@
     const char* val_str;
     PY_LONG_LONG val_int;
     Py_ssize_t buflen;
-    void* raw_buffer;
 
     args = PyTuple_New(argc);
     if (!args) {
@@ -478,16 +477,8 @@
                 break;
             case SQLITE_BLOB:
                 buflen = sqlite3_value_bytes(cur_value);
-                cur_py_value = PyBuffer_New(buflen);
-                if (!cur_py_value) {
-                    break;
-                }
-                if (PyObject_AsWriteBuffer(cur_py_value, &raw_buffer, &buflen)) {
-                    Py_DECREF(cur_py_value);
-                    cur_py_value = NULL;
-                    break;
-                }
-                memcpy(raw_buffer, sqlite3_value_blob(cur_value), buflen);
+                cur_py_value = PyBytes_FromStringAndSize(
+                    sqlite3_value_blob(cur_value), buflen);
                 break;
             case SQLITE_NULL:
             default:

Modified: python/branches/py3k-importlib/Modules/_sqlite/cursor.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/cursor.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/cursor.c	Thu Oct 11 23:44:13 2007
@@ -296,7 +296,6 @@
     PyObject* converted;
     Py_ssize_t nbytes;
     PyObject* buffer;
-    void* raw_buffer;
     const char* val_str;
     char buf[200];
     const char* colname;
@@ -380,14 +379,11 @@
             } else {
                 /* coltype == SQLITE_BLOB */
                 nbytes = sqlite3_column_bytes(self->statement->st, i);
-                buffer = PyBuffer_New(nbytes);
+                buffer = PyBytes_FromStringAndSize(
+                    sqlite3_column_blob(self->statement->st, i), nbytes);
                 if (!buffer) {
                     break;
                 }
-                if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &nbytes)) {
-                    break;
-                }
-                memcpy(raw_buffer, sqlite3_column_blob(self->statement->st, i), nbytes);
                 converted = buffer;
             }
         }

Modified: python/branches/py3k-importlib/Modules/_sqlite/statement.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sqlite/statement.c	(original)
+++ python/branches/py3k-importlib/Modules/_sqlite/statement.c	Thu Oct 11 23:44:13 2007
@@ -102,13 +102,6 @@
 #endif
     } else if (PyFloat_Check(parameter)) {
         rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
-    } else if (PyBuffer_Check(parameter)) {
-        if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
-            rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
-        } else {
-            PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
-            rc = -1;
-        }
     } else if PyString_Check(parameter) {
         string = PyString_AsString(parameter);
         rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
@@ -118,6 +111,13 @@
 
         rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
         Py_DECREF(stringval);
+    } else if (PyObject_CheckBuffer(parameter)) {
+        if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
+            rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
+        } else {
+            PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
+            rc = -1;
+        }
     } else {
         rc = -1;
     }

Deleted: /python/branches/py3k-importlib/Objects/bufferobject.c
==============================================================================
--- /python/branches/py3k-importlib/Objects/bufferobject.c	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,724 +0,0 @@
-
-/* Buffer object implementation */
-
-#include "Python.h"
-
-
-typedef struct {
-	PyObject_HEAD
-	PyObject *b_base;
-	void *b_ptr;
-	Py_ssize_t b_size;
-	Py_ssize_t b_offset;
-	int b_readonly;
-	long b_hash;
-} PyBufferObject;
-
-
-static int
-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;
-		PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
-                if ((*bp->bf_getbuffer)(self->b_base, view, flags) < 0)
-                        return 0;
-                count = view->len;
-		/* apply constraints to the start/end */
-		if (self->b_offset > count)
-			offset = count;
-		else
-			offset = self->b_offset;
-                view->buf = (char*)view->buf + offset;
-		if (self->b_size == Py_END_OF_BUFFER)
-			view->len = count;
-		else
-			view->len = self->b_size;
-		if (offset + view->len > count)
-			view->len = count - offset;
-	}
-	return 1;
-}
-
-
-static int
-buffer_getbuf(PyBufferObject *self, Py_buffer *view, int flags)
-{
-        if (view == NULL) return 0;
-        if (!get_buf(self, view, flags))
-                return -1;
-        return PyBuffer_FillInfo(view, view->buf, view->len, self->b_readonly,
-                                 flags);
-}
-
-
-static void
-buffer_releasebuf(PyBufferObject *self, Py_buffer *view) 
-{
-        /* No-op if there is no self->b_base */
-	if (self->b_base != NULL) {
-		PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
-                if (bp->bf_releasebuffer != NULL) {
-                        (*bp->bf_releasebuffer)(self->b_base, view);
-                }
-        }
-}
-
-static PyObject *
-buffer_from_memory(PyObject *base, Py_ssize_t size, Py_ssize_t offset,
-                   void *ptr, int readonly)
-{
-	PyBufferObject * b;
-
-	if (size < 0 && size != Py_END_OF_BUFFER) {
-		PyErr_SetString(PyExc_ValueError,
-				"size must be zero or positive");
-		return NULL;
-	}
-	if (offset < 0) {
-		PyErr_SetString(PyExc_ValueError,
-				"offset must be zero or positive");
-		return NULL;
-	}
-
-	b = PyObject_NEW(PyBufferObject, &PyBuffer_Type);
-	if (b == NULL)
-		return NULL;
-
-	Py_XINCREF(base);
-	b->b_base = base;
-	b->b_ptr = ptr;
-	b->b_size = size;
-	b->b_offset = offset;
-	b->b_readonly = readonly;
-	b->b_hash = -1;
-
-	return (PyObject *) b;
-}
-
-static PyObject *
-buffer_from_object(PyObject *base, Py_ssize_t size, Py_ssize_t offset,
-                   int readonly)
-{
-	if (offset < 0) {
-		PyErr_SetString(PyExc_ValueError,
-				"offset must be zero or positive");
-		return NULL;
-	}
-	if (PyBuffer_Check(base) && (((PyBufferObject *)base)->b_base)) {
-		/* another buffer, refer to the base object */
-		PyBufferObject *b = (PyBufferObject *)base;
-		if (b->b_size != Py_END_OF_BUFFER) {
-			Py_ssize_t base_size = b->b_size - offset;
-			if (base_size < 0)
-				base_size = 0;
-			if (size == Py_END_OF_BUFFER || size > base_size)
-				size = base_size;
-		}
-		offset += b->b_offset;
-		base = b->b_base;
-	}
-	return buffer_from_memory(base, size, offset, NULL, readonly);
-}
-
-
-PyObject *
-PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
-{
-	PyBufferProcs *pb = base->ob_type->tp_as_buffer;
-
-	if (pb == NULL ||
-            pb->bf_getbuffer == NULL) {
-                PyErr_SetString(PyExc_TypeError, "buffer object expected");
-		return NULL;
-	}
-
-	return buffer_from_object(base, size, offset, 1);
-}
-
-PyObject *
-PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset,
-                             Py_ssize_t size)
-{
-	PyBufferProcs *pb = base->ob_type->tp_as_buffer;
-
-	if (pb == NULL ||
-            pb->bf_getbuffer == NULL) {
-		PyErr_SetString(PyExc_TypeError, "buffer object expected");
-		return NULL;
-	}
-
-	return buffer_from_object(base, size,  offset, 0);
-}
-
-PyObject *
-PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
-{
-	return buffer_from_memory(NULL, size, 0, ptr, 1);
-}
-
-PyObject *
-PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
-{
-	return buffer_from_memory(NULL, size, 0, ptr, 0);
-}
-
-PyObject *
-PyBuffer_New(Py_ssize_t size)
-{
-	PyObject *o;
-	PyBufferObject * b;
-
-	if (size < 0) {
-		PyErr_SetString(PyExc_ValueError,
-				"size must be zero or positive");
-		return NULL;
-	}
-	/* XXX: check for overflow in multiply */
-	/* Inline PyObject_New */
-	o = (PyObject *)PyObject_MALLOC(sizeof(*b) + size);
-	if (o == NULL)
-		return PyErr_NoMemory();
-	b = (PyBufferObject *) PyObject_INIT(o, &PyBuffer_Type);
-
-	b->b_base = NULL;
-	b->b_ptr = (void *)(b + 1);
-	b->b_size = size;
-	b->b_offset = 0;
-	b->b_readonly = 0;
-	b->b_hash = -1;
-
-	return o;
-}
-
-/* Methods */
-
-static PyObject *
-buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-	PyObject *ob;
-	Py_ssize_t offset = 0;
-	Py_ssize_t size = Py_END_OF_BUFFER;
-
-	if (!_PyArg_NoKeywords("buffer()", kw))
-		return NULL;
-
-	if (!PyArg_ParseTuple(args, "O|nn:buffer", &ob, &offset, &size))
-	    return NULL;
-	return PyBuffer_FromObject(ob, offset, size);
-}
-
-PyDoc_STRVAR(buffer_doc,
-"buffer(object [, offset[, size]])\n\
-\n\
-Create a new buffer object which references the given object.\n\
-The buffer will reference a slice of the target object from the\n\
-start of the object (or at the specified offset). The slice will\n\
-extend to the end of the target object (or with the specified size).");
-
-
-static void
-buffer_dealloc(PyBufferObject *self)
-{
-	Py_XDECREF(self->b_base);
-	PyObject_DEL(self);
-}
-
-static int
-get_bufx(PyObject *obj, Py_buffer *view, int flags)
-{
-	PyBufferProcs *bp;
-
-	if (PyBuffer_Check(obj)) {
-		if (!get_buf((PyBufferObject *)obj, view, flags)) {
-			PyErr_Clear();
-			return 0;
-		}
-		else
-			return 1;
-	}
-	bp = obj->ob_type->tp_as_buffer;
-	if (bp == NULL ||
-	    bp->bf_getbuffer == NULL)
-		return 0;
-	if ((*bp->bf_getbuffer)(obj, view, PyBUF_SIMPLE) < 0)
-		return 0;
-        return 1;
-}
-
-static PyObject *
-buffer_richcompare(PyObject *self, PyObject *other, int op)
-{
-	void *p1, *p2;
-	Py_ssize_t len1, len2, min_len;
-	int cmp, ok;
-        Py_buffer v1, v2;
-
-	ok = 1;
-	if (!get_bufx(self, &v1, PyBUF_SIMPLE))
-		ok = 0;
-	if (!get_bufx(other, &v2, PyBUF_SIMPLE)) {
-                if (ok) PyObject_ReleaseBuffer((PyObject *)self, &v1);
-		ok = 0;
-        }
-	if (!ok) {
-		/* If we can't get the buffers,
-		   == and != are still defined
-		   (and the objects are unequal) */
-		PyObject *result;
-		if (op == Py_EQ)
-			result = Py_False;
-		else if (op == Py_NE)
-			result = Py_True;
-		else
-			result = Py_NotImplemented;
-		Py_INCREF(result);
-		return result;
-	}
-        len1 = v1.len;
-        len2 = v2.len;
-        p1 = v1.buf;
-        p2 = v2.buf;
-	min_len = (len1 < len2) ? len1 : len2;
-	cmp = memcmp(p1, p2, min_len);
-	if (cmp == 0)
-		cmp = (len1 < len2) ? -1 :
-		      (len1 > len2) ? 1 : 0;
-        PyObject_ReleaseBuffer((PyObject *)self, &v1);
-        PyObject_ReleaseBuffer(other, &v2);
-	return Py_CmpToRich(op, cmp);
-}
-
-static PyObject *
-buffer_repr(PyBufferObject *self)
-{
-	const char *status = self->b_readonly ? "read-only" : "read-write";
-
-	if (self->b_base == NULL)
-		return PyUnicode_FromFormat(
-                                "<%s buffer ptr %p, size %zd at %p>",
-                                status,
-                                self->b_ptr,
-                                self->b_size,
-                                self);
-	else
-		return PyUnicode_FromFormat(
-			"<%s buffer for %p, size %zd, offset %zd at %p>",
-			status,
-			self->b_base,
-			self->b_size,
-			self->b_offset,
-			self);
-}
-
-static long
-buffer_hash(PyBufferObject *self)
-{
-        Py_buffer view;
-	register Py_ssize_t len;
-	register unsigned char *p;
-	register long x;
-
-	if (self->b_hash != -1)
-		return self->b_hash;
-
-        if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return -1;
-        if (!(self->b_readonly)) {
-                PyErr_SetString(PyExc_TypeError,
-                                "writable buffers are not hashable");
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-		return -1;
-	}
-                
-	p = (unsigned char *) view.buf;
-	len = view.len;
-	x = *p << 7;
-	while (--len >= 0)
-		x = (1000003*x) ^ *p++;
-	x ^= view.len;
-	if (x == -1)
-		x = -2;
-	self->b_hash = x;
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-	return x;
-}
-
-static PyObject *
-buffer_str(PyBufferObject *self)
-{
-        Py_buffer view;
-        PyObject *res;
-
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return NULL;
-	res = PyString_FromStringAndSize((const char *)view.buf, view.len);
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-        return res;
-}
-
-/* Sequence methods */
-
-static Py_ssize_t
-buffer_length(PyBufferObject *self)
-{
-        Py_buffer view;
-
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return -1;
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-	return view.len;
-}
-
-static PyObject *
-buffer_concat(PyBufferObject *self, PyObject *other)
-{
-	PyBufferProcs *pb = other->ob_type->tp_as_buffer;
-	char *p;
-	PyObject *ob;
-        Py_buffer view, view2;
-
-	if (pb == NULL ||
-            pb->bf_getbuffer == NULL)
-	{
-		PyErr_BadArgument();
-		return NULL;
-	}
-
- 	if (!get_buf(self, &view, PyBUF_SIMPLE))
- 		return NULL;
- 
-	/* optimize special case */
-        /* XXX bad idea type-wise */
-	if (view.len == 0) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-                Py_INCREF(other);
-                return other;
-	}
-
-        if (PyObject_GetBuffer((PyObject *)other, &view2, PyBUF_SIMPLE) < 0) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-                return NULL;
-        }
-
-	/* XXX(nnorwitz): need to check for overflow! */
- 	ob = PyBytes_FromStringAndSize(NULL, view.len+view2.len);
-	if (ob == NULL) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-                PyObject_ReleaseBuffer(other, &view2);
-		return NULL;
-        }
- 	p = PyBytes_AS_STRING(ob);
- 	memcpy(p, view.buf, view.len);
- 	memcpy(p + view.len, view2.buf, view2.len);
-
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-        PyObject_ReleaseBuffer(other, &view2);
-        return ob;
-}
-
-static PyObject *
-buffer_repeat(PyBufferObject *self, Py_ssize_t count)
-{
-	PyObject *ob;
-	register char *p;
-        Py_buffer view;
-
-	if (count < 0)
-		count = 0;
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return NULL;
-	/* XXX(nnorwitz): need to check for overflow! */
-	ob = PyBytes_FromStringAndSize(NULL, view.len * count);
-	if (ob == NULL)
-		return NULL;
-
-	p = PyBytes_AS_STRING(ob);
-	while (count--) {
-	    memcpy(p, view.buf, view.len);
-	    p += view.len;
-	}
-
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-	return ob;
-}
-
-static PyObject *
-buffer_item(PyBufferObject *self, Py_ssize_t idx)
-{
-        Py_buffer view;
-        PyObject *ob;
-
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return NULL;
-	if (idx < 0 || idx >= view.len) {
-		PyErr_SetString(PyExc_IndexError, "buffer index out of range");
-		return NULL;
-	}
-	ob = PyBytes_FromStringAndSize((char *)view.buf + idx, 1);
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-        return ob;
-}
-
-static PyObject *
-buffer_subscript(PyBufferObject *self, PyObject *item)
-{
-	Py_buffer view;
-	PyObject *ob;
-	
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return NULL;
-	if (PyIndex_Check(item)) {
-		Py_ssize_t idx = PyNumber_AsSsize_t(item, PyExc_IndexError);
-
-		if (idx == -1 && PyErr_Occurred())
-			return NULL;
-		if (idx < 0)
-			idx += view.len;
-		if (idx < 0 || idx >= view.len) {
-			PyErr_SetString(PyExc_IndexError,
-					"buffer index out of range");
-			return NULL;
-		}
-		ob = PyBytes_FromStringAndSize((char *)view.buf + idx, 1);
-		PyObject_ReleaseBuffer((PyObject *)self, &view);
-		return ob;
-	}
-	else if (PySlice_Check(item)) {
-		Py_ssize_t start, stop, step, slicelength, cur, i;
-
-		if (PySlice_GetIndicesEx((PySliceObject*)item, view.len,
-				 &start, &stop, &step, &slicelength) < 0) {
-			PyObject_ReleaseBuffer((PyObject *)self, &view);
-			return NULL;
-		}
-
-		if (slicelength <= 0) {
-			PyObject_ReleaseBuffer((PyObject *)self, &view);
-			return PyBytes_FromStringAndSize("", 0);
-		}
-		else if (step == 1) {
-			ob = PyBytes_FromStringAndSize((char *)view.buf +
-							start, stop - start);
-			PyObject_ReleaseBuffer((PyObject *)self, &view);
-			return ob;
-		}
-		else {
-			char *source_buf = (char *)view.buf;
-			char *result_buf = (char *)PyMem_Malloc(slicelength);
-
-			if (result_buf == NULL)
-				return PyErr_NoMemory();
-
-			for (cur = start, i = 0; i < slicelength;
-			     cur += step, i++) {
-				result_buf[i] = source_buf[cur];
-			}
-
-			ob = PyBytes_FromStringAndSize(result_buf,
-						       slicelength);
-			PyMem_Free(result_buf);
-			PyObject_ReleaseBuffer((PyObject *)self, &view);
-			return ob;
-		}
-	}
-	else {
-		PyErr_SetString(PyExc_TypeError,
-				"sequence index must be integer");
-		return NULL;
-	}
-}
-
-static int
-buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
-{
-	PyBufferProcs *pb;
-        Py_buffer view, view2;
-
-	if (!get_buf(self, &view, PyBUF_SIMPLE))
-		return -1;
-        
-	if (self->b_readonly || view.readonly) {
-		PyErr_SetString(PyExc_TypeError,
-				"buffer is read-only");
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-		return -1;
-	}
-
-	if (idx < 0 || idx >= view.len) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-		PyErr_SetString(PyExc_IndexError,
-				"buffer assignment index out of range");
-		return -1;
-	}
-
-	pb = other ? other->ob_type->tp_as_buffer : NULL;
-	if (pb == NULL ||
-            pb->bf_getbuffer == NULL) {
-		PyErr_BadArgument();
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-		return -1;
-	}
-        
-        if (PyObject_GetBuffer(other, &view2, PyBUF_SIMPLE) < 0) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-                return -1;
-        }
-	if (view.len != 1) {
-                PyObject_ReleaseBuffer((PyObject *)self, &view);
-                PyObject_ReleaseBuffer(other, &view2);
-		PyErr_SetString(PyExc_TypeError,
-				"right operand must be a single byte");
-		return -1;
-	}
-
-	((char *)(view.buf))[idx] = *((char *)(view2.buf));
-        PyObject_ReleaseBuffer((PyObject *)self, &view);
-        PyObject_ReleaseBuffer(other, &view2);
-	return 0;
-}
-
-static int
-buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
-{
-	Py_buffer v1;
-
-	if (!get_buf(self, &v1, PyBUF_SIMPLE))
-		return -1;
-	if (self->b_readonly || v1.readonly) {
-		PyErr_SetString(PyExc_TypeError,
-				"buffer is read-only");
-		PyObject_ReleaseBuffer((PyObject *)self, &v1);
-		return -1;
-	}
-	if (PyIndex_Check(item)) {
-		Py_ssize_t idx = PyNumber_AsSsize_t(item, PyExc_IndexError);
-		if (idx == -1 && PyErr_Occurred())
-			return -1;
-		if (idx < 0)
-			idx += v1.len;
-		PyObject_ReleaseBuffer((PyObject *)self, &v1);
-		return buffer_ass_item(self, idx, value);
-	}
-	else if (PySlice_Check(item)) {
-		Py_ssize_t start, stop, step, slicelength;
-		Py_buffer v2;
-		PyBufferProcs *pb;
-		
-		if (PySlice_GetIndicesEx((PySliceObject *)item, v1.len,
-				&start, &stop, &step, &slicelength) < 0) {
-			PyObject_ReleaseBuffer((PyObject *)self, &v1);
-			return -1;
-		}
-
-		pb = value ? value->ob_type->tp_as_buffer : NULL;
-		if (pb == NULL ||
-		    pb->bf_getbuffer == NULL) {
-		    	PyObject_ReleaseBuffer((PyObject *)self, &v1);
-			PyErr_BadArgument();
-			return -1;
-		}
-		if ((*pb->bf_getbuffer)(value, &v2, PyBUF_SIMPLE) < 0) {
-			PyObject_ReleaseBuffer((PyObject *)self, &v1);
-			return -1;
-		}
-
-		if (v2.len != slicelength) {
-			PyObject_ReleaseBuffer((PyObject *)self, &v1);
-			PyObject_ReleaseBuffer(value, &v2);
-			PyErr_SetString(PyExc_TypeError, "right operand"
-					" length must match slice length");
-			return -1;
-		}
-
-		if (slicelength == 0)
-			/* nothing to do */;
-		else if (step == 1)
-			memcpy((char *)v1.buf + start, v2.buf, slicelength);
-		else {
-			Py_ssize_t cur, i;
-			
-			for (cur = start, i = 0; i < slicelength;
-			     cur += step, i++) {
-				((char *)v1.buf)[cur] = ((char *)v2.buf)[i];
-			}
-		}
-		PyObject_ReleaseBuffer((PyObject *)self, &v1);
-		PyObject_ReleaseBuffer(value, &v2);
-		return 0;
-	} else {
-		PyErr_SetString(PyExc_TypeError,
-				"buffer indices must be integers");
-		PyObject_ReleaseBuffer((PyObject *)self, &v1);
-		return -1;
-	}
-}
-
-/* Buffer methods */
-
-static PySequenceMethods buffer_as_sequence = {
-	(lenfunc)buffer_length, /*sq_length*/
-	(binaryfunc)buffer_concat, /*sq_concat*/
-	(ssizeargfunc)buffer_repeat, /*sq_repeat*/
-	(ssizeargfunc)buffer_item, /*sq_item*/
-	0, /*sq_slice*/
-	(ssizeobjargproc)buffer_ass_item, /*sq_ass_item*/
-	0, /*sq_ass_slice*/
-};
-
-static PyMappingMethods buffer_as_mapping = {
-	(lenfunc)buffer_length,
-	(binaryfunc)buffer_subscript,
-	(objobjargproc)buffer_ass_subscript,
-};
-
-static PyBufferProcs buffer_as_buffer = {
-	(getbufferproc)buffer_getbuf,
-        (releasebufferproc)buffer_releasebuf,
-};
-
-PyTypeObject PyBuffer_Type = {
-	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"buffer",
-	sizeof(PyBufferObject),
-	0,
-	(destructor)buffer_dealloc, 		/* tp_dealloc */
-	0,					/* tp_print */
-	0,					/* tp_getattr */
-	0,					/* tp_setattr */
-	0,					/* tp_compare */
-	(reprfunc)buffer_repr,			/* tp_repr */
-	0,					/* tp_as_number */
-	&buffer_as_sequence,			/* tp_as_sequence */
-	&buffer_as_mapping,			/* tp_as_mapping */
-	(hashfunc)buffer_hash,			/* tp_hash */
-	0,					/* tp_call */
-	(reprfunc)buffer_str,			/* tp_str */
-	PyObject_GenericGetAttr,		/* tp_getattro */
-	0,					/* tp_setattro */
-	&buffer_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	buffer_doc,				/* tp_doc */
-	0,					/* tp_traverse */
-	0,					/* tp_clear */
-	buffer_richcompare,			/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	0,					/* tp_iter */
-	0,					/* tp_iternext */
-	0,					/* tp_methods */	
-	0,					/* tp_members */
-	0,					/* tp_getset */
-	0,					/* tp_base */
-	0,					/* tp_dict */
-	0,					/* tp_descr_get */
-	0,					/* tp_descr_set */
-	0,					/* tp_dictoffset */
-	0,					/* tp_init */
-	0,					/* tp_alloc */
-	buffer_new,				/* tp_new */
-};

Modified: python/branches/py3k-importlib/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/bytesobject.c	(original)
+++ python/branches/py3k-importlib/Objects/bytesobject.c	Thu Oct 11 23:44:13 2007
@@ -964,8 +964,8 @@
        error, even if the comparison is for equality. */
     if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
         PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
-            PyErr_SetString(PyExc_TypeError, "can't compare bytes and str");
-            return NULL;
+        Py_INCREF(Py_NotImplemented);
+        return Py_NotImplemented;
     }
 
     self_size = _getbuffer(self, &self_bytes);

Modified: python/branches/py3k-importlib/Objects/fileobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/fileobject.c	(original)
+++ python/branches/py3k-importlib/Objects/fileobject.c	Thu Oct 11 23:44:13 2007
@@ -145,7 +145,7 @@
 		value = _PyObject_Str(v);
 	}
 	else
-		value = PyObject_ReprStr8(v);
+		value = PyObject_Repr(v);
 	if (value == NULL) {
 		Py_DECREF(writer);
 		return -1;

Modified: python/branches/py3k-importlib/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/memoryobject.c	(original)
+++ python/branches/py3k-importlib/Objects/memoryobject.c	Thu Oct 11 23:44:13 2007
@@ -8,6 +8,8 @@
 {
         if (view != NULL)
 		*view = self->view;
+	if (self->base == NULL)
+		return 0;
         return self->base->ob_type->tp_as_buffer->bf_getbuffer(self->base, NULL,
                                                                PyBUF_FULL);
 }
@@ -15,7 +17,8 @@
 static void
 memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view)
 {
-        PyObject_ReleaseBuffer(self->base, NULL);
+	if (self->base != NULL)
+		PyObject_ReleaseBuffer(self->base, NULL);
 }
 
 PyDoc_STRVAR(memory_doc,

Modified: python/branches/py3k-importlib/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/stringobject.c	(original)
+++ python/branches/py3k-importlib/Objects/stringobject.c	Thu Oct 11 23:44:13 2007
@@ -4,7 +4,256 @@
 
 #include "Python.h"
 
-#include <ctype.h>
+/* Our own locale-independent ctype.h-like macros */
+/* XXX Move into a header file? */
+
+#define FLAG_LOWER  0x01
+#define FLAG_UPPER  0x02
+#define FLAG_ALPHA  (FLAG_LOWER|FLAG_UPPER)
+#define FLAG_DIGIT  0x04
+#define FLAG_ALNUM  (FLAG_ALPHA|FLAG_DIGIT)
+#define FLAG_SPACE  0x08
+#define FLAG_XDIGIT 0x10
+
+static unsigned int ctype_table[256] = {
+    0, /* 0x0 '\x00' */
+    0, /* 0x1 '\x01' */
+    0, /* 0x2 '\x02' */
+    0, /* 0x3 '\x03' */
+    0, /* 0x4 '\x04' */
+    0, /* 0x5 '\x05' */
+    0, /* 0x6 '\x06' */
+    0, /* 0x7 '\x07' */
+    0, /* 0x8 '\x08' */
+    FLAG_SPACE, /* 0x9 '\t' */
+    FLAG_SPACE, /* 0xa '\n' */
+    FLAG_SPACE, /* 0xb '\v' */
+    FLAG_SPACE, /* 0xc '\f' */
+    FLAG_SPACE, /* 0xd '\r' */
+    0, /* 0xe '\x0e' */
+    0, /* 0xf '\x0f' */
+    0, /* 0x10 '\x10' */
+    0, /* 0x11 '\x11' */
+    0, /* 0x12 '\x12' */
+    0, /* 0x13 '\x13' */
+    0, /* 0x14 '\x14' */
+    0, /* 0x15 '\x15' */
+    0, /* 0x16 '\x16' */
+    0, /* 0x17 '\x17' */
+    0, /* 0x18 '\x18' */
+    0, /* 0x19 '\x19' */
+    0, /* 0x1a '\x1a' */
+    0, /* 0x1b '\x1b' */
+    0, /* 0x1c '\x1c' */
+    0, /* 0x1d '\x1d' */
+    0, /* 0x1e '\x1e' */
+    0, /* 0x1f '\x1f' */
+    FLAG_SPACE, /* 0x20 ' ' */
+    0, /* 0x21 '!' */
+    0, /* 0x22 '"' */
+    0, /* 0x23 '#' */
+    0, /* 0x24 '$' */
+    0, /* 0x25 '%' */
+    0, /* 0x26 '&' */
+    0, /* 0x27 "'" */
+    0, /* 0x28 '(' */
+    0, /* 0x29 ')' */
+    0, /* 0x2a '*' */
+    0, /* 0x2b '+' */
+    0, /* 0x2c ',' */
+    0, /* 0x2d '-' */
+    0, /* 0x2e '.' */
+    0, /* 0x2f '/' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x30 '0' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x31 '1' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x32 '2' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x33 '3' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x34 '4' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x35 '5' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x36 '6' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x37 '7' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x38 '8' */
+    FLAG_DIGIT|FLAG_XDIGIT, /* 0x39 '9' */
+    0, /* 0x3a ':' */
+    0, /* 0x3b ';' */
+    0, /* 0x3c '<' */
+    0, /* 0x3d '=' */
+    0, /* 0x3e '>' */
+    0, /* 0x3f '?' */
+    0, /* 0x40 '@' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x41 'A' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x42 'B' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x43 'C' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x44 'D' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x45 'E' */
+    FLAG_UPPER|FLAG_XDIGIT, /* 0x46 'F' */
+    FLAG_UPPER, /* 0x47 'G' */
+    FLAG_UPPER, /* 0x48 'H' */
+    FLAG_UPPER, /* 0x49 'I' */
+    FLAG_UPPER, /* 0x4a 'J' */
+    FLAG_UPPER, /* 0x4b 'K' */
+    FLAG_UPPER, /* 0x4c 'L' */
+    FLAG_UPPER, /* 0x4d 'M' */
+    FLAG_UPPER, /* 0x4e 'N' */
+    FLAG_UPPER, /* 0x4f 'O' */
+    FLAG_UPPER, /* 0x50 'P' */
+    FLAG_UPPER, /* 0x51 'Q' */
+    FLAG_UPPER, /* 0x52 'R' */
+    FLAG_UPPER, /* 0x53 'S' */
+    FLAG_UPPER, /* 0x54 'T' */
+    FLAG_UPPER, /* 0x55 'U' */
+    FLAG_UPPER, /* 0x56 'V' */
+    FLAG_UPPER, /* 0x57 'W' */
+    FLAG_UPPER, /* 0x58 'X' */
+    FLAG_UPPER, /* 0x59 'Y' */
+    FLAG_UPPER, /* 0x5a 'Z' */
+    0, /* 0x5b '[' */
+    0, /* 0x5c '\\' */
+    0, /* 0x5d ']' */
+    0, /* 0x5e '^' */
+    0, /* 0x5f '_' */
+    0, /* 0x60 '`' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x61 'a' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x62 'b' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x63 'c' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x64 'd' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x65 'e' */
+    FLAG_LOWER|FLAG_XDIGIT, /* 0x66 'f' */
+    FLAG_LOWER, /* 0x67 'g' */
+    FLAG_LOWER, /* 0x68 'h' */
+    FLAG_LOWER, /* 0x69 'i' */
+    FLAG_LOWER, /* 0x6a 'j' */
+    FLAG_LOWER, /* 0x6b 'k' */
+    FLAG_LOWER, /* 0x6c 'l' */
+    FLAG_LOWER, /* 0x6d 'm' */
+    FLAG_LOWER, /* 0x6e 'n' */
+    FLAG_LOWER, /* 0x6f 'o' */
+    FLAG_LOWER, /* 0x70 'p' */
+    FLAG_LOWER, /* 0x71 'q' */
+    FLAG_LOWER, /* 0x72 'r' */
+    FLAG_LOWER, /* 0x73 's' */
+    FLAG_LOWER, /* 0x74 't' */
+    FLAG_LOWER, /* 0x75 'u' */
+    FLAG_LOWER, /* 0x76 'v' */
+    FLAG_LOWER, /* 0x77 'w' */
+    FLAG_LOWER, /* 0x78 'x' */
+    FLAG_LOWER, /* 0x79 'y' */
+    FLAG_LOWER, /* 0x7a 'z' */
+    0, /* 0x7b '{' */
+    0, /* 0x7c '|' */
+    0, /* 0x7d '}' */
+    0, /* 0x7e '~' */
+    0, /* 0x7f '\x7f' */
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+#define ISLOWER(c) (ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
+#define ISUPPER(c) (ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
+#define ISALPHA(c) (ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
+#define ISDIGIT(c) (ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
+#define ISXDIGIT(c) (ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
+#define ISALNUM(c) (ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
+#define ISSPACE(c) (ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
+
+#undef islower
+#define islower(c) undefined_islower(c)
+#undef isupper
+#define isupper(c) undefined_isupper(c)
+#undef isalpha
+#define isalpha(c) undefined_isalpha(c)
+#undef isdigit
+#define isdigit(c) undefined_isdigit(c)
+#undef isxdigit
+#define isxdigit(c) undefined_isxdigit(c)
+#undef isalnum
+#define isalnum(c) undefined_isalnum(c)
+#undef isspace
+#define isspace(c) undefined_isspace(c)
+
+static unsigned char ctype_tolower[256] = {
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+    0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+    0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+static unsigned char ctype_toupper[256] = {
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+    0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+    0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+    0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+    0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+#define TOLOWER(c) (ctype_tolower[Py_CHARMASK(c)])
+#define TOUPPER(c) (ctype_toupper[Py_CHARMASK(c)])
+
+#undef tolower
+#define tolower(c) undefined_tolower(c)
+#undef toupper
+#define toupper(c) undefined_toupper(c)
 
 #ifdef COUNT_ALLOCS
 int null_strings, one_strings;
@@ -173,7 +422,7 @@
 	for (f = format; *f; f++) {
 		if (*f == '%') {
 			const char* p = f;
-			while (*++f && *f != '%' && !isalpha(Py_CHARMASK(*f)))
+			while (*++f && *f != '%' && !ISALPHA(*f))
 				;
 
 			/* skip the 'l' or 'z' in {%ld, %zd, %lu, %zu} since
@@ -242,15 +491,15 @@
 			/* parse the width.precision part (we're only
 			   interested in the precision value, if any) */
 			n = 0;
-			while (isdigit(Py_CHARMASK(*f)))
+			while (ISDIGIT(*f))
 				n = (n*10) + *f++ - '0';
 			if (*f == '.') {
 				f++;
 				n = 0;
-				while (isdigit(Py_CHARMASK(*f)))
+				while (ISDIGIT(*f))
 					n = (n*10) + *f++ - '0';
 			}
-			while (*f && *f != '%' && !isalpha(Py_CHARMASK(*f)))
+			while (*f && *f != '%' && !ISALPHA(*f))
 				f++;
 			/* handle the long flag, but only for %ld and %lu.
 			   others can be added when necessary. */
@@ -606,23 +855,22 @@
 			*p++ = c;
 			break;
 		case 'x':
-			if (isxdigit(Py_CHARMASK(s[0]))
-			    && isxdigit(Py_CHARMASK(s[1]))) {
+			if (ISXDIGIT(s[0]) && ISXDIGIT(s[1])) {
 				unsigned int x = 0;
 				c = Py_CHARMASK(*s);
 				s++;
-				if (isdigit(c))
+				if (ISDIGIT(c))
 					x = c - '0';
-				else if (islower(c))
+				else if (ISLOWER(c))
 					x = 10 + c - 'a';
 				else
 					x = 10 + c - 'A';
 				x = x << 4;
 				c = Py_CHARMASK(*s);
 				s++;
-				if (isdigit(c))
+				if (ISDIGIT(c))
 					x += c - '0';
-				else if (islower(c))
+				else if (ISLOWER(c))
 					x += 10 + c - 'a';
 				else
 					x += 10 + c - 'A';
@@ -1250,10 +1498,10 @@
 /* Always force the list to the expected size. */
 #define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
 
-#define SKIP_SPACE(s, i, len)    { while (i<len &&  isspace(Py_CHARMASK(s[i]))) i++; }
-#define SKIP_NONSPACE(s, i, len) { while (i<len && !isspace(Py_CHARMASK(s[i]))) i++; }
-#define RSKIP_SPACE(s, i)        { while (i>=0  &&  isspace(Py_CHARMASK(s[i]))) i--; }
-#define RSKIP_NONSPACE(s, i)     { while (i>=0  && !isspace(Py_CHARMASK(s[i]))) i--; }
+#define SKIP_SPACE(s, i, len)    { while (i<len &&  ISSPACE(s[i])) i++; }
+#define SKIP_NONSPACE(s, i, len) { while (i<len && !ISSPACE(s[i])) i++; }
+#define RSKIP_SPACE(s, i)        { while (i>=0  &&  ISSPACE(s[i])) i--; }
+#define RSKIP_NONSPACE(s, i)     { while (i>=0  && !ISSPACE(s[i])) i--; }
 
 Py_LOCAL_INLINE(PyObject *)
 split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxsplit)
@@ -1869,7 +2117,7 @@
 
 	i = 0;
 	if (striptype != RIGHTSTRIP) {
-		while (i < len && isspace(Py_CHARMASK(s[i]))) {
+		while (i < len && ISSPACE(s[i])) {
 			i++;
 		}
 	}
@@ -1878,7 +2126,7 @@
 	if (striptype != LEFTSTRIP) {
 		do {
 			j--;
-		} while (j >= i && isspace(Py_CHARMASK(s[j])));
+		} while (j >= i && ISSPACE(s[j]));
 		j++;
 	}
 
@@ -1979,11 +2227,6 @@
 \n\
 Return a copy of the string S converted to lowercase.");
 
-/* _tolower and _toupper are defined by SUSv2, but they're not ISO C */
-#ifndef _tolower
-#define _tolower tolower
-#endif
-
 static PyObject *
 string_lower(PyStringObject *self)
 {
@@ -2001,8 +2244,8 @@
 
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(s[i]);
-		if (isupper(c))
-			s[i] = _tolower(c);
+		if (ISUPPER(c))
+			s[i] = TOLOWER(c);
 	}
 
 	return newobj;
@@ -2013,10 +2256,6 @@
 \n\
 Return a copy of the string S converted to uppercase.");
 
-#ifndef _toupper
-#define _toupper toupper
-#endif
-
 static PyObject *
 string_upper(PyStringObject *self)
 {
@@ -2034,8 +2273,8 @@
 
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(s[i]);
-		if (islower(c))
-			s[i] = _toupper(c);
+		if (ISLOWER(c))
+			s[i] = TOUPPER(c);
 	}
 
 	return newobj;
@@ -2061,13 +2300,13 @@
 	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
-		if (islower(c)) {
+		if (ISLOWER(c)) {
 			if (!previous_is_cased)
-			    c = toupper(c);
+			    c = TOUPPER(c);
 			previous_is_cased = 1;
-		} else if (isupper(c)) {
+		} else if (ISUPPER(c)) {
 			if (previous_is_cased)
-			    c = tolower(c);
+			    c = TOLOWER(c);
 			previous_is_cased = 1;
 		} else
 			previous_is_cased = 0;
@@ -2095,16 +2334,16 @@
 	s_new = PyString_AsString(newobj);
 	if (0 < n) {
 		int c = Py_CHARMASK(*s++);
-		if (islower(c))
-			*s_new = toupper(c);
+		if (ISLOWER(c))
+			*s_new = TOUPPER(c);
 		else
 			*s_new = c;
 		s_new++;
 	}
 	for (i = 1; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
-		if (isupper(c))
-			*s_new = tolower(c);
+		if (ISUPPER(c))
+			*s_new = TOLOWER(c);
 		else
 			*s_new = c;
 		s_new++;
@@ -2173,11 +2412,11 @@
 	s_new = PyString_AsString(newobj);
 	for (i = 0; i < n; i++) {
 		int c = Py_CHARMASK(*s++);
-		if (islower(c)) {
-			*s_new = toupper(c);
+		if (ISLOWER(c)) {
+			*s_new = TOUPPER(c);
 		}
-		else if (isupper(c)) {
-			*s_new = tolower(c);
+		else if (ISUPPER(c)) {
+			*s_new = TOLOWER(c);
 		}
 		else
 			*s_new = c;
@@ -3386,7 +3625,7 @@
 
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
-	isspace(*p))
+	ISSPACE(*p))
 	return PyBool_FromLong(1);
 
     /* Special case for empty strings */
@@ -3395,7 +3634,7 @@
 
     e = p + PyString_GET_SIZE(self);
     for (; p < e; p++) {
-	if (!isspace(*p))
+	if (!ISSPACE(*p))
 	    return PyBool_FromLong(0);
     }
     return PyBool_FromLong(1);
@@ -3417,7 +3656,7 @@
 
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1 &&
-	isalpha(*p))
+	ISALPHA(*p))
 	return PyBool_FromLong(1);
 
     /* Special case for empty strings */
@@ -3426,7 +3665,7 @@
 
     e = p + PyString_GET_SIZE(self);
     for (; p < e; p++) {
-	if (!isalpha(*p))
+	if (!ISALPHA(*p))
 	    return PyBool_FromLong(0);
     }
     return PyBool_FromLong(1);
@@ -3447,8 +3686,7 @@
     register const unsigned char *e;
 
     /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 &&
-	isalnum(*p))
+    if (PyString_GET_SIZE(self) == 1 && ISALNUM(*p))
 	return PyBool_FromLong(1);
 
     /* Special case for empty strings */
@@ -3457,7 +3695,7 @@
 
     e = p + PyString_GET_SIZE(self);
     for (; p < e; p++) {
-	if (!isalnum(*p))
+	if (!ISALNUM(*p))
 	    return PyBool_FromLong(0);
     }
     return PyBool_FromLong(1);
@@ -3478,8 +3716,7 @@
     register const unsigned char *e;
 
     /* Shortcut for single character strings */
-    if (PyString_GET_SIZE(self) == 1 &&
-	isdigit(*p))
+    if (PyString_GET_SIZE(self) == 1 && ISDIGIT(*p))
 	return PyBool_FromLong(1);
 
     /* Special case for empty strings */
@@ -3488,7 +3725,7 @@
 
     e = p + PyString_GET_SIZE(self);
     for (; p < e; p++) {
-	if (!isdigit(*p))
+	if (!ISDIGIT(*p))
 	    return PyBool_FromLong(0);
     }
     return PyBool_FromLong(1);
@@ -3511,7 +3748,7 @@
 
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(islower(*p) != 0);
+	return PyBool_FromLong(ISLOWER(*p));
 
     /* Special case for empty strings */
     if (PyString_GET_SIZE(self) == 0)
@@ -3520,9 +3757,9 @@
     e = p + PyString_GET_SIZE(self);
     cased = 0;
     for (; p < e; p++) {
-	if (isupper(*p))
+	if (ISUPPER(*p))
 	    return PyBool_FromLong(0);
-	else if (!cased && islower(*p))
+	else if (!cased && ISLOWER(*p))
 	    cased = 1;
     }
     return PyBool_FromLong(cased);
@@ -3545,7 +3782,7 @@
 
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(isupper(*p) != 0);
+	return PyBool_FromLong(ISUPPER(*p));
 
     /* Special case for empty strings */
     if (PyString_GET_SIZE(self) == 0)
@@ -3554,9 +3791,9 @@
     e = p + PyString_GET_SIZE(self);
     cased = 0;
     for (; p < e; p++) {
-	if (islower(*p))
+	if (ISLOWER(*p))
 	    return PyBool_FromLong(0);
-	else if (!cased && isupper(*p))
+	else if (!cased && ISUPPER(*p))
 	    cased = 1;
     }
     return PyBool_FromLong(cased);
@@ -3581,7 +3818,7 @@
 
     /* Shortcut for single character strings */
     if (PyString_GET_SIZE(self) == 1)
-	return PyBool_FromLong(isupper(*p) != 0);
+	return PyBool_FromLong(ISUPPER(*p));
 
     /* Special case for empty strings */
     if (PyString_GET_SIZE(self) == 0)
@@ -3593,13 +3830,13 @@
     for (; p < e; p++) {
 	register const unsigned char ch = *p;
 
-	if (isupper(ch)) {
+	if (ISUPPER(ch)) {
 	    if (previous_is_cased)
 		return PyBool_FromLong(0);
 	    previous_is_cased = 1;
 	    cased = 1;
 	}
-	else if (islower(ch)) {
+	else if (ISLOWER(ch)) {
 	    if (!previous_is_cased)
 		return PyBool_FromLong(0);
 	    previous_is_cased = 1;
@@ -4434,11 +4671,11 @@
 				if (--fmtcnt >= 0)
 					c = *fmt++;
 			}
-			else if (c >= 0 && isdigit(c)) {
+			else if (c >= 0 && ISDIGIT(c)) {
 				width = c - '0';
 				while (--fmtcnt >= 0) {
 					c = Py_CHARMASK(*fmt++);
-					if (!isdigit(c))
+					if (!ISDIGIT(c))
 						break;
 					if ((width*10) / 10 != width) {
 						PyErr_SetString(
@@ -4471,11 +4708,11 @@
 					if (--fmtcnt >= 0)
 						c = *fmt++;
 				}
-				else if (c >= 0 && isdigit(c)) {
+				else if (c >= 0 && ISDIGIT(c)) {
 					prec = c - '0';
 					while (--fmtcnt >= 0) {
 						c = Py_CHARMASK(*fmt++);
-						if (!isdigit(c))
+						if (!ISDIGIT(c))
 							break;
 						if ((prec*10) / 10 != prec) {
 							PyErr_SetString(

Modified: python/branches/py3k-importlib/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/unicodeobject.c	(original)
+++ python/branches/py3k-importlib/Objects/unicodeobject.c	Thu Oct 11 23:44:13 2007
@@ -1051,6 +1051,7 @@
 			   const char *errors)
 {
     PyObject *buffer = NULL, *unicode;
+    Py_buffer info;
 
     if (encoding == NULL)
 	encoding = PyUnicode_GetDefaultEncoding();
@@ -1068,7 +1069,10 @@
         return PyUnicode_DecodeASCII(s, size, errors);
 
     /* Decode via the codec registry */
-    buffer = PyBuffer_FromMemory((void *)s, size);
+    buffer = NULL;
+    if (PyBuffer_FillInfo(&info, (void *)s, size, 1, PyBUF_SIMPLE) < 0)
+        goto onError;
+    buffer = PyMemoryView_FromMemory(&info);
     if (buffer == NULL)
         goto onError;
     unicode = PyCodec_Decode(buffer, encoding, errors);

Modified: python/branches/py3k-importlib/PC/VC6/pythoncore.dsp
==============================================================================
--- python/branches/py3k-importlib/PC/VC6/pythoncore.dsp	(original)
+++ python/branches/py3k-importlib/PC/VC6/pythoncore.dsp	Thu Oct 11 23:44:13 2007
@@ -221,10 +221,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\Objects\bufferobject.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\Objects\cellobject.c
 # End Source File
 # Begin Source File

Modified: python/branches/py3k-importlib/PC/config.c
==============================================================================
--- python/branches/py3k-importlib/PC/config.c	(original)
+++ python/branches/py3k-importlib/PC/config.c	Thu Oct 11 23:44:13 2007
@@ -28,7 +28,6 @@
 #endif
 extern void init_codecs(void);
 extern void init_weakref(void);
-extern void init_hotshot(void);
 extern void initxxsubtype(void);
 extern void initzipimport(void);
 extern void init_random(void);

Modified: python/branches/py3k-importlib/PC/os2emx/Makefile
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/Makefile	(original)
+++ python/branches/py3k-importlib/PC/os2emx/Makefile	Thu Oct 11 23:44:13 2007
@@ -366,7 +366,6 @@
 SRC.OBJECT=	$(addprefix $(TOP), \
 		Objects/abstract.c \
 		Objects/boolobject.c \
-		Objects/bufferobject.c \
 		Objects/cellobject.c \
 		Objects/classobject.c \
 		Objects/cobject.c \

Modified: python/branches/py3k-importlib/PC/os2emx/python25.def
==============================================================================
--- python/branches/py3k-importlib/PC/os2emx/python25.def	(original)
+++ python/branches/py3k-importlib/PC/os2emx/python25.def	Thu Oct 11 23:44:13 2007
@@ -181,14 +181,6 @@
   "_Py_ZeroStruct"
   "_Py_TrueStruct"
 
-; From python25_s.lib(bufferobject)
-  "PyBuffer_FromObject"
-  "PyBuffer_FromReadWriteObject"
-  "PyBuffer_FromMemory"
-  "PyBuffer_FromReadWriteMemory"
-  "PyBuffer_New"
-  "PyBuffer_Type"
-
 ; From python25_s.lib(cellobject)
   "PyCell_New"
   "PyCell_Get"

Modified: python/branches/py3k-importlib/PCbuild/python.iss
==============================================================================
--- python/branches/py3k-importlib/PCbuild/python.iss	(original)
+++ python/branches/py3k-importlib/PCbuild/python.iss	Thu Oct 11 23:44:13 2007
@@ -174,10 +174,8 @@
 Source: Lib\distutils\*.*; DestDir: {app}\Lib\distutils; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
 Source: Lib\email\*.*; DestDir: {app}\Lib\email; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
 Source: Lib\encodings\*.*; DestDir: {app}\Lib\encodings; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
-Source: Lib\hotshot\*.*; DestDir: {app}\Lib\hotshot; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
 Source: Lib\lib-old\*.*; DestDir: {app}\Lib\lib-old; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
 Source: Lib\xml\*.*; DestDir: {app}\Lib\xml; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
-Source: Lib\hotshot\*.*; DestDir: {app}\Lib\hotshot; CopyMode: alwaysoverwrite; Components: main; Flags: recursesubdirs
 Source: Lib\test\*.*; DestDir: {app}\Lib\test; CopyMode: alwaysoverwrite; Components: test; Flags: recursesubdirs
 
 Source: Lib\site-packages\README.txt; DestDir: {app}\Lib\site-packages; CopyMode: alwaysoverwrite; Components: main
@@ -284,9 +282,6 @@
 Name: {app}\Lib\encodings\*.pyc; Type: files
 Name: {app}\Lib\encodings\*.pyo; Type: files
 Name: {app}\Lib\encodings; Type: dirifempty
-Name: {app}\Lib\hotshot\*.pyc; Type: files
-Name: {app}\Lib\hotshot\*.pyo; Type: files
-Name: {app}\Lib\hotshot; Type: dirifempty
 Name: {app}\Lib\lib-old\*.pyc; Type: files
 Name: {app}\Lib\lib-old\*.pyo; Type: files
 Name: {app}\Lib\lib-old; Type: dirifempty

Modified: python/branches/py3k-importlib/PCbuild/python20.wse
==============================================================================
--- python/branches/py3k-importlib/PCbuild/python20.wse	(original)
+++ python/branches/py3k-importlib/PCbuild/python20.wse	Thu Oct 11 23:44:13 2007
@@ -2024,14 +2024,6 @@
 item: Remark
 end
 item: Install File
-  Source=..\lib\hotshot\*.py
-  Destination=%MAINDIR%\Lib\hotshot
-  Description=Fast Python profiler
-  Flags=0000000000000010
-end
-item: Remark
-end
-item: Install File
   Source=..\lib\lib-old\*.py
   Destination=%MAINDIR%\Lib\lib-old
   Description=Obsolete modules

Modified: python/branches/py3k-importlib/PCbuild/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-importlib/PCbuild/pythoncore.vcproj	(original)
+++ python/branches/py3k-importlib/PCbuild/pythoncore.vcproj	Thu Oct 11 23:44:13 2007
@@ -380,9 +380,6 @@
 			RelativePath="..\Modules\_heapqmodule.c">
 		</File>
 		<File
-			RelativePath="..\Modules\_hotshot.c">
-		</File>
-		<File
 			RelativePath="..\Modules\_localemodule.c">
 		</File>
 		<File
@@ -443,9 +440,6 @@
 			RelativePath="..\Objects\boolobject.c">
 		</File>
 		<File
-			RelativePath="..\Objects\bufferobject.c">
-		</File>
-		<File
 			RelativePath="..\Objects\bytesobject.c">
 		</File>
 		<File

Modified: python/branches/py3k-importlib/PCbuild8/pythoncore/pythoncore.vcproj
==============================================================================
--- python/branches/py3k-importlib/PCbuild8/pythoncore/pythoncore.vcproj	(original)
+++ python/branches/py3k-importlib/PCbuild8/pythoncore/pythoncore.vcproj	Thu Oct 11 23:44:13 2007
@@ -788,10 +788,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\Objects\bufferobject.c"
-				>
-			</File>
-			<File
 				RelativePath="..\..\Objects\bytesobject.c"
 				>
 			</File>
@@ -978,10 +974,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\Include\bufferobject.h"
-				>
-			</File>
-			<File
 				RelativePath="..\..\Include\cellobject.h"
 				>
 			</File>

Modified: python/branches/py3k-importlib/Parser/tokenizer.c
==============================================================================
--- python/branches/py3k-importlib/Parser/tokenizer.c	(original)
+++ python/branches/py3k-importlib/Parser/tokenizer.c	Thu Oct 11 23:44:13 2007
@@ -357,7 +357,7 @@
      1) NULL: need to call tok->decoding_readline to get a new line
      2) PyUnicodeObject *: decoding_feof has called tok->decoding_readline and
            stored the result in tok->decoding_buffer
-     3) PyStringObject *: previous call to fp_readl did not have enough room
+     3) PyBytesObject *: previous call to fp_readl did not have enough room
            (in the s buffer) to copy entire contents of the line read
            by tok->decoding_readline.  tok->decoding_buffer has the overflow.
            In this case, fp_readl is called in a loop (with an expanded buffer)
@@ -625,7 +625,7 @@
 		utf8 = translate_into_utf8(str, tok->enc);
 		if (utf8 == NULL)
 			return error_ret(tok);
-		str = PyString_AsString(utf8);
+		str = PyBytes_AsString(utf8);
 	}
 	for (s = str;; s++) {
 		if (*s == '\0') break;
@@ -1556,7 +1556,10 @@
 		Py_DECREF(unicode_text);
 	}
 	if (!ret) {
-		PyErr_Print();
+		PyErr_Clear();
+	}
+        else {
+		assert(PyBytes_Check(ret));
 	}
 	return ret;
 }
@@ -1569,8 +1572,8 @@
 		/* convert source to original encondig */
 		PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);
 		if (lineobj != NULL) {
-			int linelen = PyString_Size(lineobj);
-			const char *line = PyString_AsString(lineobj);
+			int linelen = PyBytes_GET_SIZE(lineobj);
+			const char *line = PyBytes_AS_STRING(lineobj);
 			text = PyObject_MALLOC(linelen + 1);
 			if (text != NULL && line != NULL) {
 				if (linelen)
@@ -1582,9 +1585,11 @@
 			/* adjust error offset */
 			if (*offset > 1) {
 				PyObject *offsetobj = dec_utf8(tok->encoding, 
-							       tok->buf, *offset-1);
+							       tok->buf,
+							       *offset-1);
 				if (offsetobj) {
-					*offset = PyString_Size(offsetobj) + 1;
+					*offset = 1 +
+						PyBytes_GET_SIZE(offsetobj);
 					Py_DECREF(offsetobj);
 				}
 			}

Modified: python/branches/py3k-importlib/Python/errors.c
==============================================================================
--- python/branches/py3k-importlib/Python/errors.c	(original)
+++ python/branches/py3k-importlib/Python/errors.c	Thu Oct 11 23:44:13 2007
@@ -800,13 +800,11 @@
 	PyErr_Restore(exc, v, tb);
 }
 
-/* com_fetch_program_text will attempt to load the line of text that
-   the exception refers to.  If it fails, it will return NULL but will
-   not set an exception.
+/* Attempt to load the line of text that the exception refers to.  If it
+   fails, it will return NULL but will not set an exception.
 
    XXX The functionality of this function is quite similar to the
-   functionality in tb_displayline() in traceback.c.
-*/
+   functionality in tb_displayline() in traceback.c. */
 
 PyObject *
 PyErr_ProgramText(const char *filename, int lineno)
@@ -824,7 +822,8 @@
 		char *pLastChar = &linebuf[sizeof(linebuf) - 2];
 		do {
 			*pLastChar = '\0';
-			if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)
+			if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
+						     fp, NULL) == NULL)
 				break;
 			/* fgets read *something*; if it didn't get as
 			   far as pLastChar, it must have found a newline
@@ -836,9 +835,13 @@
 	fclose(fp);
 	if (i == lineno) {
 		char *p = linebuf;
+                PyObject *res;
 		while (*p == ' ' || *p == '\t' || *p == '\014')
 			p++;
-		return PyUnicode_FromString(p);
+		res = PyUnicode_FromString(p);
+                if (res == NULL)
+			PyErr_Clear();
+		return res;
 	}
 	return NULL;
 }

Modified: python/branches/py3k-importlib/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-importlib/Python/pythonrun.c	(original)
+++ python/branches/py3k-importlib/Python/pythonrun.c	Thu Oct 11 23:44:13 2007
@@ -764,19 +764,19 @@
 	}
 	v = PySys_GetObject("ps1");
 	if (v != NULL) {
-		v = PyObject_Str(v);
+		v = PyObject_Unicode(v);
 		if (v == NULL)
 			PyErr_Clear();
-		else if (PyString_Check(v))
-			ps1 = PyString_AsString(v);
+		else if (PyUnicode_Check(v))
+			ps1 = PyUnicode_AsString(v);
 	}
 	w = PySys_GetObject("ps2");
 	if (w != NULL) {
-		w = PyObject_Str(w);
+		w = PyObject_Unicode(w);
 		if (w == NULL)
 			PyErr_Clear();
-		else if (PyString_Check(w))
-			ps2 = PyString_AsString(w);
+		else if (PyUnicode_Check(w))
+			ps2 = PyUnicode_AsString(w);
 	}
 	arena = PyArena_New();
 	if (arena == NULL) {
@@ -981,7 +981,8 @@
 		goto finally;
 	if (v == Py_None)
 		*text = NULL;
-	else if (! (*text = PyString_AsString(v)))
+        else if (!PyUnicode_Check(v) ||
+		 !(*text = PyUnicode_AsString(v)))
 		goto finally;
 	Py_DECREF(v);
 	return 1;
@@ -1095,7 +1096,7 @@
 	if (set_sys_last_vars) {
 		PySys_SetObject("last_type", exception);
 		PySys_SetObject("last_value", v);
-		PySys_SetObject("last_traceback", tb);
+		PySys_SetObject("last_traceback", tb ? tb : Py_None);
 	}
 	hook = PySys_GetObject("excepthook");
 	if (hook) {
@@ -1197,10 +1198,13 @@
 			}
 
 			moduleName = PyObject_GetAttrString(exception, "__module__");
-			if (moduleName == NULL)
+			if (moduleName == NULL || !PyUnicode_Check(moduleName))
+			{
+				Py_DECREF(moduleName);
 				err = PyFile_WriteString("<unknown>", f);
+			}
 			else {
-				char* modstr = PyString_AsString(moduleName);
+				char* modstr = PyUnicode_AsString(moduleName);
 				if (modstr && strcmp(modstr, "__builtin__"))
 				{
 					err = PyFile_WriteString(modstr, f);
@@ -1218,14 +1222,14 @@
 		else
 			err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
 		if (err == 0 && (value != Py_None)) {
-			PyObject *s = PyObject_Str(value);
+			PyObject *s = PyObject_Unicode(value);
 			/* only print colon if the str() of the
 			   object is not the empty string
 			*/
 			if (s == NULL)
 				err = -1;
-			else if (!PyString_Check(s) ||
-				 PyString_GET_SIZE(s) != 0)
+			else if (!PyUnicode_Check(s) ||
+				 PyUnicode_GetSize(s) != 0)
 				err = PyFile_WriteString(": ", f);
 			if (err == 0)
 			  err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
@@ -1532,9 +1536,9 @@
 		PyObject *type, *value, *tb;
 		PyErr_Fetch(&type, &value, &tb);
 		if (value != NULL) {
-			u = PyObject_Str(value);
+			u = PyObject_Unicode(value);
 			if (u != NULL) {
-				msg = PyString_AsString(u);
+				msg = PyUnicode_AsString(u);
 			}
 		}
 		if (msg == NULL)

Deleted: /python/branches/py3k-importlib/Tools/scripts/hotshotmain.py
==============================================================================
--- /python/branches/py3k-importlib/Tools/scripts/hotshotmain.py	Thu Oct 11 23:44:13 2007
+++ (empty file)
@@ -1,60 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
-
-"""
-Run a Python script under hotshot's control.
-
-Adapted from a posting on python-dev by Walter Dörwald
-
-usage %prog [ %prog args ] filename [ filename args ]
-
-Any arguments after the filename are used as sys.argv for the filename.
-"""
-
-import sys
-import optparse
-import os
-import hotshot
-import hotshot.stats
-
-PROFILE = "hotshot.prof"
-
-def run_hotshot(filename, profile, args):
-    prof = hotshot.Profile(profile)
-    sys.path.insert(0, os.path.dirname(filename))
-    sys.argv = [filename] + args
-    fp = open(filename)
-    try:
-        script = fp.read()
-    finally:
-        fp.close()
-    prof.run("exec(%r)" % script)
-    prof.close()
-    stats = hotshot.stats.load(profile)
-    stats.sort_stats("time", "calls")
-
-    # print_stats uses unadorned print statements, so the only way
-    # to force output to stderr is to reassign sys.stdout temporarily
-    save_stdout = sys.stdout
-    sys.stdout = sys.stderr
-    stats.print_stats()
-    sys.stdout = save_stdout
-
-    return 0
-
-def main(args):
-    parser = optparse.OptionParser(__doc__)
-    parser.disable_interspersed_args()
-    parser.add_option("-p", "--profile", action="store", default=PROFILE,
-                      dest="profile", help='Specify profile file to use')
-    (options, args) = parser.parse_args(args)
-
-    if len(args) == 0:
-        parser.print_help("missing script to execute")
-        return 1
-
-    filename = args[0]
-    return run_hotshot(filename, options.profile, args[1:])
-
-if __name__ == "__main__":
-    sys.exit(main(sys.argv[1:]))

Modified: python/branches/py3k-importlib/setup.py
==============================================================================
--- python/branches/py3k-importlib/setup.py	(original)
+++ python/branches/py3k-importlib/setup.py	Thu Oct 11 23:44:13 2007
@@ -413,8 +413,7 @@
         exts.append( Extension("atexit", ["atexitmodule.c"]) )
         # Python C API test module
         exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
-        # profilers (_lsprof is for cProfile.py)
-        exts.append( Extension('_hotshot', ['_hotshot.c']) )
+        # profiler (_lsprof is for cProfile.py)
         exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) )
         # static Unicode character database
         exts.append( Extension('unicodedata', ['unicodedata.c']) )


More information about the Python-3000-checkins mailing list