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.
This commit is contained in:
Gregory P. Smith 2008-06-09 04:58:54 +00:00
parent e98839a1f4
commit dd96db63f6
173 changed files with 2275 additions and 2280 deletions

View file

@ -241,12 +241,12 @@ PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
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) {

View file

@ -84,8 +84,8 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
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 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
}
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 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
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 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
}
if (!isolation_level) {
isolation_level = PyBytes_FromString("");
isolation_level = PyString_FromString("");
if (!isolation_level) {
return -1;
}
@ -499,12 +499,12 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} 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 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
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 @@ pysqlite_collation_callback(
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 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
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 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
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 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
}
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);

View file

@ -80,7 +80,7 @@ typedef struct
/* 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.
*/

View file

@ -178,7 +178,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
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 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
* '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 @@ PyObject* _pysqlite_build_column_name(const char* colname)
if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
pos--;
}
return PyBytes_FromStringAndSize(colname, pos - colname);
return PyString_FromStringAndSize(colname, pos - colname);
}
}
}
@ -273,7 +273,7 @@ PyObject* pysqlite_unicode_from_string(const char* val_str, int optimize)
}
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 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
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 @@ PyObject* _pysqlite_fetch_one_row(pysqlite_Cursor* self)
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 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
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 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
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 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
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 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
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;

View file

@ -137,7 +137,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
/* 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 @@ PyMODINIT_FUNC init_sqlite3(void)
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);

View file

@ -86,13 +86,13 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
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;
}

View file

@ -60,7 +60,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
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 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
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 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
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 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
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 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
}
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 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
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 @@ static int _need_adapt(PyObject* obj)
}
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 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
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,