| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 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 |  | 
| Guido van Rossum | 16b1ad9 | 2000-08-03 16:24:25 +0000 | [diff] [blame] | 14 | Copyright (c) Corporation for National Research Initiatives. | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 15 |  | 
 | 16 |    ------------------------------------------------------------------------ */ | 
 | 17 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 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 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 26 | PyAPI_FUNC(int) PyCodec_Register( | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 27 |        PyObject *search_function | 
 | 28 |        ); | 
 | 29 |  | 
| Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 30 | /* Codec registry lookup API. | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 31 |  | 
| Thomas Wouters | a977329 | 2006-04-21 09:43:23 +0000 | [diff] [blame] | 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. | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 35 |  | 
 | 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 Wouters | a977329 | 2006-04-21 09:43:23 +0000 | [diff] [blame] | 40 |    If no codec is found, a KeyError is set and NULL returned. | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 41 |  | 
 | 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öwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 48 | #ifndef Py_LIMITED_API | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 49 | PyAPI_FUNC(PyObject *) _PyCodec_Lookup( | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 50 |        const char *encoding | 
 | 51 |        ); | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 52 | #endif | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 53 |  | 
| Marc-André Lemburg | b2750b5 | 2008-06-06 12:18:17 +0000 | [diff] [blame] | 54 | /* Codec registry encoding check API. | 
 | 55 |  | 
 | 56 |    Returns 1/0 depending on whether there is a registered codec for | 
 | 57 |    the given encoding. | 
 | 58 |  | 
 | 59 | */ | 
 | 60 |  | 
 | 61 | PyAPI_FUNC(int) PyCodec_KnownEncoding( | 
 | 62 |        const char *encoding | 
 | 63 |        ); | 
 | 64 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 65 | /* Generic codec based encoding API. | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 66 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 67 |    object is passed through the encoder 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. | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 72 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 73 |  */ | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 74 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 75 | PyAPI_FUNC(PyObject *) PyCodec_Encode( | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 76 |        PyObject *object, | 
 | 77 |        const char *encoding, | 
 | 78 |        const char *errors | 
 | 79 |        ); | 
 | 80 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 81 | /* Generic codec based decoding API. | 
 | 82 |  | 
 | 83 |    object is passed through the decoder function found for the given | 
 | 84 |    encoding using the error handling method defined by errors. errors | 
 | 85 |    may be NULL to use the default method defined for the codec. | 
 | 86 |     | 
 | 87 |    Raises a LookupError in case no encoder can be found. | 
 | 88 |  | 
 | 89 |  */ | 
 | 90 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 91 | PyAPI_FUNC(PyObject *) PyCodec_Decode( | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 92 |        PyObject *object, | 
 | 93 |        const char *encoding, | 
 | 94 |        const char *errors | 
 | 95 |        ); | 
 | 96 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 97 | /* --- Codec Lookup APIs --------------------------------------------------  | 
 | 98 |  | 
 | 99 |    All APIs return a codec object with incremented refcount and are | 
 | 100 |    based on _PyCodec_Lookup().  The same comments w/r to the encoding | 
 | 101 |    name also apply to these APIs. | 
 | 102 |  | 
 | 103 | */ | 
 | 104 |  | 
 | 105 | /* Get an encoder function for the given encoding. */ | 
 | 106 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 107 | PyAPI_FUNC(PyObject *) PyCodec_Encoder( | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 108 |        const char *encoding | 
 | 109 |        ); | 
 | 110 |  | 
 | 111 | /* Get a decoder function for the given encoding. */ | 
 | 112 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 113 | PyAPI_FUNC(PyObject *) PyCodec_Decoder( | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 114 |        const char *encoding | 
 | 115 |        ); | 
 | 116 |  | 
| Thomas Wouters | a977329 | 2006-04-21 09:43:23 +0000 | [diff] [blame] | 117 | /* Get a IncrementalEncoder object for the given encoding. */ | 
 | 118 |  | 
 | 119 | PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder( | 
 | 120 |        const char *encoding, | 
 | 121 |        const char *errors | 
 | 122 |        ); | 
 | 123 |  | 
 | 124 | /* Get a IncrementalDecoder object function for the given encoding. */ | 
 | 125 |  | 
 | 126 | PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder( | 
 | 127 |        const char *encoding, | 
 | 128 |        const char *errors | 
 | 129 |        ); | 
 | 130 |  | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 131 | /* Get a StreamReader factory function for the given encoding. */ | 
 | 132 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 133 | PyAPI_FUNC(PyObject *) PyCodec_StreamReader( | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 134 |        const char *encoding, | 
 | 135 |        PyObject *stream, | 
 | 136 |        const char *errors | 
 | 137 |        ); | 
 | 138 |  | 
 | 139 | /* Get a StreamWriter factory function for the given encoding. */ | 
 | 140 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 141 | PyAPI_FUNC(PyObject *) PyCodec_StreamWriter( | 
| Fred Drake | 3ac3edc | 2000-05-09 19:51:10 +0000 | [diff] [blame] | 142 |        const char *encoding, | 
 | 143 |        PyObject *stream, | 
 | 144 |        const char *errors | 
 | 145 |        ); | 
 | 146 |  | 
| Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 147 | /* Unicode encoding error handling callback registry API */ | 
 | 148 |  | 
| Georg Brandl | bab3378 | 2010-11-20 13:44:41 +0000 | [diff] [blame] | 149 | /* Register the error handling callback function error under the given | 
| Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 150 |    name. This function will be called by the codec when it encounters | 
 | 151 |    unencodable characters/undecodable bytes and doesn't know the | 
 | 152 |    callback name, when name is specified as the error parameter | 
 | 153 |    in the call to the encode/decode function. | 
 | 154 |    Return 0 on success, -1 on error */ | 
 | 155 | PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error); | 
 | 156 |  | 
| Georg Brandl | bab3378 | 2010-11-20 13:44:41 +0000 | [diff] [blame] | 157 | /* Lookup the error handling callback function registered under the given | 
 | 158 |    name. As a special case NULL can be passed, in which case | 
| Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 159 |    the error handling callback for "strict" will be returned. */ | 
 | 160 | PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name); | 
 | 161 |  | 
 | 162 | /* raise exc as an exception */ | 
 | 163 | PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc); | 
 | 164 |  | 
 | 165 | /* ignore the unicode error, skipping the faulty input */ | 
 | 166 | PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc); | 
 | 167 |  | 
| Georg Brandl | bab3378 | 2010-11-20 13:44:41 +0000 | [diff] [blame] | 168 | /* replace the unicode encode error with ? or U+FFFD */ | 
| Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 169 | PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc); | 
 | 170 |  | 
 | 171 | /* replace the unicode encode error with XML character references */ | 
 | 172 | PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc); | 
 | 173 |  | 
 | 174 | /* replace the unicode encode error with backslash escapes (\x, \u and \U) */ | 
 | 175 | PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc); | 
 | 176 |  | 
| Guido van Rossum | 3094484 | 2000-03-10 22:32:23 +0000 | [diff] [blame] | 177 | #ifdef __cplusplus | 
 | 178 | } | 
 | 179 | #endif | 
 | 180 | #endif /* !Py_CODECREGISTRY_H */ |