用法:
class email.headerregistry.BaseHeader(name, value)name和value從header_factory調用傳遞給BaseHeader。任何標頭對象的字符串值都是完全解碼為 unicode 的value。這個基類定義了以下隻讀屬性:
BaseHeader還提供了以下方法,該方法由電子郵件庫代碼調用,一般不應由應用程序調用:BaseHeader本身不能用於創建標頭對象。它定義了一個協議,每個專用標頭與之合作以生成標頭對象。具體來說,BaseHeader要求專用類提供一個名為parse的classmethod()。該方法調用如下:parse(string, kwds)kwds是包含一個預初始化鍵defects的字典。defects是一個空列表。 parse 方法應將任何檢測到的缺陷附加到此列表中。返回時,kwds字典must至少包含鍵decoded和defects的值。decoded應該是標頭的字符串值(即完全解碼為 unicode 的標頭值)。 parse 方法應該假設string可能包含 content-transfer-encoded 部分,但也應該正確處理所有有效的 unicode 字符,以便它可以解析 un-encoded 標頭值。BaseHeader的__new__然後創建頭實例,並調用其init方法。如果專用類希望設置除BaseHeader本身提供的屬性之外的其他屬性,則隻需要提供init方法。這樣的init方法應該如下所示:def init(self, /, *args, **kw): self._myattr = kw.pop('myattr') super().init(*args, **kw)也就是說,應該刪除和處理專用類放入
kwds字典的任何額外內容,並將kw(和args)的剩餘內容傳遞給BaseHeaderinit方法。
相關用法
- Python email.headerregistry.DateHeader用法及代碼示例
- Python email.header.decode_header用法及代碼示例
- Python email.message.Message.walk用法及代碼示例
- Python email.message.EmailMessage.add_header用法及代碼示例
- Python email.utils.getaddresses用法及代碼示例
- Python email.message.EmailMessage.walk用法及代碼示例
- Python email.message.Message.add_header用法及代碼示例
- Python email.message.Message.as_bytes用法及代碼示例
- Python email.message.Message.as_string用法及代碼示例
- Python email.iterators._structure用法及代碼示例
- Python emoji轉text用法及代碼示例
- Python numpy matrix empty()用法及代碼示例
- Python numpy matrix eye()用法及代碼示例
- Python enchant.request_dict()用法及代碼示例
- Python eval()用法及代碼示例
- Python enum.IntEnum用法及代碼示例
- Python math expm1()用法及代碼示例
- Python enchant.get_enchant_version()用法及代碼示例
- Python enchant.request_pwl_dict()用法及代碼示例
- Python eval用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 email.headerregistry.BaseHeader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
