blob: 32fa82fb67dab536b6d2f2d9ec4625ea33fb70f0 [file] [log] [blame]
Guido van Rossume2d67f92000-03-10 23:09:23 +00001/* ------------------------------------------------------------------------
2
3 _codecs -- Provides access to the codec registry and the builtin
4 codecs.
5
6 This module should never be imported directly. The standard library
7 module "codecs" wraps this builtin module for use within Python.
8
9 The codec registry is accessible via:
10
11 register(search_function) -> None
12
13 lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)
14
15 The builtin Unicode codecs use the following interface:
16
Walter Dörwald9fd115c2005-11-02 08:30:08 +000017 <encoding>_encode(Unicode_object[,errors='strict']) ->
Guido van Rossume2d67f92000-03-10 23:09:23 +000018 (string object, bytes consumed)
19
Walter Dörwald9fd115c2005-11-02 08:30:08 +000020 <encoding>_decode(char_buffer_obj[,errors='strict']) ->
Guido van Rossume2d67f92000-03-10 23:09:23 +000021 (Unicode object, bytes consumed)
22
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +000023 <encoding>_encode() interfaces also accept non-Unicode object as
24 input. The objects are then converted to Unicode using
25 PyUnicode_FromObject() prior to applying the conversion.
26
Guido van Rossume2d67f92000-03-10 23:09:23 +000027 These <encoding>s are available: utf_8, unicode_escape,
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +000028 raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit),
29 mbcs (on win32).
30
Guido van Rossume2d67f92000-03-10 23:09:23 +000031
32Written by Marc-Andre Lemburg (mal@lemburg.com).
33
Guido van Rossum16b1ad92000-08-03 16:24:25 +000034Copyright (c) Corporation for National Research Initiatives.
Guido van Rossume2d67f92000-03-10 23:09:23 +000035
36 ------------------------------------------------------------------------ */
37
Martin v. Löwis18e16552006-02-15 17:27:45 +000038#define PY_SSIZE_T_CLEAN
Guido van Rossume2d67f92000-03-10 23:09:23 +000039#include "Python.h"
40
41/* --- Registry ----------------------------------------------------------- */
42
Walter Dörwald0ae29812002-10-31 13:36:29 +000043PyDoc_STRVAR(register__doc__,
44"register(search_function)\n\
45\n\
46Register a codec search function. Search functions are expected to take\n\
47one argument, the encoding name in all lower case letters, and return\n\
48a tuple of functions (encoder, decoder, stream_reader, stream_writer).");
49
Guido van Rossume2d67f92000-03-10 23:09:23 +000050static
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000051PyObject *codec_register(PyObject *self, PyObject *search_function)
Guido van Rossume2d67f92000-03-10 23:09:23 +000052{
Guido van Rossume2d67f92000-03-10 23:09:23 +000053 if (PyCodec_Register(search_function))
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000054 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +000055
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000056 Py_RETURN_NONE;
Guido van Rossume2d67f92000-03-10 23:09:23 +000057}
58
Walter Dörwald0ae29812002-10-31 13:36:29 +000059PyDoc_STRVAR(lookup__doc__,
60"lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)\n\
61\n\
62Looks up a codec tuple in the Python codec registry and returns\n\
63a tuple of functions.");
64
Guido van Rossume2d67f92000-03-10 23:09:23 +000065static
Marc-André Lemburg3f419742004-07-10 12:06:10 +000066PyObject *codec_lookup(PyObject *self, PyObject *args)
Guido van Rossume2d67f92000-03-10 23:09:23 +000067{
68 char *encoding;
69
70 if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000071 return NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +000072
73 return _PyCodec_Lookup(encoding);
Guido van Rossume2d67f92000-03-10 23:09:23 +000074}
75
Marc-André Lemburg3f419742004-07-10 12:06:10 +000076PyDoc_STRVAR(encode__doc__,
77"encode(obj, [encoding[,errors]]) -> object\n\
78\n\
79Encodes obj using the codec registered for encoding. encoding defaults\n\
80to the default encoding. errors may be given to set a different error\n\
81handling scheme. Default is 'strict' meaning that encoding errors raise\n\
82a ValueError. Other possible values are 'ignore', 'replace' and\n\
83'xmlcharrefreplace' as well as any other name registered with\n\
84codecs.register_error that can handle ValueErrors.");
85
86static PyObject *
87codec_encode(PyObject *self, PyObject *args)
88{
Brett Cannon3e377de2004-07-10 21:41:14 +000089 const char *encoding = NULL;
90 const char *errors = NULL;
Marc-André Lemburg3f419742004-07-10 12:06:10 +000091 PyObject *v;
Walter Dörwald9fd115c2005-11-02 08:30:08 +000092
Marc-André Lemburg3f419742004-07-10 12:06:10 +000093 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
94 return NULL;
95
Martin v. Löwise2713be2005-03-08 15:03:08 +000096#ifdef Py_USING_UNICODE
Marc-André Lemburg3f419742004-07-10 12:06:10 +000097 if (encoding == NULL)
98 encoding = PyUnicode_GetDefaultEncoding();
Martin v. Löwise2713be2005-03-08 15:03:08 +000099#else
100 if (encoding == NULL) {
101 PyErr_SetString(PyExc_ValueError, "no encoding specified");
102 return NULL;
103 }
104#endif
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000105
106 /* Encode via the codec registry */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000107 return PyCodec_Encode(v, encoding, errors);
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000108}
109
110PyDoc_STRVAR(decode__doc__,
111"decode(obj, [encoding[,errors]]) -> object\n\
112\n\
113Decodes obj using the codec registered for encoding. encoding defaults\n\
114to the default encoding. errors may be given to set a different error\n\
115handling scheme. Default is 'strict' meaning that encoding errors raise\n\
116a ValueError. Other possible values are 'ignore' and 'replace'\n\
117as well as any other name registerd with codecs.register_error that is\n\
118able to handle ValueErrors.");
119
120static PyObject *
121codec_decode(PyObject *self, PyObject *args)
122{
Brett Cannon3e377de2004-07-10 21:41:14 +0000123 const char *encoding = NULL;
124 const char *errors = NULL;
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000125 PyObject *v;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000126
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000127 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
128 return NULL;
129
Martin v. Löwise2713be2005-03-08 15:03:08 +0000130#ifdef Py_USING_UNICODE
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000131 if (encoding == NULL)
132 encoding = PyUnicode_GetDefaultEncoding();
Martin v. Löwise2713be2005-03-08 15:03:08 +0000133#else
134 if (encoding == NULL) {
135 PyErr_SetString(PyExc_ValueError, "no encoding specified");
136 return NULL;
137 }
138#endif
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000139
140 /* Decode via the codec registry */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000141 return PyCodec_Decode(v, encoding, errors);
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000142}
143
Guido van Rossume2d67f92000-03-10 23:09:23 +0000144/* --- Helpers ------------------------------------------------------------ */
145
146static
147PyObject *codec_tuple(PyObject *unicode,
Thomas Wouters477c8d52006-05-27 19:21:47 +0000148 Py_ssize_t len)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000149{
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000150 PyObject *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000151 if (unicode == NULL)
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000152 return NULL;
153 v = Py_BuildValue("On", unicode, len);
154 Py_DECREF(unicode);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000155 return v;
156}
157
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000158/* --- String codecs ------------------------------------------------------ */
159static PyObject *
160escape_decode(PyObject *self,
161 PyObject *args)
162{
163 const char *errors = NULL;
164 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000165 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000166
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000167 if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
168 &data, &size, &errors))
169 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000170 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000171 size);
172}
173
174static PyObject *
175escape_encode(PyObject *self,
176 PyObject *args)
177{
178 PyObject *str;
179 const char *errors = NULL;
180 char *buf;
Thomas Wouters477c8d52006-05-27 19:21:47 +0000181 Py_ssize_t len;
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000182
183 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
184 &PyString_Type, &str, &errors))
185 return NULL;
186
187 str = PyString_Repr(str, 0);
188 if (!str)
189 return NULL;
190
191 /* The string will be quoted. Unquote, similar to unicode-escape. */
192 buf = PyString_AS_STRING (str);
193 len = PyString_GET_SIZE (str);
194 memmove(buf, buf+1, len-2);
195 _PyString_Resize(&str, len-2);
196
197 return codec_tuple(str, PyString_Size(str));
198}
199
200#ifdef Py_USING_UNICODE
Guido van Rossume2d67f92000-03-10 23:09:23 +0000201/* --- Decoder ------------------------------------------------------------ */
202
203static PyObject *
204unicode_internal_decode(PyObject *self,
205 PyObject *args)
206{
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000207 PyObject *obj;
208 const char *errors = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000209 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000210 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000211
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000212 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
213 &obj, &errors))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000214 return NULL;
215
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000216 if (PyUnicode_Check(obj)) {
217 Py_INCREF(obj);
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000218 return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000219 }
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000220 else {
221 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
222 return NULL;
Walter Dörwalda47d1c02005-08-30 10:23:14 +0000223
224 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000225 size);
226 }
Guido van Rossume2d67f92000-03-10 23:09:23 +0000227}
228
229static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000230utf_7_decode(PyObject *self,
231 PyObject *args)
232{
233 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000234 Py_ssize_t size;
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000235 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000236
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000237 if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
238 &data, &size, &errors))
239 return NULL;
240
241 return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
242 size);
243}
244
245static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000246utf_8_decode(PyObject *self,
247 PyObject *args)
248{
249 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000250 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000251 const char *errors = NULL;
Walter Dörwald69652032004-09-07 20:24:22 +0000252 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000253 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000254 PyObject *decoded = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000255
Walter Dörwald69652032004-09-07 20:24:22 +0000256 if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
257 &data, &size, &errors, &final))
258 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000259 if (size < 0) {
260 PyErr_SetString(PyExc_ValueError, "negative argument");
261 return 0;
262 }
Walter Dörwald69652032004-09-07 20:24:22 +0000263 consumed = size;
264
265 decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
266 final ? NULL : &consumed);
267 if (decoded == NULL)
268 return NULL;
269 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000270}
271
272static PyObject *
273utf_16_decode(PyObject *self,
274 PyObject *args)
275{
276 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000277 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000278 const char *errors = NULL;
279 int byteorder = 0;
Walter Dörwald69652032004-09-07 20:24:22 +0000280 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000281 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000282 PyObject *decoded;
283
284 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
285 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000286 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000287 if (size < 0) {
288 PyErr_SetString(PyExc_ValueError, "negative argument");
289 return 0;
290 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000291 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000292 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
293 final ? NULL : &consumed);
294 if (decoded == NULL)
295 return NULL;
296 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000297}
298
299static PyObject *
300utf_16_le_decode(PyObject *self,
301 PyObject *args)
302{
303 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000304 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000305 const char *errors = NULL;
306 int byteorder = -1;
Walter Dörwald69652032004-09-07 20:24:22 +0000307 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000308 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000309 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000310
Walter Dörwald69652032004-09-07 20:24:22 +0000311 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
312 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000313 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000314
Martin v. Löwis18e16552006-02-15 17:27:45 +0000315 if (size < 0) {
316 PyErr_SetString(PyExc_ValueError, "negative argument");
317 return 0;
318 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000319 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000320 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
321 &byteorder, final ? NULL : &consumed);
322 if (decoded == NULL)
323 return NULL;
324 return codec_tuple(decoded, consumed);
325
Guido van Rossume2d67f92000-03-10 23:09:23 +0000326}
327
328static PyObject *
329utf_16_be_decode(PyObject *self,
330 PyObject *args)
331{
332 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000333 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000334 const char *errors = NULL;
335 int byteorder = 1;
Walter Dörwald69652032004-09-07 20:24:22 +0000336 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000337 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000338 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000339
Walter Dörwald69652032004-09-07 20:24:22 +0000340 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
341 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000342 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000343 if (size < 0) {
344 PyErr_SetString(PyExc_ValueError, "negative argument");
345 return 0;
346 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000347 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000348 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
349 &byteorder, final ? NULL : &consumed);
350 if (decoded == NULL)
351 return NULL;
352 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000353}
354
355/* This non-standard version also provides access to the byteorder
356 parameter of the builtin UTF-16 codec.
357
358 It returns a tuple (unicode, bytesread, byteorder) with byteorder
359 being the value in effect at the end of data.
360
361*/
362
363static PyObject *
364utf_16_ex_decode(PyObject *self,
365 PyObject *args)
366{
367 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000368 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000369 const char *errors = NULL;
370 int byteorder = 0;
371 PyObject *unicode, *tuple;
Walter Dörwald69652032004-09-07 20:24:22 +0000372 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000373 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000374
375 if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
376 &data, &size, &errors, &byteorder, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000377 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000378 if (size < 0) {
379 PyErr_SetString(PyExc_ValueError, "negative argument");
380 return 0;
381 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000382 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000383 unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
384 final ? NULL : &consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000385 if (unicode == NULL)
386 return NULL;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000387 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000388 Py_DECREF(unicode);
389 return tuple;
390}
391
392static PyObject *
393unicode_escape_decode(PyObject *self,
394 PyObject *args)
395{
396 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000397 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000398 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000399
Guido van Rossume2d67f92000-03-10 23:09:23 +0000400 if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
401 &data, &size, &errors))
402 return NULL;
403
404 return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
405 size);
406}
407
408static PyObject *
409raw_unicode_escape_decode(PyObject *self,
410 PyObject *args)
411{
412 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000413 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000414 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000415
Guido van Rossume2d67f92000-03-10 23:09:23 +0000416 if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
417 &data, &size, &errors))
418 return NULL;
419
420 return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
421 size);
422}
423
424static PyObject *
425latin_1_decode(PyObject *self,
426 PyObject *args)
427{
428 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000429 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000430 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000431
Guido van Rossume2d67f92000-03-10 23:09:23 +0000432 if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
433 &data, &size, &errors))
434 return NULL;
435
436 return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
437 size);
438}
439
440static PyObject *
441ascii_decode(PyObject *self,
442 PyObject *args)
443{
444 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000445 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000446 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000447
Guido van Rossume2d67f92000-03-10 23:09:23 +0000448 if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
449 &data, &size, &errors))
450 return NULL;
451
452 return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
453 size);
454}
455
456static PyObject *
457charmap_decode(PyObject *self,
458 PyObject *args)
459{
460 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000461 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000462 const char *errors = NULL;
463 PyObject *mapping = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000464
Guido van Rossume2d67f92000-03-10 23:09:23 +0000465 if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
466 &data, &size, &errors, &mapping))
467 return NULL;
468 if (mapping == Py_None)
469 mapping = NULL;
470
471 return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
472 size);
473}
474
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000475#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000476
477static PyObject *
478mbcs_decode(PyObject *self,
479 PyObject *args)
480{
481 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000482 Py_ssize_t size;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000483 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000484
Guido van Rossum24bdb042000-03-28 20:29:59 +0000485 if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
486 &data, &size, &errors))
487 return NULL;
488
489 return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
490 size);
491}
492
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000493#endif /* MS_WINDOWS */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000494
Guido van Rossume2d67f92000-03-10 23:09:23 +0000495/* --- Encoder ------------------------------------------------------------ */
496
497static PyObject *
498readbuffer_encode(PyObject *self,
499 PyObject *args)
500{
501 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000502 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000503 const char *errors = NULL;
504
505 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
506 &data, &size, &errors))
507 return NULL;
508
509 return codec_tuple(PyString_FromStringAndSize(data, size),
510 size);
511}
512
513static PyObject *
514charbuffer_encode(PyObject *self,
515 PyObject *args)
516{
517 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000518 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000519 const char *errors = NULL;
520
521 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
522 &data, &size, &errors))
523 return NULL;
524
525 return codec_tuple(PyString_FromStringAndSize(data, size),
526 size);
527}
528
529static PyObject *
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000530unicode_internal_encode(PyObject *self,
531 PyObject *args)
532{
533 PyObject *obj;
534 const char *errors = NULL;
535 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000536 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000537
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000538 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
539 &obj, &errors))
540 return NULL;
541
542 if (PyUnicode_Check(obj)) {
543 data = PyUnicode_AS_DATA(obj);
544 size = PyUnicode_GET_DATA_SIZE(obj);
545 return codec_tuple(PyString_FromStringAndSize(data, size),
546 size);
547 }
548 else {
549 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
550 return NULL;
551 return codec_tuple(PyString_FromStringAndSize(data, size),
552 size);
553 }
554}
555
556static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000557utf_7_encode(PyObject *self,
558 PyObject *args)
559{
560 PyObject *str, *v;
561 const char *errors = NULL;
562
563 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
564 &str, &errors))
565 return NULL;
566
567 str = PyUnicode_FromObject(str);
568 if (str == NULL)
569 return NULL;
570 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
571 PyUnicode_GET_SIZE(str),
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000572 0,
573 0,
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000574 errors),
575 PyUnicode_GET_SIZE(str));
576 Py_DECREF(str);
577 return v;
578}
579
580static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000581utf_8_encode(PyObject *self,
582 PyObject *args)
583{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000584 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000585 const char *errors = NULL;
586
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000587 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000588 &str, &errors))
589 return NULL;
590
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000591 str = PyUnicode_FromObject(str);
592 if (str == NULL)
593 return NULL;
594 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
595 PyUnicode_GET_SIZE(str),
596 errors),
597 PyUnicode_GET_SIZE(str));
598 Py_DECREF(str);
599 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000600}
601
602/* This version provides access to the byteorder parameter of the
603 builtin UTF-16 codecs as optional third argument. It defaults to 0
604 which means: use the native byte order and prepend the data with a
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000605 BOM mark.
Guido van Rossume2d67f92000-03-10 23:09:23 +0000606
607*/
608
609static PyObject *
610utf_16_encode(PyObject *self,
611 PyObject *args)
612{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000613 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000614 const char *errors = NULL;
615 int byteorder = 0;
616
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000617 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000618 &str, &errors, &byteorder))
619 return NULL;
620
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000621 str = PyUnicode_FromObject(str);
622 if (str == NULL)
623 return NULL;
624 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
625 PyUnicode_GET_SIZE(str),
626 errors,
627 byteorder),
628 PyUnicode_GET_SIZE(str));
629 Py_DECREF(str);
630 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000631}
632
633static PyObject *
634utf_16_le_encode(PyObject *self,
635 PyObject *args)
636{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000637 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000638 const char *errors = NULL;
639
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000640 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000641 &str, &errors))
642 return NULL;
643
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000644 str = PyUnicode_FromObject(str);
645 if (str == NULL)
646 return NULL;
647 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000648 PyUnicode_GET_SIZE(str),
649 errors,
650 -1),
651 PyUnicode_GET_SIZE(str));
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000652 Py_DECREF(str);
653 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000654}
655
656static PyObject *
657utf_16_be_encode(PyObject *self,
658 PyObject *args)
659{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000660 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000661 const char *errors = NULL;
662
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000663 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000664 &str, &errors))
665 return NULL;
666
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000667 str = PyUnicode_FromObject(str);
668 if (str == NULL)
669 return NULL;
670 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
671 PyUnicode_GET_SIZE(str),
672 errors,
673 +1),
674 PyUnicode_GET_SIZE(str));
675 Py_DECREF(str);
676 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000677}
678
679static PyObject *
680unicode_escape_encode(PyObject *self,
681 PyObject *args)
682{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000683 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000684 const char *errors = NULL;
685
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000686 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000687 &str, &errors))
688 return NULL;
689
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000690 str = PyUnicode_FromObject(str);
691 if (str == NULL)
692 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000693 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000694 PyUnicode_GET_SIZE(str)),
695 PyUnicode_GET_SIZE(str));
696 Py_DECREF(str);
697 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000698}
699
700static PyObject *
701raw_unicode_escape_encode(PyObject *self,
702 PyObject *args)
703{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000704 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000705 const char *errors = NULL;
706
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000707 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000708 &str, &errors))
709 return NULL;
710
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000711 str = PyUnicode_FromObject(str);
712 if (str == NULL)
713 return NULL;
714 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000715 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000716 PyUnicode_GET_SIZE(str)),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000717 PyUnicode_GET_SIZE(str));
718 Py_DECREF(str);
719 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000720}
721
722static PyObject *
723latin_1_encode(PyObject *self,
724 PyObject *args)
725{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000726 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000727 const char *errors = NULL;
728
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000729 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000730 &str, &errors))
731 return NULL;
732
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000733 str = PyUnicode_FromObject(str);
734 if (str == NULL)
735 return NULL;
736 v = codec_tuple(PyUnicode_EncodeLatin1(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000737 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000738 PyUnicode_GET_SIZE(str),
739 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000740 PyUnicode_GET_SIZE(str));
741 Py_DECREF(str);
742 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000743}
744
745static PyObject *
746ascii_encode(PyObject *self,
747 PyObject *args)
748{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000749 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000750 const char *errors = NULL;
751
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000752 if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000753 &str, &errors))
754 return NULL;
755
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000756 str = PyUnicode_FromObject(str);
757 if (str == NULL)
758 return NULL;
759 v = codec_tuple(PyUnicode_EncodeASCII(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000760 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000761 PyUnicode_GET_SIZE(str),
762 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000763 PyUnicode_GET_SIZE(str));
764 Py_DECREF(str);
765 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000766}
767
768static PyObject *
769charmap_encode(PyObject *self,
770 PyObject *args)
771{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000772 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000773 const char *errors = NULL;
774 PyObject *mapping = NULL;
775
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000776 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000777 &str, &errors, &mapping))
778 return NULL;
779 if (mapping == Py_None)
780 mapping = NULL;
781
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000782 str = PyUnicode_FromObject(str);
783 if (str == NULL)
784 return NULL;
785 v = codec_tuple(PyUnicode_EncodeCharmap(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000786 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000787 PyUnicode_GET_SIZE(str),
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000788 mapping,
Guido van Rossume2d67f92000-03-10 23:09:23 +0000789 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000790 PyUnicode_GET_SIZE(str));
791 Py_DECREF(str);
792 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000793}
794
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000795static PyObject*
796charmap_build(PyObject *self, PyObject *args)
797{
798 PyObject *map;
799 if (!PyArg_ParseTuple(args, "U:charmap_build", &map))
800 return NULL;
801 return PyUnicode_BuildEncodingMap(map);
802}
803
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000804#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000805
806static PyObject *
807mbcs_encode(PyObject *self,
808 PyObject *args)
809{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000810 PyObject *str, *v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000811 const char *errors = NULL;
812
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000813 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
Guido van Rossum24bdb042000-03-28 20:29:59 +0000814 &str, &errors))
815 return NULL;
816
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000817 str = PyUnicode_FromObject(str);
818 if (str == NULL)
819 return NULL;
820 v = codec_tuple(PyUnicode_EncodeMBCS(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000821 PyUnicode_AS_UNICODE(str),
Guido van Rossum24bdb042000-03-28 20:29:59 +0000822 PyUnicode_GET_SIZE(str),
823 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000824 PyUnicode_GET_SIZE(str));
825 Py_DECREF(str);
826 return v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000827}
828
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000829#endif /* MS_WINDOWS */
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000830#endif /* Py_USING_UNICODE */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000831
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000832/* --- Error handler registry --------------------------------------------- */
833
Walter Dörwald0ae29812002-10-31 13:36:29 +0000834PyDoc_STRVAR(register_error__doc__,
835"register_error(errors, handler)\n\
836\n\
837Register the specified error handler under the name\n\
838errors. handler must be a callable object, that\n\
839will be called with an exception instance containing\n\
840information about the location of the encoding/decoding\n\
841error and must return a (replacement, new position) tuple.");
842
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000843static PyObject *register_error(PyObject *self, PyObject *args)
844{
845 const char *name;
846 PyObject *handler;
847
848 if (!PyArg_ParseTuple(args, "sO:register_error",
849 &name, &handler))
850 return NULL;
851 if (PyCodec_RegisterError(name, handler))
852 return NULL;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000853 Py_RETURN_NONE;
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000854}
855
Walter Dörwald0ae29812002-10-31 13:36:29 +0000856PyDoc_STRVAR(lookup_error__doc__,
857"lookup_error(errors) -> handler\n\
858\n\
859Return the error handler for the specified error handling name\n\
860or raise a LookupError, if no handler exists under this name.");
861
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000862static PyObject *lookup_error(PyObject *self, PyObject *args)
863{
864 const char *name;
865
866 if (!PyArg_ParseTuple(args, "s:lookup_error",
867 &name))
868 return NULL;
869 return PyCodec_LookupError(name);
870}
871
Guido van Rossume2d67f92000-03-10 23:09:23 +0000872/* --- Module API --------------------------------------------------------- */
873
874static PyMethodDef _codecs_functions[] = {
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000875 {"register", codec_register, METH_O,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000876 register__doc__},
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000877 {"lookup", codec_lookup, METH_VARARGS,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000878 lookup__doc__},
Brett Cannon3e377de2004-07-10 21:41:14 +0000879 {"encode", codec_encode, METH_VARARGS,
880 encode__doc__},
881 {"decode", codec_decode, METH_VARARGS,
882 decode__doc__},
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000883 {"escape_encode", escape_encode, METH_VARARGS},
884 {"escape_decode", escape_decode, METH_VARARGS},
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000885#ifdef Py_USING_UNICODE
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000886 {"utf_8_encode", utf_8_encode, METH_VARARGS},
887 {"utf_8_decode", utf_8_decode, METH_VARARGS},
888 {"utf_7_encode", utf_7_encode, METH_VARARGS},
889 {"utf_7_decode", utf_7_decode, METH_VARARGS},
890 {"utf_16_encode", utf_16_encode, METH_VARARGS},
891 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS},
892 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS},
893 {"utf_16_decode", utf_16_decode, METH_VARARGS},
894 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS},
895 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS},
896 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
897 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS},
898 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS},
899 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS},
900 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS},
901 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS},
902 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS},
903 {"latin_1_encode", latin_1_encode, METH_VARARGS},
904 {"latin_1_decode", latin_1_decode, METH_VARARGS},
905 {"ascii_encode", ascii_encode, METH_VARARGS},
906 {"ascii_decode", ascii_decode, METH_VARARGS},
907 {"charmap_encode", charmap_encode, METH_VARARGS},
908 {"charmap_decode", charmap_decode, METH_VARARGS},
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000909 {"charmap_build", charmap_build, METH_VARARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000910 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
911 {"charbuffer_encode", charbuffer_encode, METH_VARARGS},
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000912#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000913 {"mbcs_encode", mbcs_encode, METH_VARARGS},
914 {"mbcs_decode", mbcs_decode, METH_VARARGS},
Guido van Rossum24bdb042000-03-28 20:29:59 +0000915#endif
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000916#endif /* Py_USING_UNICODE */
Walter Dörwald0ae29812002-10-31 13:36:29 +0000917 {"register_error", register_error, METH_VARARGS,
918 register_error__doc__},
919 {"lookup_error", lookup_error, METH_VARARGS,
920 lookup_error__doc__},
Guido van Rossume2d67f92000-03-10 23:09:23 +0000921 {NULL, NULL} /* sentinel */
922};
923
Mark Hammondfe51c6d2002-08-02 02:27:13 +0000924PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000925init_codecs(void)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000926{
927 Py_InitModule("_codecs", _codecs_functions);
928}