创新互联Python教程:编解码器注册与支持功能

编解码器注册与支持功能

int PyCodec_Register(PyObject *search_function)

目前累计服务客户近1000家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站建设、成都网站制作、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。

Part of the Stable ABI.

注册一个新的编解码器搜索函数。

作为副作用,其尝试加载 encodings 包,如果尚未完成,请确保它始终位于搜索函数列表的第一位。

int PyCodec_Unregister(PyObject *search_function)

Part of the Stable ABI since version 3.10.

注销一个编解码器搜索函数并清空注册表缓存。 如果指定搜索函数未被注册,则不做任何操作。 成功时返回 0。 出错时引发一个异常并返回 -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 表示使用为编码器所定义的默认方法。 如果找不到编码器则会引发 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 表示使用为编解码器所定义的默认方法。 如果找不到编解码器则会引发 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。 该回调函数将在一个编解码器遇到无法编码的字符/无法解码的字节数据并且 name 被指定为 encode/decode 函数调用的 error 形参时由该编解码器来调用。

该回调函数会接受一个 UnicodeEncodeError, UnicodeDecodeError 或 UnicodeTranslateError 的实例作为单独参数,其中包含关于有问题字符或字节序列及其在原始序列的偏移量信息(请参阅 Unicode 异常对象 了解提取此信息的函数详情)。 该回调函数必须引发给定的异常,或者返回一个包含有问题序列及相应替换序列的二元组,以及一个表示偏移量的整数,该整数指明应在什么位置上恢复编码/解码操作。

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

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

标题名称:创新互联Python教程:编解码器注册与支持功能
浏览路径:http://www.hantingmc.com/qtweb/news47/266197.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联