mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Assume there may be files returning Unicode in Python 2 too
This is the case in Python 2.7 with files implementing io.TextIOBase.
This commit is contained in:
parent
8a08114314
commit
6098ced761
|
@ -1081,10 +1081,10 @@ _pq_copy_in_v3(cursorObject *curs)
|
|||
break;
|
||||
}
|
||||
|
||||
/* a file may return unicode in Py3: encode in client encoding. */
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
/* a file may return unicode if implements io.TextIOBase */
|
||||
if (PyUnicode_Check(o)) {
|
||||
PyObject *tmp;
|
||||
Dprintf("_pq_copy_in_v3: encoding in %s", curs->conn->codec);
|
||||
if (!(tmp = PyUnicode_AsEncodedString(o, curs->conn->codec, NULL))) {
|
||||
Dprintf("_pq_copy_in_v3: encoding() failed");
|
||||
error = 1;
|
||||
|
@ -1093,7 +1093,6 @@ _pq_copy_in_v3(cursorObject *curs)
|
|||
Py_DECREF(o);
|
||||
o = tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Bytes_Check(o)) {
|
||||
Dprintf("_pq_copy_in_v3: got %s instead of bytes",
|
||||
|
|
Loading…
Reference in New Issue
Block a user