Changes in 0.1.15 and how to use same code on stable machines

John Wright jsw at debian.org
Sat Apr 10 20:37:01 UTC 2010


Hi Andreas,

On Sat, Apr 10, 2010 at 01:33:22PM +0200, Andreas Tille wrote:
> Hi,
> 
> for the Debian Pure Blends tasks pages I'm using python-debian.  I frequently
> used code like
> 
>     printsting = unicode(stanza[field], 'utf-8')
> 
> to handle UTF-8 encoded strings.  When using python-debian >= 0.1.15
> this results in
> 
>    TypeError: decoding Unicode is not supported
> 
> exceptions which is caused by the change which is refered to in the
> changelog saying:
> 
>   [ John Wright ]
>   * deb822: Better support for non-ascii values.  Deb822 objects now
>     always contain unicode objects instead of strings.  Use the encoding
>     argument to Deb822's initializer and its iter_paragraphs class
>     method if the encoding of a file you are reading in is not utf-8.
>     (The dump method also takes an encoding argument, if you wish the
>     output not to be utf-8-encoded.) (Closes: #495272)
> 
> While I'm really happy about the change which simplifies things I wonder
> what you would suggest to run the same code on development as well as
> production machines (for instance alioth.debian.org which generates the
> tasks pages).  Backports.debian.org is only featuring 0.1.14 and I have
> no idea which code relays on the old behaviour and what might be broken
> there would be a backport of the recent python-debian would be installed
> on alioth.
> 
> Any hints?

How about

    printstring = stanza[field].decode('utf-8')

As far as I have tested, both str and unicode have a decode method, and
it looks like unicode doesn't really care about what argument you give
it.

The other option is checking whether the object is unicode or str type,
but I think the above works, and is cleaner.

-- 
John Wright <jsw at debian.org>



More information about the pkg-python-debian-maint mailing list