• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_CODECREGISTRY_H
2 #define Py_CODECREGISTRY_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 /* ------------------------------------------------------------------------
8 
9    Python Codec Registry and support functions
10 
11 
12 Written by Marc-Andre Lemburg (mal@lemburg.com).
13 
14 Copyright (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 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 
26 PyAPI_FUNC(int) PyCodec_Register(
27        PyObject *search_function
28        );
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 
34 PyAPI_FUNC(int) PyCodec_Unregister(
35        PyObject *search_function
36        );
37 
38 /* Codec registry encoding check API.
39 
40    Returns 1/0 depending on whether there is a registered codec for
41    the given encoding.
42 
43 */
44 
45 PyAPI_FUNC(int) PyCodec_KnownEncoding(
46        const char *encoding
47        );
48 
49 /* Generic codec based encoding API.
50 
51    object is passed through the encoder function found for the given
52    encoding using the error handling method defined by errors. errors
53    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 
59 PyAPI_FUNC(PyObject *) PyCodec_Encode(
60        PyObject *object,
61        const char *encoding,
62        const char *errors
63        );
64 
65 /* Generic codec based decoding API.
66 
67    object is passed through the decoder function found for the given
68    encoding using the error handling method defined by errors. errors
69    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 
75 PyAPI_FUNC(PyObject *) PyCodec_Decode(
76        PyObject *object,
77        const char *encoding,
78        const char *errors
79        );
80 
81 // --- Codec Lookup APIs --------------------------------------------------
82 
83 /* Codec registry lookup API.
84 
85    Looks up the given encoding and returns a CodecInfo object with
86    function attributes which implement the different aspects of
87    processing the encoding.
88 
89    The encoding string is looked up converted to all lower-case
90    characters. This makes encodings looked up through this mechanism
91    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 not
96    yet done. This is part of the lazy load strategy for the encodings
97    package.
98  */
99 
100 /* Get an encoder function for the given encoding. */
101 
102 PyAPI_FUNC(PyObject *) PyCodec_Encoder(const char *encoding);
103 
104 /* Get a decoder function for the given encoding. */
105 
106 PyAPI_FUNC(PyObject *) PyCodec_Decoder(const char *encoding);
107 
108 /* Get an IncrementalEncoder object for the given encoding. */
109 
110 PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
111    const char *encoding,
112    const char *errors);
113 
114 /* Get an IncrementalDecoder object function for the given encoding. */
115 
116 PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
117    const char *encoding,
118    const char *errors);
119 
120 /* Get a StreamReader factory function for the given encoding. */
121 
122 PyAPI_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 
129 PyAPI_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 given
137    name. This function will be called by the codec when it encounters
138    unencodable characters/undecodable bytes and doesn't know the
139    callback name, when name is specified as the error parameter
140    in the call to the encode/decode function.
141    Return 0 on success, -1 on error */
142 PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
143 
144 /* Lookup the error handling callback function registered under the given
145    name. As a special case NULL can be passed, in which case
146    the error handling callback for "strict" will be returned. */
147 PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
148 
149 /* raise exc as an exception */
150 PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
151 
152 /* ignore the unicode error, skipping the faulty input */
153 PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
154 
155 /* replace the unicode encode error with ? or U+FFFD */
156 PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
157 
158 /* replace the unicode encode error with XML character references */
159 PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
160 
161 /* replace the unicode encode error with backslash escapes (\x, \u and \U) */
162 PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
163 
164 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
165 /* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */
166 PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc);
167 #endif
168 
169 #ifndef Py_LIMITED_API
170 PyAPI_DATA(const char *) Py_hexdigits;
171 #endif
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 #endif /* !Py_CODECREGISTRY_H */
177