email.errors: 例外及び欠陥クラス

ソースコード: Lib/email/errors.py


email.errors モジュールでは、以下の例外クラスが定義されています:

exception email.errors.MessageError

これは email パッケージが送出しうるすべての例外の基底クラスです。これは標準の Exception クラスから派生しており、追加のメソッドは定義されていません。

exception email.errors.MessageParseError

This is the base class for exceptions raised by the Parser class. It is derived from MessageError. This class is also used internally by the parser used by headerregistry.

exception email.errors.HeaderParseError

Raised under some error conditions when parsing the RFC 5322 headers of a message, this class is derived from MessageParseError. The set_boundary() method will raise this error if the content type is unknown when the method is called. Header may raise this error for certain base64 decoding errors, and when an attempt is made to create a header that appears to contain an embedded header (that is, there is what is supposed to be a continuation line that has no leading whitespace and looks like a header).

exception email.errors.BoundaryError

Deprecated and no longer used.

exception email.errors.MultipartConversionError

この例外は、 Message オブジェクトに add_payload() メソッドでペイロードを追加したが、そのペイロードがすでにスカラー値で、メッセージの Content-Type メインタイプが multipart でないか見付からない場合に送出されます。 MultipartConversionErrorMessageError と組み込みの TypeError を多重継承しています。

Message.add_payload() は非推奨なので、実際のところこの例外が送出されることはほとんどありません。 しかしながら、 attach() メソッドを MIMENonMultipart から派生したインスタンス (たとえば MIMEImage) に対して呼んだ場合にも送出されることがあります。

exception email.errors.MessageDefect

This is the base class for all defects found when parsing email messages. It is derived from ValueError.

exception email.errors.HeaderDefect

This is the base class for all defects found when parsing email headers. It is derived from MessageDefect.

以下は FeedParser がメッセージの解析中に検出する障害 (defect) の一覧です。これらの障害は、問題が見つかったメッセージに追加されるため、たとえば multipart/alternative 内にあるネストしたメッセージが異常なヘッダをもっていた場合には、そのネストしたメッセージが障害を持っているが、その親メッセージには障害はないとみなされることに注意してください。

すべての障害クラスは email.errors.MessageDefect のサブクラスです。

  • NoBoundaryInMultipartDefect -- メッセージが multipart だと宣言されているのに、 boundary パラメータがありません。

  • StartBoundaryNotFoundDefect -- Content-Type ヘッダで宣言された開始境界がありません。

  • CloseBoundaryNotFoundDefect -- 開始境界はあるが対応する終了境界がありません。

    バージョン 3.3 で追加.

  • FirstHeaderLineIsContinuationDefect -- メッセージの最初のヘッダ行が継続行です。

  • MisplacedEnvelopeHeaderDefect -- ヘッダブロックの途中に "Unix From" ヘッダがあります。

  • MissingHeaderBodySeparatorDefect - 先頭に空白はないが ':' がないヘッダの解析中に行が見付かりました。その行を本体の最初の行とみなして解析を続けます。

    バージョン 3.3 で追加.

  • MalformedHeaderDefect -- ヘッダにコロンがありません、あるいはそれ以外の不正な形式です。

    バージョン 3.3 で非推奨: この欠陥が使われていないPythonバージョンがいくつかあります。

  • MultipartInvariantViolationDefect -- メッセージが multipart だと宣言されているのに、サブパートが存在しません。 メッセージがこの欠陥を持つ場合、内容の型が multipart と宣言されていても is_multipart() メソッドは False を返すことがあるので注意してください。

  • InvalidBase64PaddingDefect -- 一連の base64 でエンコードされた bytes をデコードしているときにパディングが誤っていました。 デコードするのに十分なパディングがなされますが、デコードされた bytes は不正かもしれません。

  • InvalidBase64CharactersDefect -- 一連の base64 でエンコードされた bytes をデコードしているときに base64 アルファベット外の文字がありました。 その文字は無視されますが、デコードされた bytes は不正かもしれません。

  • InvalidBase64LengthDefect -- When decoding a block of base64 encoded bytes, the number of non-padding base64 characters was invalid (1 more than a multiple of 4). The encoded block was kept as-is.

  • InvalidDateDefect -- When decoding an invalid or unparsable date field. The original value is kept as-is.