mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 19:03:43 +03:00
In Py3, decode the tuple values before passing to the typecaster.
Not sure this is the best way to go: it is now impossible to write a binary typecaster in Python; furthermore it is the opposite approach of the codecs, which should return bytes.
This commit is contained in:
parent
ab5934dc35
commit
061079c918
|
@ -640,7 +640,27 @@ typecast_cast(PyObject *obj, const char *str, Py_ssize_t len, PyObject *curs)
|
|||
res = self->ccast(str, len, curs);
|
||||
}
|
||||
else if (self->pcast) {
|
||||
res = PyObject_CallFunction(self->pcast, "s#O", str, len, curs);
|
||||
PyObject *s;
|
||||
/* XXX we have bytes in the adapters and strings in the typecasters.
|
||||
* are you sure this is ok?
|
||||
* Notice that this way it is about impossible to create a python
|
||||
* typecaster on a binary type. */
|
||||
if (str) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
s = PyString_FromStringAndSize(str, len);
|
||||
#else
|
||||
s = PyUnicode_Decode(str, len,
|
||||
((cursorObject *)curs)->conn->codec, NULL);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
Py_INCREF(Py_None);
|
||||
s = Py_None;
|
||||
}
|
||||
if (s) {
|
||||
res = PyObject_CallFunctionObjArgs(self->pcast, s, curs, NULL);
|
||||
Py_DECREF(s);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(Error, "internal error: no casting function found");
|
||||
|
|
Loading…
Reference in New Issue
Block a user