How to use xmlrpc properly with Korean (non-ascii characters)
Seunghyun Kim
lamb100 at korea.com
Mon Oct 21 23:25:23 EDT 2002
Hi.
Recently I tried xmlrpc to support Korean. In newsgroup, there are
many complaint to xmlrpc from non-english, because it formally
supports just ASCII. Here is solution for Korean Language support. I
guess it would be properly adopted to other languages.
--
First of all, you have to get xmlrpclib 0.9.9 from pythonware, and
install it to your $PYTHON_PATH$/lib. surely overwrite previous files.
Then open xmlrpclib.py with text editor and modify it.
1. insert "import codecs"
from
------------------------------------
import re, string, time, operator
import urllib, xmllib
from types import *
from cgi import escape
------------------------------------
to
------------------------------------
import re, string, time, operator
import urllib, xmllib
import codecs # codecs
from types import *
from cgi import escape
-------------------------------------
2. modify _decode() method
from
----------------------------------------------------------------------
def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
# decode non-ascii string (if possible)
if unicode and is8bit(data):
data = unicode(data, encoding)
return data
-----------------------------------------------------------------------
to
-----------------------------------------------------------------------
def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
# decode non-ascii string (if possible)
if unicode and is8bit(data):
UTF8_encode = codecs.lookup('UTF-8')[0] # set UTF8 codec
data = UTF8_encode(unicode(data, 'mbcs'))[0]
return data
------------------------------------------------------------------------
When string include non-ascii Korean characters, it is encoded with
'EUC-KR' automatically from web server. So, Client should converted it
to 'UTF-8' type which Python can cope with skillfully. I think this
approach could be adopted to other languages.
Any comment will be appreciated.
--
Sola Pro Christo
More information about the Python-list
mailing list