Mercurial > cpython-lru_cache-weakref
annotate Modules/_codecsmodule.c @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 549c547700af |
| children | 82f56207652f |
| 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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer) |
|
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\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
48 a tuple of functions (encoder, decoder, stream_reader, stream_writer)."); |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
49 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 static |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
51 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
|
52 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 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
|
54 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
55 |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
56 Py_RETURN_NONE; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
59 PyDoc_STRVAR(lookup__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
60 "lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
61 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
62 Looks up a codec tuple in the Python codec registry and returns\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
63 a tuple of functions."); |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
64 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 static |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
66 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
|
67 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 char *encoding; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 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
|
71 return NULL; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 return _PyCodec_Lookup(encoding); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
76 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
|
77 "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
|
78 \n\ |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 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
|
83 '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
|
84 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
|
85 |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
86 static PyObject * |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
87 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
|
88 { |
|
32602
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
89 const char *encoding = NULL; |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
90 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
|
91 PyObject *v; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
92 |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
93 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
|
94 return NULL; |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
95 |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
96 #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
|
97 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
|
98 encoding = PyUnicode_GetDefaultEncoding(); |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
99 #else |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
100 if (encoding == NULL) { |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
101 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
|
102 return NULL; |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
103 } |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
104 #endif |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
105 |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
106 /* 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
|
107 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
|
108 } |
|
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 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
|
111 "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
|
112 \n\ |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
120 static PyObject * |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
121 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
|
122 { |
|
32602
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
123 const char *encoding = NULL; |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
124 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
|
125 PyObject *v; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
126 |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
127 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
|
128 return NULL; |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
129 |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
130 #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
|
131 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
|
132 encoding = PyUnicode_GetDefaultEncoding(); |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
133 #else |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
134 if (encoding == NULL) { |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
135 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
|
136 return NULL; |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
137 } |
|
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33428
diff
changeset
|
138 #endif |
|
32572
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
139 |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
140 /* 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
|
141 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
|
142 } |
|
8ea2cb1ec598
Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents:
27680
diff
changeset
|
143 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 /* --- Helpers ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 static |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 PyObject *codec_tuple(PyObject *unicode, |
|
37920
ce5585afc20f
Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
148 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
|
149 { |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
150 PyObject *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 if (unicode == NULL) |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
152 return NULL; |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
153 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
|
154 Py_DECREF(unicode); |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 return v; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
158 /* --- String codecs ------------------------------------------------------ */ |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
159 static PyObject * |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
160 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
|
161 PyObject *args) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
162 { |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
163 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
|
164 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
165 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
166 |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
167 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
|
168 &data, &size, &errors)) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
169 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
170 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
|
171 size); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
172 } |
|
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 static PyObject * |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
175 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
|
176 PyObject *args) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
177 { |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
178 PyObject *str; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
179 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
|
180 char *buf; |
|
37920
ce5585afc20f
Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
181 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
|
182 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
183 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
|
184 &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
|
185 return NULL; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
186 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
187 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
|
188 if (!str) |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
189 return NULL; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
190 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
191 /* 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
|
192 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
|
193 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
|
194 memmove(buf, buf+1, len-2); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
195 _PyString_Resize(&str, len-2); |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
196 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
197 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
|
198 } |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
199 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
200 #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
|
201 /* --- Decoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 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
|
205 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 { |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
207 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
208 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
|
209 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
210 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
211 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
212 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
|
213 &obj, &errors)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 |
|
27680
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
216 if (PyUnicode_Check(obj)) { |
|
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
217 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
|
218 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
|
219 } |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
220 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
221 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
|
222 return NULL; |
| 35485 | 223 |
| 224 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
|
225 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
226 } |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
230 utf_7_decode(PyObject *self, |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
231 PyObject *args) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
232 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
233 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
234 Py_ssize_t size; |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
235 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
236 |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
237 if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode", |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
238 &data, &size, &errors)) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
239 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
240 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
241 return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors), |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
242 size); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
243 } |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
244 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
245 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 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
|
247 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
250 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
|
251 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
|
252 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
253 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
|
254 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
|
255 |
|
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
|
256 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
|
257 &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
|
258 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
259 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
260 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
261 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
262 } |
|
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 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
|
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 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 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
|
274 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
277 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
|
278 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 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
|
280 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
281 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
|
282 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
|
283 |
|
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
|
284 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
|
285 &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
|
286 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
287 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
288 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
289 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
290 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 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
|
301 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
304 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
|
305 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 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
|
307 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
308 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
|
309 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
310 |
|
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
|
311 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
|
312 &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
|
313 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
314 |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
315 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
316 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
317 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
318 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
319 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
|
320 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
|
321 &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
|
322 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
|
323 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
|
324 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
|
325 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 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
|
330 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
333 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
|
334 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 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
|
336 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
337 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
|
338 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
339 |
|
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
|
340 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
|
341 &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
|
342 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
343 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
344 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
345 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
346 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
347 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
|
348 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
|
349 &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
|
350 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
|
351 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
|
352 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
|
353 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 /* 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
|
356 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
|
357 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 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
|
359 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
|
360 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 */ |
|
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 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 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
|
365 PyObject *args) |
|
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 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
368 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
|
369 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 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
|
372 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
373 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
|
374 |
|
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
|
375 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
|
376 &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
|
377 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
378 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
379 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
380 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
381 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
382 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
|
383 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
|
384 final ? NULL : &consumed); |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 if (unicode == NULL) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
387 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
|
388 Py_DECREF(unicode); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 return tuple; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 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
|
394 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
397 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
|
398 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
399 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 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
|
401 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 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
|
405 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 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
|
410 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
413 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
|
414 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
415 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 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
|
417 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 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
|
421 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 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
|
426 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
429 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
|
430 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
431 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 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
|
433 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 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
|
437 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 ascii_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
445 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
|
446 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
447 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 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
|
449 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 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
|
453 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 charmap_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
461 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
|
462 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 PyObject *mapping = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
464 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 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
|
466 &data, &size, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 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
|
472 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
475 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 476 |
| 477 static PyObject * | |
| 478 mbcs_decode(PyObject *self, | |
| 479 PyObject *args) | |
| 480 { | |
| 481 const char *data; | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
482 Py_ssize_t size, consumed; |
| 12074 | 483 const char *errors = NULL; |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
484 int final = 1; |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
485 PyObject *decoded; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
486 |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
487 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
|
488 &data, &size, &errors, &final)) |
| 12074 | 489 return NULL; |
| 490 | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
491 decoded = PyUnicode_DecodeMBCSStateful( |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
492 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
|
493 if (!decoded) |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
494 return NULL; |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
495 return codec_tuple(decoded, final ? size : consumed); |
| 12074 | 496 } |
| 497 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
498 #endif /* MS_WINDOWS */ |
| 12074 | 499 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 /* --- Encoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 readbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
507 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
|
508 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 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
|
511 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 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
|
515 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 charbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
523 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
|
524 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 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
|
527 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 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
|
531 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 static PyObject * |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
535 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
|
536 PyObject *args) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
537 { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
538 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
539 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
|
540 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
541 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
542 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
543 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
|
544 &obj, &errors)) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
545 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
546 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 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
|
551 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
552 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
553 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
554 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
|
555 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
556 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
|
557 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
558 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
559 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
560 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
561 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
562 utf_7_encode(PyObject *self, |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
563 PyObject *args) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
564 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
565 PyObject *str, *v; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
566 const char *errors = NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
567 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
568 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
|
569 &str, &errors)) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
570 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
571 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
572 str = PyUnicode_FromObject(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
573 if (str == NULL) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
574 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
575 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
|
576 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
|
577 0, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
578 0, |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
579 errors), |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
580 PyUnicode_GET_SIZE(str)); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
581 Py_DECREF(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
582 return v; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
583 } |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
584 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
585 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 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
|
587 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
589 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
592 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
|
593 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
596 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
|
597 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
598 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
599 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
|
600 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
|
601 errors), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
602 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
|
603 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
604 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
605 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 /* 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
|
608 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
|
609 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
|
610 BOM mark. |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 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
|
616 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
618 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
622 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
|
623 &str, &errors, &byteorder)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
626 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
|
627 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
628 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
629 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
|
630 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
|
631 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
632 byteorder), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
633 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
|
634 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
635 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 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
|
640 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
642 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
645 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
|
646 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
649 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
|
650 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
651 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
652 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
|
653 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 errors, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 -1), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 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
|
657 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
658 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
661 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 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
|
663 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
665 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
667 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
668 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
|
669 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
670 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
672 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
|
673 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
674 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
675 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
|
676 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
|
677 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
678 +1), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
679 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
|
680 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
681 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
684 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
685 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
|
686 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
688 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
691 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
695 str = PyUnicode_FromObject(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
696 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
697 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
702 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 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
|
707 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
709 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
710 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
712 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
|
713 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
716 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
|
717 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
718 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
719 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
720 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
|
721 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
|
722 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
|
723 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
724 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 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
|
729 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
731 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
732 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
733 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
734 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
|
735 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
736 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
738 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
|
739 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
740 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
741 v = codec_tuple(PyUnicode_EncodeLatin1( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
742 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
|
743 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
744 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
745 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
|
746 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
747 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
748 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
751 ascii_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
754 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
755 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
756 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
757 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
|
758 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
760 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
761 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
|
762 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
763 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
764 v = codec_tuple(PyUnicode_EncodeASCII( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
765 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
|
766 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
768 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
|
769 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
770 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 charmap_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
776 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
777 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
778 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
779 PyObject *mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
780 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
781 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
|
782 &str, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
785 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
786 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
787 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
|
788 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
789 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
790 v = codec_tuple(PyUnicode_EncodeCharmap( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
791 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
|
792 PyUnicode_GET_SIZE(str), |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
793 mapping, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
794 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
795 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
|
796 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
797 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 |
|
38586
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
800 static PyObject* |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
801 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
|
802 { |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
803 PyObject *map; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
804 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
|
805 return NULL; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
806 return PyUnicode_BuildEncodingMap(map); |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
807 } |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
808 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
809 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 810 |
| 811 static PyObject * | |
| 812 mbcs_encode(PyObject *self, | |
| 813 PyObject *args) | |
| 814 { | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
815 PyObject *str, *v; |
| 12074 | 816 const char *errors = NULL; |
| 817 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
818 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", |
| 12074 | 819 &str, &errors)) |
| 820 return NULL; | |
| 821 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
822 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
|
823 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
824 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
825 v = codec_tuple(PyUnicode_EncodeMBCS( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
826 PyUnicode_AS_UNICODE(str), |
| 12074 | 827 PyUnicode_GET_SIZE(str), |
| 828 errors), | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
829 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
|
830 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
831 return v; |
| 12074 | 832 } |
| 833 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
834 #endif /* MS_WINDOWS */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
835 #endif /* Py_USING_UNICODE */ |
| 12074 | 836 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
837 /* --- 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
|
838 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
839 PyDoc_STRVAR(register_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
840 "register_error(errors, handler)\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
841 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
842 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
848 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
|
849 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
850 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
|
851 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
|
852 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
853 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
|
854 &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
|
855 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
|
856 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
|
857 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
858 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
|
859 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
860 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
861 PyDoc_STRVAR(lookup_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
862 "lookup_error(errors) -> handler\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
863 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
864 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
|
865 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
|
866 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
867 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
|
868 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
869 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
|
870 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
871 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
|
872 &name)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
873 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
|
874 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
|
875 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
876 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
877 /* --- Module API --------------------------------------------------------- */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
878 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
879 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
|
880 {"register", codec_register, METH_O, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
881 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
|
882 {"lookup", codec_lookup, METH_VARARGS, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
883 lookup__doc__}, |
|
32602
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
884 {"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
|
885 encode__doc__}, |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
886 {"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
|
887 decode__doc__}, |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
888 {"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
|
889 {"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
|
890 #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
|
891 {"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
|
892 {"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
|
893 {"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
|
894 {"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
|
895 {"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
|
896 {"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
|
897 {"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
|
898 {"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
|
899 {"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
|
900 {"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
|
901 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
19998
diff
changeset
|
902 {"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
|
903 {"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
|
904 {"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
|
905 {"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
|
906 {"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
|
907 {"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
|
908 {"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
|
909 {"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
|
910 {"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
|
911 {"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
|
912 {"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
|
913 {"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
|
914 {"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
|
915 {"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
|
916 {"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
|
917 #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
|
918 {"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
|
919 {"mbcs_decode", mbcs_decode, METH_VARARGS}, |
| 12074 | 920 #endif |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
921 #endif /* Py_USING_UNICODE */ |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
922 {"register_error", register_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
923 register_error__doc__}, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
924 {"lookup_error", lookup_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
925 lookup_error__doc__}, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
926 {NULL, NULL} /* sentinel */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 }; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
928 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24071
diff
changeset
|
929 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13358
diff
changeset
|
930 init_codecs(void) |
|
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 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
|
933 } |
