mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-12 15:20:32 +03:00
Return memoryview object of type "c" instead of "B" from bytea
In Python 3.3 items are returned as int instead of chars. I'm not sure the way I did it is correct: worth asking some hardcore Python dev. Fixed tests after the stricter memview comparison rules in Py 3.3.
This commit is contained in:
parent
526e270934
commit
469b6f8aff
|
@ -55,7 +55,6 @@ chunk_repr(chunkObject *self)
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
|
|
||||||
/* XXX support 3.0 buffer protocol */
|
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
chunk_getreadbuffer(chunkObject *self, Py_ssize_t segment, void **ptr)
|
chunk_getreadbuffer(chunkObject *self, Py_ssize_t segment, void **ptr)
|
||||||
{
|
{
|
||||||
|
@ -90,9 +89,16 @@ static PyBufferProcs chunk_as_buffer =
|
||||||
/* 3.0 buffer interface */
|
/* 3.0 buffer interface */
|
||||||
int chunk_getbuffer(PyObject *_self, Py_buffer *view, int flags)
|
int chunk_getbuffer(PyObject *_self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
|
int rv;
|
||||||
chunkObject *self = (chunkObject*)_self;
|
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) {
|
||||||
|
/* TODO: is this really the way to do it? */
|
||||||
|
view->format = "c";
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyBufferProcs chunk_as_buffer =
|
static PyBufferProcs chunk_as_buffer =
|
||||||
{
|
{
|
||||||
chunk_getbuffer,
|
chunk_getbuffer,
|
||||||
|
|
|
@ -126,7 +126,7 @@ class TypesBasicTests(unittest.TestCase):
|
||||||
s = bytes(range(256))
|
s = bytes(range(256))
|
||||||
b = psycopg2.Binary(s)
|
b = psycopg2.Binary(s)
|
||||||
buf = self.execute("SELECT %s::bytea AS foo", (b,))
|
buf = self.execute("SELECT %s::bytea AS foo", (b,))
|
||||||
self.assertEqual(s, buf)
|
self.assertEqual(s, buf.tobytes())
|
||||||
|
|
||||||
def testBinaryNone(self):
|
def testBinaryNone(self):
|
||||||
b = psycopg2.Binary(None)
|
b = psycopg2.Binary(None)
|
||||||
|
@ -154,7 +154,7 @@ class TypesBasicTests(unittest.TestCase):
|
||||||
s = bytes(range(256))
|
s = bytes(range(256))
|
||||||
buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
|
buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
|
||||||
buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
|
buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
|
||||||
self.assertEqual(s, buf2)
|
self.assertEqual(s, buf2.tobytes())
|
||||||
|
|
||||||
def testArray(self):
|
def testArray(self):
|
||||||
s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
|
s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user