[4suite] Re: [XML-SIG] Python 1.5 support with PyXML 0.6.2/4Suite0.9.2

Uche Ogbuji uche.ogbuji@fourthought.com
Fri, 17 Nov 2000 08:38:56 -0700


Alexandre Fayolle wrote:
> 
> On Thu, 16 Nov 2000, Martin v. Loewis wrote:
> 
> > > I would like to have some clarification about the python 1.52 support in
> > > PyXML 0.6.2 and 4Suite 0.9.2. 4Suite specifies it nees PyXML 0.6.2 to
> > > run. Is it 6.2 for python 2.0 and 5.5.1 for python 1.52 ?
> >
> > PyXML supports both Python 1.5.2, and Python 2.0.
> >
> > > I could not find the xml.unicode package in pyxml 0.6.2...
> >
> > There isn't any such package. Why do you think it should be there?
> 
> Well, just 'cos it was there in PyXML 0.5.5.1 and 4Suite seems to
> heavily depend on it when running under python 1.5.2
> 
> in Printer.py, there are things like:
> 
> try:
>     #The following stanza courtesy Martin von Loewis
>     import codecs # Python 1.5 only
>     from types import UnicodeType
>     def utf8_to_code(text, encoding):
>         encoder = codecs.lookup(encoding)[0] # encode,decode,reader,writer
>         if type(text) is not UnicodeType:
>             text = unicode(text, "utf-8")
>         return encoder(text)[0] # result,size
> except ImportError:
>     def utf8_to_code(text, encoding):
>         encoding = string.upper(encoding)
>         if encoding == 'UTF-8':
>             return text
>         from xml.unicode.iso8859 import wstring
>         wstring.install_alias('ISO-8859-1', 'ISO_8859-1:1987')
>         #Note: Pass through to wstrop.  This means we don't play nice and
>         #Escape characters that are not in the target encoding.
>         ws = wstring.from_utf8(text)
>         text = ws.encode(encoding)
>         #This version would skip all untranslatable chars: see wstrop.c
>         #text = ws.encode(encoding, 1)
>         return text
> 
> There is an error in the comment of line 3 of the above snippet
> (codecs are only in python2.0), so Python 1.5 will actually execute the
> except statement, and therefore an xml.unicode.iso8859 package seems to be
> required.

Yes.  I too am trying to clarify the sitruation with the unicode
package.  Martin von Loewis actually helped with the code you quote, so
I'm surprised that he is surprised that we should be expecting the
xml.unicode package to still be in PyXML.


-- 
Uche Ogbuji                               Principal Consultant
uche.ogbuji@fourthought.com               +1 303 583 9900 x 101
Fourthought, Inc.                         http://Fourthought.com 
4735 East Walnut St, Ste. C, Boulder, CO 80301-2537, USA
Software-engineering, knowledge-management, XML, CORBA, Linux, Python