編解碼器注冊與支持功能?

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

注冊一個新的編解碼器搜索函數。

作為副作用,其嘗試加載 encodings 包,如果尚未完成,請確保它始終位于搜索函數列表的第一位。

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

注銷一個編解碼器搜索函數并清空注冊表緩存。 如果指定搜索函數未被注冊,則不做任何操作。 成功時返回 0。 出錯時引發(fā)一個異常并返回 -1。

3.10 新版功能.

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

根據注冊的給定 encoding 的編解碼器是否已存在而返回 10。此函數總能成功。

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

泛型編解碼器基本編碼 API。

object 使用由 errors 所定義的錯誤處理方法傳遞給定 encoding 的編碼器函數。 errors 可以為 NULL 表示使用為編碼器所定義的默認方法。 如果找不到編碼器則會引發(fā) LookupError。

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

泛型編解碼器基本解碼 API。

object 使用由 errors 所定義的錯誤處理方法傳遞給定 encoding 的解碼器函數。 errors 可以為 NULL 表示使用為編解碼器所定義的默認方法。 如果找不到編解碼器則會引發(fā) LookupError

Codec 查找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.

為給定的 encoding 獲取一個 IncrementalEncoder 對象。

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

為給定的 encoding 獲取一個 IncrementalDecoder 對象。

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

為給定的 encoding 獲取一個 StreamReader 工廠函數。

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

為給定的 encoding 獲取一個 StreamWriter 工廠函數。

用于Unicode編碼錯誤處理程序的注冊表API?

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

在給定的 name 之下注冊錯誤處理回調函數 error。 該回調函數將在一個編解碼器遇到無法編碼的字符/無法解碼的字節(jié)數據并且 name 被指定為 encode/decode 函數調用的 error 形參時由該編解碼器來調用。

該回調函數會接受一個 UnicodeEncodeError, UnicodeDecodeErrorUnicodeTranslateError 的實例作為單獨參數,其中包含關于有問題字符或字節(jié)序列及其在原始序列的偏移量信息(請參閱 Unicode 異常對象 了解提取此信息的函數詳情)。 該回調函數必須引發(fā)給定的異常,或者返回一個包含有問題序列及相應替換序列的二元組,以及一個表示偏移量的整數,該整數指明應在什么位置上恢復編碼/解碼操作。

成功則返回``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.

引發(fā) 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.

使用 ?U+FFFD 替換 unicode 編碼錯誤。

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

使用 XML 字符引用替換 unicode 編碼錯誤。

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

使用反斜杠轉義符 (\x, \u\U) 替換 unicode 編碼錯誤。

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

使用 \N{...} 轉義符替換 unicode 編碼錯誤。

3.5 新版功能.