1cdef extern from "Python.h": 2 3 ########################################################################### 4 # Codec registry and support functions 5 ########################################################################### 6 7 int PyCodec_Register(object search_function) 8 # Register a new codec search function. 9 10 # As side effect, this tries to load the encodings package, if not yet 11 # done, to make sure that it is always first in the list of search 12 # functions. 13 14 int PyCodec_KnownEncoding(const char *encoding) 15 # Return 1 or 0 depending on whether there is a registered codec for the 16 # given encoding. This function always succeeds. 17 18 object PyCodec_Encode(object o, const char *encoding, const char *errors) 19 # Return value: New reference. 20 # Generic codec based encoding API. 21 22 # o is passed through the encoder function found for the given encoding 23 # using the error handling method defined by errors. errors may be NULL 24 # to use the default method defined for the codec. Raises a LookupError 25 # if no encoder can be found. 26 27 object PyCodec_Decode(object o, const char *encoding, const char *errors) 28 # Return value: New reference. 29 # Generic codec based decoding API. 30 31 # o is passed through the decoder function found for the given encoding 32 # using the error handling method defined by errors. errors may be NULL 33 # to use the default method defined for the codec. Raises a LookupError 34 # if no encoder can be found. 35 36 37 # Codec lookup API 38 39 # In the following functions, the encoding string is looked up converted 40 # to all lower-case characters, which makes encodings looked up through 41 # this mechanism effectively case-insensitive. If no codec is found, a 42 # KeyError is set and NULL returned. 43 44 object PyCodec_Encoder(const char *encoding) 45 # Return value: New reference. 46 # Get an encoder function for the given encoding. 47 48 object PyCodec_Decoder(const char *encoding) 49 # Return value: New reference. 50 # Get a decoder function for the given encoding. 51 52 object PyCodec_IncrementalEncoder(const char *encoding, const char *errors) 53 # Return value: New reference. 54 # Get an IncrementalEncoder object for the given encoding. 55 56 object PyCodec_IncrementalDecoder(const char *encoding, const char *errors) 57 # Return value: New reference. 58 # Get an IncrementalDecoder object for the given encoding. 59 60 object PyCodec_StreamReader(const char *encoding, object stream, const char *errors) 61 # Return value: New reference. 62 # Get a StreamReader factory function for the given encoding. 63 64 object PyCodec_StreamWriter(const char *encoding, object stream, const char *errors) 65 # Return value: New reference. 66 # Get a StreamWriter factory function for the given encoding. 67 68 69 # Registry API for Unicode encoding error handlers 70 71 int PyCodec_RegisterError(const char *name, object error) except? -1 72 # Register the error handling callback function error under the given 73 # name. This callback function will be called by a codec when it 74 # encounters unencodable characters/undecodable bytes and name is 75 # specified as the error parameter in the call to the encode/decode 76 # function. 77 78 # The callback gets a single argument, an instance of 79 # UnicodeEncodeError, UnicodeDecodeError or UnicodeTranslateError that 80 # holds information about the problematic sequence of characters or bytes 81 # and their offset in the original string (see Unicode Exception Objects 82 # for functions to extract this information). The callback must either 83 # raise the given exception, or return a two-item tuple containing the 84 # replacement for the problematic sequence, and an integer giving the 85 # offset in the original string at which encoding/decoding should be 86 # resumed. 87 88 # Return 0 on success, -1 on error. 89 90 object PyCodec_LookupError(const char *name) 91 # Return value: New reference. 92 # Lookup the error handling callback function registered under name. As a 93 # special case NULL can be passed, in which case the error handling 94 # callback for "strict" will be returned. 95 96 object PyCodec_StrictErrors(object exc) 97 # Return value: Always NULL. 98 # Raise exc as an exception. 99 100 object PyCodec_IgnoreErrors(object exc) 101 # Return value: New reference. 102 # Ignore the unicode error, skipping the faulty input. 103 104 object PyCodec_ReplaceErrors(object exc) 105 # Return value: New reference. 106 # Replace the unicode encode error with "?" or "U+FFFD". 107 108 object PyCodec_XMLCharRefReplaceErrors(object exc) 109 # Return value: New reference. 110 # Replace the unicode encode error with XML character references. 111 112 object PyCodec_BackslashReplaceErrors(object exc) 113 # Return value: New reference. 114 # Replace the unicode encode error with backslash escapes ("\x", "\u" 115 # and "\U"). 116 117 object PyCodec_NameReplaceErrors(object exc) 118 # Return value: New reference. 119 # Replace the unicode encode error with "\N{...}" escapes. 120 121 # New in version 3.5. 122