Merged revisions 53304-53433,53435-53450 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r53304 | vinay.sajip | 2007-01-09 15:50:28 +0100 (Tue, 09 Jan 2007) | 1 line

  Bug #1627575: Added _open() method to FileHandler which can be used to reopen files. The FileHandler instance now saves the encoding (which can be None) in an attribute called "encoding".
........
  r53305 | vinay.sajip | 2007-01-09 15:51:36 +0100 (Tue, 09 Jan 2007) | 1 line

  Added entry about addition of _open() method to logging.FileHandler.
........
  r53306 | vinay.sajip | 2007-01-09 15:54:56 +0100 (Tue, 09 Jan 2007) | 1 line

  Added a docstring
........
  r53316 | thomas.heller | 2007-01-09 20:19:33 +0100 (Tue, 09 Jan 2007) | 4 lines

  Verify the sizes of the basic ctypes data types against the struct
  module.

  Will backport to release25-maint.
........
  r53340 | gustavo.niemeyer | 2007-01-10 17:13:40 +0100 (Wed, 10 Jan 2007) | 3 lines

  Mention in the int() docstring that a base zero has meaning, as
  stated in http://docs.python.org/lib/built-in-funcs.html as well.
........
  r53341 | gustavo.niemeyer | 2007-01-10 17:15:48 +0100 (Wed, 10 Jan 2007) | 2 lines

  Minor change in int() docstring for proper spacing.
........
  r53358 | thomas.heller | 2007-01-10 21:12:13 +0100 (Wed, 10 Jan 2007) | 1 line

  Change the ctypes version number to "1.1.0".
........
  r53361 | thomas.heller | 2007-01-10 21:51:19 +0100 (Wed, 10 Jan 2007) | 1 line

  Must change the version number in the _ctypes extension as well.
........
  r53362 | guido.van.rossum | 2007-01-11 00:12:56 +0100 (Thu, 11 Jan 2007) | 3 lines

  Fix the signature of log_error().  (A subclass that did the right thing
  was getting complaints from pychecker.)
........
  r53370 | matthias.klose | 2007-01-11 11:26:31 +0100 (Thu, 11 Jan 2007) | 2 lines

  - Make the documentation match the code and the docstring
