diff Modules/_sqlite/module.c @ 74850:0fc10a33eb4c

Undocument and clean up sqlite3.OptimizedUnicode Closes #13921.
author Petri Lehtinen <petri@digip.org>
date Thu, 09 Feb 2012 21:09:03 +0200
parents 7109f31300fb
children f13bb1e40fbc
line wrap: on
line diff
--- a/Modules/_sqlite/module.c	Thu Feb 09 18:27:48 2012 +0800
+++ b/Modules/_sqlite/module.c	Thu Feb 09 21:09:03 2012 +0200
@@ -37,7 +37,7 @@
 
 PyObject* pysqlite_Error, *pysqlite_Warning, *pysqlite_InterfaceError, *pysqlite_DatabaseError,
     *pysqlite_InternalError, *pysqlite_OperationalError, *pysqlite_ProgrammingError,
-    *pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError, *pysqlite_OptimizedUnicode;
+    *pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError;
 
 PyObject* converters;
 int _enable_callback_tracebacks;
@@ -407,13 +407,13 @@
     }
     PyDict_SetItemString(dict, "NotSupportedError", pysqlite_NotSupportedError);
 
-    /* We just need "something" unique for pysqlite_OptimizedUnicode. It does not really
-     * need to be a string subclass. Just anything that can act as a special
-     * marker for us. So I pulled PyCell_Type out of my magic hat.
-     */
-    Py_INCREF((PyObject*)&PyCell_Type);
-    pysqlite_OptimizedUnicode = (PyObject*)&PyCell_Type;
-    PyDict_SetItemString(dict, "OptimizedUnicode", pysqlite_OptimizedUnicode);
+    /* In Python 2.x, setting Connection.text_factory to
+       OptimizedUnicode caused Unicode objects to be returned for
+       non-ASCII data and bytestrings to be returned for ASCII data.
+       Now OptimizedUnicode is an alias for str, so it has no
+       effect. */
+    Py_INCREF((PyObject*)&PyUnicode_Type);
+    PyDict_SetItemString(dict, "OptimizedUnicode", (PyObject*)&PyUnicode_Type);
 
     /* Set integer constants */
     for (i = 0; _int_constants[i].constant_name != 0; i++) {