Chapter 21. MIME and Network Encodings
travels on a network are streams of bytes or text. However, what you
want to send over the network often has more structure. The
Multipurpose Internet Mail Extensions (MIME) and other encoding
standards bridge the gap by specifying how to represent structured
data as bytes or text. Python supports such encodings through many
library modules, such as
uu, and the modules of
Encoding Binary Data as Text
Several kinds of media (e.g., email messages) contain only text. When you want to transmit binary data via such media, you need to encode the data as text strings. The Python standard library supplies modules that support the standard encodings known as Base 64, Quoted Printable, and UU.
The base64 Module
base64 module supports the encoding specified in
RFC 1521 as Base 64. The Base 64 encoding is a compact way to
represent arbitrary binary data as text, without any attempt to
produce human-readable results. Module
supplies four functions.
The quopri Module
quopri module supports the encoding specified in
RFC 1521 as Quoted Printable (QP). QP can represent any binary data
as text, but it’s mainly intended for data that is
textual, with a relatively modest amount of characters with the high
bit set (i.e., characters outside of the ASCII range). For such data,
QP produces results that are both compact and rather human-readable.
quopri supplies ...