From bc28cc8b0025c86e66e4fec3c1b7bfdccfb729b2 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 29 Dec 2010 23:53:03 +0100 Subject: [PATCH] Use unicode keys as strings in Py3. This fixes pyformat style argument passing. Unicode and bytes don't compare equal (even if they hash the same). --- psycopg/bytes_format.c | 3 +-- psycopg/cursor_type.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/psycopg/bytes_format.c b/psycopg/bytes_format.c index 1c49a011..ab57bc3f 100644 --- a/psycopg/bytes_format.c +++ b/psycopg/bytes_format.c @@ -207,8 +207,7 @@ PyBytes_Format(PyObject *format, PyObject *args) "incomplete format key"); goto error; } - key = PyBytes_FromStringAndSize(keystart, - keylen); + key = PyUnicode_FromStringAndSize(keystart, keylen); if (key == NULL) goto error; if (args_owned) { diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 5290c238..2491081b 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -116,7 +116,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new) for (d = c + 2; *d && *d != ')'; d++); if (*d == ')') { - key = Bytes_FromStringAndSize(c+2, (Py_ssize_t) (d-c-2)); + key = Text_FromUTF8AndSize(c+2, (Py_ssize_t) (d-c-2)); value = PyObject_GetItem(var, key); /* key has refcnt 1, value the original value + 1 */