1 /**
2   Mirror _codecs.h
3 
4   [which was]
5 
6 Written by Marc-Andre Lemburg (mal@lemburg.com).
7 
8 Copyright (c) Corporation for National Research Initiatives.
9 
10    Python Codec Registry and support functions
11   */
12 module deimos.python.codecs;
13 
14 import deimos.python.pyport;
15 import deimos.python.object;
16 
17 extern(C):
18 // Python-header-file: Include/codecs.h:
19 
20 /** Register a new codec search function.
21 
22    As side effect, this tries to load the encodings package, if not
23    yet done, to make sure that it is always first in the list of
24    search functions.
25 
26    The search_function's refcount is incremented by this function. */
27 int PyCodec_Register(PyObject* search_function);
28 /** Codec register lookup API.
29 
30    Looks up the given encoding and returns a CodecInfo object with
31    function attributes which implement the different aspects of
32    processing the encoding.
33 
34    The encoding string is looked up converted to all lower-case
35    characters. This makes encodings looked up through this mechanism
36    effectively case-insensitive.
37 
38    If no codec is found, a KeyError is set and NULL returned.
39 
40    As side effect, this tries to load the encodings package, if not
41    yet done. This is part of the lazy load strategy for the encodings
42    package.
43 
44  */
45 PyObject* _PyCodec_Lookup(const(char)* encoding);
46 version(Python_3_0_Or_Later) {
47     /// Availability: 3.*
48     int PyCodec_KnownEncoding(
49             const(char)* encoding
50             );
51 }
52 /** Generic codec based _encoding API.
53 
54    object is passed through the encoder function found for the given
55    encoding using the error handling method defined by errors. errors
56    may be NULL to use the default method defined for the codec.
57 
58    Raises a LookupError in case no encoder can be found.
59 
60  */
61 PyObject* PyCodec_Encode(PyObject* object, const(char)* encoding, const(char)* errors);
62 /** Generic codec based decoding API.
63 
64    object is passed through the decoder function found for the given
65    encoding using the error handling method defined by errors. errors
66    may be NULL to use the default method defined for the codec.
67 
68    Raises a LookupError in case no encoder can be found.
69 
70  */
71 PyObject* PyCodec_Decode(PyObject* object, const(char)* encoding, const(char)* errors);
72 /** Get an encoder function for the given encoding. */
73 PyObject* PyCodec_Encoder(const(char)* encoding);
74 /** Get a decoder function for the given encoding. */
75 PyObject* PyCodec_Decoder(const(char)* encoding);
76 version(Python_2_5_Or_Later) {
77     /** Get a IncrementalEncoder object for the given encoding. */
78     /// Availability: >= 2.5
79 
80     PyObject* PyCodec_IncrementalEncoder(
81             const(char)* encoding,
82             const(char)* errors
83             );
84 
85     /** Get a IncrementalDecoder object function for the given encoding. */
86     /// Availability: >= 2.5
87 
88     PyObject* PyCodec_IncrementalDecoder(
89             const(char)* encoding,
90             const(char)* errors
91             );
92 }
93 /** Get a StreamReader factory function for the given encoding. */
94 PyObject* PyCodec_StreamReader(
95         const(char)* encoding,
96         PyObject* stream,
97         const(char)* errors);
98 /** Get a StreamWriter factory function for the given encoding. */
99 PyObject* PyCodec_StreamWriter(const(char)* encoding, PyObject* stream, const(char)* errors);
100 
101 //-//////////////////////////////////////////////////////////////////////////
102 // UNICODE ENCODING INTERFACE
103 //-//////////////////////////////////////////////////////////////////////////
104 
105 /** Register the _error handling callback function error under the given
106    name. This function will be called by the codec when it encounters
107    unencodable characters/undecodable bytes and doesn't know the
108    callback _name, when name is specified as the error parameter
109    in the call to the encode/decode function.
110    Return 0 on success, -1 on _error */
111 int PyCodec_RegisterError(const(char)* name, PyObject* error);
112 /** Lookup the error handling callback function registered under the given
113    name. As a special case NULL can be passed, in which case
114    the error handling callback for "strict" will be returned. */
115 PyObject* PyCodec_LookupError(const(char)* name);
116 /** raise exc as an exception */
117 PyObject* PyCodec_StrictErrors(PyObject* exc);
118 /** ignore the unicode error, skipping the faulty input */
119 PyObject* PyCodec_IgnoreErrors(PyObject* exc);
120 /** replace the unicode encode error with ? or U+FFFD */
121 PyObject* PyCodec_ReplaceErrors(PyObject* exc);
122 /** replace the unicode encode error with XML character references */
123 PyObject* PyCodec_XMLCharRefReplaceErrors(PyObject* exc);
124 /** replace the unicode encode error with backslash escapes (\x, \u and \U) */
125 PyObject* PyCodec_BackslashReplaceErrors(PyObject* exc);
126 
127 version(Python_3_5_Or_Later) {
128     /** replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */
129     PyObject* PyCodec_NameReplaceErrors(PyObject* exc);
130 }
131