[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: python-xml and Debian boot floppies



As it seems that bf now depend on python-dev >= 2.1, unicode support (and
character conversion) is certainly there.  So the iconv module is no longer
required and needed at all.

The following patch seems to provide one of the possible solutions.  I'd
appreciate if somebody could test it before I put it into CVS.  It works for
me. :))  (When I put it into CVS, two more modifications will be done: iconv.c
will be removed, and all the references to this code will also be removed.)

The code previously expected UTF-8 sequences from python-xml, and then either
tried to convert them to a local charset or left as they were.

Well, the first impression is that python-xml v0.7 now supports only python
unicode strings.  To my mind, that's where the error comes from.  However, if
you look at the patch, you'll see that it's a some sort of a `dirty hack'.
Which I do not quite like, while I do not quite understand why it's required.

--
Misha
Index: dumper.py
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/langs/dumper.py,v
retrieving revision 1.4
diff -u -b -r1.4 dumper.py
--- dumper.py	2000/11/27 21:41:37	1.4
+++ dumper.py	2002/01/05 11:14:47
@@ -1,7 +1,7 @@
 #
 __copyright__ = '''
- Copyright (C) 1999 The Software in the Public Interest (SPI)
- Written by Michael Sobolev <mss@transas.com>
+ Copyright (C) 1999-2001 The Software in the Public Interest (SPI)
+ Written by Mikhail Sobolev <mss@mawhrin.net>
 
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
@@ -20,15 +20,20 @@
 
 import string, time
 
-from iconv import engine
-
 from helpers import Storage, compare_by_ename
 
 from pprint import pprint
+
+class produce:
+    def __init__ (self, charset):
+        self.charset = charset
 
-class do_not_convert:
     def convert (self, what):
-        return what
+        if type (what) == type (''):
+            what = unicode (what, 'utf-8')
+        # print 'convert:', type (what), what
+
+        return what.encode (self.charset)
 
 def dumper (arch):
     if available_dumpers.has_key (arch):
@@ -92,9 +97,9 @@
 
     for lang in what:
         if do_convert:
-            e = engine ('UTF-8', lang.charset)
+            e = produce (lang.charset)
         else:
-            e = do_not_convert ()
+            e = produce ('utf-8')
 
         outfile.write ('  {\n')
         outfile.write ('    "%s",\n' % lang.ename)
@@ -112,9 +117,9 @@
 
     for lang in what:
         if do_convert:
-            e = engine ('UTF-8', lang.charset)
+            e = produce (lang.charset)
         else:
-            e = do_not_convert ()
+            e = produce ('utf-8')
 
         dump_list_c (outfile, e, strings, items, lists, string.lower (lang.ename), lang.list)
 

Reply to: