From e816aa07b67efc8a327c194db6857e2c4df6e3a1 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Wed, 2 Mar 2005 14:51:24 +0000 Subject: [PATCH] Adding missing __conform__ methods before release. --- ChangeLog | 3 ++- examples/binary.py | 4 ++-- examples/dialtone.py | 9 +++++---- psycopg/adapter_binary.c | 19 ++++++++++++------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 634dfcc0..59400d96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2005-03-02 Federico Di Gregorio - * Release 1.99.12. + * psycopg/adapter_binary.c (binary_conform): started to add + __conform__ to all adapters. * psycopg/adapter_qstring.c (qstring_quote): we now use PyString_AsStringAndSize() instead of strlen() that would stop at diff --git a/examples/binary.py b/examples/binary.py index f15a5fa6..35b6327b 100644 --- a/examples/binary.py +++ b/examples/binary.py @@ -46,9 +46,9 @@ data2 = {'id':2, 'name':'whereareyou.jpg', 'img':buffer(open('whereareyou.jpg').read())} curs.execute("""INSERT INTO test_binary - VALUES (%(id)d, %(name)s, %(img)s)""", data1) + VALUES (%(id)s, %(name)s, %(img)s)""", data1) curs.execute("""INSERT INTO test_binary - VALUES (%(id)d, %(name)s, %(img)s)""", data2) + VALUES (%(id)s, %(name)s, %(img)s)""", data2) # now we try to extract the images as simple text strings diff --git a/examples/dialtone.py b/examples/dialtone.py index 9e453c34..1203a2c7 100644 --- a/examples/dialtone.py +++ b/examples/dialtone.py @@ -15,7 +15,7 @@ intrusive for your classes (don't want inheritance from an 'Item' or from datetime import datetime import psycopg -from psycopg.extensions import adapters, adapt +from psycopg.extensions import adapt, register_adapter try: sorted() except NameError: @@ -28,7 +28,7 @@ except NameError: # its job on that instance class ObjectMapper(object): - def __init__(self, orig): + def __init__(self, orig, curs=None): self.orig = orig self.tmp = {} self.items, self.fields = self._gatherState() @@ -80,8 +80,9 @@ class Order(object): self.price = 34 self.order_id = self.id Order.id = Order.id + 1 - -adapters.update({Album: ObjectMapper, Order: ObjectMapper}) + +register_adapter(Album, ObjectMapper) +register_adapter(Order, ObjectMapper) # Describe what is needed to save on each object # This is actually just configuration, you can use xml with a parser if you diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index 43be441e..a114f3f4 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -31,6 +31,7 @@ #include "psycopg/python.h" #include "psycopg/psycopg.h" #include "psycopg/adapter_binary.h" +#include "psycopg/microprotocols_proto.h" /** the quoting code */ @@ -165,14 +166,19 @@ binary_getquoted(binaryObject *self, PyObject *args) } PyObject * -binary_prepare(binaryObject *self, PyObject *args) +binary_conform(binaryObject *self, PyObject *args) { - PyObject *fake; + PyObject *res, *proto; - if (!PyArg_ParseTuple(args, "O", &fake)) return NULL; + if (!PyArg_ParseTuple(args, "O", &proto)) return NULL; - Py_INCREF(Py_None); - return Py_None; + if (proto == (PyObject*)&isqlquoteType) + res = (PyObject*)self; + else + res = Py_None; + + Py_INCREF(res); + return res; } /** the Binary object **/ @@ -190,8 +196,7 @@ static struct PyMemberDef binaryObject_members[] = { static PyMethodDef binaryObject_methods[] = { {"getquoted", (PyCFunction)binary_getquoted, METH_VARARGS, "getquoted() -> wrapped object value as SQL-quoted binary string"}, - /* {"prepare", (PyCFunction)binary_prepare, METH_VARARGS, - "prepare(conn) -> currently does nothing"},*/ + {"__conform__", (PyCFunction)binary_conform, METH_VARARGS, NULL}, {NULL} /* Sentinel */ };