|
| 1 | +/* Copyright (c) 2018, Oracle and/or its affiliates. |
| 2 | + * Copyright (C) 1996-2017 Python Software Foundation |
| 3 | + * |
| 4 | + * Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef Py_CODECREGISTRY_H |
| 8 | +#define Py_CODECREGISTRY_H |
| 9 | +#ifdef __cplusplus |
| 10 | +extern "C" { |
| 11 | +#endif |
| 12 | + |
| 13 | +/* ------------------------------------------------------------------------ |
| 14 | +
|
| 15 | + Python Codec Registry and support functions |
| 16 | +
|
| 17 | +
|
| 18 | +Written by Marc-Andre Lemburg ([email protected]). |
| 19 | +
|
| 20 | +Copyright (c) Corporation for National Research Initiatives. |
| 21 | +
|
| 22 | + ------------------------------------------------------------------------ */ |
| 23 | + |
| 24 | +/* Register a new codec search function. |
| 25 | +
|
| 26 | + As side effect, this tries to load the encodings package, if not |
| 27 | + yet done, to make sure that it is always first in the list of |
| 28 | + search functions. |
| 29 | +
|
| 30 | + The search_function's refcount is incremented by this function. */ |
| 31 | + |
| 32 | +PyAPI_FUNC(int) PyCodec_Register( |
| 33 | + PyObject *search_function |
| 34 | + ); |
| 35 | + |
| 36 | +/* Codec registry lookup API. |
| 37 | +
|
| 38 | + Looks up the given encoding and returns a CodecInfo object with |
| 39 | + function attributes which implement the different aspects of |
| 40 | + processing the encoding. |
| 41 | +
|
| 42 | + The encoding string is looked up converted to all lower-case |
| 43 | + characters. This makes encodings looked up through this mechanism |
| 44 | + effectively case-insensitive. |
| 45 | +
|
| 46 | + If no codec is found, a KeyError is set and NULL returned. |
| 47 | +
|
| 48 | + As side effect, this tries to load the encodings package, if not |
| 49 | + yet done. This is part of the lazy load strategy for the encodings |
| 50 | + package. |
| 51 | +
|
| 52 | + */ |
| 53 | + |
| 54 | +#ifndef Py_LIMITED_API |
| 55 | +PyAPI_FUNC(PyObject *) _PyCodec_Lookup( |
| 56 | + const char *encoding |
| 57 | + ); |
| 58 | + |
| 59 | +PyAPI_FUNC(int) _PyCodec_Forget( |
| 60 | + const char *encoding |
| 61 | + ); |
| 62 | +#endif |
| 63 | + |
| 64 | +/* Codec registry encoding check API. |
| 65 | +
|
| 66 | + Returns 1/0 depending on whether there is a registered codec for |
| 67 | + the given encoding. |
| 68 | +
|
| 69 | +*/ |
| 70 | + |
| 71 | +PyAPI_FUNC(int) PyCodec_KnownEncoding( |
| 72 | + const char *encoding |
| 73 | + ); |
| 74 | + |
| 75 | +/* Generic codec based encoding API. |
| 76 | +
|
| 77 | + object is passed through the encoder function found for the given |
| 78 | + encoding using the error handling method defined by errors. errors |
| 79 | + may be NULL to use the default method defined for the codec. |
| 80 | +
|
| 81 | + Raises a LookupError in case no encoder can be found. |
| 82 | +
|
| 83 | + */ |
| 84 | + |
| 85 | +PyAPI_FUNC(PyObject *) PyCodec_Encode( |
| 86 | + PyObject *object, |
| 87 | + const char *encoding, |
| 88 | + const char *errors |
| 89 | + ); |
| 90 | + |
| 91 | +/* Generic codec based decoding API. |
| 92 | +
|
| 93 | + object is passed through the decoder function found for the given |
| 94 | + encoding using the error handling method defined by errors. errors |
| 95 | + may be NULL to use the default method defined for the codec. |
| 96 | +
|
| 97 | + Raises a LookupError in case no encoder can be found. |
| 98 | +
|
| 99 | + */ |
| 100 | + |
| 101 | +PyAPI_FUNC(PyObject *) PyCodec_Decode( |
| 102 | + PyObject *object, |
| 103 | + const char *encoding, |
| 104 | + const char *errors |
| 105 | + ); |
| 106 | + |
| 107 | +#ifndef Py_LIMITED_API |
| 108 | +/* Text codec specific encoding and decoding API. |
| 109 | +
|
| 110 | + Checks the encoding against a list of codecs which do not |
| 111 | + implement a str<->bytes encoding before attempting the |
| 112 | + operation. |
| 113 | +
|
| 114 | + Please note that these APIs are internal and should not |
| 115 | + be used in Python C extensions. |
| 116 | +
|
| 117 | + XXX (ncoghlan): should we make these, or something like them, public |
| 118 | + in Python 3.5+? |
| 119 | +
|
| 120 | + */ |
| 121 | +PyAPI_FUNC(PyObject *) _PyCodec_LookupTextEncoding( |
| 122 | + const char *encoding, |
| 123 | + const char *alternate_command |
| 124 | + ); |
| 125 | + |
| 126 | +PyAPI_FUNC(PyObject *) _PyCodec_EncodeText( |
| 127 | + PyObject *object, |
| 128 | + const char *encoding, |
| 129 | + const char *errors |
| 130 | + ); |
| 131 | + |
| 132 | +PyAPI_FUNC(PyObject *) _PyCodec_DecodeText( |
| 133 | + PyObject *object, |
| 134 | + const char *encoding, |
| 135 | + const char *errors |
| 136 | + ); |
| 137 | + |
| 138 | +/* These two aren't actually text encoding specific, but _io.TextIOWrapper |
| 139 | + * is the only current API consumer. |
| 140 | + */ |
| 141 | +PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalDecoder( |
| 142 | + PyObject *codec_info, |
| 143 | + const char *errors |
| 144 | + ); |
| 145 | + |
| 146 | +PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder( |
| 147 | + PyObject *codec_info, |
| 148 | + const char *errors |
| 149 | + ); |
| 150 | +#endif |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +/* --- Codec Lookup APIs -------------------------------------------------- |
| 155 | +
|
| 156 | + All APIs return a codec object with incremented refcount and are |
| 157 | + based on _PyCodec_Lookup(). The same comments w/r to the encoding |
| 158 | + name also apply to these APIs. |
| 159 | +
|
| 160 | +*/ |
| 161 | + |
| 162 | +/* Get an encoder function for the given encoding. */ |
| 163 | + |
| 164 | +PyAPI_FUNC(PyObject *) PyCodec_Encoder( |
| 165 | + const char *encoding |
| 166 | + ); |
| 167 | + |
| 168 | +/* Get a decoder function for the given encoding. */ |
| 169 | + |
| 170 | +PyAPI_FUNC(PyObject *) PyCodec_Decoder( |
| 171 | + const char *encoding |
| 172 | + ); |
| 173 | + |
| 174 | +/* Get an IncrementalEncoder object for the given encoding. */ |
| 175 | + |
| 176 | +PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder( |
| 177 | + const char *encoding, |
| 178 | + const char *errors |
| 179 | + ); |
| 180 | + |
| 181 | +/* Get an IncrementalDecoder object function for the given encoding. */ |
| 182 | + |
| 183 | +PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder( |
| 184 | + const char *encoding, |
| 185 | + const char *errors |
| 186 | + ); |
| 187 | + |
| 188 | +/* Get a StreamReader factory function for the given encoding. */ |
| 189 | + |
| 190 | +PyAPI_FUNC(PyObject *) PyCodec_StreamReader( |
| 191 | + const char *encoding, |
| 192 | + PyObject *stream, |
| 193 | + const char *errors |
| 194 | + ); |
| 195 | + |
| 196 | +/* Get a StreamWriter factory function for the given encoding. */ |
| 197 | + |
| 198 | +PyAPI_FUNC(PyObject *) PyCodec_StreamWriter( |
| 199 | + const char *encoding, |
| 200 | + PyObject *stream, |
| 201 | + const char *errors |
| 202 | + ); |
| 203 | + |
| 204 | +/* Unicode encoding error handling callback registry API */ |
| 205 | + |
| 206 | +/* Register the error handling callback function error under the given |
| 207 | + name. This function will be called by the codec when it encounters |
| 208 | + unencodable characters/undecodable bytes and doesn't know the |
| 209 | + callback name, when name is specified as the error parameter |
| 210 | + in the call to the encode/decode function. |
| 211 | + Return 0 on success, -1 on error */ |
| 212 | +PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error); |
| 213 | + |
| 214 | +/* Lookup the error handling callback function registered under the given |
| 215 | + name. As a special case NULL can be passed, in which case |
| 216 | + the error handling callback for "strict" will be returned. */ |
| 217 | +PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name); |
| 218 | + |
| 219 | +/* raise exc as an exception */ |
| 220 | +PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc); |
| 221 | + |
| 222 | +/* ignore the unicode error, skipping the faulty input */ |
| 223 | +PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc); |
| 224 | + |
| 225 | +/* replace the unicode encode error with ? or U+FFFD */ |
| 226 | +PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc); |
| 227 | + |
| 228 | +/* replace the unicode encode error with XML character references */ |
| 229 | +PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc); |
| 230 | + |
| 231 | +/* replace the unicode encode error with backslash escapes (\x, \u and \U) */ |
| 232 | +PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc); |
| 233 | + |
| 234 | +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 |
| 235 | +/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */ |
| 236 | +PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc); |
| 237 | +#endif |
| 238 | + |
| 239 | +#ifndef Py_LIMITED_API |
| 240 | +PyAPI_DATA(const char *) Py_hexdigits; |
| 241 | +#endif |
| 242 | + |
| 243 | +#ifdef __cplusplus |
| 244 | +} |
| 245 | +#endif |
| 246 | +#endif /* !Py_CODECREGISTRY_H */ |
0 commit comments