........
  r53375 | matthias.klose | 2007-01-11 12:44:04 +0100 (Thu, 11 Jan 2007) | 2 lines

  - idle: Honor the "Cancel" action in the save dialog (Debian bug #299092).
........
  r53381 | raymond.hettinger | 2007-01-11 19:22:55 +0100 (Thu, 11 Jan 2007) | 1 line

  SF #1486663 -- Allow keyword args in subclasses of set() and frozenset().
........
  r53388 | thomas.heller | 2007-01-11 22:18:56 +0100 (Thu, 11 Jan 2007) | 4 lines

  Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions
  of HANDLE, WPARAM, LPARAM data types.  Make parameterless foreign
  function calls work.
........
  r53390 | thomas.heller | 2007-01-11 22:23:12 +0100 (Thu, 11 Jan 2007) | 2 lines

  Correct the comments: the code is right.
........
  r53393 | brett.cannon | 2007-01-12 08:27:52 +0100 (Fri, 12 Jan 2007) | 3 lines

  Fix error where the end of a funcdesc environment was accidentally moved too
  far down.
........
  r53397 | anthony.baxter | 2007-01-12 10:35:56 +0100 (Fri, 12 Jan 2007) | 3 lines

  add parsetok.h as a dependency - previously, changing this file doesn't
  cause the right files to be rebuilt.
........
  r53401 | thomas.heller | 2007-01-12 21:08:19 +0100 (Fri, 12 Jan 2007) | 3 lines

  Avoid warnings in the test suite because ctypes.wintypes cannot be
  imported on non-windows systems.
........
  r53402 | thomas.heller | 2007-01-12 21:17:34 +0100 (Fri, 12 Jan 2007) | 6 lines

  patch #1610795: BSD version of ctypes.util.find_library, by Martin
  Kammerhofer.

  release25-maint backport candidate, but the release manager has to
  decide.
........
  r53403 | thomas.heller | 2007-01-12 21:21:53 +0100 (Fri, 12 Jan 2007) | 3 lines

  patch #1610795: BSD version of ctypes.util.find_library, by Martin
  Kammerhofer.
........
  r53406 | brett.cannon | 2007-01-13 01:29:49 +0100 (Sat, 13 Jan 2007) | 2 lines

  Deprecate the sets module.
........
  r53407 | georg.brandl | 2007-01-13 13:31:51 +0100 (Sat, 13 Jan 2007) | 3 lines

  Fix typo.
........
  r53409 | marc-andre.lemburg | 2007-01-13 22:00:08 +0100 (Sat, 13 Jan 2007) | 16 lines

  Bump version number and change copyright year.

  Add new API linux_distribution() which supports reading the full distribution
  name and also knows how to parse LSB-style release files.

  Redirect the old dist() API to the new API (using the short distribution name
  taken from the release file filename).

  Add branch and revision to _sys_version().

  Add work-around for Cygwin to libc_ver().

  Add support for IronPython (thanks for Anthony Baxter) and make
  Jython support more robust.
........
  r53410 | neal.norwitz | 2007-01-13 22:22:37 +0100 (Sat, 13 Jan 2007) | 1 line

  Fix grammar in docstrings
........
  r53411 | marc-andre.lemburg | 2007-01-13 23:32:21 +0100 (Sat, 13 Jan 2007) | 9 lines

  Add parameter sys_version to _sys_version().

  Change the cache for _sys_version() to take the parameter into account.

  Add support for parsing the IronPython 1.0.1 sys.version value - even
  though it still returns '1.0.0'; the version string no longer includes
  the patch level.
........
  r53412 | peter.astrand | 2007-01-13 23:35:35 +0100 (Sat, 13 Jan 2007) | 1 line

  Fix for bug #1634343: allow specifying empty arguments on Windows
........
  r53414 | marc-andre.lemburg | 2007-01-13 23:59:36 +0100 (Sat, 13 Jan 2007) | 14 lines

  Add Python implementation to the machine details.

  Pretty-print the Python version used for running PyBench.

  Let the user know when calibration has finished.

  [ 1563844 ] pybench support for IronPython:

  Simplify Unicode version detection.

  Make garbage collection and check interval settings optional if
  the Python implementation doesn't support thess (e.g. IronPython).
........
  r53415 | marc-andre.lemburg | 2007-01-14 00:13:54 +0100 (Sun, 14 Jan 2007) | 5 lines

  Use defaults if sys.executable isn't set (e.g. on Jython).

  This change allows running PyBench under Jython.
........
  r53416 | marc-andre.lemburg | 2007-01-14 00:15:33 +0100 (Sun, 14 Jan 2007) | 3 lines

  Jython doesn't have sys.setcheckinterval() - ignore it in that case.
........
  r53420 | gerhard.haering | 2007-01-14 02:43:50 +0100 (Sun, 14 Jan 2007) | 29 lines

  Merged changes from standalone version 2.3.3. This should probably all be
  merged into the 2.5 maintenance branch:

  - self->statement was not checked while fetching data, which could
    lead to crashes if you used the pysqlite API in unusual ways.
    Closing the cursor and continuing to fetch data was enough.

  - Converters are stored in a converters dictionary. The converter name
    is uppercased first. The old upper-casing algorithm was wrong and
    was replaced by a simple call to the Python string's upper() method
    instead.

  -Applied patch by Glyph Lefkowitz that fixes the problem with
   subsequent SQLITE_SCHEMA errors.

  - Improvement to the row type: rows can now be iterated over and have a keys()
    method. This improves compatibility with both tuple and dict a lot.

  - A bugfix for the subsecond resolution in timestamps.

  - Corrected the way the flags PARSE_DECLTYPES and PARSE_COLNAMES are
    checked for. Now they work as documented.

  - gcc on Linux sucks. It exports all symbols by default in shared
    libraries, so if symbols are not unique it can lead to problems with
    symbol lookup.  pysqlite used to crash under Apache when mod_cache
    was enabled because both modules had the symbol cache_init. I fixed
    this by applying the prefix pysqlite_ almost everywhere. Sigh.
........
  r53423 | guido.van.rossum | 2007-01-14 04:46:33 +0100 (Sun, 14 Jan 2007) | 2 lines

  Remove a dependency of this test on $COLUMNS.
........
  r53425 | ka-ping.yee | 2007-01-14 05:25:15 +0100 (Sun, 14 Jan 2007) | 3 lines

  Handle old-style instances more gracefully (display documentation on
  the relevant class instead of documentation on <type 'instance'>).
........
  r53440 | vinay.sajip | 2007-01-14 22:49:59 +0100 (Sun, 14 Jan 2007) | 1 line

  Added WatchedFileHandler (based on SF patch #1598415)
........
  r53441 | vinay.sajip | 2007-01-14 22:50:50 +0100 (Sun, 14 Jan 2007) | 1 line

  Added documentation for WatchedFileHandler (based on SF patch #1598415)
........
  r53442 | guido.van.rossum | 2007-01-15 01:02:35 +0100 (Mon, 15 Jan 2007) | 2 lines

  Doc patch matching r53434 (htonl etc. now always take/return positive ints).
........
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 703af15..924d582 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -32,7 +32,7 @@
 
 #include "pythread.h"
 
-static int connection_set_isolation_level(Connection* self, PyObject* isolation_level);
+static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level);
 
 
 void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len)
@@ -43,11 +43,11 @@
 #if SQLITE_VERSION_NUMBER >= 3003003
     sqlite3_result_error(ctx, errmsg, len);
 #else
-    PyErr_SetString(OperationalError, errmsg);
+    PyErr_SetString(pysqlite_OperationalError, errmsg);
 #endif
 }
 
