blob: b165f970eee37247aa7b7d1246c2888f7586716f [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
96 if (encoding == NULL)
97 encoding = PyUnicode_GetDefaultEncoding();
98
99 /* Encode via the codec registry */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000100 return PyCodec_Encode(v, encoding, errors);
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000101}
102
103PyDoc_STRVAR(decode__doc__,
104"decode(obj, [encoding[,errors]]) -> object\n\
105\n\
106Decodes obj using the codec registered for encoding. encoding defaults\n\
107to the default encoding. errors may be given to set a different error\n\
108handling scheme. Default is 'strict' meaning that encoding errors raise\n\
109a ValueError. Other possible values are 'ignore' and 'replace'\n\
110as well as any other name registerd with codecs.register_error that is\n\
111able to handle ValueErrors.");
112
113static PyObject *
114codec_decode(PyObject *self, PyObject *args)
115{
Brett Cannon3e377de2004-07-10 21:41:14 +0000116 const char *encoding = NULL;
117 const char *errors = NULL;
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000118 PyObject *v;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000119
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000120 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
121 return NULL;
122
123 if (encoding == NULL)
124 encoding = PyUnicode_GetDefaultEncoding();
125
126 /* Decode via the codec registry */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000127 return PyCodec_Decode(v, encoding, errors);
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000128}
129
Guido van Rossume2d67f92000-03-10 23:09:23 +0000130/* --- Helpers ------------------------------------------------------------ */
131
132static
133PyObject *codec_tuple(PyObject *unicode,
Thomas Wouters477c8d52006-05-27 19:21:47 +0000134 Py_ssize_t len)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000135{
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000136 PyObject *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000137 if (unicode == NULL)
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000138 return NULL;
139 v = Py_BuildValue("On", unicode, len);
140 Py_DECREF(unicode);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000141 return v;
142}
143
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000144/* --- String codecs ------------------------------------------------------ */
145static PyObject *
146escape_decode(PyObject *self,
147 PyObject *args)
148{
149 const char *errors = NULL;
150 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000151 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000152
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000153 if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
154 &data, &size, &errors))
155 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000156 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000157 size);
158}
159
160static PyObject *
161escape_encode(PyObject *self,
162 PyObject *args)
163{
164 PyObject *str;
165 const char *errors = NULL;
166 char *buf;
Thomas Wouters477c8d52006-05-27 19:21:47 +0000167 Py_ssize_t len;
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000168
169 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
170 &PyString_Type, &str, &errors))
171 return NULL;
172
173 str = PyString_Repr(str, 0);
174 if (!str)
175 return NULL;
176
177 /* The string will be quoted. Unquote, similar to unicode-escape. */
178 buf = PyString_AS_STRING (str);
179 len = PyString_GET_SIZE (str);
180 memmove(buf, buf+1, len-2);
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000181 if (_PyString_Resize(&str, len-2) < 0)
182 return NULL;
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000183
184 return codec_tuple(str, PyString_Size(str));
185}
186
Guido van Rossume2d67f92000-03-10 23:09:23 +0000187/* --- Decoder ------------------------------------------------------------ */
188
189static PyObject *
190unicode_internal_decode(PyObject *self,
191 PyObject *args)
192{
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000193 PyObject *obj;
194 const char *errors = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000195 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000196 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000197
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000198 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
199 &obj, &errors))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000200 return NULL;
201
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000202 if (PyUnicode_Check(obj)) {
203 Py_INCREF(obj);
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000204 return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
Marc-André Lemburg29273c82003-02-04 19:35:03 +0000205 }
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000206 else {
207 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
208 return NULL;
Walter Dörwalda47d1c02005-08-30 10:23:14 +0000209
210 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000211 size);
212 }
Guido van Rossume2d67f92000-03-10 23:09:23 +0000213}
214
215static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000216utf_7_decode(PyObject *self,
217 PyObject *args)
218{
219 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000220 Py_ssize_t size;
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000221 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000222
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000223 if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
224 &data, &size, &errors))
225 return NULL;
226
227 return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
228 size);
229}
230
231static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000232utf_8_decode(PyObject *self,
233 PyObject *args)
234{
235 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000236 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000237 const char *errors = NULL;
Walter Dörwald69652032004-09-07 20:24:22 +0000238 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000239 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000240 PyObject *decoded = NULL;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000241
Walter Dörwald69652032004-09-07 20:24:22 +0000242 if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
243 &data, &size, &errors, &final))
244 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000245 if (size < 0) {
246 PyErr_SetString(PyExc_ValueError, "negative argument");
247 return 0;
248 }
Walter Dörwald69652032004-09-07 20:24:22 +0000249 consumed = size;
250
251 decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
252 final ? NULL : &consumed);
253 if (decoded == NULL)
254 return NULL;
255 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000256}
257
258static PyObject *
259utf_16_decode(PyObject *self,
260 PyObject *args)
261{
262 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000263 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000264 const char *errors = NULL;
265 int byteorder = 0;
Walter Dörwald69652032004-09-07 20:24:22 +0000266 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000267 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000268 PyObject *decoded;
269
270 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
271 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000272 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000273 if (size < 0) {
274 PyErr_SetString(PyExc_ValueError, "negative argument");
275 return 0;
276 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000277 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000278 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
279 final ? NULL : &consumed);
280 if (decoded == NULL)
281 return NULL;
282 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000283}
284
285static PyObject *
286utf_16_le_decode(PyObject *self,
287 PyObject *args)
288{
289 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000290 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000291 const char *errors = NULL;
292 int byteorder = -1;
Walter Dörwald69652032004-09-07 20:24:22 +0000293 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000294 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000295 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000296
Walter Dörwald69652032004-09-07 20:24:22 +0000297 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
298 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000299 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000300
Martin v. Löwis18e16552006-02-15 17:27:45 +0000301 if (size < 0) {
302 PyErr_SetString(PyExc_ValueError, "negative argument");
303 return 0;
304 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000305 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000306 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
307 &byteorder, final ? NULL : &consumed);
308 if (decoded == NULL)
309 return NULL;
310 return codec_tuple(decoded, consumed);
311
Guido van Rossume2d67f92000-03-10 23:09:23 +0000312}
313
314static PyObject *
315utf_16_be_decode(PyObject *self,
316 PyObject *args)
317{
318 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000319 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000320 const char *errors = NULL;
321 int byteorder = 1;
Walter Dörwald69652032004-09-07 20:24:22 +0000322 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000323 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000324 PyObject *decoded = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000325
Walter Dörwald69652032004-09-07 20:24:22 +0000326 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
327 &data, &size, &errors, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000328 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000329 if (size < 0) {
330 PyErr_SetString(PyExc_ValueError, "negative argument");
331 return 0;
332 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000333 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000334 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
335 &byteorder, final ? NULL : &consumed);
336 if (decoded == NULL)
337 return NULL;
338 return codec_tuple(decoded, consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000339}
340
341/* This non-standard version also provides access to the byteorder
342 parameter of the builtin UTF-16 codec.
343
344 It returns a tuple (unicode, bytesread, byteorder) with byteorder
345 being the value in effect at the end of data.
346
347*/
348
349static PyObject *
350utf_16_ex_decode(PyObject *self,
351 PyObject *args)
352{
353 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000354 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000355 const char *errors = NULL;
356 int byteorder = 0;
357 PyObject *unicode, *tuple;
Walter Dörwald69652032004-09-07 20:24:22 +0000358 int final = 0;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000359 Py_ssize_t consumed;
Walter Dörwald69652032004-09-07 20:24:22 +0000360
361 if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
362 &data, &size, &errors, &byteorder, &final))
Guido van Rossume2d67f92000-03-10 23:09:23 +0000363 return NULL;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000364 if (size < 0) {
365 PyErr_SetString(PyExc_ValueError, "negative argument");
366 return 0;
367 }
Thomas Wouters477c8d52006-05-27 19:21:47 +0000368 consumed = size; /* This is overwritten unless final is true. */
Walter Dörwald69652032004-09-07 20:24:22 +0000369 unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
370 final ? NULL : &consumed);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000371 if (unicode == NULL)
372 return NULL;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000373 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
Guido van Rossume2d67f92000-03-10 23:09:23 +0000374 Py_DECREF(unicode);
375 return tuple;
376}
377
378static PyObject *
379unicode_escape_decode(PyObject *self,
380 PyObject *args)
381{
382 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000383 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000384 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000385
Guido van Rossume2d67f92000-03-10 23:09:23 +0000386 if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
387 &data, &size, &errors))
388 return NULL;
389
390 return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
391 size);
392}
393
394static PyObject *
395raw_unicode_escape_decode(PyObject *self,
396 PyObject *args)
397{
398 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000399 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000400 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000401
Guido van Rossume2d67f92000-03-10 23:09:23 +0000402 if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
403 &data, &size, &errors))
404 return NULL;
405
406 return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
407 size);
408}
409
410static PyObject *
411latin_1_decode(PyObject *self,
412 PyObject *args)
413{
414 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000415 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000416 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000417
Guido van Rossume2d67f92000-03-10 23:09:23 +0000418 if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
419 &data, &size, &errors))
420 return NULL;
421
422 return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
423 size);
424}
425
426static PyObject *
427ascii_decode(PyObject *self,
428 PyObject *args)
429{
430 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000431 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000432 const char *errors = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000433
Guido van Rossume2d67f92000-03-10 23:09:23 +0000434 if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
435 &data, &size, &errors))
436 return NULL;
437
438 return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
439 size);
440}
441
442static PyObject *
443charmap_decode(PyObject *self,
444 PyObject *args)
445{
446 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000447 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000448 const char *errors = NULL;
449 PyObject *mapping = NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000450
Guido van Rossume2d67f92000-03-10 23:09:23 +0000451 if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
452 &data, &size, &errors, &mapping))
453 return NULL;
454 if (mapping == Py_None)
455 mapping = NULL;
456
457 return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
458 size);
459}
460
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000461#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000462
463static PyObject *
464mbcs_decode(PyObject *self,
465 PyObject *args)
466{
467 const char *data;
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000468 Py_ssize_t size, consumed;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000469 const char *errors = NULL;
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000470 int final = 0;
471 PyObject *decoded;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000472
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000473 if (!PyArg_ParseTuple(args, "t#|zi:mbcs_decode",
474 &data, &size, &errors, &final))
Guido van Rossum24bdb042000-03-28 20:29:59 +0000475 return NULL;
476
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000477 decoded = PyUnicode_DecodeMBCSStateful(
478 data, size, errors, final ? NULL : &consumed);
479 if (!decoded)
480 return NULL;
481 return codec_tuple(decoded, final ? size : consumed);
Guido van Rossum24bdb042000-03-28 20:29:59 +0000482}
483
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000484#endif /* MS_WINDOWS */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000485
Guido van Rossume2d67f92000-03-10 23:09:23 +0000486/* --- Encoder ------------------------------------------------------------ */
487
488static PyObject *
489readbuffer_encode(PyObject *self,
490 PyObject *args)
491{
492 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000493 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000494 const char *errors = NULL;
495
496 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
497 &data, &size, &errors))
498 return NULL;
499
500 return codec_tuple(PyString_FromStringAndSize(data, size),
501 size);
502}
503
504static PyObject *
505charbuffer_encode(PyObject *self,
506 PyObject *args)
507{
508 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000509 Py_ssize_t size;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000510 const char *errors = NULL;
511
512 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
513 &data, &size, &errors))
514 return NULL;
515
516 return codec_tuple(PyString_FromStringAndSize(data, size),
517 size);
518}
519
520static PyObject *
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000521unicode_internal_encode(PyObject *self,
522 PyObject *args)
523{
524 PyObject *obj;
525 const char *errors = NULL;
526 const char *data;
Martin v. Löwis18e16552006-02-15 17:27:45 +0000527 Py_ssize_t size;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000528
Marc-André Lemburgb425f5e2000-09-21 21:09:45 +0000529 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
530 &obj, &errors))
531 return NULL;
532
533 if (PyUnicode_Check(obj)) {
534 data = PyUnicode_AS_DATA(obj);
535 size = PyUnicode_GET_DATA_SIZE(obj);
536 return codec_tuple(PyString_FromStringAndSize(data, size),
537 size);
538 }
539 else {
540 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
541 return NULL;
542 return codec_tuple(PyString_FromStringAndSize(data, size),
543 size);
544 }
545}
546
547static PyObject *
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000548utf_7_encode(PyObject *self,
549 PyObject *args)
550{
551 PyObject *str, *v;
552 const char *errors = NULL;
553
554 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
555 &str, &errors))
556 return NULL;
557
558 str = PyUnicode_FromObject(str);
559 if (str == NULL)
560 return NULL;
561 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
562 PyUnicode_GET_SIZE(str),
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000563 0,
564 0,
Marc-André Lemburgc60e6f72001-09-20 10:35:46 +0000565 errors),
566 PyUnicode_GET_SIZE(str));
567 Py_DECREF(str);
568 return v;
569}
570
571static PyObject *
Guido van Rossume2d67f92000-03-10 23:09:23 +0000572utf_8_encode(PyObject *self,
573 PyObject *args)
574{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000575 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000576 const char *errors = NULL;
577
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000578 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000579 &str, &errors))
580 return NULL;
581
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000582 str = PyUnicode_FromObject(str);
583 if (str == NULL)
584 return NULL;
585 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
586 PyUnicode_GET_SIZE(str),
587 errors),
588 PyUnicode_GET_SIZE(str));
589 Py_DECREF(str);
590 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000591}
592
593/* This version provides access to the byteorder parameter of the
594 builtin UTF-16 codecs as optional third argument. It defaults to 0
595 which means: use the native byte order and prepend the data with a
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000596 BOM mark.
Guido van Rossume2d67f92000-03-10 23:09:23 +0000597
598*/
599
600static PyObject *
601utf_16_encode(PyObject *self,
602 PyObject *args)
603{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000604 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000605 const char *errors = NULL;
606 int byteorder = 0;
607
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000608 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000609 &str, &errors, &byteorder))
610 return NULL;
611
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000612 str = PyUnicode_FromObject(str);
613 if (str == NULL)
614 return NULL;
615 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
616 PyUnicode_GET_SIZE(str),
617 errors,
618 byteorder),
619 PyUnicode_GET_SIZE(str));
620 Py_DECREF(str);
621 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000622}
623
624static PyObject *
625utf_16_le_encode(PyObject *self,
626 PyObject *args)
627{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000628 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000629 const char *errors = NULL;
630
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000631 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000632 &str, &errors))
633 return NULL;
634
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000635 str = PyUnicode_FromObject(str);
636 if (str == NULL)
637 return NULL;
638 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000639 PyUnicode_GET_SIZE(str),
640 errors,
641 -1),
642 PyUnicode_GET_SIZE(str));
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000643 Py_DECREF(str);
644 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000645}
646
647static PyObject *
648utf_16_be_encode(PyObject *self,
649 PyObject *args)
650{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000651 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000652 const char *errors = NULL;
653
Marc-André Lemburg4157dd52001-06-17 18:32:36 +0000654 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000655 &str, &errors))
656 return NULL;
657
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000658 str = PyUnicode_FromObject(str);
659 if (str == NULL)
660 return NULL;
661 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
662 PyUnicode_GET_SIZE(str),
663 errors,
664 +1),
665 PyUnicode_GET_SIZE(str));
666 Py_DECREF(str);
667 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000668}
669
670static PyObject *
671unicode_escape_encode(PyObject *self,
672 PyObject *args)
673{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000674 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000675 const char *errors = NULL;
676
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000677 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000678 &str, &errors))
679 return NULL;
680
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000681 str = PyUnicode_FromObject(str);
682 if (str == NULL)
683 return NULL;
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000684 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000685 PyUnicode_GET_SIZE(str)),
686 PyUnicode_GET_SIZE(str));
687 Py_DECREF(str);
688 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000689}
690
691static PyObject *
692raw_unicode_escape_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é Lemburg5f0e29e2000-07-05 11:24:13 +0000698 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_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_EncodeRawUnicodeEscape(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000706 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000707 PyUnicode_GET_SIZE(str)),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000708 PyUnicode_GET_SIZE(str));
709 Py_DECREF(str);
710 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000711}
712
713static PyObject *
714latin_1_encode(PyObject *self,
715 PyObject *args)
716{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000717 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000718 const char *errors = NULL;
719
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000720 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000721 &str, &errors))
722 return NULL;
723
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000724 str = PyUnicode_FromObject(str);
725 if (str == NULL)
726 return NULL;
727 v = codec_tuple(PyUnicode_EncodeLatin1(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000728 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000729 PyUnicode_GET_SIZE(str),
730 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000731 PyUnicode_GET_SIZE(str));
732 Py_DECREF(str);
733 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000734}
735
736static PyObject *
737ascii_encode(PyObject *self,
738 PyObject *args)
739{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000740 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000741 const char *errors = NULL;
742
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000743 if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000744 &str, &errors))
745 return NULL;
746
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000747 str = PyUnicode_FromObject(str);
748 if (str == NULL)
749 return NULL;
750 v = codec_tuple(PyUnicode_EncodeASCII(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000751 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000752 PyUnicode_GET_SIZE(str),
753 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000754 PyUnicode_GET_SIZE(str));
755 Py_DECREF(str);
756 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000757}
758
759static PyObject *
760charmap_encode(PyObject *self,
761 PyObject *args)
762{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000763 PyObject *str, *v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000764 const char *errors = NULL;
765 PyObject *mapping = NULL;
766
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000767 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
Guido van Rossume2d67f92000-03-10 23:09:23 +0000768 &str, &errors, &mapping))
769 return NULL;
770 if (mapping == Py_None)
771 mapping = NULL;
772
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000773 str = PyUnicode_FromObject(str);
774 if (str == NULL)
775 return NULL;
776 v = codec_tuple(PyUnicode_EncodeCharmap(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000777 PyUnicode_AS_UNICODE(str),
Guido van Rossume2d67f92000-03-10 23:09:23 +0000778 PyUnicode_GET_SIZE(str),
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000779 mapping,
Guido van Rossume2d67f92000-03-10 23:09:23 +0000780 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000781 PyUnicode_GET_SIZE(str));
782 Py_DECREF(str);
783 return v;
Guido van Rossume2d67f92000-03-10 23:09:23 +0000784}
785
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000786static PyObject*
787charmap_build(PyObject *self, PyObject *args)
788{
789 PyObject *map;
790 if (!PyArg_ParseTuple(args, "U:charmap_build", &map))
791 return NULL;
792 return PyUnicode_BuildEncodingMap(map);
793}
794
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000795#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Guido van Rossum24bdb042000-03-28 20:29:59 +0000796
797static PyObject *
798mbcs_encode(PyObject *self,
799 PyObject *args)
800{
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000801 PyObject *str, *v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000802 const char *errors = NULL;
803
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000804 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
Guido van Rossum24bdb042000-03-28 20:29:59 +0000805 &str, &errors))
806 return NULL;
807
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000808 str = PyUnicode_FromObject(str);
809 if (str == NULL)
810 return NULL;
811 v = codec_tuple(PyUnicode_EncodeMBCS(
Walter Dörwald9fd115c2005-11-02 08:30:08 +0000812 PyUnicode_AS_UNICODE(str),
Guido van Rossum24bdb042000-03-28 20:29:59 +0000813 PyUnicode_GET_SIZE(str),
814 errors),
Marc-André Lemburg5f0e29e2000-07-05 11:24:13 +0000815 PyUnicode_GET_SIZE(str));
816 Py_DECREF(str);
817 return v;
Guido van Rossum24bdb042000-03-28 20:29:59 +0000818}
819
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000820#endif /* MS_WINDOWS */
Guido van Rossum24bdb042000-03-28 20:29:59 +0000821
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000822/* --- Error handler registry --------------------------------------------- */
823
Walter Dörwald0ae29812002-10-31 13:36:29 +0000824PyDoc_STRVAR(register_error__doc__,
825"register_error(errors, handler)\n\
826\n\
827Register the specified error handler under the name\n\
828errors. handler must be a callable object, that\n\
829will be called with an exception instance containing\n\
830information about the location of the encoding/decoding\n\
831error and must return a (replacement, new position) tuple.");
832
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000833static PyObject *register_error(PyObject *self, PyObject *args)
834{
835 const char *name;
836 PyObject *handler;
837
838 if (!PyArg_ParseTuple(args, "sO:register_error",
839 &name, &handler))
840 return NULL;
841 if (PyCodec_RegisterError(name, handler))
842 return NULL;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000843 Py_RETURN_NONE;
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000844}
845
Walter Dörwald0ae29812002-10-31 13:36:29 +0000846PyDoc_STRVAR(lookup_error__doc__,
847"lookup_error(errors) -> handler\n\
848\n\
849Return the error handler for the specified error handling name\n\
850or raise a LookupError, if no handler exists under this name.");
851
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000852static PyObject *lookup_error(PyObject *self, PyObject *args)
853{
854 const char *name;
855
856 if (!PyArg_ParseTuple(args, "s:lookup_error",
857 &name))
858 return NULL;
859 return PyCodec_LookupError(name);
860}
861
Guido van Rossume2d67f92000-03-10 23:09:23 +0000862/* --- Module API --------------------------------------------------------- */
863
864static PyMethodDef _codecs_functions[] = {
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000865 {"register", codec_register, METH_O,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000866 register__doc__},
Marc-André Lemburg3f419742004-07-10 12:06:10 +0000867 {"lookup", codec_lookup, METH_VARARGS,
Walter Dörwald0ae29812002-10-31 13:36:29 +0000868 lookup__doc__},
Brett Cannon3e377de2004-07-10 21:41:14 +0000869 {"encode", codec_encode, METH_VARARGS,
870 encode__doc__},
871 {"decode", codec_decode, METH_VARARGS,
872 decode__doc__},
Martin v. Löwis8a8da792002-08-14 07:46:28 +0000873 {"escape_encode", escape_encode, METH_VARARGS},
874 {"escape_decode", escape_decode, METH_VARARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000875 {"utf_8_encode", utf_8_encode, METH_VARARGS},
876 {"utf_8_decode", utf_8_decode, METH_VARARGS},
877 {"utf_7_encode", utf_7_encode, METH_VARARGS},
878 {"utf_7_decode", utf_7_decode, METH_VARARGS},
879 {"utf_16_encode", utf_16_encode, METH_VARARGS},
880 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS},
881 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS},
882 {"utf_16_decode", utf_16_decode, METH_VARARGS},
883 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS},
884 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS},
885 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
886 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS},
887 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS},
888 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS},
889 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS},
890 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS},
891 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS},
892 {"latin_1_encode", latin_1_encode, METH_VARARGS},
893 {"latin_1_decode", latin_1_decode, METH_VARARGS},
894 {"ascii_encode", ascii_encode, METH_VARARGS},
895 {"ascii_decode", ascii_decode, METH_VARARGS},
896 {"charmap_encode", charmap_encode, METH_VARARGS},
897 {"charmap_decode", charmap_decode, METH_VARARGS},
Thomas Wouters73e5a5b2006-06-08 15:35:45 +0000898 {"charmap_build", charmap_build, METH_VARARGS},
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000899 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
900 {"charbuffer_encode", charbuffer_encode, METH_VARARGS},
Martin v. Löwis6238d2b2002-06-30 15:26:10 +0000901#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
Martin v. Löwis43b936d2002-01-17 23:15:58 +0000902 {"mbcs_encode", mbcs_encode, METH_VARARGS},
903 {"mbcs_decode", mbcs_decode, METH_VARARGS},
Guido van Rossum24bdb042000-03-28 20:29:59 +0000904#endif
Walter Dörwald0ae29812002-10-31 13:36:29 +0000905 {"register_error", register_error, METH_VARARGS,
906 register_error__doc__},
907 {"lookup_error", lookup_error, METH_VARARGS,
908 lookup_error__doc__},
Guido van Rossume2d67f92000-03-10 23:09:23 +0000909 {NULL, NULL} /* sentinel */
910};
911
Mark Hammondfe51c6d2002-08-02 02:27:13 +0000912PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000913init_codecs(void)
Guido van Rossume2d67f92000-03-10 23:09:23 +0000914{
915 Py_InitModule("_codecs", _codecs_functions);
916}