Additional EBCDIC codecs
ebcdic
is a Python package adding additional EBCDIC codecs for data
exchange with legacy system. It works with Python 2.7 and Python 3.4+.
EBCDIC <https://en.wikipedia.org/wiki/EBCDIC>
_ is short for Extended Binary
Coded Decimal Interchange Code and is a family of character encodings that is
mainly used on mainframe computers. There is no real point in using it unless
you have to exchange data with legacy systems that still only support EBCDIC
as character encoding.
The ebcdic
package is available from https://pypi.python.org/pypi/ebcdic
and can be installed using pip::
pip install ebcdic
To encode 'hello world'
on EBCDIC systems in German speaking countries,
use::
import ebcdic 'hello world'.encode('cp1141') b'\x88\x85\x93\x93\x96@\xa6\x96\x99\x93\x84O'
The ebcdic
package includes EBCDIC codecs for the following regions:
It also includes legacy codecs:
Codecs in the standard library overrule some of these codecs. At the time of this writing this concerns cp037, cp273 (since 3.4), cp500 and cp1140.
To see get a list of EBCDIC codecs that are already provided by different
sources, use ebcdic.ignored_codec_names()
. For example, with Python 3.6
the result is::
ebcdic.ignored_codec_names() ['cp037', 'cp1140', 'cp273', 'cp424', 'cp500', 'cp875']
According to a
comprehensive list of code pages <https://www.aivosto.com/articles/charsets-codepages.html>
_,
there are additional codecs this package does not support yet. Possible
reasons and solutions are:
CodecMapper
can easily support them by increasing the mapping size from 256 to 65536.
Due lack of test date and access to Asian mainframes this was deemed too
experimental for now.build.xml
as described below.These codecs have been generated using CodecMapper, available from https://github.com/roskakori/CodecMapper. Read the README in order to to build the ebcdic package from source.
To add another 8 bit EBCDIC codec just extend the ant target ebcdic
in
build.xml
using a line like::
Replace XXX
by the number of the 8 bit code page you want to include.
Then run::
ant test
to build and test the distribution.
The ebcdic/setup.py
automatically includes the new encoding in the package
and ebcdic/__init__.py
registers it during import ebcdic
, so no
further steps are needed.
Version 1.1.1, 2019-08-09
Moved license information from README to LICENSE (#5). This required the distribution to change from sdist to wheel because apparently it is a major challenge to include a text file in a platform independent way (#11).
Sadly this breaks compatibility with Python 2.6, 3.1, 3.2 and 3.3. If you
still need ebcdic
with one of these Python versions, use
ebcdic-1.0.0
.
This took several attempts and intermediate releases that where broken in
different ways on different platforms. To prevent people from accidentally
installing one of these broken releases they have been removed from PyPI.
If you still want to take a look at them, use the
respective tags <https://github.com/roskakori/CodecMapper/releases>
_.
Version 1.0.0, 2019-06-06
Version 0.7, 2014-11-17
ebcdic
package. Also added a function
ebcdic.ignored_codec_names()
that returns the name of the EBCDIC codecs
provided by other means. To obtain access to ebcdic
codecs overruled by
the standard library, use ebcdic.lookup()
.Version 0.6, 2014-11-15
gencodec.py
that still builds maps
instead of tables so the generated codecs work with Python versions earlier
than 3.3. It also does a from __future__ import unicode_literals
so the
codecs even work with Python 2.6+ using the same source code. As a side
effect, this simplifies building the codecs because it removes the the need
for a local copy of the cpython source code.Version 0.5, 2014-11-13