Home | Trees | Indices | Help |
|
---|
|
iconv_codec: module to register python codecs to encode/decode any char supported by system's iconv command.
iconv supports codecs unsupported by python:
>>> u'testing'.encode('ansi_x3.110-1983') Traceback (most recent call last): ... LookupError: unknown encoding: ansi_x3.110-1983 >>> import iconv_codecs >>> 'ansi_x3.110-1983' in iconv_codecs.get_supported_codecs() True
Just register the codec you want:
>>> iconv_codecs.register('ansi_x3.110-1983')
Then you can use it:
>>> u'testing'.encode('ansi_x3.110-1983') 'testing'
If you want to force iconv usage for an encoding already supported by python, just use the encoding name with an 'iconv:' prefix (no need to register):
>>> '\x87'.decode('iconv:CP860') u'\xe7'
To register all python unsupported codecs, just call register() without parameters:
>>> iconv_codecs.register() >>> u'\xe7'.encode('utf32') '\xff\xfe\x00\x00\xe7\x00\x00\x00'
That will poll iconv for a list of codecs it supports and register the ones python doesn't support already.
The module will look for iconv in the path. If you need a different iconv location just set it:
>>> iconv_codecs.ICONV_EXECUTABLE = '/usr/bin/iconv'
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
ICONV_EXECUTABLE =
change this to reflect your installation path |
|||
_codecs =
Global with the names of registered codecs |
|
Register the codecs passed for iconv usage. Codecs previously registered will be unregistered. >>> import iconv_codecs >>> iconv_codecs.register('ansi_x3.110-1983') Then you can use it: >>> u'testing'.encode('ansi_x3.110-1983') 'testing' If you want to register all codecs not already supported by python, just suppress all arguments: >>> iconv_codecs.register()
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Mar 5 18:56:44 2009 | http://epydoc.sourceforge.net |