Codec registry and support functions

intPyCodec_Register(PyObject*search_function)
Μέρος τουΣταθερό ABI.

Register a new codec search function.

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

intPyCodec_Unregister(PyObject*search_function)
Μέρος τουΣταθερό ABI από την έκδοση 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.

Added in version 3.10.

intPyCodec_KnownEncoding(constchar*encoding)
Μέρος τουΣταθερό ABI.

Return1 or0 depending on whether there is a registered codec forthe givenencoding. This function always succeeds.

PyObject*PyCodec_Encode(PyObject*object,constchar*encoding,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Generic codec based encoding API.

object is passed through the encoder function found for the givenencoding using the error handling method defined byerrors.errors maybeNULL to use the default method defined for the codec. Raises aLookupError if no encoder can be found.

PyObject*PyCodec_Decode(PyObject*object,constchar*encoding,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Generic codec based decoding API.

object is passed through the decoder function found for the givenencoding using the error handling method defined byerrors.errors maybeNULL to use the default method defined for the codec. Raises aLookupError if no encoder can be found.

Codec lookup API

In the following functions, theencoding string is looked up converted to alllower-case characters, which makes encodings looked up through this mechanismeffectively case-insensitive. If no codec is found, aKeyError is setandNULL returned.

PyObject*PyCodec_Encoder(constchar*encoding)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get an encoder function for the givenencoding.

PyObject*PyCodec_Decoder(constchar*encoding)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get a decoder function for the givenencoding.

PyObject*PyCodec_IncrementalEncoder(constchar*encoding,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get anIncrementalEncoder object for the givenencoding.

PyObject*PyCodec_IncrementalDecoder(constchar*encoding,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get anIncrementalDecoder object for the givenencoding.

PyObject*PyCodec_StreamReader(constchar*encoding,PyObject*stream,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get aStreamReader factory function for the givenencoding.

PyObject*PyCodec_StreamWriter(constchar*encoding,PyObject*stream,constchar*errors)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Get aStreamWriter factory function for the givenencoding.

Registry API for Unicode encoding error handlers

intPyCodec_RegisterError(constchar*name,PyObject*error)
Μέρος τουΣταθερό ABI.

Register the error handling callback functionerror under the givenname.This callback function will be called by a codec when it encountersunencodable characters/undecodable bytes andname is specified as the errorparameter in the call to the encode/decode function.

The callback gets a single argument, an instance ofUnicodeEncodeError,UnicodeDecodeError orUnicodeTranslateError that holds information about the problematicsequence of characters or bytes and their offset in the original string (seeUnicode Exception Objects for functions to extract this information). Thecallback must either raise the given exception, or return a two-item tuplecontaining the replacement for the problematic sequence, and an integergiving the offset in the original string at which encoding/decoding should beresumed.

Return0 on success,-1 on error.

PyObject*PyCodec_LookupError(constchar*name)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Lookup the error handling callback function registered undername. As aspecial caseNULL can be passed, in which case the error handling callbackfor «strict» will be returned.

PyObject*PyCodec_StrictErrors(PyObject*exc)
Επιστρεφόμενη τιμή: Πάντοτε NULL. Μέρος τουΣταθερό ABI.

Raiseexc as an exception.

PyObject*PyCodec_IgnoreErrors(PyObject*exc)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Ignore the unicode error, skipping the faulty input.

PyObject*PyCodec_ReplaceErrors(PyObject*exc)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Replace the unicode encode error with? orU+FFFD.

PyObject*PyCodec_XMLCharRefReplaceErrors(PyObject*exc)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Replace the unicode encode error with XML character references.

PyObject*PyCodec_BackslashReplaceErrors(PyObject*exc)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI.

Replace the unicode encode error with backslash escapes (\x,\u and\U).

PyObject*PyCodec_NameReplaceErrors(PyObject*exc)
Επιστρεφόμενη τιμή: New reference. Μέρος τουΣταθερό ABI από την έκδοση 3.7.

Replace the unicode encode error with\N{...} escapes.

Added in version 3.5.