Python Codec for ITU T.61 Strings
t61codec is a Python library that provides a codec for handling ITU T.61 character strings. It allows encoding Python strings into T.61 byte sequences and decoding T.61 byte sequences back into Python strings. The current version is 2.0.0 and it maintains a semantic versioning release cadence, though updates are infrequent.
Common errors
-
LookupError: unknown encoding: t.61
cause The `t61codec` library has not been registered with Python's `codecs` module.fixAdd `t61codec.register()` at the beginning of your script or before attempting to use the 't.61' encoding. -
UnicodeEncodeError: 't.61' codec can't encode character '\u20ac' in position X: character maps to <undefined>
cause The input string contains a Unicode character (e.g., Euro sign '€') that is not supported by the ITU T.61 encoding.fixFilter out or replace unsupported characters before encoding, or specify an error handler like `errors='replace'` or `errors='ignore'` in the `encode` call (e.g., `codecs.encode(my_string, 't.61', errors='replace')`).
Warnings
- gotcha The `t.61` codec must be explicitly registered with Python's `codecs` registry before it can be used. Forgetting to call `t61codec.register()` will result in a `LookupError` when trying to use the 't.61' encoding.
- gotcha ITU T.61 is an 8-bit encoding. While it can represent some non-ASCII characters, it has a limited character set compared to modern encodings like UTF-8. Attempting to encode characters not supported by T.61 will raise a `UnicodeEncodeError`.
Install
-
pip install t61codec
Imports
- t61codec
import codecs codecs.encode('hello', 't.61')import t61codec t61codec.register()
Quickstart
import t61codec
import codecs
t61codec.register()
# Encode a Python string to T.61 bytes
python_string = "Hello, World!"
t61_bytes = codecs.encode(python_string, 't.61')
print(f"Encoded: {t61_bytes!r}")
# Decode T.61 bytes back to a Python string
decoded_string = codecs.decode(t61_bytes, 't.61')
print(f"Decoded: {decoded_string}")
# Example with characters that might be specific to T.61 (if applicable)
# For simplicity, using basic ASCII characters as T.61 is an 8-bit encoding
# For specific non-ASCII T.61 characters, consult ITU-T T.61 standard.