Mercurial > cpython-lru_cache-weakref
annotate Modules/_codecsmodule.c @ 44825:ef859cd754a7 legacy-trunk
Fixed a wrong assumption in configure.in and Include/pyport.h. The is finite function is not called isfinite() but finite(). Sorry, my fault. :)
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Sun, 20 Jan 2008 14:28:28 +0000 |
| parents | e8ac1ae4503c |
| children | 4fe192d48960 |
| 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']) -> |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 (string object, bytes consumed) |
|
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\ |
|
42317
c02a33788a8f
Document that codecs.lookup() returns a CodecInfo object.
Walter Dörwald <walter@livinglogic.de>
parents:
39445
diff
changeset
|
64 a tuple of function (or 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) |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
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) { |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
102 PyErr_SetString(PyExc_ValueError, "no encoding specified"); |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
103 return NULL; |
|
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\ |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
118 as well as any other name registerd with codecs.register_error that is\n\ |
|
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) |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
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) { |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
136 PyErr_SetString(PyExc_ValueError, "no encoding specified"); |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
137 return NULL; |
|
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, |
|
37920
ce5585afc20f
Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
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, |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
162 PyObject *args) |
|
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", |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
169 &data, &size, &errors)) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
170 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
171 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL), |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
172 size); |
|
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, |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
177 PyObject *args) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
178 { |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
179 PyObject *str; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
180 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
|
181 char *buf; |
|
37920
ce5585afc20f
Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
182 Py_ssize_t len; |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
183 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
184 if (!PyArg_ParseTuple(args, "O!|z:escape_encode", |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
185 &PyString_Type, &str, &errors)) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
186 return NULL; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
187 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
188 str = PyString_Repr(str, 0); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
189 if (!str) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
190 return NULL; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
191 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
192 /* The string will be quoted. Unquote, similar to unicode-escape. */ |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
193 buf = PyString_AS_STRING (str); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
194 len = PyString_GET_SIZE (str); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
195 memmove(buf, buf+1, len-2); |
|
39445
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39359
diff
changeset
|
196 if (_PyString_Resize(&str, len-2) < 0) |
|
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39359
diff
changeset
|
197 return NULL; |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
198 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
199 return codec_tuple(str, PyString_Size(str)); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
200 } |
|
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 #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
|
203 /* --- Decoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 unicode_internal_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 { |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
209 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
210 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
|
211 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
212 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
213 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
214 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
215 &obj, &errors)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 |
|
27680
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
218 if (PyUnicode_Check(obj)) { |
|
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
219 Py_INCREF(obj); |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
220 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
|
221 } |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
222 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
223 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
224 return NULL; |
| 35485 | 225 |
| 226 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors), | |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
227 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
228 } |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 } |
|
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 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
232 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
|
233 PyObject *args) |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
234 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
235 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
236 Py_ssize_t size; |
|
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 |
|
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
|
242 if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode", |
|
e8ac1ae4503c
The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42649
diff
changeset
|
243 &data, &size, &errors, &final)) |
|
e8ac1ae4503c
The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42649
diff
changeset
|
244 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
|
245 consumed = size; |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
246 |
|
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
|
247 decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors, |
|
e8ac1ae4503c
The incremental decoder for utf-7 must preserve its state between calls.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
42649
diff
changeset
|
248 final ? NULL : &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
|
249 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
|
250 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
|
251 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
|
252 } |
|
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 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 utf_8_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
259 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
|
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 |
|
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
|
265 if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode", |
|
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
|
266 &data, &size, &errors, &final)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
268 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
269 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
270 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
271 } |
|
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
|
272 consumed = size; |
|
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 |
|
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
|
274 decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors, |
|
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 final ? NULL : &consumed); |
|
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
|
276 if (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
|
277 return 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
|
278 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
|
279 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 utf_16_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
286 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
|
287 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 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
|
289 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
290 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
|
291 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
|
292 |
|
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
|
293 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode", |
|
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
|
294 &data, &size, &errors, &final)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
296 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
297 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
298 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
299 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
300 consumed = size; /* This is overwritten unless final is true. */ |
|
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
|
301 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, |
|
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
|
302 final ? NULL : &consumed); |
|
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
|
303 if (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
|
304 return 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
|
305 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
|
306 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 utf_16_le_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
313 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
|
314 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 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
|
316 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
317 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
|
318 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
319 |
|
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 (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode", |
|
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
|
321 &data, &size, &errors, &final)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
323 |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
324 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
325 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
326 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
327 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
328 consumed = size; /* This is overwritten unless final is true. */ |
|
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
|
329 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, |
|
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
|
330 &byteorder, final ? NULL : &consumed); |
|
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
|
331 if (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
|
332 return 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
|
333 return codec_tuple(decoded, consumed); |
|
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 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 utf_16_be_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
342 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
|
343 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 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
|
345 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
346 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
|
347 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
348 |
|
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
|
349 if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode", |
|
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
|
350 &data, &size, &errors, &final)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
352 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
353 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
354 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
355 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
356 consumed = size; /* This is overwritten unless final is true. */ |
|
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
|
357 decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, |
|
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
|
358 &byteorder, final ? NULL : &consumed); |
|
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
|
359 if (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
|
360 return 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
|
361 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
|
362 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 /* 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
|
365 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
|
366 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 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
|
368 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
|
369 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 utf_16_ex_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
377 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
|
378 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 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
|
381 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
382 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
|
383 |
|
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
|
384 if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode", |
|
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
|
385 &data, &size, &errors, &byteorder, &final)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
387 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
388 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
389 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
390 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
391 consumed = size; /* This is overwritten unless final is true. */ |
|
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
|
392 unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder, |
|
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
|
393 final ? NULL : &consumed); |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 if (unicode == NULL) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
396 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
|
397 Py_DECREF(unicode); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 return tuple; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 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
|
402 utf_32_decode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
403 PyObject *args) |
|
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 const char *data; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
406 Py_ssize_t size; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 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
|
411 PyObject *decoded; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
412 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
413 if (!PyArg_ParseTuple(args, "t#|zi:utf_32_decode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
414 &data, &size, &errors, &final)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
415 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
416 if (size < 0) { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
417 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
418 return 0; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
419 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
420 consumed = size; /* This is overwritten unless final is true. */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
421 decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
422 final ? NULL : &consumed); |
|
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) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
424 return NULL; |
|
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_le_decode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
430 PyObject *args) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
431 { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
432 const char *data; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
433 Py_ssize_t size; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 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
|
438 PyObject *decoded = NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
439 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
440 if (!PyArg_ParseTuple(args, "t#|zi:utf_32_le_decode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
441 &data, &size, &errors, &final)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
442 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
443 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
444 if (size < 0) { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
445 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
446 return 0; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
447 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
448 consumed = size; /* This is overwritten unless final is true. */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
449 decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
450 &byteorder, final ? NULL : &consumed); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
451 if (decoded == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
452 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
453 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
|
454 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
455 } |
|
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 static PyObject * |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
458 utf_32_be_decode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
459 PyObject *args) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
460 { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
461 const char *data; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
462 Py_ssize_t size; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
463 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
|
464 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
|
465 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
|
466 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
|
467 PyObject *decoded = NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
468 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
469 if (!PyArg_ParseTuple(args, "t#|zi:utf_32_be_decode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
470 &data, &size, &errors, &final)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
471 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
472 if (size < 0) { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
473 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
474 return 0; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
475 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
476 consumed = size; /* This is overwritten unless final is true. */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
477 decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
478 &byteorder, final ? NULL : &consumed); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
479 if (decoded == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
480 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
481 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
|
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 /* 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
|
485 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
|
486 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
487 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
|
488 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
|
489 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
490 */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
491 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
492 static PyObject * |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
493 utf_32_ex_decode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
494 PyObject *args) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
495 { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
496 const char *data; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
497 Py_ssize_t size; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
504 if (!PyArg_ParseTuple(args, "t#|zii:utf_32_ex_decode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
505 &data, &size, &errors, &byteorder, &final)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
506 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
507 if (size < 0) { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
508 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
509 return 0; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
510 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
511 consumed = size; /* This is overwritten unless final is true. */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
512 unicode = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
513 final ? NULL : &consumed); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
514 if (unicode == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
515 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
516 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
|
517 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
|
518 return tuple; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
519 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
520 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
521 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 unicode_escape_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
526 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
|
527 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
528 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
532 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
538 raw_unicode_escape_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
542 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
|
543 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
544 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
546 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
553 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 latin_1_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
555 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
556 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
558 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
|
559 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
560 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
561 if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
562 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
563 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
565 return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
569 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
570 ascii_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
574 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
|
575 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
576 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
577 if (!PyArg_ParseTuple(args, "t#|z:ascii_decode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
579 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
581 return codec_tuple(PyUnicode_DecodeASCII(data, size, errors), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
582 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 charmap_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
590 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
|
591 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 PyObject *mapping = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
593 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 &data, &size, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
597 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
598 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
600 return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
603 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
604 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 605 |
| 606 static PyObject * | |
| 607 mbcs_decode(PyObject *self, | |
| 608 PyObject *args) | |
| 609 { | |
| 610 const char *data; | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
611 Py_ssize_t size, consumed; |
| 12074 | 612 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
|
613 int final = 0; |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
614 PyObject *decoded; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
615 |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
616 if (!PyArg_ParseTuple(args, "t#|zi:mbcs_decode", |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
617 &data, &size, &errors, &final)) |
| 12074 | 618 return NULL; |
| 619 | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
620 decoded = PyUnicode_DecodeMBCSStateful( |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
621 data, size, errors, final ? NULL : &consumed); |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
622 if (!decoded) |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
623 return NULL; |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
624 return codec_tuple(decoded, final ? size : consumed); |
| 12074 | 625 } |
| 626 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
627 #endif /* MS_WINDOWS */ |
| 12074 | 628 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 /* --- Encoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 readbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
636 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
|
637 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 return codec_tuple(PyString_FromStringAndSize(data, size), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
645 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 charbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
650 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
652 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
|
653 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode", |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
658 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 return codec_tuple(PyString_FromStringAndSize(data, size), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
661 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 static PyObject * |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
664 unicode_internal_encode(PyObject *self, |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
665 PyObject *args) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
666 { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
667 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
668 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
|
669 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
670 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
671 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
672 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode", |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
673 &obj, &errors)) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
674 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
675 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
676 if (PyUnicode_Check(obj)) { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
677 data = PyUnicode_AS_DATA(obj); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
678 size = PyUnicode_GET_DATA_SIZE(obj); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
679 return codec_tuple(PyString_FromStringAndSize(data, size), |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
680 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
681 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
682 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
683 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
684 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
685 return codec_tuple(PyString_FromStringAndSize(data, size), |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
686 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
687 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
688 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
689 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
690 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
691 utf_7_encode(PyObject *self, |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
692 PyObject *args) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
693 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
694 PyObject *str, *v; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
695 const char *errors = NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
696 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
697 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
698 &str, &errors)) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
699 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
700 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
701 str = PyUnicode_FromObject(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
702 if (str == NULL) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
703 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
704 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str), |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
705 PyUnicode_GET_SIZE(str), |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
706 0, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
707 0, |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
708 errors), |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
709 PyUnicode_GET_SIZE(str)); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
710 Py_DECREF(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
711 return v; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
712 } |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
713 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
714 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 utf_8_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
718 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 const char *errors = NULL; |
|
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|z:utf_8_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 return NULL; |
|
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) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
727 return NULL; |
|
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_EncodeUTF8(PyUnicode_AS_UNICODE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
729 PyUnicode_GET_SIZE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
730 errors), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
731 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
732 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
733 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 } |
|
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 /* 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
|
737 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
|
738 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
|
739 BOM mark. |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
740 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
741 */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
742 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
744 utf_16_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
745 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
747 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
748 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
751 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 &str, &errors, &byteorder)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
755 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
|
756 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
757 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
758 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
759 PyUnicode_GET_SIZE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
760 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
761 byteorder), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
762 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
763 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
764 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
765 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
766 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 utf_16_le_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
769 PyObject *args) |
|
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 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
774 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
776 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
777 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
778 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
|
779 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
780 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
781 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
782 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 errors, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 -1), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
785 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
|
786 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
787 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
788 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
789 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
790 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
791 utf_16_be_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
792 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
793 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
794 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
795 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
796 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
797 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
800 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
801 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
|
802 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
803 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
804 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
805 PyUnicode_GET_SIZE(str), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
806 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
807 +1), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
808 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
809 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
810 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
811 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
812 |
|
42649
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
813 /* 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
|
814 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
|
815 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
|
816 BOM mark. |
|
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 */ |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
819 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
820 static PyObject * |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
821 utf_32_encode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
822 PyObject *args) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
823 { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
824 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
|
825 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
|
826 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
|
827 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
828 if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
829 &str, &errors, &byteorder)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
830 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
831 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
832 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
|
833 if (str == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
834 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
835 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
836 PyUnicode_GET_SIZE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
837 errors, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
838 byteorder), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
839 PyUnicode_GET_SIZE(str)); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
840 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
|
841 return v; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
842 } |
|
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 static PyObject * |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
845 utf_32_le_encode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
846 PyObject *args) |
|
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 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
|
849 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
|
850 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
851 if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
852 &str, &errors)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
853 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
854 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
855 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
|
856 if (str == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
857 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
858 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
859 PyUnicode_GET_SIZE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
860 errors, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
861 -1), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
862 PyUnicode_GET_SIZE(str)); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
863 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
|
864 return v; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
865 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
866 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
867 static PyObject * |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
868 utf_32_be_encode(PyObject *self, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
869 PyObject *args) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
870 { |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
871 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
|
872 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
|
873 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
874 if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
875 &str, &errors)) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
876 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
877 |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
878 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
|
879 if (str == NULL) |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
880 return NULL; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
881 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
882 PyUnicode_GET_SIZE(str), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
883 errors, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
884 +1), |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
885 PyUnicode_GET_SIZE(str)); |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
886 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
|
887 return v; |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
888 } |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
889 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
890 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
891 unicode_escape_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
892 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
893 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
894 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
895 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
896 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
897 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
898 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
899 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
900 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
901 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
|
902 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
903 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
904 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
905 PyUnicode_GET_SIZE(str)), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
906 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
907 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
908 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
910 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
911 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
912 raw_unicode_escape_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
913 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
914 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
915 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
916 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
917 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
918 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
919 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
920 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
921 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
922 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
|
923 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
924 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
925 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
926 PyUnicode_AS_UNICODE(str), |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 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
|
928 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
929 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
930 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
931 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
932 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
933 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
934 latin_1_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
935 PyObject *args) |
|
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 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
938 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
939 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
940 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
941 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
942 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
943 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
944 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
|
945 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
946 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
947 v = codec_tuple(PyUnicode_EncodeLatin1( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
948 PyUnicode_AS_UNICODE(str), |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
949 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
950 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
951 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
952 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
953 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
955 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
956 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
957 ascii_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
958 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
959 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
960 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
961 const char *errors = NULL; |
|
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 if (!PyArg_ParseTuple(args, "O|z:ascii_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
966 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
967 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
|
968 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
969 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
970 v = codec_tuple(PyUnicode_EncodeASCII( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
971 PyUnicode_AS_UNICODE(str), |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
974 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
975 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
976 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
978 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 charmap_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
981 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
982 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
983 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
984 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
985 PyObject *mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
986 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
987 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 &str, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
989 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
990 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
991 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
992 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
993 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
|
994 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
995 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
996 v = codec_tuple(PyUnicode_EncodeCharmap( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
997 PyUnicode_AS_UNICODE(str), |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
998 PyUnicode_GET_SIZE(str), |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
999 mapping, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1000 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1001 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1002 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1003 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1004 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1005 |
|
38586
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1006 static PyObject* |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1007 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
|
1008 { |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1009 PyObject *map; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1010 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
|
1011 return NULL; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1012 return PyUnicode_BuildEncodingMap(map); |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1013 } |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1014 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
1015 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 1016 |
| 1017 static PyObject * | |
| 1018 mbcs_encode(PyObject *self, | |
| 1019 PyObject *args) | |
| 1020 { | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1021 PyObject *str, *v; |
| 12074 | 1022 const char *errors = NULL; |
| 1023 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1024 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", |
| 12074 | 1025 &str, &errors)) |
| 1026 return NULL; | |
| 1027 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1028 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
|
1029 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1030 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1031 v = codec_tuple(PyUnicode_EncodeMBCS( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
1032 PyUnicode_AS_UNICODE(str), |
| 12074 | 1033 PyUnicode_GET_SIZE(str), |
| 1034 errors), | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1035 PyUnicode_GET_SIZE(str)); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1036 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
1037 return v; |
| 12074 | 1038 } |
| 1039 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
1040 #endif /* MS_WINDOWS */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
1041 #endif /* Py_USING_UNICODE */ |
| 12074 | 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 /* --- 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
|
1044 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1045 PyDoc_STRVAR(register_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1046 "register_error(errors, handler)\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1047 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 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
|
1053 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1054 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
|
1055 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1056 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
|
1057 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
|
1058 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1059 if (!PyArg_ParseTuple(args, "sO:register_error", |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1060 &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
|
1061 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1062 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
|
1063 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
1064 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
|
1065 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1066 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1067 PyDoc_STRVAR(lookup_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1068 "lookup_error(errors) -> handler\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1069 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1070 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
|
1071 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
|
1072 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1073 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
|
1074 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1075 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
|
1076 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1077 if (!PyArg_ParseTuple(args, "s:lookup_error", |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1078 &name)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1079 return NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1080 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
|
1081 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
1082 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1083 /* --- Module API --------------------------------------------------------- */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1084 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1085 static PyMethodDef _codecs_functions[] = { |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
1086 {"register", codec_register, METH_O, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1087 register__doc__}, |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
1088 {"lookup", codec_lookup, METH_VARARGS, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1089 lookup__doc__}, |
|
32602
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
1090 {"encode", codec_encode, METH_VARARGS, |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
1091 encode__doc__}, |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
1092 {"decode", codec_decode, METH_VARARGS, |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
1093 decode__doc__}, |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
1094 {"escape_encode", escape_encode, METH_VARARGS}, |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
1095 {"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
|
1096 #ifdef Py_USING_UNICODE |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1097 {"utf_8_encode", utf_8_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1098 {"utf_8_decode", utf_8_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1099 {"utf_7_encode", utf_7_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1100 {"utf_7_decode", utf_7_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1101 {"utf_16_encode", utf_16_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1102 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1103 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1104 {"utf_16_decode", utf_16_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1105 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1106 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1107 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS}, |
|
42649
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1108 {"utf_32_encode", utf_32_encode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1109 {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1110 {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1111 {"utf_32_decode", utf_32_decode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1112 {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1113 {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS}, |
|
c916731321c0
Backport r57105 and r57145 from the py3k branch: UTF-32 codecs.
Walter Dörwald <walter@livinglogic.de>
parents:
42317
diff
changeset
|
1114 {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS}, |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1115 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1116 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1117 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1118 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1119 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1120 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1121 {"latin_1_encode", latin_1_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1122 {"latin_1_decode", latin_1_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1123 {"ascii_encode", ascii_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1124 {"ascii_decode", ascii_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1125 {"charmap_encode", charmap_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1126 {"charmap_decode", charmap_decode, METH_VARARGS}, |
|
38586
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
1127 {"charmap_build", charmap_build, METH_VARARGS}, |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1128 {"readbuffer_encode", readbuffer_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1129 {"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
|
1130 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1131 {"mbcs_encode", mbcs_encode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
1132 {"mbcs_decode", mbcs_decode, METH_VARARGS}, |
| 12074 | 1133 #endif |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
1134 #endif /* Py_USING_UNICODE */ |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1135 {"register_error", register_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1136 register_error__doc__}, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1137 {"lookup_error", lookup_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
1138 lookup_error__doc__}, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1139 {NULL, NULL} /* sentinel */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1140 }; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1141 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24071
diff
changeset
|
1142 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13358
diff
changeset
|
1143 init_codecs(void) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1144 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1145 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
|
1146 } |
