Hi Florent!

Florent Guillaume wrote:
I have some iso-8859-15 strings that I want to export (I don't care about the <?xml?> header encoding).

Today if I do
  value = unicode(value, 'iso-8859-15')
  child.setAttribute('value', value)
I get an error on write:

File "/Users/fg/zope/zope29/Products/GenericSetup/utils.py", line 685, in exportObjects
    exportObjects(sub, path+'/', context)
File "/Users/fg/zope/zope29/Products/GenericSetup/utils.py", line 681, in exportObjects
    context.writeDataFile(filename, body, exporter.mime_type)
File "/Users/fg/zope/zope29/Products/GenericSetup/context.py", line 388, in writeDataFile
    self._archive.addfile( info, stream )
  File "/usr/local/lib/python2.4/tarfile.py", line 1302, in addfile
    copyfileobj(fileobj, self.fileobj, tarinfo.size)
  File "/usr/local/lib/python2.4/tarfile.py", line 173, in copyfileobj
    dst.write(buf)
  File "/usr/local/lib/python2.4/gzip.py", line 202, in write
    self.crc = zlib.crc32(data, self.crc)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 297: ordinal not in range(128)

Is that expected? For now I convert to utf-8 instead of unicode, but it feels like the writer should take care of that, no? Or is that a minidom restriction?

1.) The configuration setup machinery is not tested with non-ascii values. AFAICS most sites that need non-English settings translate them on the fly. Feel free to extend the machinery if you need support for other encodings.

2.) Looks like toprettyxml has to be called with encoding='utf-8' to set the writer to utf-8 mode. But that also sets the encoding specified in the XML header. (Since utf-8 is the default we might want to suppress the second effect in PrettyDocument)


Cheers,

        Yuppie

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to