quopri --- 编码与解码 MIME 转码的可打印数据

源代码: Lib/quopri.py


此模块会执行转换后可打印的传输编码与解码,具体定义见 RFC 1521: "MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies"。 转换后可打印的编码格式被设计用于只包含相对较少的不可打印字符的数据;如果存在大量这样的字符,通过 base64 模块所提供的 base64 编码方案会更为紧凑,例如当发送图片文件时。

quopri.decode(input, output, header=False, *, strip_ws=False)

Decode the contents of the input file and write the resulting decoded binary data to the output file. input and output must be binary file objects. If the optional argument header is present and true, underscore will be decoded as space. This is used to decode "Q"-encoded headers as described in RFC 1522: "MIME (Multipurpose Internet Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text". If the optional argument strip_ws is true, trailing whitespace is stripped from each line, as required by RFC 2045.

在 3.16.0a1 (unreleased) 版本发生变更: Added the strip_ws parameter.

quopri.encode(input, output, quotetabs, header=False)

编码 input 文件的内容并将转换后可打印的数据结果写入 output 文件。 input 和 output 必须为 二进制文件对象. quotetabs 是一个非可选的旗标,它控制是否要编码内嵌的空格与制表符;当为真值时将编码此类内嵌空白符,当为假值时则保持原样不进行编码。 请注意出现在行尾的空格与制表符总是会被编码,具体描述见 RFC 1521。 header 旗标控制空格符是否要编码为下划线,具体描述见 RFC 1522.

quopri.decodestring(s, header=False, *, strip_ws=False)

类似 decode(),区别在于它接受一个源 bytes 并返回对应的已解码 bytes。

在 3.16.0a1 (unreleased) 版本发生变更: Added the strip_ws parameter.

quopri.encodestring(s, quotetabs=False, header=False)

类似 encode(),区别在于它接受一个源 bytes 并返回对应的已编码 bytes。 在默认情况下,它会发送 False 值给 encode() 函数的 quotetabs 形参。

参见

模块 base64

编码与解码 MIME base64 数据