[Spambayes] Re: Mailbox class in the spambayes project & python 2.2.1

David Eppstein eppstein@ics.uci.edu
Wed, 25 Sep 2002 11:55:21 -0700


In article <200209251651.g8PGpQj11912@odiug.zope.com>,
 Guido van Rossum <guido@python.org> wrote:

> I tried this:
> 
>   if isinstance(x, tuple):
>      assert len(x) == 3
>      x = unicode(x[2], x[0]).encode('ascii')
> 
> but this didn't work because while Python's encodings package knows
> 'ansi_x3.4_1968' and 'ansi_x3.4_1986' (sic) as aliases for 'ascii', it
> doesn't know 'ansi-x3-4-1968'. :-(

How about:

  if isinstance(x, tuple):
     assert len(x) == 3
     try:
        x = unicode(x[2], x[0]).encode('ascii')
     except:
        x = x[2]

(probably the except should be more careful about what exceptions it 
watches...)

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein@ics.uci.edu http://www.ics.uci.edu/~eppstein/