API Reference¶
baudot¶
Baudot – Tools for handling stateful 5-bit encoding
-
baudot.
decode
(reader: baudot.handlers.core.BaudotReader, codec: baudot.codecs.core.BaudotCodec, stream: io.TextIOBase)[source]¶ Decode a baudot code stream from a reader to a unicode stream, using a given codec.
Parameters: - reader – Reader instance that will read codes from an input
- codec – Codec to use for decoding
- stream – Unicode stream to write to (can be a file)
-
baudot.
decode_to_str
(reader: baudot.handlers.core.BaudotReader, codec: baudot.codecs.core.BaudotCodec) → str[source]¶ Decode a baudot code stream from a reader to a unicode string, using a given codec.
Parameters: - reader – Reader instance that will read codes from an input
- codec – Codec to use for decoding
Returns: Decoded Unicode string
-
baudot.
encode
(stream: io.TextIOBase, codec: baudot.codecs.core.BaudotCodec, writer: baudot.handlers.core.BaudotWriter)[source]¶ Encode unicode characters from an input stream to an output writer, using the given codec.
Parameters: - stream – Unicode character stream to encode (can be a file)
- codec – Codec to use for encoding
- writer – Writer instance for the wanted output format
-
baudot.
encode_str
(chars: str, codec: baudot.codecs.core.BaudotCodec, writer: baudot.handlers.core.BaudotWriter)[source]¶ Encode unicode characters from an input string to an output writer, using the given codec.
Parameters: - chars – Unicode string to encode
- codec – Codec to use for encoding
- writer – Writer instance for the wanted output format
baudot.core¶
Core encoding/decoding logic of the library
All tools from this module are available from baudot
for convenience.
baudot.codecs¶
Codecs are the tools used to convert encoded-data (5-bit digits) into Unicode characters and back.
-
baudot.codecs.
ITA1_CONTINENTAL
¶ Codec for the original Baudot code, a.k.a. ITA1 continental
-
baudot.codecs.
ITA2_STANDARD
¶ Codec for the standard Baudot-Murray code, a.k.a. ITA2
-
baudot.codecs.
ITA2_US
¶ Codec for the US variant of the Baudot-Murray code, a.k.a. US-TTY
-
class
baudot.codecs.
BaudotCodec
[source]¶ Bases:
abc.ABC
Abstract Base Class for a Codec
-
class
baudot.codecs.
SimpleTabledCodec
(name: str, tables: Dict[baudot.codecs.core.Shift, List[Union[str, baudot.codecs.core.Shift]]])[source]¶ Bases:
baudot.codecs.core.BaudotCodec
Creates a codec based on a character table.
The input format must be a dictionary of which the keys are the possible states (instances of
Shift
) and the values are lists of length 32 exactly, containing characters or shifts.The
Shift
instances are the only control characters this library knows of. Any other must be taken from ASCII/Unicode.-
decode
(code: int, state: Optional[baudot.codecs.core.Shift]) → Union[str, baudot.codecs.core.Shift][source]¶ Get the character or state shift corresponding to a given code in a given state.
Parameters: - code – Code to look up
- state – State to apply. This may be None, so that a the state can be initialized.
Returns: Decoded character or state shift
-
encode
(value: Union[str, baudot.codecs.core.Shift], state: baudot.codecs.core.Shift) → Tuple[int, baudot.codecs.core.Shift][source]¶ Get the code of the given character of Shift for this codec.
Actually, this logic returns not only the code but also the state required for this code. The current state should also be passed so that more complicated cases can be solved.
Parameters: - value – Value (character or state shift) to encode
- state – Current state of encoding
Returns: Code for this value, and required state
-
baudot.handlers¶
The handlers are interfaces to read and write 5-bit data from a variety of formats.
baudot.handlers.hexbytes¶
Handler for reading and writing 5-bit codes as a hexadecimal bit stream.
baudot.handlers.tape¶
Handler for reading and writing to pretty tape-like formatted text
For example, the tape might look like::
***.**
* *.
. *
* .*
* .*
** .
*.
* .**
** .
* .*
* .*
* . *
** .**
**. *
(Which reads ‘HELLO WORLD!’)
-
class
baudot.handlers.tape.
TapeConfig
¶ Bases:
tuple
Object for storing a tape representation format.
-
blank
¶ Alias for field number 1
-
punch
¶ Alias for field number 0
-
sep
¶ Alias for field number 2
-
baudot.exceptions¶
Custom exceptions for the Baudot library
-
exception
baudot.exceptions.
BaudotException
[source]¶ Bases:
Exception
Core exception class for this library
-
exception
baudot.exceptions.
DecodingError
[source]¶ Bases:
baudot.exceptions.BaudotException
Raised on decoding error
-
exception
baudot.exceptions.
EncodingError
[source]¶ Bases:
baudot.exceptions.BaudotException
Raised on encoding error
-
exception
baudot.exceptions.
IncoherentTable
[source]¶ Bases:
baudot.exceptions.BaudotException
Raised when an encoding/decoding table is not valid
-
exception
baudot.exceptions.
ReadError
[source]¶ Bases:
baudot.exceptions.BaudotException
Raised when reading a 5-bit stream fails
-
exception
baudot.exceptions.
WriteError
[source]¶ Bases:
baudot.exceptions.BaudotException
Raised when writing a 5-bit stream fails