Added information on function name added to LogRecord, and the 'extra' keyword parameter.
[python.git] / Modules / _codecsmodule.c
blob8b225c36a306ee706384749c45abb551d99cdcc4
1 /* ------------------------------------------------------------------------
3 _codecs -- Provides access to the codec registry and the builtin
4 codecs.
6 This module should never be imported directly. The standard library
7 module "codecs" wraps this builtin module for use within Python.
9 The codec registry is accessible via:
11 register(search_function) -> None
13 lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)
15 The builtin Unicode codecs use the following interface:
17 <encoding>_encode(Unicode_object[,errors='strict']) ->
18 (string object, bytes consumed)
20 <encoding>_decode(char_buffer_obj[,errors='strict']) ->
21 (Unicode object, bytes consumed)
23 <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.
27 These <encoding>s are available: utf_8, unicode_escape,
28 raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit),
29 mbcs (on win32).
32 Written by Marc-Andre Lemburg (mal@lemburg.com).
34 Copyright (c) Corporation for National Research Initiatives.
36 ------------------------------------------------------------------------ */
38 #include "Python.h"
40 /* --- Registry ----------------------------------------------------------- */
42 PyDoc_STRVAR(register__doc__,
43 "register(search_function)\n\
44 \n\
45 Register a codec search function. Search functions are expected to take\n\
46 one argument, the encoding name in all lower case letters, and return\n\
47 a tuple of functions (encoder, decoder, stream_reader, stream_writer).");
49 static
50 PyObject *codec_register(PyObject *self, PyObject *args)
52 PyObject *search_function;
54 if (!PyArg_ParseTuple(args, "O:register", &search_function))
55 goto onError;
57 if (PyCodec_Register(search_function))
58 goto onError;
60 Py_INCREF(Py_None);
61 return Py_None;
63 onError:
64 return NULL;
67 PyDoc_STRVAR(lookup__doc__,
68 "lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)\n\
69 \n\
70 Looks up a codec tuple in the Python codec registry and returns\n\
71 a tuple of functions.");
73 static
74 PyObject *codec_lookup(PyObject *self, PyObject *args)
76 char *encoding;
78 if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
79 goto onError;
81 return _PyCodec_Lookup(encoding);
83 onError:
84 return NULL;
87 PyDoc_STRVAR(encode__doc__,
88 "encode(obj, [encoding[,errors]]) -> object\n\
89 \n\
90 Encodes obj using the codec registered for encoding. encoding defaults\n\
91 to the default encoding. errors may be given to set a different error\n\
92 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
93 a ValueError. Other possible values are 'ignore', 'replace' and\n\
94 'xmlcharrefreplace' as well as any other name registered with\n\
95 codecs.register_error that can handle ValueErrors.");
97 static PyObject *
98 codec_encode(PyObject *self, PyObject *args)
100 const char *encoding = NULL;
101 const char *errors = NULL;
102 PyObject *v;
104 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
105 return NULL;
107 #ifdef Py_USING_UNICODE
108 if (encoding == NULL)
109 encoding = PyUnicode_GetDefaultEncoding();
110 #else
111 if (encoding == NULL) {
112 PyErr_SetString(PyExc_ValueError, "no encoding specified");
113 return NULL;
115 #endif
117 /* Encode via the codec registry */
118 v = PyCodec_Encode(v, encoding, errors);
119 if (v == NULL)
120 goto onError;
121 return v;
123 onError:
124 return NULL;
127 PyDoc_STRVAR(decode__doc__,
128 "decode(obj, [encoding[,errors]]) -> object\n\
130 Decodes obj using the codec registered for encoding. encoding defaults\n\
131 to the default encoding. errors may be given to set a different error\n\
132 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
133 a ValueError. Other possible values are 'ignore' and 'replace'\n\
134 as well as any other name registerd with codecs.register_error that is\n\
135 able to handle ValueErrors.");
137 static PyObject *
138 codec_decode(PyObject *self, PyObject *args)
140 const char *encoding = NULL;
141 const char *errors = NULL;
142 PyObject *v;
144 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
145 return NULL;
147 #ifdef Py_USING_UNICODE
148 if (encoding == NULL)
149 encoding = PyUnicode_GetDefaultEncoding();
150 #else
151 if (encoding == NULL) {
152 PyErr_SetString(PyExc_ValueError, "no encoding specified");
153 return NULL;
155 #endif
157 /* Decode via the codec registry */
158 v = PyCodec_Decode(v, encoding, errors);
159 if (v == NULL)
160 goto onError;
161 return v;
163 onError:
164 return NULL;
167 /* --- Helpers ------------------------------------------------------------ */
169 static
170 PyObject *codec_tuple(PyObject *unicode,
171 int len)
173 PyObject *v,*w;
175 if (unicode == NULL)
176 return NULL;
177 v = PyTuple_New(2);
178 if (v == NULL) {
179 Py_DECREF(unicode);
180 return NULL;
182 PyTuple_SET_ITEM(v,0,unicode);
183 w = PyInt_FromLong(len);
184 if (w == NULL) {
185 Py_DECREF(v);
186 return NULL;
188 PyTuple_SET_ITEM(v,1,w);
189 return v;
192 /* --- String codecs ------------------------------------------------------ */
193 static PyObject *
194 escape_decode(PyObject *self,
195 PyObject *args)
197 const char *errors = NULL;
198 const char *data;
199 int size;
201 if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
202 &data, &size, &errors))
203 return NULL;
204 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
205 size);
208 static PyObject *
209 escape_encode(PyObject *self,
210 PyObject *args)
212 PyObject *str;
213 const char *errors = NULL;
214 char *buf;
215 int len;
217 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
218 &PyString_Type, &str, &errors))
219 return NULL;
221 str = PyString_Repr(str, 0);
222 if (!str)
223 return NULL;
225 /* The string will be quoted. Unquote, similar to unicode-escape. */
226 buf = PyString_AS_STRING (str);
227 len = PyString_GET_SIZE (str);
228 memmove(buf, buf+1, len-2);
229 _PyString_Resize(&str, len-2);
231 return codec_tuple(str, PyString_Size(str));
234 #ifdef Py_USING_UNICODE
235 /* --- Decoder ------------------------------------------------------------ */
237 static PyObject *
238 unicode_internal_decode(PyObject *self,
239 PyObject *args)
241 PyObject *obj;
242 const char *errors = NULL;
243 const char *data;
244 int size;
246 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
247 &obj, &errors))
248 return NULL;
250 if (PyUnicode_Check(obj)) {
251 Py_INCREF(obj);
252 return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
254 else {
255 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
256 return NULL;
258 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
259 size);
263 static PyObject *
264 utf_7_decode(PyObject *self,
265 PyObject *args)
267 const char *data;
268 int size;
269 const char *errors = NULL;
271 if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
272 &data, &size, &errors))
273 return NULL;
275 return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
276 size);
279 static PyObject *
280 utf_8_decode(PyObject *self,
281 PyObject *args)
283 const char *data;
284 int size;
285 const char *errors = NULL;
286 int final = 0;
287 int consumed;
288 PyObject *decoded = NULL;
290 if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
291 &data, &size, &errors, &final))
292 return NULL;
293 consumed = size;
295 decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
296 final ? NULL : &consumed);
297 if (decoded == NULL)
298 return NULL;
299 return codec_tuple(decoded, consumed);
302 static PyObject *
303 utf_16_decode(PyObject *self,
304 PyObject *args)
306 const char *data;
307 int size;
308 const char *errors = NULL;
309 int byteorder = 0;
310 int final = 0;
311 int consumed;
312 PyObject *decoded;
314 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
315 &data, &size, &errors, &final))
316 return NULL;
317 consumed = size;
318 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
319 final ? NULL : &consumed);
320 if (decoded == NULL)
321 return NULL;
322 return codec_tuple(decoded, consumed);
325 static PyObject *
326 utf_16_le_decode(PyObject *self,
327 PyObject *args)
329 const char *data;
330 int size;
331 const char *errors = NULL;
332 int byteorder = -1;
333 int final = 0;
334 int consumed;
335 PyObject *decoded = NULL;
337 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
338 &data, &size, &errors, &final))
339 return NULL;
340 consumed = size;
341 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
342 &byteorder, final ? NULL : &consumed);
343 if (decoded == NULL)
344 return NULL;
345 return codec_tuple(decoded, consumed);
349 static PyObject *
350 utf_16_be_decode(PyObject *self,
351 PyObject *args)
353 const char *data;
354 int size;
355 const char *errors = NULL;
356 int byteorder = 1;
357 int final = 0;
358 int consumed;
359 PyObject *decoded = NULL;
361 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
362 &data, &size, &errors, &final))
363 return NULL;
364 consumed = size;
365 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
366 &byteorder, final ? NULL : &consumed);
367 if (decoded == NULL)
368 return NULL;
369 return codec_tuple(decoded, consumed);
372 /* This non-standard version also provides access to the byteorder
373 parameter of the builtin UTF-16 codec.
375 It returns a tuple (unicode, bytesread, byteorder) with byteorder
376 being the value in effect at the end of data.
380 static PyObject *
381 utf_16_ex_decode(PyObject *self,
382 PyObject *args)
384 const char *data;
385 int size;
386 const char *errors = NULL;
387 int byteorder = 0;
388 PyObject *unicode, *tuple;
389 int final = 0;
390 int consumed;
392 if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
393 &data, &size, &errors, &byteorder, &final))
394 return NULL;
396 consumed = size;
397 unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
398 final ? NULL : &consumed);
399 if (unicode == NULL)
400 return NULL;
401 tuple = Py_BuildValue("Oii", unicode, consumed, byteorder);
402 Py_DECREF(unicode);
403 return tuple;
406 static PyObject *
407 unicode_escape_decode(PyObject *self,
408 PyObject *args)
410 const char *data;
411 int size;
412 const char *errors = NULL;
414 if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
415 &data, &size, &errors))
416 return NULL;
418 return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
419 size);
422 static PyObject *
423 raw_unicode_escape_decode(PyObject *self,
424 PyObject *args)
426 const char *data;
427 int size;
428 const char *errors = NULL;
430 if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
431 &data, &size, &errors))
432 return NULL;
434 return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
435 size);
438 static PyObject *
439 latin_1_decode(PyObject *self,
440 PyObject *args)
442 const char *data;
443 int size;
444 const char *errors = NULL;
446 if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
447 &data, &size, &errors))
448 return NULL;
450 return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
451 size);
454 static PyObject *
455 ascii_decode(PyObject *self,
456 PyObject *args)
458 const char *data;
459 int size;
460 const char *errors = NULL;
462 if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
463 &data, &size, &errors))
464 return NULL;
466 return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
467 size);
470 static PyObject *
471 charmap_decode(PyObject *self,
472 PyObject *args)
474 const char *data;
475 int size;
476 const char *errors = NULL;
477 PyObject *mapping = NULL;
479 if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
480 &data, &size, &errors, &mapping))
481 return NULL;
482 if (mapping == Py_None)
483 mapping = NULL;
485 return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
486 size);
489 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
491 static PyObject *
492 mbcs_decode(PyObject *self,
493 PyObject *args)
495 const char *data;
496 int size;
497 const char *errors = NULL;
499 if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
500 &data, &size, &errors))
501 return NULL;
503 return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
504 size);
507 #endif /* MS_WINDOWS */
509 /* --- Encoder ------------------------------------------------------------ */
511 static PyObject *
512 readbuffer_encode(PyObject *self,
513 PyObject *args)
515 const char *data;
516 int size;
517 const char *errors = NULL;
519 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
520 &data, &size, &errors))
521 return NULL;
523 return codec_tuple(PyString_FromStringAndSize(data, size),
524 size);
527 static PyObject *
528 charbuffer_encode(PyObject *self,
529 PyObject *args)
531 const char *data;
532 int size;
533 const char *errors = NULL;
535 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
536 &data, &size, &errors))
537 return NULL;
539 return codec_tuple(PyString_FromStringAndSize(data, size),
540 size);
543 static PyObject *
544 unicode_internal_encode(PyObject *self,
545 PyObject *args)
547 PyObject *obj;
548 const char *errors = NULL;
549 const char *data;
550 int size;
552 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
553 &obj, &errors))
554 return NULL;
556 if (PyUnicode_Check(obj)) {
557 data = PyUnicode_AS_DATA(obj);
558 size = PyUnicode_GET_DATA_SIZE(obj);
559 return codec_tuple(PyString_FromStringAndSize(data, size),
560 size);
562 else {
563 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
564 return NULL;
565 return codec_tuple(PyString_FromStringAndSize(data, size),
566 size);
570 static PyObject *
571 utf_7_encode(PyObject *self,
572 PyObject *args)
574 PyObject *str, *v;
575 const char *errors = NULL;
577 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
578 &str, &errors))
579 return NULL;
581 str = PyUnicode_FromObject(str);
582 if (str == NULL)
583 return NULL;
584 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
585 PyUnicode_GET_SIZE(str),
588 errors),
589 PyUnicode_GET_SIZE(str));
590 Py_DECREF(str);
591 return v;
594 static PyObject *
595 utf_8_encode(PyObject *self,
596 PyObject *args)
598 PyObject *str, *v;
599 const char *errors = NULL;
601 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
602 &str, &errors))
603 return NULL;
605 str = PyUnicode_FromObject(str);
606 if (str == NULL)
607 return NULL;
608 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
609 PyUnicode_GET_SIZE(str),
610 errors),
611 PyUnicode_GET_SIZE(str));
612 Py_DECREF(str);
613 return v;
616 /* This version provides access to the byteorder parameter of the
617 builtin UTF-16 codecs as optional third argument. It defaults to 0
618 which means: use the native byte order and prepend the data with a
619 BOM mark.
623 static PyObject *
624 utf_16_encode(PyObject *self,
625 PyObject *args)
627 PyObject *str, *v;
628 const char *errors = NULL;
629 int byteorder = 0;
631 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
632 &str, &errors, &byteorder))
633 return NULL;
635 str = PyUnicode_FromObject(str);
636 if (str == NULL)
637 return NULL;
638 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
639 PyUnicode_GET_SIZE(str),
640 errors,
641 byteorder),
642 PyUnicode_GET_SIZE(str));
643 Py_DECREF(str);
644 return v;
647 static PyObject *
648 utf_16_le_encode(PyObject *self,
649 PyObject *args)
651 PyObject *str, *v;
652 const char *errors = NULL;
654 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
655 &str, &errors))
656 return NULL;
658 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;
670 static PyObject *
671 utf_16_be_encode(PyObject *self,
672 PyObject *args)
674 PyObject *str, *v;
675 const char *errors = NULL;
677 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
678 &str, &errors))
679 return NULL;
681 str = PyUnicode_FromObject(str);
682 if (str == NULL)
683 return NULL;
684 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
685 PyUnicode_GET_SIZE(str),
686 errors,
687 +1),
688 PyUnicode_GET_SIZE(str));
689 Py_DECREF(str);
690 return v;
693 static PyObject *
694 unicode_escape_encode(PyObject *self,
695 PyObject *args)
697 PyObject *str, *v;
698 const char *errors = NULL;
700 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
701 &str, &errors))
702 return NULL;
704 str = PyUnicode_FromObject(str);
705 if (str == NULL)
706 return NULL;
707 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
708 PyUnicode_GET_SIZE(str)),
709 PyUnicode_GET_SIZE(str));
710 Py_DECREF(str);
711 return v;
714 static PyObject *
715 raw_unicode_escape_encode(PyObject *self,
716 PyObject *args)
718 PyObject *str, *v;
719 const char *errors = NULL;
721 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
722 &str, &errors))
723 return NULL;
725 str = PyUnicode_FromObject(str);
726 if (str == NULL)
727 return NULL;
728 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
729 PyUnicode_AS_UNICODE(str),
730 PyUnicode_GET_SIZE(str)),
731 PyUnicode_GET_SIZE(str));
732 Py_DECREF(str);
733 return v;
736 static PyObject *
737 latin_1_encode(PyObject *self,
738 PyObject *args)
740 PyObject *str, *v;
741 const char *errors = NULL;
743 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
744 &str, &errors))
745 return NULL;
747 str = PyUnicode_FromObject(str);
748 if (str == NULL)
749 return NULL;
750 v = codec_tuple(PyUnicode_EncodeLatin1(
751 PyUnicode_AS_UNICODE(str),
752 PyUnicode_GET_SIZE(str),
753 errors),
754 PyUnicode_GET_SIZE(str));
755 Py_DECREF(str);
756 return v;
759 static PyObject *
760 ascii_encode(PyObject *self,
761 PyObject *args)
763 PyObject *str, *v;
764 const char *errors = NULL;
766 if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
767 &str, &errors))
768 return NULL;
770 str = PyUnicode_FromObject(str);
771 if (str == NULL)
772 return NULL;
773 v = codec_tuple(PyUnicode_EncodeASCII(
774 PyUnicode_AS_UNICODE(str),
775 PyUnicode_GET_SIZE(str),
776 errors),
777 PyUnicode_GET_SIZE(str));
778 Py_DECREF(str);
779 return v;
782 static PyObject *
783 charmap_encode(PyObject *self,
784 PyObject *args)
786 PyObject *str, *v;
787 const char *errors = NULL;
788 PyObject *mapping = NULL;
790 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
791 &str, &errors, &mapping))
792 return NULL;
793 if (mapping == Py_None)
794 mapping = NULL;
796 str = PyUnicode_FromObject(str);
797 if (str == NULL)
798 return NULL;
799 v = codec_tuple(PyUnicode_EncodeCharmap(
800 PyUnicode_AS_UNICODE(str),
801 PyUnicode_GET_SIZE(str),
802 mapping,
803 errors),
804 PyUnicode_GET_SIZE(str));
805 Py_DECREF(str);
806 return v;
809 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
811 static PyObject *
812 mbcs_encode(PyObject *self,
813 PyObject *args)
815 PyObject *str, *v;
816 const char *errors = NULL;
818 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
819 &str, &errors))
820 return NULL;
822 str = PyUnicode_FromObject(str);
823 if (str == NULL)
824 return NULL;
825 v = codec_tuple(PyUnicode_EncodeMBCS(
826 PyUnicode_AS_UNICODE(str),
827 PyUnicode_GET_SIZE(str),
828 errors),
829 PyUnicode_GET_SIZE(str));
830 Py_DECREF(str);
831 return v;
834 #endif /* MS_WINDOWS */
835 #endif /* Py_USING_UNICODE */
837 /* --- Error handler registry --------------------------------------------- */
839 PyDoc_STRVAR(register_error__doc__,
840 "register_error(errors, handler)\n\
842 Register the specified error handler under the name\n\
843 errors. handler must be a callable object, that\n\
844 will be called with an exception instance containing\n\
845 information about the location of the encoding/decoding\n\
846 error and must return a (replacement, new position) tuple.");
848 static PyObject *register_error(PyObject *self, PyObject *args)
850 const char *name;
851 PyObject *handler;
853 if (!PyArg_ParseTuple(args, "sO:register_error",
854 &name, &handler))
855 return NULL;
856 if (PyCodec_RegisterError(name, handler))
857 return NULL;
858 Py_INCREF(Py_None);
859 return Py_None;
862 PyDoc_STRVAR(lookup_error__doc__,
863 "lookup_error(errors) -> handler\n\
865 Return the error handler for the specified error handling name\n\
866 or raise a LookupError, if no handler exists under this name.");
868 static PyObject *lookup_error(PyObject *self, PyObject *args)
870 const char *name;
872 if (!PyArg_ParseTuple(args, "s:lookup_error",
873 &name))
874 return NULL;
875 return PyCodec_LookupError(name);
878 /* --- Module API --------------------------------------------------------- */
880 static PyMethodDef _codecs_functions[] = {
881 {"register", codec_register, METH_VARARGS,
882 register__doc__},
883 {"lookup", codec_lookup, METH_VARARGS,
884 lookup__doc__},
885 {"encode", codec_encode, METH_VARARGS,
886 encode__doc__},
887 {"decode", codec_decode, METH_VARARGS,
888 decode__doc__},
889 {"escape_encode", escape_encode, METH_VARARGS},
890 {"escape_decode", escape_decode, METH_VARARGS},
891 #ifdef Py_USING_UNICODE
892 {"utf_8_encode", utf_8_encode, METH_VARARGS},
893 {"utf_8_decode", utf_8_decode, METH_VARARGS},
894 {"utf_7_encode", utf_7_encode, METH_VARARGS},
895 {"utf_7_decode", utf_7_decode, METH_VARARGS},
896 {"utf_16_encode", utf_16_encode, METH_VARARGS},
897 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS},
898 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS},
899 {"utf_16_decode", utf_16_decode, METH_VARARGS},
900 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS},
901 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS},
902 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
903 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS},
904 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS},
905 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS},
906 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS},
907 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS},
908 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS},
909 {"latin_1_encode", latin_1_encode, METH_VARARGS},
910 {"latin_1_decode", latin_1_decode, METH_VARARGS},
911 {"ascii_encode", ascii_encode, METH_VARARGS},
912 {"ascii_decode", ascii_decode, METH_VARARGS},
913 {"charmap_encode", charmap_encode, METH_VARARGS},
914 {"charmap_decode", charmap_decode, METH_VARARGS},
915 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
916 {"charbuffer_encode", charbuffer_encode, METH_VARARGS},
917 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
918 {"mbcs_encode", mbcs_encode, METH_VARARGS},
919 {"mbcs_decode", mbcs_decode, METH_VARARGS},
920 #endif
921 #endif /* Py_USING_UNICODE */
922 {"register_error", register_error, METH_VARARGS,
923 register_error__doc__},
924 {"lookup_error", lookup_error, METH_VARARGS,
925 lookup_error__doc__},
926 {NULL, NULL} /* sentinel */
929 PyMODINIT_FUNC
930 init_codecs(void)
932 Py_InitModule("_codecs", _codecs_functions);