Re: client encoding name normalization in psycopg 2.4 - Mailing list psycopg

From Federico Di Gregorio
Subject Re: client encoding name normalization in psycopg 2.4
Date
Msg-id 4D9F0A18.9050205@dndg.it
Whole thread Raw
In response to Re: client encoding name normalization in psycopg 2.4  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
On 08/04/11 14:59, Daniele Varrazzo wrote:
> On Fri, Apr 8, 2011 at 12:34 PM, Federico Di Gregorio
> <federico.digregorio@dndg.it> wrote:
>> > On 07/04/11 21:46, Peter Eisentraut wrote:
>> > [snip]
>>> >> Attached is a patch that implements that.  Note that the PostgreSQL
>>> >> backend version of this actually lowercases the encoding names during
>>> >> normalization.  I have made this patch uppercase them to keep the patch
>>> >> smaller, but you may want to consider doing the lowercasing, to keep
>>> >> things consistent.
>> >
>> > The patch seems fine to me. I'll check it in later during the we.
> I was working on the patch, but there's something not straightforward.
>
> I think assuming that psycopg2.extensions.encodings[conn.encoding]
> will always work is reasonable (also because it's the only way to
> convert the PG encoding to a Python encoding). The patch breaks this
> assumption, without which getting the Python codec name from the PG
> encoding becomes a convoluted operation.
>
> A better fix is probably to set connection.encoding to the normalized
> string, so that the lookup will always work. This means that
> connection.encoding is no more exactly what returned by SHOW
> connection_encoding but I don't think this is really important
> (furthermore the current code already converts it in uppercase).

Yep, that was my idea too. The patch already contains code to normalize
the encoding so it should be straightforward to have a normalized
conn.encoding.

federico

--
Federico Di Gregorio                         federico.digregorio@dndg.it
Studio Associato Di Nunzio e Di Gregorio                  http://dndg.it
  99.99999999999999999999% still isn't 100% but sometimes suffice. -- Me

psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: client encoding name normalization in psycopg 2.4
Next
From: Mark Sienkiewicz
Date:
Subject: Re: portable DBAPI auto-increment