Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
676
|
21 章 EmailMIME 與其他網路編碼
將二進位資料編碼為 ASCII 文字
有數種媒體(例如電子郵件訊息)只能含有 ASCII 文字。當你想要透過這
種媒體傳送任意的二進位資料,你就得將那些資料編碼為 ASCII 文字字
串。Python 標準程式庫提供了模組支援標準的編碼,例如 Base64Quoted
Printable UU
base64 模組
base64
模組支援 RFC 3548 中規範的編碼 Base16Base32 Base64。這些
編碼中每個都是將任意二進位資料表示為 ASCII 文字的簡潔方式,而不會
嘗試產生人類可讀的結果。
base64
提供 10 個函式:Base64 的有 6 個,加
Base32 Base16 2 個。那 6 Base64 函式為:
b64decode b64decode(s,altchars=None, validate=False)
解碼 Base64 所編碼的位元組字串
s
,並回傳解碼後的位元組字
串。
altchars
,若不為
None
,就必須是至少兩個字元(其餘的字元
會被忽略)的一個位元組字串,指定兩個非標準的字元用來取代
+
/
(可用來處理具 URL 安全性或檔案系統安全性的 Base64
碼字串)。
validate
只能在 v3 中傳入:若為
True
,當
s
含有的任
何位元組不是有效的 Base64 編碼字串,此呼叫會提出一個例外
(預設情況中,這種位元組單純會被忽略並跳過)。如果
s
沒有依
Base64 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819