codec レジストリとサポート関数

int PyCodec_Register(PyObject *search_function)
Part of the Stable ABI.

新しい codec 検索関数を登録します。

As side effect, this tries to load the encodings package, if not yet done, to make sure that it is always first in the list of search functions.

int PyCodec_Unregister(PyObject *search_function)
Part of the Stable ABI since version 3.10.

Unregister a codec search function and clear the registry's cache. If the search function is not registered, do nothing. Return 0 on success. Raise an exception and return -1 on error.

バージョン 3.10 で追加.

int PyCodec_KnownEncoding(const char *encoding)
Part of the Stable ABI.

encoding のための登録された codec が存在するかどうかに応じて 10 を返します。 この関数は常に成功します。

PyObject *PyCodec_Encode(PyObject *object, const char *encoding, const char *errors)
Return value: New reference. Part of the Stable ABI.

汎用の codec ベースの encode API.

encoding に応じて見つかったエンコーダ関数に対して object を渡します。 エラーハンドリングメソッドは errors で指定します。 errorsNULL でもよく、その場合はその codec のデフォルトのメソッドが利用されます。 エンコーダが見つからなかった場合は LookupError を発生させます。

PyObject *PyCodec_Decode(PyObject *object, const char *encoding, const char *errors)
Return value: New reference. Part of the Stable ABI.

汎用の codec ベースのデコード API.

encoding に応じて見つかったデコーダ関数に対して object を渡します。 エラーハンドリングメソッドは errors で指定します。 errorsNULL でもよく、その場合はその codec のデフォルトのメソッドが利用されます。 デコーダが見つからなかった場合は LookupError を発生させます。

コーデック検索API

次の関数では、文字列 encoding は全て小文字に変換することで、効率的に、大文字小文字を無視した検索をします。 コーデックが見つからない場合、 KeyError を設定して NULL を返します。

PyObject *PyCodec_Encoder(const char *encoding)
Return value: New reference. Part of the Stable ABI.

与えられた encoding のエンコーダ関数を返します。

PyObject *PyCodec_Decoder(const char *encoding)
Return value: New reference. Part of the Stable ABI.

与えられた encoding のデコーダ関数を返します。

PyObject *PyCodec_IncrementalEncoder(const char *encoding, const char *errors)
Return value: New reference. Part of the Stable ABI.

与えられた encodingIncrementalEncoder オブジェクトを返します。

PyObject *PyCodec_IncrementalDecoder(const char *encoding, const char *errors)
Return value: New reference. Part of the Stable ABI.

与えられた encodingIncrementalDecoder オブジェクトを返します。

PyObject *PyCodec_StreamReader(const char *encoding, PyObject *stream, const char *errors)
Return value: New reference. Part of the Stable ABI.

与えられた encodingStreamReader ファクトリ関数を返します。

PyObject *PyCodec_StreamWriter(const char *encoding, PyObject *stream, const char *errors)
Return value: New reference. Part of the Stable ABI.

与えられた encodingStreamWriter ファクトリ関数を返します。

Unicode エラーハンドラ用レジストリ API

int PyCodec_RegisterError(const char *name, PyObject *error)
Part of the Stable ABI.

エラーハンドルのためのコールバック関数 errorname で登録します。このコールバック関数は、コーデックがエンコードできない文字/デコードできないバイトに遭遇した時に、そのエンコード/デコード関数の呼び出しで name が指定されていたら呼び出されます。

コールバックは1つの引数として、 UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError のどれかのインスタンスを受け取ります。このインスタンスは問題のある文字列やバイト列に関する情報と、その元の文字列中のオフセットを持っています。(その情報を取得するための関数については Unicode 例外オブジェクト を参照してください。) コールバックは渡された例外を発生させるか、2要素のタプルに問題のシーケンスの代替と、 encode/decode を再開する元の文字列中のオフセットとなる整数を格納して返します。

成功したら 0 を、エラー時は -1 を返します。

PyObject *PyCodec_LookupError(const char *name)
Return value: New reference. Part of the Stable ABI.

name で登録されたエラーハンドリングコールバック関数を検索します。 特別な場合として、NULL が渡された場合、"strict" のエラーハンドリングコールバック関数を返します。

PyObject *PyCodec_StrictErrors(PyObject *exc)
Return value: Always NULL. Part of the Stable ABI.

exc を例外として発生させます。

PyObject *PyCodec_IgnoreErrors(PyObject *exc)
Return value: New reference. Part of the Stable ABI.

unicode エラーを無視し、問題の入力をスキップします。

PyObject *PyCodec_ReplaceErrors(PyObject *exc)
Return value: New reference. Part of the Stable ABI.

unicode エラーを ?U+FFFD で置き換えます。

PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
Return value: New reference. Part of the Stable ABI.

unicode encode エラーを XML文字参照で置き換えます。

PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
Return value: New reference. Part of the Stable ABI.

unicode encode エラーをバックスラッシュエスケープ (\x, \u, \U) で置き換えます。

PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
Return value: New reference. Part of the Stable ABI since version 3.7.

unicode encode エラーを \N{...} で置き換えます。

バージョン 3.5 で追加.