1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/iconv.py Mon Dec 12 00:40:54 2016 +0100
1.3 @@ -0,0 +1,36 @@
1.4 +# -*- coding: ISO-8859-1 -*-
1.5 +
1.6 +from posix.iconv import Converter, EINVAL, EILSEQ
1.7 +
1.8 +to_utf8 = Converter("ISO-8859-1", "UTF-8")
1.9 +to_utf16 = Converter("ISO-8859-1", "UTF-16")
1.10 +from_utf8 = Converter("UTF-8", "ISO-8859-1")
1.11 +from_utf16 = Converter("UTF-16", "ISO-8859-1")
1.12 +
1.13 +try:
1.14 + iso = "æøå"
1.15 + print iso # æøå
1.16 + utf = to_utf8.convert(iso)
1.17 + print utf # æøå
1.18 + print from_utf8.convert(utf) # æøå
1.19 + utf = to_utf16.convert(iso)
1.20 + print utf # ...
1.21 + try:
1.22 + print from_utf16.convert(utf) # æøå
1.23 + except OSError, exc:
1.24 + if exc.value == EINVAL:
1.25 + print "Incomplete input", exc.arg
1.26 + elif exc.value == EILSEQ:
1.27 + print "Invalid input", exc.arg
1.28 + else:
1.29 + print exc.value, exc.arg
1.30 +finally:
1.31 + to_utf8.close()
1.32 + to_utf16.close()
1.33 + from_utf8.close()
1.34 + from_utf16.close()
1.35 +
1.36 +try:
1.37 + Converter("horses", "giraffes")
1.38 +except OSError, exc:
1.39 + print 'Converter("horses", "giraffes"): not valid encodings; error is', exc.value