-int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
+int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
 
@@ -82,7 +82,7 @@
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         return -1;
     }
 
@@ -95,10 +95,10 @@
         Py_INCREF(isolation_level);
     }
     self->isolation_level = NULL;
-    connection_set_isolation_level(self, isolation_level);
+    pysqlite_connection_set_isolation_level(self, isolation_level);
     Py_DECREF(isolation_level);
 
-    self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "Oi", self, cached_statements);
+    self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "Oi", self, cached_statements);
     if (PyErr_Occurred()) {
         return -1;
     }
@@ -135,41 +135,41 @@
         return -1;
     }
 
-    self->Warning = Warning;
-    self->Error = Error;
-    self->InterfaceError = InterfaceError;
-    self->DatabaseError = DatabaseError;
-    self->DataError = DataError;
-    self->OperationalError = OperationalError;
-    self->IntegrityError = IntegrityError;
-    self->InternalError = InternalError;
-    self->ProgrammingError = ProgrammingError;
-    self->NotSupportedError = NotSupportedError;
+    self->Warning               = pysqlite_Warning;
+    self->Error                 = pysqlite_Error;
+    self->InterfaceError        = pysqlite_InterfaceError;
+    self->DatabaseError         = pysqlite_DatabaseError;
+    self->DataError             = pysqlite_DataError;
+    self->OperationalError      = pysqlite_OperationalError;
+    self->IntegrityError        = pysqlite_IntegrityError;
+    self->InternalError         = pysqlite_InternalError;
+    self->ProgrammingError      = pysqlite_ProgrammingError;
+    self->NotSupportedError     = pysqlite_NotSupportedError;
 
     return 0;
 }
 
 /* Empty the entire statement cache of this connection */
-void flush_statement_cache(Connection* self)
+void pysqlite_flush_statement_cache(pysqlite_Connection* self)
 {
-    Node* node;
-    Statement* statement;
+    pysqlite_Node* node;
+    pysqlite_Statement* statement;
 
     node = self->statement_cache->first;
 
     while (node) {
-        statement = (Statement*)(node->data);
-        (void)statement_finalize(statement);
+        statement = (pysqlite_Statement*)(node->data);
+        (void)pysqlite_statement_finalize(statement);
         node = node->next;
     }
 
     Py_DECREF(self->statement_cache);
-    self->statement_cache = (Cache*)PyObject_CallFunction((PyObject*)&CacheType, "O", self);
+    self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "O", self);
     Py_DECREF(self);
     self->statement_cache->decref_factory = 0;
 }
 
