quopri --- 編碼和解碼 MIME 可列印字元資料¶
原始碼:Lib/quopri.py
該模組根據 RFC 1521:「MIME(多功能網際網路郵件擴充)第一部分:指定和描述網際網路訊息正文格式的機制」中的定義來執行可列印字元 (quoted-printable) 傳輸編碼和解碼。可列印字元編碼是為不可列印字元相對較少的資料而設計的;如果存在許多此類字元(例如發送圖形檔案時),則透過 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,一個非可選旗標,控制是否對嵌入的空格和製表符號 (tab) 進行編碼;當為 true 時,它將對此類嵌入的空白進行編碼,當為 false 時,它將不對它們進行編碼。請注意,出現在列尾的空格和製表符號都會按照 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。預設情況下,它向encode()函式的 quotetabs 參數發送一個False值。
也參考
base64模組對 MIME Base64 資料進行編碼和解碼