Re: Can't register an adapter for an "old style" python class

Поиск
Список
Период
Сортировка
От Ghislain LEVEQUE
Тема Re: Can't register an adapter for an "old style" python class
Дата
Msg-id 4EB1458C.7040501@clarisys.fr
обсуждение исходный текст
Ответ на Re: Can't register an adapter for an "old style" python class  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Ответы Re: Can't register an adapter for an "old style" python class  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
Le 02/11/2011 13:00, Daniele Varrazzo a écrit :
> On Wed, Nov 2, 2011 at 10:56 AM, Ghislain LEVEQUE
> <ghislain.leveque@clarisys.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


В списке psycopg по дате отправления:

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Can't register an adapter for an "old style" python class
Следующее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Can't register an adapter for an "old style" python class