From: | Ghislain LEVEQUE <ghislain(dot)leveque(at)clarisys(dot)fr> |
---|---|
To: | psycopg(at)postgresql(dot)org |
Subject: | Re: Can't register an adapter for an "old style" python class |
Date: | 2011-11-02 13:28:44 |
Message-ID: | 4EB1458C.7040501@clarisys.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
Le 02/11/2011 13:00, Daniele Varrazzo a écrit :
> On Wed, Nov 2, 2011 at 10:56 AM, Ghislain LEVEQUE
> <ghislain(dot)leveque(at)clarisys(dot)fr> wrote:
>> I guess psycopg2 uses type instead of isinstance and this does not work with
>> old-style python class :
>
> Yes, as far as I can see it has always worked this way: roughly there
> is a mapping type -> adapter in psycopg2.extensions.adapters and the
> adapter is looked up by adapters[type(obj)]. If we had to use
> isinstance instead, it would take a linear scan of the adapters map
> for every adapted object. So It seems psycopg has worked with new
> style classes since they were really new, and never bothered with
> old-style ones.
Is it possible to (re)define 'adapt' so that it first check if type(obj)
= 'instance' and then perform a scan on the mapping. Else, get the
adapter the usual way ?
>> What is the "right" way to do this ?
> I would say very simply copy the dateutil module into your project,
> patch it to make a new style class it and use it: I think the license
> (PSF) allows that. Also consider filing a request to the dateutil
> author to make it a new-style class. Oh, it looks like you are a
> contributor:<https://launchpad.net/dateutil>. Why don't you make it a
> new-style class?
Well I think I'll have to do this. Thanks
> There is also this, cropped up in a google search, don't know what it
> is:<http://pypi.python.org/pypi/psycopg2-dateutils/0.1>.
Yes, I've based my work on this code but it's incomplete (only in the
SQL->python way) and I needed both ways
--
Ghislain LEVEQUE - Clarisys Informatique
http://www.clarisys.fr - 09 72 11 43 60
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2011-11-02 13:51:09 | Re: Can't register an adapter for an "old style" python class |
Previous Message | Daniele Varrazzo | 2011-11-02 12:00:17 | Re: Can't register an adapter for an "old style" python class |