6.5.1. boing.net.bytes — UNICODE encoding

The boing.net.bytes module implements the adapter design pattern by providing the standard string encoding functionalities as Encoder and Decoder objects.

boing.net.bytes.encode(string, encoding="utf-8", errors="strict")

Return an encoded version of string as a bytes object. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. The default for errors is ‘strict’, meaning that encoding errors raise a UnicodeError. Other possible values are ‘ignore’, ‘replace’, ‘xmlcharrefreplace’, ‘backslashreplace’

boing.net.bytes.decode(data, encoding="utf-8", errors="strict")

Return a string decoded from the given bytes. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. The default for errors is ‘strict’, meaning that encoding errors raise a UnicodeError. Other possible values are ‘ignore’, ‘replace’ and any other name registered via codecs.register_error().

class boing.net.bytes.Encoder(encoding="utf-8", errors="strict")

The Encoder is able to produce encoded version of string objects as byte objects.

encode(string)

Return an encoded version of string as a bytes object.

reset()

NOP method.

class boing.net.bytes.Decoder(encoding="utf-8", errors="strict")

The Decoder is able to convert byte objects into strings.

decode(data)

Return the list of strings decoded from the given bytes.

reset()

NOP method.

Previous topic

6.5. boing.net — Networking and encoding tools

Next topic

6.5.2. boing.net.slip — SLIP encoding