annotate Modules/_codecsmodule.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents b36cb4602e21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* ------------------------------------------------------------------------
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 _codecs -- Provides access to the codec registry and the builtin
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 codecs.
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 This module should never be imported directly. The standard library
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 module "codecs" wraps this builtin module for use within Python.
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 The codec registry is accessible via:
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 register(search_function) -> None
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
42317
c02a33788a8f Document that codecs.lookup() returns a CodecInfo object.
Walter Dörwald <walter@livinglogic.de>
parents: 39445
diff changeset
13 lookup(encoding) -> CodecInfo object
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 The builtin Unicode codecs use the following interface:
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
17 <encoding>_encode(Unicode_object[,errors='strict']) ->
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
18 (string object, bytes consumed)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
20 <encoding>_decode(char_buffer_obj[,errors='strict']) ->
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 (Unicode object, bytes consumed)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
23 <encoding>_encode() interfaces also accept non-Unicode object as
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
24 input. The objects are then converted to Unicode using
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
25 PyUnicode_FromObject() prior to applying the conversion.
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
26
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 These <encoding>s are available: utf_8, unicode_escape,
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
28 raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit),
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
29 mbcs (on win32).
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
30
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 Written by Marc-Andre Lemburg (mal@lemburg.com).
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
13828
254f8b7c4a83 Changing the CNRI copyright notice according to CNRI's instructions.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
34 Copyright (c) Corporation for National Research Initiatives.
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 ------------------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
38 #define PY_SSIZE_T_CLEAN
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include "Python.h"
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 /* --- Registry ----------------------------------------------------------- */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
43 PyDoc_STRVAR(register__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
44 "register(search_function)\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
45 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
46 Register a codec search function. Search functions are expected to take\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
47 one argument, the encoding name in all lower case letters, and return\n\
42317
c02a33788a8f Document that codecs.lookup() returns a CodecInfo object.
Walter Dörwald <walter@livinglogic.de>
parents: 39445
diff changeset
48 a tuple of functions (encoder, decoder, stream_reader, stream_writer)\n\
c02a33788a8f Document that codecs.lookup() returns a CodecInfo object.
Walter Dörwald <walter@livinglogic.de>
parents: 39445
diff changeset
49 (or a CodecInfo object).");
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
50
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 static
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
52 PyObject *codec_register(PyObject *self, PyObject *search_function)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 if (PyCodec_Register(search_function))
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
55 return NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
56
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
57 Py_RETURN_NONE;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
60 PyDoc_STRVAR(lookup__doc__,
42317
c02a33788a8f Document that codecs.lookup() returns a CodecInfo object.
Walter Dörwald <walter@livinglogic.de>
parents: 39445
diff changeset
61 "lookup(encoding) -> CodecInfo\n\
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
62 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
63 Looks up a codec tuple in the Python codec registry and returns\n\
52909
f3b26a729e82 Merged revisions 69578-69580,69901,69907,69994,70022-70023,70025-70026,70166,70273,70275,70342,70386-70387,70389-70390,70392-70393,70395,70397,70400,70418 via svnmerge
Georg Brandl <georg@python.org>
parents: 49431
diff changeset
64 a CodecInfo object.");
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
65
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 static
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
67 PyObject *codec_lookup(PyObject *self, PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 char *encoding;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
72 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return _PyCodec_Lookup(encoding);
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
77 PyDoc_STRVAR(encode__doc__,
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
78 "encode(obj, [encoding[,errors]]) -> object\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
79 \n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
80 Encodes obj using the codec registered for encoding. encoding defaults\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
81 to the default encoding. errors may be given to set a different error\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
82 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
83 a ValueError. Other possible values are 'ignore', 'replace' and\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
84 'xmlcharrefreplace' as well as any other name registered with\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
85 codecs.register_error that can handle ValueErrors.");
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
86
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
87 static PyObject *
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
88 codec_encode(PyObject *self, PyObject *args)
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
89 {
32602
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
90 const char *encoding = NULL;
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
91 const char *errors = NULL;
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
92 PyObject *v;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
93
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
94 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
95 return NULL;
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
96
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
97 #ifdef Py_USING_UNICODE
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
98 if (encoding == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
99 encoding = PyUnicode_GetDefaultEncoding();
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
100 #else
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
101 if (encoding == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
102 PyErr_SetString(PyExc_ValueError, "no encoding specified");
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
103 return NULL;
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
104 }
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
105 #endif
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
106
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
107 /* Encode via the codec registry */
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
108 return PyCodec_Encode(v, encoding, errors);
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
109 }
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
110
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
111 PyDoc_STRVAR(decode__doc__,
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
112 "decode(obj, [encoding[,errors]]) -> object\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
113 \n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
114 Decodes obj using the codec registered for encoding. encoding defaults\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
115 to the default encoding. errors may be given to set a different error\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
116 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
117 a ValueError. Other possible values are 'ignore' and 'replace'\n\
49431
2e794757bdc8 Merged revisions 66766-66767,66771-66772,66774,66776,66783-66787,66790,66793,66797 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48221
diff changeset
118 as well as any other name registered with codecs.register_error that is\n\
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
119 able to handle ValueErrors.");
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
120
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
121 static PyObject *
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
122 codec_decode(PyObject *self, PyObject *args)
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
123 {
32602
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
124 const char *encoding = NULL;
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
125 const char *errors = NULL;
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
126 PyObject *v;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
127
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
128 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
129 return NULL;
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
130
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
131 #ifdef Py_USING_UNICODE
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
132 if (encoding == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
133 encoding = PyUnicode_GetDefaultEncoding();
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
134 #else
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
135 if (encoding == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
136 PyErr_SetString(PyExc_ValueError, "no encoding specified");
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
137 return NULL;
34707
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
138 }
0d44d9071e97 Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents: 33428
diff changeset
139 #endif
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
140
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
141 /* Decode via the codec registry */
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
142 return PyCodec_Decode(v, encoding, errors);
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
143 }
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
144
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 /* --- Helpers ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 static
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 PyObject *codec_tuple(PyObject *unicode,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
149 Py_ssize_t len)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 {
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
151 PyObject *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 if (unicode == NULL)
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
153 return NULL;
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
154 v = Py_BuildValue("On", unicode, len);
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
155 Py_DECREF(unicode);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 return v;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
158
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
159 /* --- String codecs ------------------------------------------------------ */
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
160 static PyObject *
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
161 escape_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
162 PyObject *args)
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
163 {
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
164 const char *errors = NULL;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
165 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
166 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
167
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
168 if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
169 &data, &size, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
170 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
171 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
172 size);
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
173 }
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
174
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
175 static PyObject *
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
176 escape_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
177 PyObject *args)
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
178 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
179 PyObject *str;
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
180 const char *errors = NULL;
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
181 char *buf;
62214
a2ea1a23186b Merged revisions 79779 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents: 62209
diff changeset
182 Py_ssize_t consumed, len;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
183
62214
a2ea1a23186b Merged revisions 79779 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents: 62209
diff changeset
184 if (!PyArg_ParseTuple(args, "S|z:escape_encode",
a2ea1a23186b Merged revisions 79779 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents: 62209
diff changeset
185 &str, &errors))
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
186 return NULL;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
187
62214
a2ea1a23186b Merged revisions 79779 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents: 62209
diff changeset
188 consumed = PyString_GET_SIZE(str);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
189 str = PyString_Repr(str, 0);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
190 if (!str)
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
191 return NULL;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
192
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
193 /* The string will be quoted. Unquote, similar to unicode-escape. */
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
194 buf = PyString_AS_STRING (str);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
195 len = PyString_GET_SIZE (str);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
196 memmove(buf, buf+1, len-2);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
197 if (_PyString_Resize(&str, len-2) < 0)
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
198 return NULL;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
199
62214
a2ea1a23186b Merged revisions 79779 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents: 62209
diff changeset
200 return codec_tuple(str, consumed);
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
201 }
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
202
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
203 #ifdef Py_USING_UNICODE
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 /* --- Decoder ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 unicode_internal_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
208 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 {
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
210 PyObject *obj;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
211 const char *errors = NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
213 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
214
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
215 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
216 &obj, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
217 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
27680
b19aaaeb6d64 Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents: 25974
diff changeset
219 if (PyUnicode_Check(obj)) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
220 Py_INCREF(obj);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
221 return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
27680
b19aaaeb6d64 Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents: 25974
diff changeset
222 }
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
223 else {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
224 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
225 return NULL;
35485
6b8c55877755 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 34707
diff changeset
226
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
227 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
228 size);
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
229 }
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 static PyObject *
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
233 utf_7_decode(PyObject *self,
43932
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
234 PyObject *args)
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
235 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
236 Py_buffer pbuf;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
237 const char *errors = NULL;
43932
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
238 int final = 0;
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
239 Py_ssize_t consumed;
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
240 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
241
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
242 if (!PyArg_ParseTuple(args, "s*|zi:utf_7_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
243 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
244 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
245 consumed = pbuf.len;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
246
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
247 decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
248 final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
249 PyBuffer_Release(&pbuf);
43932
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
250 if (decoded == NULL)
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
251 return NULL;
e8ac1ae4503c The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 42649
diff changeset
252 return codec_tuple(decoded, consumed);
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
253 }
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
254
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
255 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 utf_8_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
257 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
259 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 const char *errors = NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
261 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
262 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
263 PyObject *decoded = NULL;
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
264
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
265 if (!PyArg_ParseTuple(args, "s*|zi:utf_8_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
266 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
267 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
268 consumed = pbuf.len;
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
269
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
270 decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
271 final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
272 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
273 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
274 return NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
275 return codec_tuple(decoded, consumed);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
277
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 utf_16_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
280 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
282 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 int byteorder = 0;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
285 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
286 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
287 PyObject *decoded;
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
288
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
289 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
290 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
291 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
292 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
293 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
294 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
295 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
296 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
297 return NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
298 return codec_tuple(decoded, consumed);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 utf_16_le_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
303 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
305 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 int byteorder = -1;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
308 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
309 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
310 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
311
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
312 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_le_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
313 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
314 return NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
315
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
316 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
317 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
318 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
319 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
320 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
321 return NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
322 return codec_tuple(decoded, consumed);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 utf_16_be_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
327 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
329 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 int byteorder = 1;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
332 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
333 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
334 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
335
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
336 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_be_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
337 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
338 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
339
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
340 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
341 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
342 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
343 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
344 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
345 return NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
346 return codec_tuple(decoded, consumed);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
348
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 /* This non-standard version also provides access to the byteorder
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 parameter of the builtin UTF-16 codec.
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
351
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 It returns a tuple (unicode, bytesread, byteorder) with byteorder
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 being the value in effect at the end of data.
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
354
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
356
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 utf_16_ex_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
359 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
361 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 int byteorder = 0;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 PyObject *unicode, *tuple;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
365 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
366 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
367
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
368 if (!PyArg_ParseTuple(args, "s*|zii:utf_16_ex_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
369 &pbuf, &errors, &byteorder, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
370 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
371 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
372 unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
373 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
374 PyBuffer_Release(&pbuf);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 if (unicode == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
376 return NULL;
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
377 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 Py_DECREF(unicode);
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 return tuple;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
381
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 static PyObject *
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
383 utf_32_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
384 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
385 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
386 Py_buffer pbuf;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
387 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
388 int byteorder = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
389 int final = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
390 Py_ssize_t consumed;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
391 PyObject *decoded;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
392
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
393 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
394 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
395 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
396 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
397 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
398 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
399 PyBuffer_Release(&pbuf);
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
400 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
401 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
402 return codec_tuple(decoded, consumed);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
403 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
404
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
405 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
406 utf_32_le_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
407 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
408 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
409 Py_buffer pbuf;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
410 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
411 int byteorder = -1;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
412 int final = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
413 Py_ssize_t consumed;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
414 PyObject *decoded;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
415
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
416 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_le_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
417 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
418 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
419 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
420 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
421 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
422 PyBuffer_Release(&pbuf);
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
423 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
424 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
425 return codec_tuple(decoded, consumed);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
426 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
427
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
428 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
429 utf_32_be_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
430 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
431 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
432 Py_buffer pbuf;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
433 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
434 int byteorder = 1;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
435 int final = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
436 Py_ssize_t consumed;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
437 PyObject *decoded;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
438
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
439 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_be_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
440 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
441 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
442 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
443 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
444 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
445 PyBuffer_Release(&pbuf);
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
446 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
447 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
448 return codec_tuple(decoded, consumed);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
449 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
450
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
451 /* This non-standard version also provides access to the byteorder
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
452 parameter of the builtin UTF-32 codec.
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
453
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
454 It returns a tuple (unicode, bytesread, byteorder) with byteorder
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
455 being the value in effect at the end of data.
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
456
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
457 */
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
458
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
459 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
460 utf_32_ex_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
461 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
462 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
463 Py_buffer pbuf;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
464 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
465 int byteorder = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
466 PyObject *unicode, *tuple;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
467 int final = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
468 Py_ssize_t consumed;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
469
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
470 if (!PyArg_ParseTuple(args, "s*|zii:utf_32_ex_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
471 &pbuf, &errors, &byteorder, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
472 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
473 consumed = pbuf.len; /* This is overwritten unless final is true. */
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
474 unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
475 &byteorder, final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
476 PyBuffer_Release(&pbuf);
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
477 if (unicode == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
478 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
479 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
480 Py_DECREF(unicode);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
481 return tuple;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
482 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
483
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
484 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 unicode_escape_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
486 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
487 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
488 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 const char *errors = NULL;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
490 PyObject *unicode;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
491
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
492 if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
493 &pbuf, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
494 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
495
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
496 unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
497 PyBuffer_Release(&pbuf);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
498 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
500
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 raw_unicode_escape_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
503 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
505 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 const char *errors = NULL;
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
507 PyObject *unicode;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
508
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
509 if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
510 &pbuf, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
511 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
512
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
513 unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
514 PyBuffer_Release(&pbuf);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
515 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
517
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
518 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 latin_1_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
520 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
522 Py_buffer pbuf;
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
523 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 const char *errors = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
525
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
526 if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
527 &pbuf, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
528 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
529
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
530 unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
531 PyBuffer_Release(&pbuf);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
532 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
533 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
534
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 ascii_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
537 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
539 Py_buffer pbuf;
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
540 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
541 const char *errors = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
542
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
543 if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
544 &pbuf, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
545 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
546
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
547 unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
548 PyBuffer_Release(&pbuf);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
549 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
551
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
552 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
553 charmap_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
554 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
556 Py_buffer pbuf;
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
557 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 PyObject *mapping = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
560
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
561 if (!PyArg_ParseTuple(args, "s*|zO:charmap_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
562 &pbuf, &errors, &mapping))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
563 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 if (mapping == Py_None)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
565 mapping = NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
566
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
567 unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
568 PyBuffer_Release(&pbuf);
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
569 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
571
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
572 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
573
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
574 static PyObject *
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
575 mbcs_decode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
576 PyObject *args)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
577 {
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
578 Py_buffer pbuf;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
579 const char *errors = NULL;
39359
82f56207652f Correction of patch #1455898: In the mbcs decoder, set final=False
Martin v. Löwis <martin@v.loewis.de>
parents: 38817
diff changeset
580 int final = 0;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
581 Py_ssize_t consumed;
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
582 PyObject *decoded = NULL;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
583
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
584 if (!PyArg_ParseTuple(args, "s*|zi:mbcs_decode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
585 &pbuf, &errors, &final))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
586 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
587 consumed = pbuf.len;
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
588
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
589 decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
590 final ? NULL : &consumed);
62209
c1145e668d72 Merged revisions 81860 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61465
diff changeset
591 PyBuffer_Release(&pbuf);
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
592 if (decoded == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
593 return NULL;
48221
b8c4bf393794 Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
Martin v. Löwis <martin@v.loewis.de>
parents: 47527
diff changeset
594 return codec_tuple(decoded, consumed);
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
595 }
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
596
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
597 #endif /* MS_WINDOWS */
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
598
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 /* --- Encoder ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
600
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 readbuffer_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
603 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
606 Py_ssize_t size;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
610 &data, &size, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
611 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
612
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
613 return codec_tuple(PyString_FromStringAndSize(data, size),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
614 size);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
615 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
616
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 charbuffer_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
619 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
622 Py_ssize_t size;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
624
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
626 &data, &size, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
627 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
628
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
629 return codec_tuple(PyString_FromStringAndSize(data, size),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
630 size);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
632
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 static PyObject *
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
634 unicode_internal_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
635 PyObject *args)
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
636 {
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
637 PyObject *obj;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
638 const char *errors = NULL;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
639 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
640 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
641
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
642 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
643 &obj, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
644 return NULL;
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
645
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
646 if (PyUnicode_Check(obj)) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
647 data = PyUnicode_AS_DATA(obj);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
648 size = PyUnicode_GET_DATA_SIZE(obj);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
649 return codec_tuple(PyString_FromStringAndSize(data, size),
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60339
diff changeset
650 PyUnicode_GET_SIZE(obj));
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
651 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
652 else {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
653 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
654 return NULL;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
655 return codec_tuple(PyString_FromStringAndSize(data, size),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
656 size);
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
657 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
658 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
659
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
660 static PyObject *
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
661 utf_7_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
662 PyObject *args)
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
663 {
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
664 PyObject *str, *v;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
665 const char *errors = NULL;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
666
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
667 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
668 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
669 return NULL;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
670
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
671 str = PyUnicode_FromObject(str);
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
672 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
673 return NULL;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
674 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
675 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
676 0,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
677 0,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
678 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
679 PyUnicode_GET_SIZE(str));
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
680 Py_DECREF(str);
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
681 return v;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
682 }
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
683
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
684 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
685 utf_8_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
686 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
688 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
689 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
690
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
691 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
692 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
693 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
694
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
695 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
696 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
697 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
698 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
699 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
700 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
701 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
702 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
703 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
705
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 /* This version provides access to the byteorder parameter of the
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 builtin UTF-16 codecs as optional third argument. It defaults to 0
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 which means: use the native byte order and prepend the data with a
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
709 BOM mark.
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
710
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
711 */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
712
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 utf_16_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
715 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
717 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
718 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
719 int byteorder = 0;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
720
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
721 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
722 &str, &errors, &byteorder))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
723 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
724
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
725 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
726 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
727 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
728 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
729 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
730 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
731 byteorder),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
732 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
733 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
734 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
736
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 utf_16_le_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
739 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
741 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
742 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
743
18139
354a4df09e38 Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents: 14733
diff changeset
744 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
745 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
746 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
747
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
748 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
749 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
750 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
751 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
752 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
753 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
754 -1),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
755 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
756 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
757 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
759
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
761 utf_16_be_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
762 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
763 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
764 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
766
18139
354a4df09e38 Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents: 14733
diff changeset
767 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
768 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
769 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
770
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
771 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
772 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
773 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
774 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
775 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
776 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
777 +1),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
778 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
779 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
780 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
781 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
782
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
783 /* This version provides access to the byteorder parameter of the
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
784 builtin UTF-32 codecs as optional third argument. It defaults to 0
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
785 which means: use the native byte order and prepend the data with a
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
786 BOM mark.
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
787
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
788 */
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
789
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
790 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
791 utf_32_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
792 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
793 {
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
794 PyObject *str, *v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
795 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
796 int byteorder = 0;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
797
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
798 if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
799 &str, &errors, &byteorder))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
800 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
801
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
802 str = PyUnicode_FromObject(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
803 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
804 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
805 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
806 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
807 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
808 byteorder),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
809 PyUnicode_GET_SIZE(str));
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
810 Py_DECREF(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
811 return v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
812 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
813
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
814 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
815 utf_32_le_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
816 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
817 {
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
818 PyObject *str, *v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
819 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
820
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
821 if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
822 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
823 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
824
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
825 str = PyUnicode_FromObject(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
826 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
827 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
828 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
829 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
830 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
831 -1),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
832 PyUnicode_GET_SIZE(str));
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
833 Py_DECREF(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
834 return v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
835 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
836
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
837 static PyObject *
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
838 utf_32_be_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
839 PyObject *args)
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
840 {
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
841 PyObject *str, *v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
842 const char *errors = NULL;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
843
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
844 if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
845 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
846 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
847
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
848 str = PyUnicode_FromObject(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
849 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
850 return NULL;
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
851 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
852 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
853 errors,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
854 +1),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
855 PyUnicode_GET_SIZE(str));
42649
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
856 Py_DECREF(str);
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
857 return v;
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
858 }
c916731321c0 Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents: 42317
diff changeset
859
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
860 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
861 unicode_escape_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
862 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
863 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
864 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
865 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
866
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
867 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
868 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
869 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
870
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
871 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
872 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
873 return NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
874 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
875 PyUnicode_GET_SIZE(str)),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
876 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
877 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
878 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
879 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
880
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
881 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
882 raw_unicode_escape_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
883 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
884 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
885 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
886 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
887
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
888 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
889 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
890 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
891
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
892 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
893 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
894 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
895 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
896 PyUnicode_AS_UNICODE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
897 PyUnicode_GET_SIZE(str)),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
898 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
899 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
900 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
901 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
902
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
904 latin_1_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
905 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
907 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
909
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
910 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
911 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
912 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
913
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
914 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
915 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
916 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
917 v = codec_tuple(PyUnicode_EncodeLatin1(
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
918 PyUnicode_AS_UNICODE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
919 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
920 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
921 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
922 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
923 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
924 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
925
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
926 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
927 ascii_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
928 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
929 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
930 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
931 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
932
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
933 if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
934 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
935 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
936
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
937 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
938 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
939 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
940 v = codec_tuple(PyUnicode_EncodeASCII(
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
941 PyUnicode_AS_UNICODE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
942 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
943 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
944 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
945 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
946 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
947 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
948
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
949 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
950 charmap_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
951 PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
952 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
953 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
954 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
955 PyObject *mapping = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
956
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
957 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
958 &str, &errors, &mapping))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
959 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
960 if (mapping == Py_None)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
961 mapping = NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
962
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
963 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
964 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
965 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
966 v = codec_tuple(PyUnicode_EncodeCharmap(
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
967 PyUnicode_AS_UNICODE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
968 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
969 mapping,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
970 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
971 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
972 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
973 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
974 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
975
38586
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
976 static PyObject*
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
977 charmap_build(PyObject *self, PyObject *args)
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
978 {
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
979 PyObject *map;
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
980 if (!PyArg_ParseTuple(args, "U:charmap_build", &map))
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
981 return NULL;
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
982 return PyUnicode_BuildEncodingMap(map);
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
983 }
9e0b050ce46f Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
984
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
985 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
986
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
987 static PyObject *
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
988 mbcs_encode(PyObject *self,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
989 PyObject *args)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
990 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
991 PyObject *str, *v;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
992 const char *errors = NULL;
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
993
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
994 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
995 &str, &errors))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
996 return NULL;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
997
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
998 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
999 if (str == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1000 return NULL;
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1001 v = codec_tuple(PyUnicode_EncodeMBCS(
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1002 PyUnicode_AS_UNICODE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1003 PyUnicode_GET_SIZE(str),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1004 errors),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1005 PyUnicode_GET_SIZE(str));
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1006 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1007 return v;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1008 }
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1009
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
1010 #endif /* MS_WINDOWS */
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18278
diff changeset
1011 #endif /* Py_USING_UNICODE */
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1012
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1013 /* --- Error handler registry --------------------------------------------- */
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1014
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1015 PyDoc_STRVAR(register_error__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1016 "register_error(errors, handler)\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1017 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1018 Register the specified error handler under the name\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1019 errors. handler must be a callable object, that\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1020 will be called with an exception instance containing\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1021 information about the location of the encoding/decoding\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1022 error and must return a (replacement, new position) tuple.");
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1023
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1024 static PyObject *register_error(PyObject *self, PyObject *args)
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1025 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1026 const char *name;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1027 PyObject *handler;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1028
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1029 if (!PyArg_ParseTuple(args, "sO:register_error",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1030 &name, &handler))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1031 return NULL;
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1032 if (PyCodec_RegisterError(name, handler))
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1033 return NULL;
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38423
diff changeset
1034 Py_RETURN_NONE;
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1035 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1036
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1037 PyDoc_STRVAR(lookup_error__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1038 "lookup_error(errors) -> handler\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1039 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1040 Return the error handler for the specified error handling name\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1041 or raise a LookupError, if no handler exists under this name.");
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1042
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1043 static PyObject *lookup_error(PyObject *self, PyObject *args)
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1044 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1045 const char *name;
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1046
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1047 if (!PyArg_ParseTuple(args, "s:lookup_error",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1048 &name))
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1049 return NULL;
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1050 return PyCodec_LookupError(name);
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1051 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1052
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1053 /* --- Module API --------------------------------------------------------- */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1054
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1055 static PyMethodDef _codecs_functions[] = {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1056 {"register", codec_register, METH_O,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1057 register__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1058 {"lookup", codec_lookup, METH_VARARGS,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1059 lookup__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1060 {"encode", codec_encode, METH_VARARGS,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1061 encode__doc__},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1062 {"decode", codec_decode, METH_VARARGS,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1063 decode__doc__},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1064 {"escape_encode", escape_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1065 {"escape_decode", escape_decode, METH_VARARGS},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18278
diff changeset
1066 #ifdef Py_USING_UNICODE
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1067 {"utf_8_encode", utf_8_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1068 {"utf_8_decode", utf_8_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1069 {"utf_7_encode", utf_7_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1070 {"utf_7_decode", utf_7_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1071 {"utf_16_encode", utf_16_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1072 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1073 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1074 {"utf_16_decode", utf_16_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1075 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1076 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1077 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1078 {"utf_32_encode", utf_32_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1079 {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1080 {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1081 {"utf_32_decode", utf_32_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1082 {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1083 {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1084 {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1085 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1086 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1087 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1088 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1089 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1090 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1091 {"latin_1_encode", latin_1_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1092 {"latin_1_decode", latin_1_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1093 {"ascii_encode", ascii_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1094 {"ascii_decode", ascii_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1095 {"charmap_encode", charmap_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1096 {"charmap_decode", charmap_decode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1097 {"charmap_build", charmap_build, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1098 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1099 {"charbuffer_encode", charbuffer_encode, METH_VARARGS},
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
1100 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1101 {"mbcs_encode", mbcs_encode, METH_VARARGS},
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1102 {"mbcs_decode", mbcs_decode, METH_VARARGS},
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1103 #endif
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18278
diff changeset
1104 #endif /* Py_USING_UNICODE */
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1105 {"register_error", register_error, METH_VARARGS,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1106 register_error__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1107 {"lookup_error", lookup_error, METH_VARARGS,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1108 lookup_error__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 52909
diff changeset
1109 {NULL, NULL} /* sentinel */
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1110 };
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1111
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24071
diff changeset
1112 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13358
diff changeset
1113 init_codecs(void)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1114 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1115 Py_InitModule("_codecs", _codecs_functions);
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1116 }