-void reset_all_statements(Connection* self)
+void pysqlite_reset_all_statements(pysqlite_Connection* self)
 {
     int i;
     PyObject* weakref;
@@ -179,12 +179,12 @@
         weakref = PyList_GetItem(self->statements, i);
         statement = PyWeakref_GetObject(weakref);
         if (statement != Py_None) {
-            (void)statement_reset((Statement*)statement);
+            (void)pysqlite_statement_reset((pysqlite_Statement*)statement);
         }
     }
 }
 
-void connection_dealloc(Connection* self)
+void pysqlite_connection_dealloc(pysqlite_Connection* self)
 {
     Py_XDECREF(self->statement_cache);
 
@@ -208,7 +208,7 @@
     self->ob_type->tp_free((PyObject*)self);
 }
 
-PyObject* connection_cursor(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"factory", NULL, NULL};
     PyObject* factory = NULL;
@@ -220,34 +220,34 @@
         return NULL;
     }
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
     if (factory == NULL) {
-        factory = (PyObject*)&CursorType;
+        factory = (PyObject*)&pysqlite_CursorType;
     }
 
     cursor = PyObject_CallFunction(factory, "O", self);
 
     if (cursor && self->row_factory != Py_None) {
-        Py_XDECREF(((Cursor*)cursor)->row_factory);
+        Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory);
         Py_INCREF(self->row_factory);
-        ((Cursor*)cursor)->row_factory = self->row_factory;
+        ((pysqlite_Cursor*)cursor)->row_factory = self->row_factory;
     }
 
     return cursor;
 }
 
-PyObject* connection_close(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
 
-    if (!check_thread(self)) {
+    if (!pysqlite_check_thread(self)) {
         return NULL;
     }
 
-    flush_statement_cache(self);
+    pysqlite_flush_statement_cache(self);
 
     if (self->db) {
         Py_BEGIN_ALLOW_THREADS
@@ -255,7 +255,7 @@
         Py_END_ALLOW_THREADS
 
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             return NULL;
         } else {
             self->db = NULL;
@@ -271,17 +271,17 @@
  *
  * 0 => error; 1 => ok
  */
-int check_connection(Connection* con)
+int pysqlite_check_connection(pysqlite_Connection* con)
 {
     if (!con->db) {
-        PyErr_SetString(ProgrammingError, "Cannot operate on a closed database.");
+        PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed database.");
         return 0;
     } else {
         return 1;
     }
 }
 
-PyObject* _connection_begin(Connection* self)
+PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
 {
     int rc;
     const char* tail;
@@ -292,7 +292,7 @@
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         goto error;
     }
 
@@ -300,7 +300,7 @@
     if (rc == SQLITE_DONE) {
         self->inTransaction = 1;
     } else {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
     }
 
     Py_BEGIN_ALLOW_THREADS
@@ -308,7 +308,7 @@
     Py_END_ALLOW_THREADS
 
     if (rc != SQLITE_OK && !PyErr_Occurred()) {
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
     }
 
 error:
@@ -320,13 +320,13 @@
     }
 }
 
-PyObject* connection_commit(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
     const char* tail;
     sqlite3_stmt* statement;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
@@ -335,7 +335,7 @@
         rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             goto error;
         }
 
@@ -343,14 +343,14 @@
         if (rc == SQLITE_DONE) {
             self->inTransaction = 0;
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_finalize(statement);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK && !PyErr_Occurred()) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
     }
@@ -364,24 +364,24 @@
     }
 }
 
-PyObject* connection_rollback(Connection* self, PyObject* args)
+PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args)
 {
     int rc;
     const char* tail;
     sqlite3_stmt* statement;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         return NULL;
     }
 
     if (self->inTransaction) {
-        reset_all_statements(self);
+        pysqlite_reset_all_statements(self);
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_prepare(self->db, "ROLLBACK", -1, &statement, &tail);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
             goto error;
         }
 
