Mercurial > cpython-lru_cache-weakref
annotate Modules/_codecsmodule.c @ 40203:bb0db45f20ea 2.5
[Bug #1575506] The _singlefileMailbox class was using the wrong file object in its flush() method, causing an error
| author | Andrew M. Kuchling <amk@amk.ca> |
|---|---|
| date | Fri, 27 Oct 2006 16:57:44 +0000 |
| parents | e11caad7e029 |
| children | c02a33788a8f |
| 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); |
|
39445
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39359
diff
changeset
|
195 if (_PyString_Resize(&str, len-2) < 0) |
|
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39359
diff
changeset
|
196 return NULL; |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
197 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
198 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
|
199 } |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
200 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
201 #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
|
202 /* --- Decoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 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
|
206 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 { |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
208 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
209 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
|
210 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
211 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
212 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
213 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
|
214 &obj, &errors)) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 |
|
27680
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
217 if (PyUnicode_Check(obj)) { |
|
b19aaaeb6d64
Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents:
25974
diff
changeset
|
218 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
|
219 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
|
220 } |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
221 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
222 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
|
223 return NULL; |
| 35485 | 224 |
| 225 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
|
226 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
227 } |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
231 utf_7_decode(PyObject *self, |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
232 PyObject *args) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
233 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
234 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
235 Py_ssize_t size; |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
236 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
237 |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
238 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
|
239 &data, &size, &errors)) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
240 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
241 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
242 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
|
243 size); |
|
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 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
246 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 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
|
248 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
251 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
|
252 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
|
253 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
254 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
|
255 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
|
256 |
|
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 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
|
258 &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
|
259 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
260 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
261 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
262 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
263 } |
|
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
|
264 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
|
265 |
|
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 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 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
|
275 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
278 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
|
279 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 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
|
281 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
282 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
|
283 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
|
284 |
|
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 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
|
286 &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
|
287 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
288 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
289 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
290 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
291 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 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
|
302 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
305 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
|
306 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 int byteorder = -1; |
|
33428
57478a13fbf6
SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents:
32602
diff
changeset
|
308 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
309 Py_ssize_t consumed; |
|
33428
57478a13fbf6
SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents:
32602
diff
changeset
|
310 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
311 |
|
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
|
312 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
|
313 &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
|
314 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
315 |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
316 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
317 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
318 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
319 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
320 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
|
321 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
|
322 &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
|
323 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
|
324 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
|
325 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
|
326 |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 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
|
331 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
334 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
|
335 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 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
|
337 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
338 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
|
339 PyObject *decoded = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
340 |
|
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
|
341 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
|
342 &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
|
343 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
344 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
345 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
346 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
347 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
348 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
|
349 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
|
350 &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
|
351 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
|
352 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
|
353 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
|
354 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 /* 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
|
357 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
|
358 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 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
|
360 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
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 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
|
366 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
369 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
|
370 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 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
|
373 int final = 0; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
374 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
|
375 |
|
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 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
|
377 &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
|
378 return NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
379 if (size < 0) { |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
380 PyErr_SetString(PyExc_ValueError, "negative argument"); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
381 return 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
382 } |
|
38423
68e1a02a5b29
Explain why 'consumed' is initialized.
Martin v. Löwis <martin@v.loewis.de>
parents:
37920
diff
changeset
|
383 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
|
384 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
|
385 final ? NULL : &consumed); |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 if (unicode == NULL) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
388 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
|
389 Py_DECREF(unicode); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 return tuple; |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 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
|
395 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
398 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
|
399 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
400 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 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
|
402 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 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
|
406 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 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
|
411 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
414 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
|
415 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
416 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 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
|
418 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 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
|
422 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 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
|
427 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
430 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
|
431 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
432 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 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
|
434 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 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
|
438 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 ascii_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
446 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
|
447 const char *errors = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
448 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 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
|
450 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 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
|
454 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 charmap_decode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
462 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
|
463 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 PyObject *mapping = NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
465 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 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
|
467 &data, &size, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 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
|
473 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
476 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 477 |
| 478 static PyObject * | |
| 479 mbcs_decode(PyObject *self, | |
| 480 PyObject *args) | |
| 481 { | |
| 482 const char *data; | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
483 Py_ssize_t size, consumed; |
| 12074 | 484 const char *errors = NULL; |
|
39359
82f56207652f
Correction of patch #1455898: In the mbcs decoder, set final=False
Martin v. Löwis <martin@v.loewis.de>
parents:
38817
diff
changeset
|
485 int final = 0; |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
486 PyObject *decoded; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
487 |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
488 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
|
489 &data, &size, &errors, &final)) |
| 12074 | 490 return NULL; |
| 491 | |
|
38817
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
492 decoded = PyUnicode_DecodeMBCSStateful( |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
493 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
|
494 if (!decoded) |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
495 return NULL; |
|
549c547700af
Patch #1455898: Incremental mode for "mbcs" codec.
Martin v. Löwis <martin@v.loewis.de>
parents:
38586
diff
changeset
|
496 return codec_tuple(decoded, final ? size : consumed); |
| 12074 | 497 } |
| 498 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
499 #endif /* MS_WINDOWS */ |
| 12074 | 500 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 /* --- Encoder ------------------------------------------------------------ */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 readbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
508 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
|
509 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 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
|
512 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 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
|
516 size); |
|
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 charbuffer_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
524 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
|
525 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 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
|
528 &data, &size, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 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
|
532 size); |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 static PyObject * |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
536 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
|
537 PyObject *args) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
538 { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
539 PyObject *obj; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
540 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
|
541 const char *data; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35825
diff
changeset
|
542 Py_ssize_t size; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
543 |
|
14733
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
544 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
|
545 &obj, &errors)) |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
546 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
547 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 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
|
552 size); |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
553 } |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
554 else { |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
555 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
|
556 return NULL; |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
557 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
|
558 size); |
|
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 |
|
814f421e0326
Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents:
13828
diff
changeset
|
562 static PyObject * |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
563 utf_7_encode(PyObject *self, |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
564 PyObject *args) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
565 { |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
566 PyObject *str, *v; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
567 const char *errors = NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
568 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
569 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
|
570 &str, &errors)) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
571 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
572 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
573 str = PyUnicode_FromObject(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
574 if (str == NULL) |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
575 return NULL; |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
576 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
|
577 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
|
578 0, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
579 0, |
|
19998
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
580 errors), |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
581 PyUnicode_GET_SIZE(str)); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
582 Py_DECREF(str); |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
583 return v; |
|
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 |
|
8a0c97453df4
Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents:
19343
diff
changeset
|
586 static PyObject * |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 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
|
588 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
590 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
593 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
|
594 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
597 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
|
598 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
599 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
600 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
|
601 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
|
602 errors), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
603 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
|
604 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
605 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 /* 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
|
609 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
|
610 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
|
611 BOM mark. |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 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
|
617 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
619 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 int byteorder = 0; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
623 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
|
624 &str, &errors, &byteorder)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
627 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
|
628 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
629 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
630 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
|
631 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
|
632 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
633 byteorder), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
634 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
|
635 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
636 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 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
|
641 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
643 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
645 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
646 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
|
647 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
650 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
|
651 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
652 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
653 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
|
654 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 errors, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 -1), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 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
|
658 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
659 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 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
|
664 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
666 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
667 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
668 |
|
18139
354a4df09e38
Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents:
14733
diff
changeset
|
669 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
|
670 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
672 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
673 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
|
674 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
675 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
676 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
|
677 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
|
678 errors, |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
679 +1), |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
680 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
|
681 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
682 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
685 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 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
|
687 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
689 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
692 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
|
693 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
696 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
|
697 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
698 return NULL; |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
699 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
|
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 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
|
702 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
703 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 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
|
708 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
710 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
713 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
|
714 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
717 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
|
718 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
719 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
720 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
721 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
|
722 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
|
723 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
|
724 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
725 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
729 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
|
730 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
731 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
732 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
733 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
735 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
|
736 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
739 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
|
740 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
741 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
742 v = codec_tuple(PyUnicode_EncodeLatin1( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
743 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
|
744 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
745 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
746 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
|
747 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
748 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
751 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 ascii_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
755 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
756 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
758 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
|
759 &str, &errors)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
760 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
762 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
|
763 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
764 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
765 v = codec_tuple(PyUnicode_EncodeASCII( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
766 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
|
767 PyUnicode_GET_SIZE(str), |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
769 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
|
770 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
771 return v; |
|
11980
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 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 static PyObject * |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 charmap_encode(PyObject *self, |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
776 PyObject *args) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
777 { |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
778 PyObject *str, *v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
779 const char *errors = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
780 PyObject *mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
781 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
782 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
|
783 &str, &errors, &mapping)) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 return NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
785 if (mapping == Py_None) |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
786 mapping = NULL; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
787 |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
788 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
|
789 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
790 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
791 v = codec_tuple(PyUnicode_EncodeCharmap( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
792 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
|
793 PyUnicode_GET_SIZE(str), |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
794 mapping, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
795 errors), |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
796 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
|
797 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
798 return v; |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 } |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
800 |
|
38586
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
801 static PyObject* |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
802 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
|
803 { |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
804 PyObject *map; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
805 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
|
806 return NULL; |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
807 return PyUnicode_BuildEncodingMap(map); |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
808 } |
|
9e0b050ce46f
Patch #1359618: Speed-up charmap encoder.
Martin v. Löwis <martin@v.loewis.de>
parents:
38489
diff
changeset
|
809 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
810 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
| 12074 | 811 |
| 812 static PyObject * | |
| 813 mbcs_encode(PyObject *self, | |
| 814 PyObject *args) | |
| 815 { | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
816 PyObject *str, *v; |
| 12074 | 817 const char *errors = NULL; |
| 818 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
819 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", |
| 12074 | 820 &str, &errors)) |
| 821 return NULL; | |
| 822 | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
823 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
|
824 if (str == NULL) |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
825 return NULL; |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
826 v = codec_tuple(PyUnicode_EncodeMBCS( |
|
35825
cc17a582518a
Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
827 PyUnicode_AS_UNICODE(str), |
| 12074 | 828 PyUnicode_GET_SIZE(str), |
| 829 errors), | |
|
13358
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
830 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
|
831 Py_DECREF(str); |
|
c8706e5a882f
Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents:
12074
diff
changeset
|
832 return v; |
| 12074 | 833 } |
| 834 | |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
835 #endif /* MS_WINDOWS */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
836 #endif /* Py_USING_UNICODE */ |
| 12074 | 837 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
838 /* --- 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
|
839 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
840 PyDoc_STRVAR(register_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
841 "register_error(errors, handler)\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
842 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
843 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
|
844 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
|
845 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
|
846 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
|
847 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
|
848 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
849 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
|
850 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
851 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
|
852 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
|
853 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
854 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
|
855 &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
|
856 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
|
857 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
|
858 return NULL; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38423
diff
changeset
|
859 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
|
860 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
861 |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
862 PyDoc_STRVAR(lookup_error__doc__, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
863 "lookup_error(errors) -> handler\n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
864 \n\ |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
865 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
|
866 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
|
867 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
868 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
|
869 { |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
870 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
|
871 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
872 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
|
873 &name)) |
|
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 NULL; |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
875 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
|
876 } |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
24808
diff
changeset
|
877 |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
878 /* --- Module API --------------------------------------------------------- */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
879 |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
880 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
|
881 {"register", codec_register, METH_O, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
882 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
|
883 {"lookup", codec_lookup, METH_VARARGS, |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
884 lookup__doc__}, |
|
32602
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
885 {"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
|
886 encode__doc__}, |
|
ab979ff8b02a
Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents:
32572
diff
changeset
|
887 {"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
|
888 decode__doc__}, |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
889 {"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
|
890 {"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
|
891 #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
|
892 {"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
|
893 {"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
|
894 {"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
|
895 {"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
|
896 {"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
|
897 {"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
|
898 {"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
|
899 {"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
|
900 {"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
|
901 {"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
|
902 {"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
|
903 {"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
|
904 {"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
|
905 {"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
|
906 {"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
|
907 {"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
|
908 {"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
|
909 {"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
|
910 {"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
|
911 {"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
|
912 {"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
|
913 {"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
|
914 {"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
|
915 {"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
|
916 {"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
|
917 {"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
|
918 #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
|
919 {"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
|
920 {"mbcs_decode", mbcs_decode, METH_VARARGS}, |
| 12074 | 921 #endif |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18278
diff
changeset
|
922 #endif /* Py_USING_UNICODE */ |
|
25974
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
923 {"register_error", register_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
924 register_error__doc__}, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
925 {"lookup_error", lookup_error, METH_VARARGS, |
|
040af9c736bb
Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
926 lookup_error__doc__}, |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 {NULL, NULL} /* sentinel */ |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
928 }; |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
929 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24071
diff
changeset
|
930 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13358
diff
changeset
|
931 init_codecs(void) |
|
11980
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
932 { |
|
a9b5a31ff8cb
Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
933 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
|
934 } |
