[XML-SIG] problems reading iso-8859-1 data
Alexandre Fayolle
Alexandre.Fayolle@logilab.fr
Mon, 30 Apr 2001 15:52:38 +0200 (CEST)
On 30 Apr 2001, Don Allingham wrote:
> Yes, I have the encoding="iso-8859-1" set the file. It sounds as if
> expat is converting the iso-8859-1 to UTF-8. Is there a way to convert
> back to iso-8859-1? Unfortunately, I'm stuck with 1.5.2.
Try this :
---------------------------8<---------------------------------
from xml.unicode.utf8_iso import utf8_to_code, code_to_utf8
import cStringIO
def utf8_to_latin(s):
buff = cStringIO.StringIO()
while s:
try:
head,s = utf8_to_code(1,s)
except Exception,e:
from traceback import print_exc
print_exc()
head = ''
s = s[1:]
buff.write(head)
ans = buff.getvalue()
buff.close()
return ans
def latin_to_utf8(s):
buff = cStringIO.StringIO()
for c in s:
try:
cv = code_to_utf8(1,c)
except Exception,e:
from traceback import print_exc
print_exc()
cv = ''
buff.write(cv)
ans = buff.getvalue()
buff.close()
return ans
---------------------------------8<--------------------------
Alexandre Fayolle
--
http://www.logilab.com
Narval is the first software agent available as free software (GPL).
LOGILAB, Paris (France).