annotate Modules/_codecsmodule.c @ 33526:175eee09cb98 legacy-trunk

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