summaryrefslogtreecommitdiffstats
path: root/iconvmodule/README.en
blob: 83a84203353ea94074d9df5b27e8689d00a9c9c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Iconv-based codec library for Python
====================================
Written by Martin v. Loewis

This package provides a set of codecs to Python based on the
underlying iconv library of the operating system, as available on
glibc 2, Solaris, or other Unix variants. It consists of two modules:
iconv and iconvcodec.

Installation
------------
To install the module, simply type

python setup.py install

This module package requires atleast Python 2.0.

Module iconv
------------
The iconv module exposes a global function to create iconv objects:

open(tocode, fromcode)
Return descriptor for character set conversion. If the conversion
of fromcode to tocode is not known to the system, a ValueError is
raised.

Iconv objects provide a single method to convert a string

iconv(in[, outlen[, return_unicode[, count_only]]])
Return the string resulting from the conversion of in. The parameter
in can be a byte or unicode string, or an arbitrary buffer object.
It is the caller's responsibility to guarantee that the internal
representation of the in object indeed uses fromcode of the Iconv
object. The parameter outlen represents an estimate of the resulting
string size (in bytes, or in characters if return_unicode is true).
If the buffer is to small, an exception is thrown. If return_unicode
is set, a Unicode object is the result. If count_only is set,
no conversion is attempted, but the number of necessary bytes is
returned.

In case of an error, the iconv method raises the exception iconv.error.
This exception has four arguments:
  - the error string as returned from strerror
  - the error number
  - the number of input bytes processed
  - the output string produced so far

Module iconvcodecs
------------------
This module encapsulates the iconv module into a set of codecs. To use it,
simply import it. As a result, the C library's codecs will be available:

  unicode("Hello","T.61")
  u"World".encode("JOHAB")

License
-------
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Author
------
Martin v. Loewis
loewis@informatik.hu-berlin.de