@@ -389,14 +389,14 @@
         if (rc == SQLITE_DONE) {
             self->inTransaction = 0;
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_finalize(statement);
         Py_END_ALLOW_THREADS
         if (rc != SQLITE_OK && !PyErr_Occurred()) {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
     }
@@ -410,7 +410,7 @@
     }
 }
 
-void _set_result(sqlite3_context* context, PyObject* py_val)
+void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
 {
     long longval;
     const char* buffer;
@@ -445,7 +445,7 @@
     }
 }
 
-PyObject* _build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv)
+PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv)
 {
     PyObject* args;
     int i;
@@ -512,7 +512,7 @@
     return args;
 }
 
-void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
+void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
 {
     PyObject* args;
     PyObject* py_func;
@@ -524,14 +524,14 @@
 
     py_func = (PyObject*)sqlite3_user_data(context);
 
-    args = _build_py_params(context, argc, argv);
+    args = _pysqlite_build_py_params(context, argc, argv);
     if (args) {
         py_retval = PyObject_CallObject(py_func, args);
         Py_DECREF(args);
     }
 
     if (py_retval) {
-        _set_result(context, py_retval);
+        _pysqlite_set_result(context, py_retval);
         Py_DECREF(py_retval);
     } else {
         if (_enable_callback_tracebacks) {
@@ -545,7 +545,7 @@
     PyGILState_Release(threadstate);
 }
 
-static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
+static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
 {
     PyObject* args;
     PyObject* function_result = NULL;
@@ -581,7 +581,7 @@
         goto error;
     }
 
-    args = _build_py_params(context, argc, params);
+    args = _pysqlite_build_py_params(context, argc, params);
     if (!args) {
         goto error;
     }
@@ -605,7 +605,7 @@
     PyGILState_Release(threadstate);
 }
 
-void _final_callback(sqlite3_context* context)
+void _pysqlite_final_callback(sqlite3_context* context)
 {
     PyObject* function_result = NULL;
     PyObject** aggregate_instance;
@@ -634,7 +634,7 @@
         }
         _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
     } else {
-        _set_result(context, function_result);
+        _pysqlite_set_result(context, function_result);
     }
 
 error:
@@ -644,7 +644,7 @@
     PyGILState_Release(threadstate);
 }
 
-void _drop_unused_statement_references(Connection* self)
+void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self)
 {
     PyObject* new_list;
     PyObject* weakref;
@@ -676,7 +676,7 @@
     self->statements = new_list;
 }
 
-PyObject* connection_create_function(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"name", "narg", "func", NULL, NULL};
 
@@ -691,11 +691,11 @@
         return NULL;
     }
 
-    rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _func_callback, NULL, NULL);
+    rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _pysqlite_func_callback, NULL, NULL);
 
     if (rc != SQLITE_OK) {
         /* Workaround for SQLite bug: no error code or string is available here */
-        PyErr_SetString(OperationalError, "Error creating function");
+        PyErr_SetString(pysqlite_OperationalError, "Error creating function");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, func, Py_None);
@@ -705,7 +705,7 @@
     }
 }
 
-PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* aggregate_class;
 
@@ -719,10 +719,10 @@
         return NULL;
     }
 
-    rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_step_callback, &_final_callback);
+    rc = sqlite3_create_function(self->db, name, n_arg, SQLITE_UTF8, (void*)aggregate_class, 0, &_pysqlite_step_callback, &_pysqlite_final_callback);
     if (rc != SQLITE_OK) {
         /* Workaround for SQLite bug: no error code or string is available here */
-        PyErr_SetString(OperationalError, "Error creating aggregate");
+        PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None);
@@ -732,7 +732,7 @@
     }
 }
 
-int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
+static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
 {
     PyObject *ret;
     int rc;
@@ -762,7 +762,7 @@
     return rc;
 }
 
-PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* authorizer_cb;
 
@@ -777,7 +777,7 @@
     rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb);
 
     if (rc != SQLITE_OK) {
-        PyErr_SetString(OperationalError, "Error setting authorizer callback");
+        PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback");
         return NULL;
     } else {
         PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None);
