summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-15 17:30:43 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-15 17:30:43 +0000
commit3ae2f221b38719ccd9c91321b0031c0b1d68a9d6 (patch)
treec58ea79305266e67ead44d978cdadaf75d619742 /psycopg
parentc96ba553dadd921b9e1e0b3d66092a4182036a55 (diff)
downloadpsycopg2-3ae2f221b38719ccd9c91321b0031c0b1d68a9d6.tar.gz
Adapt bytearray and memoryview to bytes if available
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/adapter_binary.c5
-rw-r--r--psycopg/psycopgmodule.c9
2 files changed, 13 insertions, 1 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index d54d17a..31b2502 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -61,8 +61,11 @@ binary_quote(binaryObject *self)
if (Bytes_Check(self->wrapped)
#if PY_MAJOR_VERSION < 3
|| PyBuffer_Check(self->wrapped)
-#else
+#endif
+#if PY_MAJOR_VERSION >= 3 || PY_MINOR_VERSION >= 6
|| PyByteArray_Check(self->wrapped)
+#endif
+#if PY_MAJOR_VERSION >= 3 || PY_MINOR_VERSION >= 7
|| PyMemoryView_Check(self->wrapped)
#endif
) {
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index f91483d..7b6a334 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -315,17 +315,26 @@ psyco_adapters_init(PyObject *mod)
microprotocols_add(&PyLong_Type, NULL, (PyObject*)&asisType);
microprotocols_add(&PyBool_Type, NULL, (PyObject*)&pbooleanType);
+ /* strings */
#if PY_MAJOR_VERSION < 3
microprotocols_add(&PyString_Type, NULL, (PyObject*)&qstringType);
#endif
microprotocols_add(&PyUnicode_Type, NULL, (PyObject*)&qstringType);
+
+ /* binary */
#if PY_MAJOR_VERSION < 3
microprotocols_add(&PyBuffer_Type, NULL, (PyObject*)&binaryType);
#else
microprotocols_add(&PyBytes_Type, NULL, (PyObject*)&binaryType);
+#endif
+
+#if PY_MAJOR_VERSION >= 3 || PY_MINOR_VERSION >= 6
microprotocols_add(&PyByteArray_Type, NULL, (PyObject*)&binaryType);
+#endif
+#if PY_MAJOR_VERSION >= 3 || PY_MINOR_VERSION >= 7
microprotocols_add(&PyMemoryView_Type, NULL, (PyObject*)&binaryType);
#endif
+
microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType);
if ((type = (PyTypeObject*)psyco_GetDecimalType()) != NULL)