diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-12-24 15:43:27 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-12-31 03:18:26 +0100 |
| commit | 56e4c2bd55239dc30d4feee6adafe851f13b8e24 (patch) | |
| tree | f8637987977c7517c41d857a0f517c46910828be /psycopg/microprotocols.c | |
| parent | 014b6a6d5b6ba1cbc35c49f7200644ba3dfb86be (diff) | |
| download | psycopg2-56e4c2bd55239dc30d4feee6adafe851f13b8e24.tar.gz | |
Redefining the microprotocol on Py3 as returning bytes.
Diffstat (limited to 'psycopg/microprotocols.c')
| -rw-r--r-- | psycopg/microprotocols.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c index 067729f..45b26f8 100644 --- a/psycopg/microprotocols.c +++ b/psycopg/microprotocols.c @@ -203,7 +203,10 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) return NULL; } -/* microprotocol_getquoted - utility function that adapt and call getquoted */ +/* microprotocol_getquoted - utility function that adapt and call getquoted. + * + * Return a bytes string, NULL on error. + */ PyObject * microprotocol_getquoted(PyObject *obj, connectionObject *conn) @@ -241,6 +244,16 @@ microprotocol_getquoted(PyObject *obj, connectionObject *conn) adapted to the right protocol) */ res = PyObject_CallMethod(adapted, "getquoted", NULL); + /* Convert to bytes. */ + if (res && PyUnicode_CheckExact(res)) { + PyObject *b; + const char *codec; + codec = (conn && conn->codec) ? conn->codec : "utf8"; + b = PyUnicode_AsEncodedString(res, codec, NULL); + Py_DECREF(res); + res = b; + } + exit: Py_XDECREF(adapted); Py_XDECREF(prepare); |
