#ifndef Py_CODECREGISTRY_H1#define Py_CODECREGISTRY_H2#ifdef __cplusplus3extern "C" {4#endif56/* ------------------------------------------------------------------------78Python Codec Registry and support functions91011Written by Marc-Andre Lemburg ([email protected]).1213Copyright (c) Corporation for National Research Initiatives.1415------------------------------------------------------------------------ */1617/* Register a new codec search function.1819As side effect, this tries to load the encodings package, if not20yet done, to make sure that it is always first in the list of21search functions.2223The search_function's refcount is incremented by this function. */2425PyAPI_FUNC(int) PyCodec_Register(26PyObject *search_function27);2829/* Unregister a codec search function and clear the registry's cache.30If the search function is not registered, do nothing.31Return 0 on success. Raise an exception and return -1 on error. */3233PyAPI_FUNC(int) PyCodec_Unregister(34PyObject *search_function35);3637/* Codec registry encoding check API.3839Returns 1/0 depending on whether there is a registered codec for40the given encoding.4142*/4344PyAPI_FUNC(int) PyCodec_KnownEncoding(45const char *encoding46);4748/* Generic codec based encoding API.4950object is passed through the encoder function found for the given51encoding using the error handling method defined by errors. errors52may be NULL to use the default method defined for the codec.5354Raises a LookupError in case no encoder can be found.5556*/5758PyAPI_FUNC(PyObject *) PyCodec_Encode(59PyObject *object,60const char *encoding,61const char *errors62);6364/* Generic codec based decoding API.6566object is passed through the decoder function found for the given67encoding using the error handling method defined by errors. errors68may be NULL to use the default method defined for the codec.6970Raises a LookupError in case no encoder can be found.7172*/7374PyAPI_FUNC(PyObject *) PyCodec_Decode(75PyObject *object,76const char *encoding,77const char *errors78);7980// --- Codec Lookup APIs --------------------------------------------------8182/* Codec registry lookup API.8384Looks up the given encoding and returns a CodecInfo object with85function attributes which implement the different aspects of86processing the encoding.8788The encoding string is looked up converted to all lower-case89characters. This makes encodings looked up through this mechanism90effectively case-insensitive.9192If no codec is found, a KeyError is set and NULL returned.9394As side effect, this tries to load the encodings package, if not95yet done. This is part of the lazy load strategy for the encodings96package.97*/9899/* Get an encoder function for the given encoding. */100101PyAPI_FUNC(PyObject *) PyCodec_Encoder(const char *encoding);102103/* Get a decoder function for the given encoding. */104105PyAPI_FUNC(PyObject *) PyCodec_Decoder(const char *encoding);106107/* Get an IncrementalEncoder object for the given encoding. */108109PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(110const char *encoding,111const char *errors);112113/* Get an IncrementalDecoder object function for the given encoding. */114115PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(116const char *encoding,117const char *errors);118119/* Get a StreamReader factory function for the given encoding. */120121PyAPI_FUNC(PyObject *) PyCodec_StreamReader(122const char *encoding,123PyObject *stream,124const char *errors);125126/* Get a StreamWriter factory function for the given encoding. */127128PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(129const char *encoding,130PyObject *stream,131const char *errors);132133/* Unicode encoding error handling callback registry API */134135/* Register the error handling callback function error under the given136name. This function will be called by the codec when it encounters137unencodable characters/undecodable bytes and doesn't know the138callback name, when name is specified as the error parameter139in the call to the encode/decode function.140Return 0 on success, -1 on error */141PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);142143/* Lookup the error handling callback function registered under the given144name. As a special case NULL can be passed, in which case145the error handling callback for "strict" will be returned. */146PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);147148/* raise exc as an exception */149PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);150151/* ignore the unicode error, skipping the faulty input */152PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);153154/* replace the unicode encode error with ? or U+FFFD */155PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);156157/* replace the unicode encode error with XML character references */158PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);159160/* replace the unicode encode error with backslash escapes (\x, \u and \U) */161PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);162163#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000164/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */165PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);166#endif167168#ifndef Py_LIMITED_API169PyAPI_DATA(const char *) Py_hexdigits;170#endif171172#ifdef __cplusplus173}174#endif175#endif /* !Py_CODECREGISTRY_H */176177178