diff --git a/NEWS b/NEWS index e49f384b..c128ceca 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ What's new in psycopg 2.5 - Added JSON adaptation. - Added support for PostgreSQL 9.2 range types. + - Added support for Python 3.3. - 'connection' and 'cursor' objects can be used in 'with' statements as context managers as specified by recent DBAPI extension. - Added support for backward scrollable cursors. Thanks to Jon Nelson diff --git a/psycopg/typecast_binary.c b/psycopg/typecast_binary.c index 49eb547f..d63c7025 100644 --- a/psycopg/typecast_binary.c +++ b/psycopg/typecast_binary.c @@ -55,7 +55,6 @@ chunk_repr(chunkObject *self) #if PY_MAJOR_VERSION < 3 -/* XXX support 3.0 buffer protocol */ static Py_ssize_t chunk_getreadbuffer(chunkObject *self, Py_ssize_t segment, void **ptr) { @@ -90,9 +89,15 @@ static PyBufferProcs chunk_as_buffer = /* 3.0 buffer interface */ int chunk_getbuffer(PyObject *_self, Py_buffer *view, int flags) { + int rv; chunkObject *self = (chunkObject*)_self; - return PyBuffer_FillInfo(view, _self, self->base, self->len, 1, flags); + rv = PyBuffer_FillInfo(view, _self, self->base, self->len, 1, flags); + if (rv == 0) { + view->format = "c"; + } + return rv; } + static PyBufferProcs chunk_as_buffer = { chunk_getbuffer, diff --git a/setup.py b/setup.py index b48fab5a..3791c149 100644 --- a/setup.py +++ b/setup.py @@ -347,14 +347,15 @@ class psycopg_build_ext(build_ext): self.libraries.append('ssl') self.libraries.append('crypto') - def finalize_linux2(self): + def finalize_linux(self): """Finalize build system configuration on GNU/Linux platform.""" # tell piro that GCC is fine and dandy, but not so MS compilers for extension in self.extensions: extension.extra_compile_args.append( '-Wdeclaration-after-statement') - finalize_linux3 = finalize_linux2 + finalize_linux2 = finalize_linux + finalize_linux3 = finalize_linux def finalize_options(self): """Complete the build system configuation.""" diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py index e442fc62..c2a47e93 100755 --- a/tests/test_types_basic.py +++ b/tests/test_types_basic.py @@ -126,7 +126,7 @@ class TypesBasicTests(unittest.TestCase): s = bytes(range(256)) b = psycopg2.Binary(s) buf = self.execute("SELECT %s::bytea AS foo", (b,)) - self.assertEqual(s, buf) + self.assertEqual(s, buf.tobytes()) def testBinaryNone(self): b = psycopg2.Binary(None) @@ -154,7 +154,7 @@ class TypesBasicTests(unittest.TestCase): s = bytes(range(256)) buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),)) buf2 = self.execute("SELECT %s::bytea AS foo", (buf,)) - self.assertEqual(s, buf2) + self.assertEqual(s, buf2.tobytes()) def testArray(self): s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))