blob: d8d23c4050f0e620562ee6c6b60e84d1b4856b22 [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
Marc-André Lemburg3f419742004-07-10 12:06:10 +000051PyObject *codec_register(PyObject *self, PyObject *args)
Guido van Rossume2d67f92000-03-10 23:09:23 +000052{
53 PyObject *search_function;
54
55 if (!PyArg_ParseTuple(args, "O:register", &search_function))
56 goto onError;
57
58 if (PyCodec_Register(search_function))
59 goto onError;
Walter Dörwald9fd115c2005-11-02 08:30:08 +000060
Guido van Rossume2d67f92000-03-10 23:09:23 +000061 Py_INCREF(Py_None);
62 return Py_None;
63
64 onError:
65 return NULL;
66}
67
Walter Dörwald0ae29812002-10-31 13:36:29 +000068PyDoc_STRVAR(lookup__doc__,
69"lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)\n\
70\n\
71Looks up a codec tuple in the Python codec registry and returns\n\
72a tuple of functions.");
73
Guido van Rossume2d67f92000-03-10 23:09:23 +000074static
Marc-André Lemburg3f419742004-07-10 12:06:10 +000075PyObject *codec_lookup(PyObject *self, PyObject *args)
Guido van Rossume2d67f92000-03-10 23:09:23 +000076{
77 char *encoding;
78
79 if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
80 goto onError;
81
82 return _PyCodec_Lookup(encoding);
83
84 onError:
85 return NULL;
86}
87
Marc-André Lemburg3f419742004-07-10 12:06:10 +000088PyDoc_STRVAR(encode__doc__,
89"encode(obj, [encoding[,errors]]) -> object\n\
90\n\
91Encodes obj using the codec registered for encoding. encoding defaults\n\
92to the default encoding. errors may be given to set a different error\n\
93handling scheme. Default is 'strict' meaning that encoding errors raise\n\
94a ValueError. Other possible values are 'ignore', 'replace' and\n\
95'xmlcharrefreplace' as well as any other name registered with\n\
96codecs.register_error that can handle ValueErrors.");
97
98static PyObject *
99codec_encode(PyObject *self, PyObject *args)
100{
Brett Cannon3e377de2004-07-10 21:41:14 +0000101 const char *encoding = NULL;
102 const char *errors = NULL;
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000103 PyObject *v;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000104
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000105 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
106 return NULL;
107
Martin v. Löwise2713be2005-03-08 15:03:08 +0000108#ifdef Py_USING_UNICODE
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000109 if (encoding == NULL)
110 encoding = PyUnicode_GetDefaultEncoding();
Martin v. Löwise2713be2005-03-08 15:03:08 +0000111#else
112 if (encoding == NULL) {
113 PyErr_SetString(PyExc_ValueError, "no encoding specified");
114 return NULL;
115 }
116#endif
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000117
118 /* Encode via the codec registry */
119 v = PyCodec_Encode(v, encoding, errors);
120 if (v == NULL)
121 goto onError;
122 return v;
123
124 onError:
125 return NULL;
126}
127
128PyDoc_STRVAR(decode__doc__,
129"decode(obj, [encoding[,errors]]) -> object\n\
130\n\
131Decodes obj using the codec registered for encoding. encoding defaults\n\
132to the default encoding. errors may be given to set a different error\n\
133handling scheme. Default is 'strict' meaning that encoding errors raise\n\
134a ValueError. Other possible values are 'ignore' and 'replace'\n\
135as well as any other name registerd with codecs.register_error that is\n\
136able to handle ValueErrors.");
137
138static PyObject *
139codec_decode(PyObject *self, PyObject *args)
140{
Brett Cannon3e377de2004-07-10 21:41:14 +0000141 const char *encoding = NULL;
142 const char *errors = NULL;
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000143 PyObject *v;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000144
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000145 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
146 return NULL;
147
Martin v. Löwise2713be2005-03-08 15:03:08 +0000148#ifdef Py_USING_UNICODE
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000149 if (encoding == NULL)
150 encoding = PyUnicode_GetDefaultEncoding();
Martin v. Löwise2713be2005-03-08 15:03:08 +0000151#else
152 if (encoding == NULL) {
153 PyErr_SetString(PyExc_ValueError, "no encoding specified");
154 return NULL;
155 }
156#endif
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000157
158 /* Decode via the codec registry */
159 v = PyCodec_Decode(v, encoding, errors);
160 if (v == NULL)
161 goto onError;
162 return v;
163
164 onError:
165 return NULL;
166}
167
Guido van Rossume2d67f92000-03-10 23:09:23 +0000168/* --- Helpers ------------------------------------------------------------ */
169
170static
171PyObject *codec_tuple(PyObject *unicode,
Martin v. Löwis66851282006-04-22 11:40:03 +0000172 Py_ssize_t len)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000173{
174 PyObject *v,*w;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000175
Guido van Rossume2d67f92000-03-10 23:09:23 +0000176 if (unicode == NULL)
177 return NULL;
178 v = PyTuple_New(2);
179 if (v == NULL) {
180 Py_DECREF(unicode);
181 return NULL;
182 }
183 PyTuple_SET_ITEM(v,0,unicode);
Martin v. Löwis66851282006-04-22 11:40:03 +0000184 w = PyInt_FromSsize_t(len);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000185 if (w == NULL) {
186 Py_DECREF(v);
187 return NULL;
188 }
189 PyTuple_SET_ITEM(v,1,w);
190 return v;
191}
192
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000193/* --- String codecs ------------------------------------------------------ */
194static PyObject *
195escape_decode(PyObject *self,
196 PyObject *args)
197{
198 const char *errors = NULL;
199 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000200 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000201
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000202 if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
203 &data, &size, &errors))
204 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000205 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000206 size);
207}
208
209static PyObject *
210escape_encode(PyObject *self,
211 PyObject *args)
212{
213 PyObject *str;
214 const char *errors = NULL;
215 char *buf;
Martin v. Löwis66851282006-04-22 11:40:03 +0000216 Py_ssize_t len;
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000217
218 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
219 &PyString_Type, &str, &errors))
220 return NULL;
221
222 str = PyString_Repr(str, 0);
223 if (!str)
224 return NULL;
225
226 /* The string will be quoted. Unquote, similar to unicode-escape. */
227 buf = PyString_AS_STRING (str);
228 len = PyString_GET_SIZE (str);
229 memmove(buf, buf+1, len-2);
230 _PyString_Resize(&str, len-2);
231
232 return codec_tuple(str, PyString_Size(str));
233}
234
235#ifdef Py_USING_UNICODE
Guido van Rossume2d67f92000-03-10 23:09:23 +0000236/* --- Decoder ------------------------------------------------------------ */
237
238static PyObject *
239unicode_internal_decode(PyObject *self,
240 PyObject *args)
241{
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000242 PyObject *obj;
243 const char *errors = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000244 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000245 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000246
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000247 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
248 &obj, &errors))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000249 return NULL;
250
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000251 if (PyUnicode_Check(obj)) {
252 Py_INCREF(obj);
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000253 return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000254 }
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000255 else {
256 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
257 return NULL;
Walter Dörwalda47d1c02005-08-30 10:23:14 +0000258
259 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000260 size);
261 }
Guido van Rossume2d67f92000-03-10 23:09:23 +0000262}
263
264static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000265utf_7_decode(PyObject *self,
266 PyObject *args)
267{
268 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000269 Py_ssize_t size;
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000270 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000271
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000272 if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
273 &data, &size, &errors))
274 return NULL;
275
276 return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
277 size);
278}
279
280static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000281utf_8_decode(PyObject *self,
282 PyObject *args)
283{
284 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000285 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000286 const char *errors = NULL;
Walter Dörwald69652032004-09-07 20:24:22 +0000287 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000288 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000289 PyObject *decoded = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000290
Walter Dörwald69652032004-09-07 20:24:22 +0000291 if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
292 &data, &size, &errors, &final))
293 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000294 if (size < 0) {
295 PyErr_SetString(PyExc_ValueError, "negative argument");
296 return 0;
297 }
Walter Dörwald69652032004-09-07 20:24:22 +0000298 consumed = size;
299
300 decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
301 final ? NULL : &consumed);
302 if (decoded == NULL)
303 return NULL;
304 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000305}
306
307static PyObject *
308utf_16_decode(PyObject *self,
309 PyObject *args)
310{
311 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000312 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000313 const char *errors = NULL;
314 int byteorder = 0;
Walter Dörwald69652032004-09-07 20:24:22 +0000315 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000316 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000317 PyObject *decoded;
318
319 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
320 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000321 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000322 if (size < 0) {
323 PyErr_SetString(PyExc_ValueError, "negative argument");
324 return 0;
325 }
Martin v. Löwisd532ba02006-05-27 08:54:29 +0000326 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000327 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
328 final ? NULL : &consumed);
329 if (decoded == NULL)
330 return NULL;
331 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000332}
333
334static PyObject *
335utf_16_le_decode(PyObject *self,
336 PyObject *args)
337{
338 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000339 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000340 const char *errors = NULL;
341 int byteorder = -1;
Walter Dörwald69652032004-09-07 20:24:22 +0000342 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000343 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000344 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000345
Walter Dörwald69652032004-09-07 20:24:22 +0000346 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
347 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000348 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000349
Martin v. Löwis18e16552006-02-15 17:27:45 +0000350 if (size < 0) {
351 PyErr_SetString(PyExc_ValueError, "negative argument");
352 return 0;
353 }
Martin v. Löwisd532ba02006-05-27 08:54:29 +0000354 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000355 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
356 &byteorder, final ? NULL : &consumed);
357 if (decoded == NULL)
358 return NULL;
359 return codec_tuple(decoded, consumed);
360
Guido van Rossume2d67f92000-03-10 23:09:23 +0000361}
362
363static PyObject *
364utf_16_be_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 = 1;
Walter Dörwald69652032004-09-07 20:24:22 +0000371 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000372 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000373 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000374
Walter Dörwald69652032004-09-07 20:24:22 +0000375 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
376 &data, &size, &errors, &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 }
Martin v. Löwisd532ba02006-05-27 08:54:29 +0000382 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000383 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
384 &byteorder, final ? NULL : &consumed);
385 if (decoded == NULL)
386 return NULL;
387 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000388}
389
390/* This non-standard version also provides access to the byteorder
391 parameter of the builtin UTF-16 codec.
392
393 It returns a tuple (unicode, bytesread, byteorder) with byteorder
394 being the value in effect at the end of data.
395
396*/
397
398static PyObject *
399utf_16_ex_decode(PyObject *self,
400 PyObject *args)
401{
402 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000403 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000404 const char *errors = NULL;
405 int byteorder = 0;
406 PyObject *unicode, *tuple;
Walter Dörwald69652032004-09-07 20:24:22 +0000407 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000408 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000409
410 if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
411 &data, &size, &errors, &byteorder, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000412 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000413 if (size < 0) {
414 PyErr_SetString(PyExc_ValueError, "negative argument");
415 return 0;
416 }
Martin v. Löwisd532ba02006-05-27 08:54:29 +0000417 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000418 unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
419 final ? NULL : &consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000420 if (unicode == NULL)
421 return NULL;
Walter Dörwald69652032004-09-07 20:24:22 +0000422 tuple = Py_BuildValue("Oii", unicode, consumed, byteorder);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000423 Py_DECREF(unicode);
424 return tuple;
425}
426
427static PyObject *
428unicode_escape_decode(PyObject *self,
429 PyObject *args)
430{
431 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000432 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000433 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000434
Guido van Rossume2d67f92000-03-10 23:09:23 +0000435 if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
436 &data, &size, &errors))
437 return NULL;
438
439 return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
440 size);
441}
442
443static PyObject *
444raw_unicode_escape_decode(PyObject *self,
445 PyObject *args)
446{
447 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000448 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000449 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000450
Guido van Rossume2d67f92000-03-10 23:09:23 +0000451 if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
452 &data, &size, &errors))
453 return NULL;
454
455 return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
456 size);
457}
458
459static PyObject *
460latin_1_decode(PyObject *self,
461 PyObject *args)
462{
463 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000464 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000465 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000466
Guido van Rossume2d67f92000-03-10 23:09:23 +0000467 if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
468 &data, &size, &errors))
469 return NULL;
470
471 return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
472 size);
473}
474
475static PyObject *
476ascii_decode(PyObject *self,
477 PyObject *args)
478{
479 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000480 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000481 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000482
Guido van Rossume2d67f92000-03-10 23:09:23 +0000483 if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
484 &data, &size, &errors))
485 return NULL;
486
487 return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
488 size);
489}
490
491static PyObject *
492charmap_decode(PyObject *self,
493 PyObject *args)
494{
495 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000496 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000497 const char *errors = NULL;
498 PyObject *mapping = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000499
Guido van Rossume2d67f92000-03-10 23:09:23 +0000500 if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
501 &data, &size, &errors, &mapping))
502 return NULL;
503 if (mapping == Py_None)
504 mapping = NULL;
505
506 return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
507 size);
508}
509
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000510#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000511
512static PyObject *
513mbcs_decode(PyObject *self,
514 PyObject *args)
515{
516 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000517 Py_ssize_t size;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000518 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000519
Guido van Rossum24bdb042000-03-28 20:29:59 +0000520 if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
521 &data, &size, &errors))
522 return NULL;
523
524 return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
525 size);
526}
527
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000528#endif /* MS_WINDOWS */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000529
Guido van Rossume2d67f92000-03-10 23:09:23 +0000530/* --- Encoder ------------------------------------------------------------ */
531
532static PyObject *
533readbuffer_encode(PyObject *self,
534 PyObject *args)
535{
536 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000537 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000538 const char *errors = NULL;
539
540 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
541 &data, &size, &errors))
542 return NULL;
543
544 return codec_tuple(PyString_FromStringAndSize(data, size),
545 size);
546}
547
548static PyObject *
549charbuffer_encode(PyObject *self,
550 PyObject *args)
551{
552 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000553 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000554 const char *errors = NULL;
555
556 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
557 &data, &size, &errors))
558 return NULL;
559
560 return codec_tuple(PyString_FromStringAndSize(data, size),
561 size);
562}
563
564static PyObject *
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000565unicode_internal_encode(PyObject *self,
566 PyObject *args)
567{
568 PyObject *obj;
569 const char *errors = NULL;
570 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000571 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000572
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000573 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
574 &obj, &errors))
575 return NULL;
576
577 if (PyUnicode_Check(obj)) {
578 data = PyUnicode_AS_DATA(obj);
579 size = PyUnicode_GET_DATA_SIZE(obj);
580 return codec_tuple(PyString_FromStringAndSize(data, size),
581 size);
582 }
583 else {
584 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
585 return NULL;
586 return codec_tuple(PyString_FromStringAndSize(data, size),
587 size);
588 }
589}
590
591static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000592utf_7_encode(PyObject *self,
593 PyObject *args)
594{
595 PyObject *str, *v;
596 const char *errors = NULL;
597
598 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
599 &str, &errors))
600 return NULL;
601
602 str = PyUnicode_FromObject(str);
603 if (str == NULL)
604 return NULL;
605 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
606 PyUnicode_GET_SIZE(str),
607 0,
608 0,
609 errors),
610 PyUnicode_GET_SIZE(str));
611 Py_DECREF(str);
612 return v;
613}
614
615static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000616utf_8_encode(PyObject *self,
617 PyObject *args)
618{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000619 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000620 const char *errors = NULL;
621
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000622 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000623 &str, &errors))
624 return NULL;
625
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000626 str = PyUnicode_FromObject(str);
627 if (str == NULL)
628 return NULL;
629 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
630 PyUnicode_GET_SIZE(str),
631 errors),
632 PyUnicode_GET_SIZE(str));
633 Py_DECREF(str);
634 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000635}
636
637/* This version provides access to the byteorder parameter of the
638 builtin UTF-16 codecs as optional third argument. It defaults to 0
639 which means: use the native byte order and prepend the data with a
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000640 BOM mark.
Guido van Rossume2d67f92000-03-10 23:09:23 +0000641
642*/
643
644static PyObject *
645utf_16_encode(PyObject *self,
646 PyObject *args)
647{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000648 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000649 const char *errors = NULL;
650 int byteorder = 0;
651
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000652 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000653 &str, &errors, &byteorder))
654 return NULL;
655
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000656 str = PyUnicode_FromObject(str);
657 if (str == NULL)
658 return NULL;
659 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
660 PyUnicode_GET_SIZE(str),
661 errors,
662 byteorder),
663 PyUnicode_GET_SIZE(str));
664 Py_DECREF(str);
665 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000666}
667
668static PyObject *
669utf_16_le_encode(PyObject *self,
670 PyObject *args)
671{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000672 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000673 const char *errors = NULL;
674
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000675 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000676 &str, &errors))
677 return NULL;
678
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000679 str = PyUnicode_FromObject(str);
680 if (str == NULL)
681 return NULL;
682 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000683 PyUnicode_GET_SIZE(str),
684 errors,
685 -1),
686 PyUnicode_GET_SIZE(str));
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000687 Py_DECREF(str);
688 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000689}
690
691static PyObject *
692utf_16_be_encode(PyObject *self,
693 PyObject *args)
694{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000695 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000696 const char *errors = NULL;
697
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000698 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000699 &str, &errors))
700 return NULL;
701
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000702 str = PyUnicode_FromObject(str);
703 if (str == NULL)
704 return NULL;
705 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
706 PyUnicode_GET_SIZE(str),
707 errors,
708 +1),
709 PyUnicode_GET_SIZE(str));
710 Py_DECREF(str);
711 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000712}
713
714static PyObject *
715unicode_escape_encode(PyObject *self,
716 PyObject *args)
717{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000718 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000719 const char *errors = NULL;
720
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000721 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000722 &str, &errors))
723 return NULL;
724
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000725 str = PyUnicode_FromObject(str);
726 if (str == NULL)
727 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000728 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000729 PyUnicode_GET_SIZE(str)),
730 PyUnicode_GET_SIZE(str));
731 Py_DECREF(str);
732 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000733}
734
735static PyObject *
736raw_unicode_escape_encode(PyObject *self,
737 PyObject *args)
738{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000739 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000740 const char *errors = NULL;
741
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000742 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000743 &str, &errors))
744 return NULL;
745
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000746 str = PyUnicode_FromObject(str);
747 if (str == NULL)
748 return NULL;
749 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000750 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000751 PyUnicode_GET_SIZE(str)),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000752 PyUnicode_GET_SIZE(str));
753 Py_DECREF(str);
754 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000755}
756
757static PyObject *
758latin_1_encode(PyObject *self,
759 PyObject *args)
760{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000761 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000762 const char *errors = NULL;
763
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000764 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000765 &str, &errors))
766 return NULL;
767
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000768 str = PyUnicode_FromObject(str);
769 if (str == NULL)
770 return NULL;
771 v = codec_tuple(PyUnicode_EncodeLatin1(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000772 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000773 PyUnicode_GET_SIZE(str),
774 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000775 PyUnicode_GET_SIZE(str));
776 Py_DECREF(str);
777 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000778}
779
780static PyObject *
781ascii_encode(PyObject *self,
782 PyObject *args)
783{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000784 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000785 const char *errors = NULL;
786
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000787 if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000788 &str, &errors))
789 return NULL;
790
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000791 str = PyUnicode_FromObject(str);
792 if (str == NULL)
793 return NULL;
794 v = codec_tuple(PyUnicode_EncodeASCII(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000795 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000796 PyUnicode_GET_SIZE(str),
797 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000798 PyUnicode_GET_SIZE(str));
799 Py_DECREF(str);
800 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000801}
802
803static PyObject *
804charmap_encode(PyObject *self,
805 PyObject *args)
806{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000807 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000808 const char *errors = NULL;
809 PyObject *mapping = NULL;
810
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000811 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000812 &str, &errors, &mapping))
813 return NULL;
814 if (mapping == Py_None)
815 mapping = 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_EncodeCharmap(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000821 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000822 PyUnicode_GET_SIZE(str),
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000823 mapping,
Guido van Rossume2d67f92000-03-10 23:09:23 +0000824 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000825 PyUnicode_GET_SIZE(str));
826 Py_DECREF(str);
827 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000828}
829
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000830#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000831
832static PyObject *
833mbcs_encode(PyObject *self,
834 PyObject *args)
835{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000836 PyObject *str, *v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000837 const char *errors = NULL;
838
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000839 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
Guido van Rossum24bdb042000-03-28 20:29:59 +0000840 &str, &errors))
841 return NULL;
842
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000843 str = PyUnicode_FromObject(str);
844 if (str == NULL)
845 return NULL;
846 v = codec_tuple(PyUnicode_EncodeMBCS(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000847 PyUnicode_AS_UNICODE(str),
Guido van Rossum24bdb042000-03-28 20:29:59 +0000848 PyUnicode_GET_SIZE(str),
849 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000850 PyUnicode_GET_SIZE(str));
851 Py_DECREF(str);
852 return v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000853}
854
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000855#endif /* MS_WINDOWS */
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000856#endif /* Py_USING_UNICODE */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000857
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000858/* --- Error handler registry --------------------------------------------- */
859
Walter Dörwald0ae29812002-10-31 13:36:29 +0000860PyDoc_STRVAR(register_error__doc__,
861"register_error(errors, handler)\n\
862\n\
863Register the specified error handler under the name\n\
864errors. handler must be a callable object, that\n\
865will be called with an exception instance containing\n\
866information about the location of the encoding/decoding\n\
867error and must return a (replacement, new position) tuple.");
868
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000869static PyObject *register_error(PyObject *self, PyObject *args)
870{
871 const char *name;
872 PyObject *handler;
873
874 if (!PyArg_ParseTuple(args, "sO:register_error",
875 &name, &handler))
876 return NULL;
877 if (PyCodec_RegisterError(name, handler))
878 return NULL;
879 Py_INCREF(Py_None);
880 return Py_None;
881}
882
Walter Dörwald0ae29812002-10-31 13:36:29 +0000883PyDoc_STRVAR(lookup_error__doc__,
884"lookup_error(errors) -> handler\n\
885\n\
886Return the error handler for the specified error handling name\n\
887or raise a LookupError, if no handler exists under this name.");
888
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000889static PyObject *lookup_error(PyObject *self, PyObject *args)
890{
891 const char *name;
892
893 if (!PyArg_ParseTuple(args, "s:lookup_error",
894 &name))
895 return NULL;
896 return PyCodec_LookupError(name);
897}
898
Guido van Rossume2d67f92000-03-10 23:09:23 +0000899/* --- Module API --------------------------------------------------------- */
900
901static PyMethodDef _codecs_functions[] = {
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000902 {"register", codec_register, METH_VARARGS,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000903 register__doc__},
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000904 {"lookup", codec_lookup, METH_VARARGS,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000905 lookup__doc__},
Brett Cannon3e377de2004-07-10 21:41:14 +0000906 {"encode", codec_encode, METH_VARARGS,
907 encode__doc__},
908 {"decode", codec_decode, METH_VARARGS,
909 decode__doc__},
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000910 {"escape_encode", escape_encode, METH_VARARGS},
911 {"escape_decode", escape_decode, METH_VARARGS},
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000912#ifdef Py_USING_UNICODE
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000913 {"utf_8_encode", utf_8_encode, METH_VARARGS},
914 {"utf_8_decode", utf_8_decode, METH_VARARGS},
915 {"utf_7_encode", utf_7_encode, METH_VARARGS},
916 {"utf_7_decode", utf_7_decode, METH_VARARGS},
917 {"utf_16_encode", utf_16_encode, METH_VARARGS},
918 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS},
919 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS},
920 {"utf_16_decode", utf_16_decode, METH_VARARGS},
921 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS},
922 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS},
923 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
924 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS},
925 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS},
926 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS},
927 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS},
928 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS},
929 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS},
930 {"latin_1_encode", latin_1_encode, METH_VARARGS},
931 {"latin_1_decode", latin_1_decode, METH_VARARGS},
932 {"ascii_encode", ascii_encode, METH_VARARGS},
933 {"ascii_decode", ascii_decode, METH_VARARGS},
934 {"charmap_encode", charmap_encode, METH_VARARGS},
935 {"charmap_decode", charmap_decode, METH_VARARGS},
936 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
937 {"charbuffer_encode", charbuffer_encode, METH_VARARGS},
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000938#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000939 {"mbcs_encode", mbcs_encode, METH_VARARGS},
940 {"mbcs_decode", mbcs_decode, METH_VARARGS},
Guido van Rossum24bdb042000-03-28 20:29:59 +0000941#endif
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000942#endif /* Py_USING_UNICODE */
Walter Dörwald0ae29812002-10-31 13:36:29 +0000943 {"register_error", register_error, METH_VARARGS,
944 register_error__doc__},
945 {"lookup_error", lookup_error, METH_VARARGS,
946 lookup_error__doc__},
Guido van Rossume2d67f92000-03-10 23:09:23 +0000947 {NULL, NULL} /* sentinel */
948};
949
Mark Hammondfe51c6d2002-08-02 02:27:13 +0000950PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000951init_codecs(void)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000952{
953 Py_InitModule("_codecs", _codecs_functions);
954}