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

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

注冊一個(gè)新的編解碼器搜索函數。

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

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

注銷(xiāo)一個(gè)編解碼器搜索函數并清空注冊表緩存。 如果指定搜索函數未被注冊,則不做任何操作。 成功時(shí)返回 0。 出錯時(shí)引發(fā)一個(gè)異常并返回 -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 表示使用為編碼器所定義的默認方法。 如果找不到編碼器則會(huì )引發(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 表示使用為編解碼器所定義的默認方法。 如果找不到編解碼器則會(huì )引發(fā) LookupError。

Codec 查找API?

在下列函數中,encoding 字符串會(huì )被查找并轉換為小寫(xiě)字母形式,這使得通過(guò)此機制查找編碼格式實(shí)際上對大小寫(xiě)不敏感。 如果未找到任何編解碼器,則將設置 KeyError 并返回 NULL。

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

為給定的 encoding 獲取一個(gè)編碼器函數。

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

為給定的 encoding 獲取一個(gè)解碼器函數。

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

為給定的 encoding 獲取一個(gè) IncrementalEncoder 對象。

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

為給定的 encoding 獲取一個(gè) IncrementalDecoder 對象。

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

為給定的 encoding 獲取一個(gè) StreamReader 工廠(chǎng)函數。

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

為給定的 encoding 獲取一個(gè) StreamWriter 工廠(chǎng)函數。

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

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

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

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

成功則返回``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 錯誤,跳過(guò)錯誤的輸入。

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 新版功能.