@@ -787,11 +787,11 @@
     }
 }
 
-int check_thread(Connection* self)
+int pysqlite_check_thread(pysqlite_Connection* self)
 {
     if (self->check_same_thread) {
         if (PyThread_get_thread_ident() != self->thread_ident) {
-            PyErr_Format(ProgrammingError,
+            PyErr_Format(pysqlite_ProgrammingError,
                         "SQLite objects created in a thread can only be used in that same thread."
                         "The object was created in thread id %ld and this is thread id %ld",
                         self->thread_ident, PyThread_get_thread_ident());
@@ -803,22 +803,22 @@
     return 1;
 }
 
-static PyObject* connection_get_isolation_level(Connection* self, void* unused)
+static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
 {
     Py_INCREF(self->isolation_level);
     return self->isolation_level;
 }
 
-static PyObject* connection_get_total_changes(Connection* self, void* unused)
+static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused)
 {
-    if (!check_connection(self)) {
+    if (!pysqlite_check_connection(self)) {
         return NULL;
     } else {
         return Py_BuildValue("i", sqlite3_total_changes(self->db));
     }
 }
 
-static int connection_set_isolation_level(Connection* self, PyObject* isolation_level)
+static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level)
 {
     PyObject* res;
     PyObject* begin_statement;
@@ -834,7 +834,7 @@
         Py_INCREF(Py_None);
         self->isolation_level = Py_None;
 
-        res = connection_commit(self, NULL);
+        res = pysqlite_connection_commit(self, NULL);
         if (!res) {
             return -1;
         }
@@ -866,10 +866,10 @@
     return 0;
 }
 
-PyObject* connection_call(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* sql;
-    Statement* statement;
+    pysqlite_Statement* statement;
     PyObject* weakref;
     int rc;
 
@@ -877,22 +877,22 @@
         return NULL;
     }
 
-    _drop_unused_statement_references(self);
+    _pysqlite_drop_unused_statement_references(self);
 
-    statement = PyObject_New(Statement, &StatementType);
+    statement = PyObject_New(pysqlite_Statement, &pysqlite_StatementType);
     if (!statement) {
         return NULL;
     }
 
-    rc = statement_create(statement, self, sql);
+    rc = pysqlite_statement_create(statement, self, sql);
 
     if (rc != SQLITE_OK) {
         if (rc == PYSQLITE_TOO_MUCH_SQL) {
-            PyErr_SetString(Warning, "You can only execute one statement at a time.");
+            PyErr_SetString(pysqlite_Warning, "You can only execute one statement at a time.");
         } else if (rc == PYSQLITE_SQL_WRONG_TYPE) {
-            PyErr_SetString(Warning, "SQL is of wrong type. Must be string or unicode.");
+            PyErr_SetString(pysqlite_Warning, "SQL is of wrong type. Must be string or unicode.");
         } else {
-            _seterror(self->db);
+            _pysqlite_seterror(self->db);
         }
 
         Py_DECREF(statement);
@@ -918,7 +918,7 @@
     return (PyObject*)statement;
 }
 
-PyObject* connection_execute(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -949,7 +949,7 @@
     return cursor;
 }
 
-PyObject* connection_executemany(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -980,7 +980,7 @@
     return cursor;
 }
 
-PyObject* connection_executescript(Connection* self, PyObject* args, PyObject* kwargs)
+PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
 {
     PyObject* cursor = 0;
     PyObject* result = 0;
@@ -1014,7 +1014,7 @@
 /* ------------------------- COLLATION CODE ------------------------ */
 
 static int
-collation_callback(
+pysqlite_collation_callback(
         void* context,
         int text1_length, const void* text1_data,
         int text2_length, const void* text2_data)
@@ -1063,11 +1063,11 @@
 }
 
 static PyObject *
-connection_interrupt(Connection* self, PyObject* args)
+pysqlite_connection_interrupt(pysqlite_Connection* self, PyObject* args)
 {
     PyObject* retval = NULL;
 
-    if (!check_connection(self)) {
+    if (!pysqlite_check_connection(self)) {
         goto finally;
     }
 
@@ -1081,7 +1081,7 @@
 }
 
 static PyObject *
-connection_create_collation(Connection* self, PyObject* args)
+pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
 {
     PyObject* callable;
     PyObject* uppercase_name = 0;
@@ -1090,7 +1090,7 @@
     char* chk;
     int rc;
 
-    if (!check_thread(self) || !check_connection(self)) {
+    if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
         goto finally;
     }
 
@@ -1111,7 +1111,7 @@
         {
             chk++;
         } else {
-            PyErr_SetString(ProgrammingError, "invalid character in collation name");
+            PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
             goto finally;
         }
     }
@@ -1131,10 +1131,10 @@
                                   PyString_AsString(uppercase_name),
                                   SQLITE_UTF8,
                                   (callable != Py_None) ? callable : NULL,
-                                  (callable != Py_None) ? collation_callback : NULL);
+                                  (callable != Py_None) ? pysqlite_collation_callback : NULL);
     if (rc != SQLITE_OK) {
         PyDict_DelItem(self->collations, uppercase_name);
-        _seterror(self->db);
+        _pysqlite_seterror(self->db);
         goto finally;
     }
 
@@ -1155,63 +1155,63 @@
 PyDoc_STR("SQLite database connection object.");
 
 static PyGetSetDef connection_getset[] = {
-    {"isolation_level",  (getter)connection_get_isolation_level, (setter)connection_set_isolation_level},
-    {"total_changes",  (getter)connection_get_total_changes, (setter)0},
+    {"isolation_level",  (getter)pysqlite_connection_get_isolation_level, (setter)pysqlite_connection_set_isolation_level},
+    {"total_changes",  (getter)pysqlite_connection_get_total_changes, (setter)0},
     {NULL}
 };
 
 static PyMethodDef connection_methods[] = {
-    {"cursor", (PyCFunction)connection_cursor, METH_VARARGS|METH_KEYWORDS,
+    {"cursor", (PyCFunction)pysqlite_connection_cursor, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Return a cursor for the connection.")},
-    {"close", (PyCFunction)connection_close, METH_NOARGS,
+    {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS,
         PyDoc_STR("Closes the connection.")},
-    {"commit", (PyCFunction)connection_commit, METH_NOARGS,
+    {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS,
         PyDoc_STR("Commit the current transaction.")},
-    {"rollback", (PyCFunction)connection_rollback, METH_NOARGS,
+    {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS,
         PyDoc_STR("Roll back the current transaction.")},
-    {"create_function", (PyCFunction)connection_create_function, METH_VARARGS|METH_KEYWORDS,
+    {"create_function", (PyCFunction)pysqlite_connection_create_function, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Creates a new function. Non-standard.")},
-    {"create_aggregate", (PyCFunction)connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
+    {"create_aggregate", (PyCFunction)pysqlite_connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Creates a new aggregate. Non-standard.")},
-    {"set_authorizer", (PyCFunction)connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
+    {"set_authorizer", (PyCFunction)pysqlite_connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
         PyDoc_STR("Sets authorizer callback. Non-standard.")},
-    {"execute", (PyCFunction)connection_execute, METH_VARARGS,
+    {"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS,
         PyDoc_STR("Executes a SQL statement. Non-standard.")},
-    {"executemany", (PyCFunction)connection_executemany, METH_VARARGS,
+    {"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS,
         PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")},
-    {"executescript", (PyCFunction)connection_executescript, METH_VARARGS,
+    {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS,
         PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
-    {"create_collation", (PyCFunction)connection_create_collation, METH_VARARGS,
+    {"create_collation", (PyCFunction)pysqlite_connection_create_collation, METH_VARARGS,
         PyDoc_STR("Creates a collation function. Non-standard.")},
-    {"interrupt", (PyCFunction)connection_interrupt, METH_NOARGS,
+    {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS,
         PyDoc_STR("Abort any pending database operation. Non-standard.")},
     {NULL, NULL}
 };
 
 static struct PyMemberDef connection_members[] =
 {
-    {"Warning", T_OBJECT, offsetof(Connection, Warning), RO},
-    {"Error", T_OBJECT, offsetof(Connection, Error), RO},
-    {"InterfaceError", T_OBJECT, offsetof(Connection, InterfaceError), RO},
-    {"DatabaseError", T_OBJECT, offsetof(Connection, DatabaseError), RO},
-    {"DataError", T_OBJECT, offsetof(Connection, DataError), RO},
-    {"OperationalError", T_OBJECT, offsetof(Connection, OperationalError), RO},
-    {"IntegrityError", T_OBJECT, offsetof(Connection, IntegrityError), RO},
-    {"InternalError", T_OBJECT, offsetof(Connection, InternalError), RO},
-    {"ProgrammingError", T_OBJECT, offsetof(Connection, ProgrammingError), RO},
-    {"NotSupportedError", T_OBJECT, offsetof(Connection, NotSupportedError), RO},
-    {"row_factory", T_OBJECT, offsetof(Connection, row_factory)},
-    {"text_factory", T_OBJECT, offsetof(Connection, text_factory)},
+    {"Warning", T_OBJECT, offsetof(pysqlite_Connection, Warning), RO},
+    {"Error", T_OBJECT, offsetof(pysqlite_Connection, Error), RO},
+    {"InterfaceError", T_OBJECT, offsetof(pysqlite_Connection, InterfaceError), RO},
+    {"DatabaseError", T_OBJECT, offsetof(pysqlite_Connection, DatabaseError), RO},
+    {"DataError", T_OBJECT, offsetof(pysqlite_Connection, DataError), RO},
+    {"OperationalError", T_OBJECT, offsetof(pysqlite_Connection, OperationalError), RO},
+    {"IntegrityError", T_OBJECT, offsetof(pysqlite_Connection, IntegrityError), RO},
+    {"InternalError", T_OBJECT, offsetof(pysqlite_Connection, InternalError), RO},
+    {"ProgrammingError", T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), RO},
+    {"NotSupportedError", T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), RO},
+    {"row_factory", T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
+    {"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
     {NULL}
 };
 
-PyTypeObject ConnectionType = {
+PyTypeObject pysqlite_ConnectionType = {
         PyObject_HEAD_INIT(NULL)
         0,                                              /* ob_size */
         MODULE_NAME ".Connection",                      /* tp_name */
-        sizeof(Connection),                             /* tp_basicsize */
+        sizeof(pysqlite_Connection),                    /* tp_basicsize */
         0,                                              /* tp_itemsize */
-        (destructor)connection_dealloc,                 /* tp_dealloc */
+        (destructor)pysqlite_connection_dealloc,        /* tp_dealloc */
         0,                                              /* tp_print */
         0,                                              /* tp_getattr */
         0,                                              /* tp_setattr */
@@ -1221,7 +1221,7 @@
         0,                                              /* tp_as_sequence */
         0,                                              /* tp_as_mapping */
         0,                                              /* tp_hash */
-        (ternaryfunc)connection_call,                   /* tp_call */
+        (ternaryfunc)pysqlite_connection_call,          /* tp_call */
         0,                                              /* tp_str */
         0,                                              /* tp_getattro */
         0,                                              /* tp_setattro */
@@ -1242,14 +1242,14 @@
         0,                                              /* tp_descr_get */
         0,                                              /* tp_descr_set */
         0,                                              /* tp_dictoffset */
-        (initproc)connection_init,                      /* tp_init */
+        (initproc)pysqlite_connection_init,             /* tp_init */
         0,                                              /* tp_alloc */
         0,                                              /* tp_new */
         0                                               /* tp_free */
 };
 
-extern int connection_setup_types(void)
+extern int pysqlite_connection_setup_types(void)
 {
-    ConnectionType.tp_new = PyType_GenericNew;
-    return PyType_Ready(&ConnectionType);
+    pysqlite_ConnectionType.tp_new = PyType_GenericNew;
+    return PyType_Ready(&pysqlite_ConnectionType);
 }