2001-05-13 01:56:57 +00:00
|
|
|
|
2001-05-17 23:08:27 +00:00
|
|
|
import cStringIO
|
2001-05-13 01:56:57 +00:00
|
|
|
|
2001-05-17 23:08:27 +00:00
|
|
|
try:
|
|
|
|
from xml.unicode.utf8_iso import code_to_utf8
|
|
|
|
from xml.unicode.iso8859 import UTF8String
|
2001-05-13 01:56:57 +00:00
|
|
|
|
2001-05-17 23:08:27 +00:00
|
|
|
def utf8_to_latin(s):
|
|
|
|
y = UTF8String(s)
|
|
|
|
return y.encode("iso-8859-1")
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
def utf8_to_latin(s):
|
|
|
|
return s
|
2001-05-13 01:56:57 +00:00
|
|
|
|
2001-05-17 23:08:27 +00:00
|
|
|
def latin_to_utf8(s):
|
|
|
|
return s
|
2001-05-13 01:56:57 +00:00
|
|
|
|
2001-05-17 23:08:27 +00:00
|
|
|
|