1
#ifndef Py_CODECREGISTRY_H
2
#define Py_CODECREGISTRY_H
7
/* ------------------------------------------------------------------------
9
Python Codec Registry and support functions
12
Written by Marc-Andre Lemburg (mal@lemburg.com).
14
Copyright (c) Corporation for National Research Initiatives.
16
------------------------------------------------------------------------ */
18
/* Register a new codec search function.
20
As side effect, this tries to load the encodings package, if not
21
yet done, to make sure that it is always first in the list of
24
The search_function's refcount is incremented by this function. */
26
PyAPI_FUNC(int) PyCodec_Register(
27
PyObject *search_function
30
/* Codec registry lookup API.
32
Looks up the given encoding and returns a CodecInfo object with
33
function attributes which implement the different aspects of
34
processing the encoding.
36
The encoding string is looked up converted to all lower-case
37
characters. This makes encodings looked up through this mechanism
38
effectively case-insensitive.
40
If no codec is found, a KeyError is set and NULL returned.
42
As side effect, this tries to load the encodings package, if not
43
yet done. This is part of the lazy load strategy for the encodings
48
#ifndef Py_LIMITED_API
49
PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
53
PyAPI_FUNC(int) _PyCodec_Forget(
58
/* Codec registry encoding check API.
60
Returns 1/0 depending on whether there is a registered codec for
65
PyAPI_FUNC(int) PyCodec_KnownEncoding(
69
/* Generic codec based encoding API.
71
object is passed through the encoder function found for the given
72
encoding using the error handling method defined by errors. errors
73
may be NULL to use the default method defined for the codec.
75
Raises a LookupError in case no encoder can be found.
79
PyAPI_FUNC(PyObject *) PyCodec_Encode(
85
/* Generic codec based decoding API.
87
object is passed through the decoder function found for the given
88
encoding using the error handling method defined by errors. errors
89
may be NULL to use the default method defined for the codec.
91
Raises a LookupError in case no encoder can be found.
95
PyAPI_FUNC(PyObject *) PyCodec_Decode(
101
#ifndef Py_LIMITED_API
102
/* Text codec specific encoding and decoding API.
104
Checks the encoding against a list of codecs which do not
105
implement a str<->bytes encoding before attempting the
108
Please note that these APIs are internal and should not
109
be used in Python C extensions.
111
XXX (ncoghlan): should we make these, or something like them, public
115
PyAPI_FUNC(PyObject *) _PyCodec_LookupTextEncoding(
116
const char *encoding,
117
const char *alternate_command
120
PyAPI_FUNC(PyObject *) _PyCodec_EncodeText(
122
const char *encoding,
126
PyAPI_FUNC(PyObject *) _PyCodec_DecodeText(
128
const char *encoding,
132
/* These two aren't actually text encoding specific, but _io.TextIOWrapper
133
* is the only current API consumer.
135
PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalDecoder(
136
PyObject *codec_info,
140
PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder(
141
PyObject *codec_info,
148
/* --- Codec Lookup APIs --------------------------------------------------
150
All APIs return a codec object with incremented refcount and are
151
based on _PyCodec_Lookup(). The same comments w/r to the encoding
152
name also apply to these APIs.
156
/* Get an encoder function for the given encoding. */
158
PyAPI_FUNC(PyObject *) PyCodec_Encoder(
162
/* Get a decoder function for the given encoding. */
164
PyAPI_FUNC(PyObject *) PyCodec_Decoder(
168
/* Get an IncrementalEncoder object for the given encoding. */
170
PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
171
const char *encoding,
175
/* Get an IncrementalDecoder object function for the given encoding. */
177
PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
178
const char *encoding,
182
/* Get a StreamReader factory function for the given encoding. */
184
PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
185
const char *encoding,
190
/* Get a StreamWriter factory function for the given encoding. */
192
PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
193
const char *encoding,
198
/* Unicode encoding error handling callback registry API */
200
/* Register the error handling callback function error under the given
201
name. This function will be called by the codec when it encounters
202
unencodable characters/undecodable bytes and doesn't know the
203
callback name, when name is specified as the error parameter
204
in the call to the encode/decode function.
205
Return 0 on success, -1 on error */
206
PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
208
/* Lookup the error handling callback function registered under the given
209
name. As a special case NULL can be passed, in which case
210
the error handling callback for "strict" will be returned. */
211
PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
213
/* raise exc as an exception */
214
PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
216
/* ignore the unicode error, skipping the faulty input */
217
PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
219
/* replace the unicode encode error with ? or U+FFFD */
220
PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
222
/* replace the unicode encode error with XML character references */
223
PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
225
/* replace the unicode encode error with backslash escapes (\x, \u and \U) */
226
PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
228
/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */
229
PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);
231
PyAPI_DATA(const char *) Py_hexdigits;
236
#endif /* !Py_CODECREGISTRY_H */