codekingpro/portable-devtools
115k
1#ifndef Py_CODECREGISTRY_H2#define Py_CODECREGISTRY_H3#ifdef __cplusplus4extern "C" {5#endif6 7/* ------------------------------------------------------------------------8 9 Python Codec Registry and support functions10 11 12Written by Marc-Andre Lemburg (mal@lemburg.com).13 14Copyright (c) Corporation for National Research Initiatives.15 16 ------------------------------------------------------------------------ */17 18/* Register a new codec search function.19 20 As side effect, this tries to load the encodings package, if not21 yet done, to make sure that it is always first in the list of22 search functions.23 24 The search_function's refcount is incremented by this function. */25 26PyAPI_FUNC(int) PyCodec_Register(27 PyObject *search_function28 );29 30/* Unregister a codec search function and clear the registry's cache.31 If the search function is not registered, do nothing.32 Return 0 on success. Raise an exception and return -1 on error. */33 34PyAPI_FUNC(int) PyCodec_Unregister(35 PyObject *search_function36 );37 38/* Codec registry encoding check API.39 40 Returns 1/0 depending on whether there is a registered codec for41 the given encoding.42 43*/44 45PyAPI_FUNC(int) PyCodec_KnownEncoding(46 const char *encoding47 );48 49/* Generic codec based encoding API.50 51 object is passed through the encoder function found for the given52 encoding using the error handling method defined by errors. errors53 may be NULL to use the default method defined for the codec.54 55 Raises a LookupError in case no encoder can be found.56 57 */58 59PyAPI_FUNC(PyObject *) PyCodec_Encode(60 PyObject *object,61 const char *encoding,62 const char *errors63 );64 65/* Generic codec based decoding API.66 67 object is passed through the decoder function found for the given68 encoding using the error handling method defined by errors. errors69 may be NULL to use the default method defined for the codec.70 71 Raises a LookupError in case no encoder can be found.72 73 */74 75PyAPI_FUNC(PyObject *) PyCodec_Decode(76 PyObject *object,77 const char *encoding,78 const char *errors79 );80 81// --- Codec Lookup APIs --------------------------------------------------82 83/* Codec registry lookup API.84 85 Looks up the given encoding and returns a CodecInfo object with86 function attributes which implement the different aspects of87 processing the encoding.88 89 The encoding string is looked up converted to all lower-case90 characters. This makes encodings looked up through this mechanism91 effectively case-insensitive.92 93 If no codec is found, a KeyError is set and NULL returned.94 95 As side effect, this tries to load the encodings package, if not96 yet done. This is part of the lazy load strategy for the encodings97 package.98 */99 100/* Get an encoder function for the given encoding. */101 102PyAPI_FUNC(PyObject *) PyCodec_Encoder(const char *encoding);103 104/* Get a decoder function for the given encoding. */105 106PyAPI_FUNC(PyObject *) PyCodec_Decoder(const char *encoding);107 108/* Get an IncrementalEncoder object for the given encoding. */109 110PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(111 const char *encoding,112 const char *errors);113 114/* Get an IncrementalDecoder object function for the given encoding. */115 116PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(117 const char *encoding,118 const char *errors);119 120/* Get a StreamReader factory function for the given encoding. */121 122PyAPI_FUNC(PyObject *) PyCodec_StreamReader(123 const char *encoding,124 PyObject *stream,125 const char *errors);126 127/* Get a StreamWriter factory function for the given encoding. */128 129PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(130 const char *encoding,131 PyObject *stream,132 const char *errors);133 134/* Unicode encoding error handling callback registry API */135 136/* Register the error handling callback function error under the given137 name. This function will be called by the codec when it encounters138 unencodable characters/undecodable bytes and doesn't know the139 callback name, when name is specified as the error parameter140 in the call to the encode/decode function.141 Return 0 on success, -1 on error */142PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);143 144/* Lookup the error handling callback function registered under the given145 name. As a special case NULL can be passed, in which case146 the error handling callback for "strict" will be returned. */147PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);148 149/* raise exc as an exception */150PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);151 152/* ignore the unicode error, skipping the faulty input */153PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);154 155/* replace the unicode encode error with ? or U+FFFD */156PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);157 158/* replace the unicode encode error with XML character references */159PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);160 161/* replace the unicode encode error with backslash escapes (\x, \u and \U) */162PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);163 164#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000165/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */166PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);167#endif168 169#ifndef Py_LIMITED_API170PyAPI_DATA(const char *) Py_hexdigits;171#endif172 173#ifdef __cplusplus174}175#endif176#endif /* !Py_CODECREGISTRY_H */177 