blob: 3ad0f2b5aae79c71c54fabfd51a41aca618f1ac0 [file] [log] [blame]
Guido van Rossum30944842000-03-10 22:32:23 +00001#ifndef Py_CODECREGISTRY_H
2#define Py_CODECREGISTRY_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/* ------------------------------------------------------------------------
8
9 Python Codec Registry and support functions
10
11
12Written by Marc-Andre Lemburg (mal@lemburg.com).
13
Guido van Rossum16b1ad92000-08-03 16:24:25 +000014Copyright (c) Corporation for National Research Initiatives.
Guido van Rossum30944842000-03-10 22:32:23 +000015
16 ------------------------------------------------------------------------ */
17
Fred Drake3ac3edc2000-05-09 19:51:10 +000018/* Register a new codec search function.
19
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
22 search functions.
23
24 The search_function's refcount is incremented by this function. */
25
Mark Hammond91a681d2002-08-12 07:21:58 +000026PyAPI_FUNC(int) PyCodec_Register(
Guido van Rossum30944842000-03-10 22:32:23 +000027 PyObject *search_function
28 );
29
Marc-André Lemburgb2750b52008-06-06 12:18:17 +000030/* Codec registry lookup API.
Fred Drake3ac3edc2000-05-09 19:51:10 +000031
Thomas Woutersa9773292006-04-21 09:43:23 +000032 Looks up the given encoding and returns a CodecInfo object with
33 function attributes which implement the different aspects of
34 processing the encoding.
Fred Drake3ac3edc2000-05-09 19:51:10 +000035
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.
39
Thomas Woutersa9773292006-04-21 09:43:23 +000040 If no codec is found, a KeyError is set and NULL returned.
Fred Drake3ac3edc2000-05-09 19:51:10 +000041
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
44 package.
45
46 */
47
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000048#ifndef Py_LIMITED_API
Mark Hammond91a681d2002-08-12 07:21:58 +000049PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
Guido van Rossum30944842000-03-10 22:32:23 +000050 const char *encoding
51 );
Nick Coghlan8fad1672014-09-15 23:50:44 +120052
53PyAPI_FUNC(int) _PyCodec_Forget(
54 const char *encoding
55 );
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000056#endif
Guido van Rossum30944842000-03-10 22:32:23 +000057
Marc-André Lemburgb2750b52008-06-06 12:18:17 +000058/* Codec registry encoding check API.
59
60 Returns 1/0 depending on whether there is a registered codec for
61 the given encoding.
62
63*/
64
65PyAPI_FUNC(int) PyCodec_KnownEncoding(
66 const char *encoding
67 );
68
Fred Drake3ac3edc2000-05-09 19:51:10 +000069/* Generic codec based encoding API.
Guido van Rossum30944842000-03-10 22:32:23 +000070
Fred Drake3ac3edc2000-05-09 19:51:10 +000071 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.
Serhiy Storchaka009b8112015-03-18 21:53:15 +020074
Fred Drake3ac3edc2000-05-09 19:51:10 +000075 Raises a LookupError in case no encoder can be found.
Guido van Rossum30944842000-03-10 22:32:23 +000076
Fred Drake3ac3edc2000-05-09 19:51:10 +000077 */
Guido van Rossum30944842000-03-10 22:32:23 +000078
Mark Hammond91a681d2002-08-12 07:21:58 +000079PyAPI_FUNC(PyObject *) PyCodec_Encode(
Guido van Rossum30944842000-03-10 22:32:23 +000080 PyObject *object,
81 const char *encoding,
82 const char *errors
83 );
84
Fred Drake3ac3edc2000-05-09 19:51:10 +000085/* Generic codec based decoding API.
86
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.
Serhiy Storchaka009b8112015-03-18 21:53:15 +020090
Fred Drake3ac3edc2000-05-09 19:51:10 +000091 Raises a LookupError in case no encoder can be found.
92
93 */
94
Mark Hammond91a681d2002-08-12 07:21:58 +000095PyAPI_FUNC(PyObject *) PyCodec_Decode(
Guido van Rossum30944842000-03-10 22:32:23 +000096 PyObject *object,
97 const char *encoding,
98 const char *errors
99 );
100
Martin v. Löwis1c0689c2014-01-03 21:36:49 +0100101#ifndef Py_LIMITED_API
Nick Coghlanc72e4e62013-11-22 22:39:36 +1000102/* Text codec specific encoding and decoding API.
103
104 Checks the encoding against a list of codecs which do not
105 implement a str<->bytes encoding before attempting the
106 operation.
107
108 Please note that these APIs are internal and should not
109 be used in Python C extensions.
110
Nick Coghlana9b15242014-02-04 22:11:18 +1000111 XXX (ncoghlan): should we make these, or something like them, public
112 in Python 3.5+?
113
Nick Coghlanc72e4e62013-11-22 22:39:36 +1000114 */
Nick Coghlana9b15242014-02-04 22:11:18 +1000115PyAPI_FUNC(PyObject *) _PyCodec_LookupTextEncoding(
116 const char *encoding,
117 const char *alternate_command
118 );
Nick Coghlanc72e4e62013-11-22 22:39:36 +1000119
120PyAPI_FUNC(PyObject *) _PyCodec_EncodeText(
121 PyObject *object,
122 const char *encoding,
123 const char *errors
124 );
125
126PyAPI_FUNC(PyObject *) _PyCodec_DecodeText(
127 PyObject *object,
128 const char *encoding,
129 const char *errors
130 );
Nick Coghlana9b15242014-02-04 22:11:18 +1000131
132/* These two aren't actually text encoding specific, but _io.TextIOWrapper
133 * is the only current API consumer.
134 */
135PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalDecoder(
136 PyObject *codec_info,
137 const char *errors
138 );
139
140PyAPI_FUNC(PyObject *) _PyCodecInfo_GetIncrementalEncoder(
141 PyObject *codec_info,
142 const char *errors
143 );
Nick Coghlanc72e4e62013-11-22 22:39:36 +1000144#endif
145
146
147
Serhiy Storchaka009b8112015-03-18 21:53:15 +0200148/* --- Codec Lookup APIs --------------------------------------------------
Fred Drake3ac3edc2000-05-09 19:51:10 +0000149
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.
153
154*/
155
156/* Get an encoder function for the given encoding. */
157
Mark Hammond91a681d2002-08-12 07:21:58 +0000158PyAPI_FUNC(PyObject *) PyCodec_Encoder(
Fred Drake3ac3edc2000-05-09 19:51:10 +0000159 const char *encoding
160 );
161
162/* Get a decoder function for the given encoding. */
163
Mark Hammond91a681d2002-08-12 07:21:58 +0000164PyAPI_FUNC(PyObject *) PyCodec_Decoder(
Fred Drake3ac3edc2000-05-09 19:51:10 +0000165 const char *encoding
166 );
167
Martin Panter7462b6492015-11-02 03:37:02 +0000168/* Get an IncrementalEncoder object for the given encoding. */
Thomas Woutersa9773292006-04-21 09:43:23 +0000169
170PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
171 const char *encoding,
172 const char *errors
173 );
174
Martin Panter7462b6492015-11-02 03:37:02 +0000175/* Get an IncrementalDecoder object function for the given encoding. */
Thomas Woutersa9773292006-04-21 09:43:23 +0000176
177PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
178 const char *encoding,
179 const char *errors
180 );
181
Fred Drake3ac3edc2000-05-09 19:51:10 +0000182/* Get a StreamReader factory function for the given encoding. */
183
Mark Hammond91a681d2002-08-12 07:21:58 +0000184PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
Fred Drake3ac3edc2000-05-09 19:51:10 +0000185 const char *encoding,
186 PyObject *stream,
187 const char *errors
188 );
189
190/* Get a StreamWriter factory function for the given encoding. */
191
Mark Hammond91a681d2002-08-12 07:21:58 +0000192PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
Fred Drake3ac3edc2000-05-09 19:51:10 +0000193 const char *encoding,
194 PyObject *stream,
195 const char *errors
196 );
197
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000198/* Unicode encoding error handling callback registry API */
199
Georg Brandlbab33782010-11-20 13:44:41 +0000200/* Register the error handling callback function error under the given
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000201 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 */
206PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
207
Georg Brandlbab33782010-11-20 13:44:41 +0000208/* Lookup the error handling callback function registered under the given
209 name. As a special case NULL can be passed, in which case
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000210 the error handling callback for "strict" will be returned. */
211PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
212
213/* raise exc as an exception */
214PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
215
216/* ignore the unicode error, skipping the faulty input */
217PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
218
Georg Brandlbab33782010-11-20 13:44:41 +0000219/* replace the unicode encode error with ? or U+FFFD */
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000220PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
221
222/* replace the unicode encode error with XML character references */
223PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
224
225/* replace the unicode encode error with backslash escapes (\x, \u and \U) */
226PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
227
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200228#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
Serhiy Storchaka166ebc42014-11-25 13:57:17 +0200229/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */
230PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200231#endif
Serhiy Storchaka166ebc42014-11-25 13:57:17 +0200232
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200233#ifndef Py_LIMITED_API
Antoine Pitroue6069832011-10-15 16:38:20 +0200234PyAPI_DATA(const char *) Py_hexdigits;
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +0200235#endif
Victor Stinnerf5cff562011-10-14 02:13:11 +0200236
Guido van Rossum30944842000-03-10 22:32:23 +0000237#ifdef __cplusplus
238}
239#endif
240#endif /* !Py_CODECREGISTRY_H */