This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html
Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names
in the spirit of 3.0 are available via a #define only. See the email thread.
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index 3362a5c..85118fc 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -241,12 +241,12 @@
if (!fmt_args) {
return NULL;
}
- template = PyBytes_FromString("%s <- %s ->%s\n");
+ template = PyString_FromString("%s <- %s ->%s\n");
if (!template) {
Py_DECREF(fmt_args);
return NULL;
}
- display_str = PyBytes_Format(template, fmt_args);
+ display_str = PyString_Format(template, fmt_args);
Py_DECREF(template);
Py_DECREF(fmt_args);
if (!display_str) {
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 927c983..8269e0b 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -84,8 +84,8 @@
Py_INCREF(&PyUnicode_Type);
self->text_factory = (PyObject*)&PyUnicode_Type;
- if (PyBytes_Check(database) || PyUnicode_Check(database)) {
- if (PyBytes_Check(database)) {
+ if (PyString_Check(database) || PyUnicode_Check(database)) {
+ if (PyString_Check(database)) {
database_utf8 = database;
Py_INCREF(database_utf8);
} else {
@@ -96,7 +96,7 @@
}
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_open(PyBytes_AsString(database_utf8), &self->db);
+ rc = sqlite3_open(PyString_AsString(database_utf8), &self->db);
Py_END_ALLOW_THREADS
Py_DECREF(database_utf8);
@@ -111,7 +111,7 @@
if (class_attr) {
class_attr_str = PyObject_Str(class_attr);
if (class_attr_str) {
- if (strcmp(PyBytes_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) {
+ if (strcmp(PyString_AsString(class_attr_str), "<type 'apsw.Connection'>") == 0) {
/* In the APSW Connection object, the first entry after
* PyObject_HEAD is the sqlite3* we want to get hold of.
* Luckily, this is the same layout as we have in our
@@ -134,7 +134,7 @@
}
if (!isolation_level) {
- isolation_level = PyBytes_FromString("");
+ isolation_level = PyString_FromString("");
if (!isolation_level) {
return -1;
}
@@ -499,12 +499,12 @@
} else {
sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
}
- } else if (PyBytes_Check(py_val)) {
- sqlite3_result_text(context, PyBytes_AsString(py_val), -1, 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)) {
stringval = PyUnicode_AsUTF8String(py_val);
if (stringval) {
- sqlite3_result_text(context, PyBytes_AsString(stringval), -1, SQLITE_TRANSIENT);
+ sqlite3_result_text(context, PyString_AsString(stringval), -1, SQLITE_TRANSIENT);
Py_DECREF(stringval);
}
} else {
@@ -963,21 +963,21 @@
Py_INCREF(isolation_level);
self->isolation_level = isolation_level;
- begin_statement = PyBytes_FromString("BEGIN ");
+ begin_statement = PyString_FromString("BEGIN ");
if (!begin_statement) {
return -1;
}
- PyBytes_Concat(&begin_statement, isolation_level);
+ PyString_Concat(&begin_statement, isolation_level);
if (!begin_statement) {
return -1;
}
- self->begin_statement = PyMem_Malloc(PyBytes_Size(begin_statement) + 2);
+ self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2);
if (!self->begin_statement) {
return -1;
}
- strcpy(self->begin_statement, PyBytes_AsString(begin_statement));
+ strcpy(self->begin_statement, PyString_AsString(begin_statement));
Py_DECREF(begin_statement);
}
@@ -1152,8 +1152,8 @@
goto finally;
}
- string1 = PyBytes_FromStringAndSize((const char*)text1_data, text1_length);
- string2 = PyBytes_FromStringAndSize((const char*)text2_data, text2_length);
+ string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
+ string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
if (!string1 || !string2) {
goto finally; /* failed to allocate strings */
@@ -1259,7 +1259,7 @@
goto finally;
}
- if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyBytes_Type, &name, &callable)) {
+ if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) {
goto finally;
}
@@ -1268,7 +1268,7 @@
goto finally;
}
- chk = PyBytes_AsString(uppercase_name);
+ chk = PyString_AsString(uppercase_name);
while (*chk) {
if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z')
@@ -1293,7 +1293,7 @@
}
rc = sqlite3_create_collation(self->db,
- PyBytes_AsString(uppercase_name),
+ PyString_AsString(uppercase_name),
SQLITE_UTF8,
(callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL);
diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h
index c5d0fd0..3b1c632 100644
--- a/Modules/_sqlite/connection.h
+++ b/Modules/_sqlite/connection.h
@@ -80,7 +80,7 @@
/* Determines how bytestrings from SQLite are converted to Python objects:
* - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
* - OptimizedUnicode: Like before, but for ASCII data, only PyStrings are created.
- * - PyBytes_Type: PyStrings are created as-is.
+ * - PyString_Type: PyStrings are created as-is.
* - Any custom callable: Any object returned from the callable called with the bytestring
* as single parameter.
*/
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 23d1e06..0d7d59a 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -178,7 +178,7 @@
if (*pos == '[') {
type_start = pos + 1;
} else if (*pos == ']' && type_start != (const char*)-1) {
- key = PyBytes_FromStringAndSize(type_start, pos - type_start);
+ key = PyString_FromStringAndSize(type_start, pos - type_start);
if (!key) {
/* creating a string failed, but it is too complicated
* to propagate the error here, we just assume there is
@@ -203,7 +203,7 @@
* 'NUMBER(10)' to be treated as 'NUMBER', for example.
* In other words, it will work as people expect it to work.*/
if (*pos == ' ' || *pos == '(' || *pos == 0) {
- py_decltype = PyBytes_FromStringAndSize(decltype, pos - decltype);
+ py_decltype = PyString_FromStringAndSize(decltype, pos - decltype);
if (!py_decltype) {
return -1;
}
@@ -248,7 +248,7 @@
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
pos--;
}
- return PyBytes_FromStringAndSize(colname, pos - colname);
+ return PyString_FromStringAndSize(colname, pos - colname);
}
}
}
@@ -273,7 +273,7 @@
}
if (is_ascii) {
- return PyBytes_FromString(val_str);
+ return PyString_FromString(val_str);
} else {
return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
}
@@ -327,7 +327,7 @@
Py_INCREF(Py_None);
converted = Py_None;
} else {
- item = PyBytes_FromStringAndSize(val_str, nbytes);
+ item = PyString_FromStringAndSize(val_str, nbytes);
if (!item) {
return NULL;
}
@@ -370,8 +370,8 @@
colname , val_str);
PyErr_SetString(pysqlite_OperationalError, buf);
}
- } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
- converted = PyBytes_FromString(val_str);
+ } else if (self->connection->text_factory == (PyObject*)&PyString_Type) {
+ converted = PyString_FromString(val_str);
} else {
converted = PyObject_CallFunction(self->connection->text_factory, "s", val_str);
}
@@ -442,7 +442,7 @@
return NULL;
}
- if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) {
+ if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL;
}
@@ -464,7 +464,7 @@
return NULL;
}
- if (!PyBytes_Check(operation) && !PyUnicode_Check(operation)) {
+ if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
return NULL;
}
@@ -499,15 +499,15 @@
rc = pysqlite_statement_reset(self->statement);
}
- if (PyBytes_Check(operation)) {
- operation_cstr = PyBytes_AsString(operation);
+ if (PyString_Check(operation)) {
+ operation_cstr = PyString_AsString(operation);
} else {
operation_bytestr = PyUnicode_AsUTF8String(operation);
if (!operation_bytestr) {
goto error;
}
- operation_cstr = PyBytes_AsString(operation_bytestr);
+ operation_cstr = PyString_AsString(operation_bytestr);
}
/* reset description and rowcount */
@@ -764,15 +764,15 @@
return NULL;
}
- if (PyBytes_Check(script_obj)) {
- script_cstr = PyBytes_AsString(script_obj);
+ if (PyString_Check(script_obj)) {
+ script_cstr = PyString_AsString(script_obj);
} else if (PyUnicode_Check(script_obj)) {
script_str = PyUnicode_AsUTF8String(script_obj);
if (!script_str) {
return NULL;
}
- script_cstr = PyBytes_AsString(script_str);
+ script_cstr = PyString_AsString(script_str);
} else {
PyErr_SetString(PyExc_ValueError, "script argument must be unicode or string.");
return NULL;
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index f77452c..af7eace 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -137,7 +137,7 @@
/* a basic type is adapted; there's a performance optimization if that's not the case
* (99 % of all usages) */
if (type == &PyInt_Type || type == &PyLong_Type || type == &PyFloat_Type
- || type == &PyBytes_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) {
+ || type == &PyString_Type || type == &PyUnicode_Type || type == &PyBuffer_Type) {
pysqlite_BaseTypeAdapted = 1;
}
@@ -367,13 +367,13 @@
Py_DECREF(tmp_obj);
}
- if (!(tmp_obj = PyBytes_FromString(PYSQLITE_VERSION))) {
+ if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
goto error;
}
PyDict_SetItemString(dict, "version", tmp_obj);
Py_DECREF(tmp_obj);
- if (!(tmp_obj = PyBytes_FromString(sqlite3_libversion()))) {
+ if (!(tmp_obj = PyString_FromString(sqlite3_libversion()))) {
goto error;
}
PyDict_SetItemString(dict, "sqlite_version", tmp_obj);
diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c
index 8815116..3419267 100644
--- a/Modules/_sqlite/row.c
+++ b/Modules/_sqlite/row.c
@@ -86,13 +86,13 @@
item = PyTuple_GetItem(self->data, _idx);
Py_XINCREF(item);
return item;
- } else if (PyBytes_Check(idx)) {
- key = PyBytes_AsString(idx);
+ } else if (PyString_Check(idx)) {
+ key = PyString_AsString(idx);
nitems = PyTuple_Size(self->description);
for (i = 0; i < nitems; i++) {
- compare_key = PyBytes_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
+ compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
if (!compare_key) {
return NULL;
}
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index b9245f7..0e77668 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -60,7 +60,7 @@
self->st = NULL;
self->in_use = 0;
- if (PyBytes_Check(sql)) {
+ if (PyString_Check(sql)) {
sql_str = sql;
Py_INCREF(sql_str);
} else if (PyUnicode_Check(sql)) {
@@ -77,7 +77,7 @@
self->in_weakreflist = NULL;
self->sql = sql_str;
- sql_cstr = PyBytes_AsString(sql_str);
+ sql_cstr = PyString_AsString(sql_str);
rc = sqlite3_prepare(connection->db,
sql_cstr,
@@ -119,7 +119,7 @@
paramtype = TYPE_LONG;
} else if (PyFloat_CheckExact(parameter)) {
paramtype = TYPE_FLOAT;
- } else if (PyBytes_CheckExact(parameter)) {
+ } else if (PyString_CheckExact(parameter)) {
paramtype = TYPE_STRING;
} else if (PyUnicode_CheckExact(parameter)) {
paramtype = TYPE_UNICODE;
@@ -131,7 +131,7 @@
paramtype = TYPE_LONG;
} else if (PyFloat_Check(parameter)) {
paramtype = TYPE_FLOAT;
- } else if (PyBytes_Check(parameter)) {
+ } else if (PyString_Check(parameter)) {
paramtype = TYPE_STRING;
} else if (PyUnicode_Check(parameter)) {
paramtype = TYPE_UNICODE;
@@ -140,7 +140,7 @@
}
if (paramtype == TYPE_STRING && !allow_8bit_chars) {
- string = PyBytes_AS_STRING(parameter);
+ string = PyString_AS_STRING(parameter);
for (c = string; *c != 0; c++) {
if (*c & 0x80) {
PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
@@ -164,12 +164,12 @@
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
break;
case TYPE_STRING:
- string = PyBytes_AS_STRING(parameter);
+ string = PyString_AS_STRING(parameter);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
break;
case TYPE_UNICODE:
stringval = PyUnicode_AsUTF8String(parameter);
- string = PyBytes_AsString(stringval);
+ string = PyString_AsString(stringval);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
Py_DECREF(stringval);
break;
@@ -197,7 +197,7 @@
}
if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
- || PyFloat_CheckExact(obj) || PyBytes_CheckExact(obj)
+ || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
|| PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
return 0;
} else {
@@ -326,7 +326,7 @@
char* sql_cstr;
sqlite3_stmt* new_st;
- sql_cstr = PyBytes_AsString(self->sql);
+ sql_cstr = PyString_AsString(self->sql);
rc = sqlite3_prepare(self->db,
sql_cstr,