quopri
— Encode and decode MIME quoted-printable data编码和解码MIME引用的可打印数据¶
Source code: Lib/quopri.py
This module performs quoted-printable transport encoding and decoding, as defined in RFC 1521: “MIME (Multipurpose Internet Mail Extensions) Part One:
Mechanisms for Specifying and Describing the Format of Internet Message Bodies”. 该模块执行引用的可打印传输编码和解码,如RFC 1521“MIME(多用途Internet邮件扩展)第一部分:指定和描述Internet消息体格式的机制”中所定义。The quoted-printable encoding is designed for data where there are relatively few nonprintable characters; the base64 encoding scheme available via the 引用的可打印编码是为非打印字符相对较少的数据设计的;如果有许多这样的字符,例如发送图形文件时,通过base64
module is more compact if there are many such characters, as when sending a graphics file.base64
模块可用的base64编码方案更紧凑。
-
quopri.
decode
(input, output, header=False)¶ Decode the contents of the input file and write the resulting decoded binary data to the output file.对input文件的内容进行解码,并将解码后的二进制数据写入output文件。input and output must be binary file objects.input和output必须是二进制文件对象。If the optional argument header is present and true, underscore will be decoded as space.如果可选参数header存在且为true
,则下划线将被解码为空格。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”.这用于解码RFC 1522“MIME(多用途Internet邮件扩展)第二部分:非ASCII文本的消息头扩展”中描述的“Q”编码头。
-
quopri.
encode
(input, output, quotetabs, header=False)¶ Encode the contents of the input file and write the resulting quoted-printable data to the output file.对input文件的内容进行编码,并将结果引用的可打印数据写入output文件。input and output must be binary file objects.input和output必须是二进制文件对象。quotetabs, a non-optional flag which controls whether to encode embedded spaces and tabs; when true it encodes such embedded whitespace, and when false it leaves them unencoded.quotetabs,一个非可选标志,控制是否对嵌入的空格和制表符进行编码;当为true
时,它对这种嵌入的空格进行编码,当为false
时,它将它们保留为未编码。Note that spaces and tabs appearing at the end of lines are always encoded, as per RFC 1521.请注意,根据RFC 1521,出现在行尾的空格和制表符始终是编码的。header is a flag which controls if spaces are encoded as underscores as per RFC 1522.header报头是一个标志,它控制空格是否按照RFC 1522编码为下划线。
-
quopri.
decodestring
(s, header=False)¶ Like与decode()
, except that it accepts a sourcebytes
and returns the corresponding decodedbytes
.decode()
类似,只是它接受源bytes
并返回相应的解码bytes
。
-
quopri.
encodestring
(s, quotetabs=False, header=False)¶ Like与encode()
, except that it accepts a sourcebytes
and returns the corresponding encodedbytes
.encode()
类似,只是它接受源bytes
并返回相应的编码bytes
。By default, it sends a默认情况下,它会向False
value to quotetabs parameter of theencode()
function.encode()
函数的quotetabs参数发送一个False
值。
See also另请参见
- Module
base64
Encode and decode MIME base64 data编码和解码MIME base64数据