annotate Modules/_codecsmodule.c @ 58664:993f703a61ba

Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done partially before. Also add a comment describing how this might have to work with different versions of the interpreter. ........ r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line Fixed typo ........ r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line #7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such. ........ r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line Add note about usage of STRINGLIB_EMPTY. ........ r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line Fix internal reference. ........ r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines data descriptors do not override the class dictionary if __get__ is not defined Adjust documentation and add a test to verify this behavior. See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for discussion. ........ r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines Do not compile stubs for the sha2 series hashes in the openssl hashlib module when the openssl version is too old to support them. That leads both compiled code bloat and to unittests attempting to test implementations that don't exist for comparison purposes on such platforms. ........ r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line Add two more test_strtod test values. ........ r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line #7762: fix refcount annotation of PyUnicode_Tailmatch(). ........ r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line #7725: fix referencing issue. ........ r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line mention from_float() in error message ........ r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line #7802: fix invalid example (heh). ........ r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines Fix-up ftplib documentation: move exception descriptions to toplevel, not inside a class remove attribution in "versionadded" spell and grammar check docstring of FTP_TLS ........ r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line Minor modification to unittest documentation. ........
author Benjamin Peterson <benjamin@python.org>
date Wed, 03 Feb 2010 02:35:45 +0000
parents 63b23bd3904d
children f197407bdba2 cfe5fa34db46
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
42324
4bbbe0c55fa2 Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42124
diff changeset
13 lookup(encoding) -> CodecInfo object
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 The builtin Unicode codecs use the following interface:
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
17 <encoding>_encode(Unicode_object[,errors='strict']) ->
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 (string object, bytes consumed)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
20 <encoding>_decode(char_buffer_obj[,errors='strict']) ->
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 (Unicode object, bytes consumed)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
23 <encoding>_encode() interfaces also accept non-Unicode object as
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
24 input. The objects are then converted to Unicode using
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
25 PyUnicode_FromObject() prior to applying the conversion.
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
26
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 These <encoding>s are available: utf_8, unicode_escape,
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
28 raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit),
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
29 mbcs (on win32).
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
30
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 Written by Marc-Andre Lemburg (mal@lemburg.com).
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
13828
254f8b7c4a83 Changing the CNRI copyright notice according to CNRI's instructions.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
34 Copyright (c) Corporation for National Research Initiatives.
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 ------------------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
38 #define PY_SSIZE_T_CLEAN
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include "Python.h"
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 /* --- Registry ----------------------------------------------------------- */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
43 PyDoc_STRVAR(register__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
44 "register(search_function)\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
45 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
46 Register a codec search function. Search functions are expected to take\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
47 one argument, the encoding name in all lower case letters, and return\n\
42324
4bbbe0c55fa2 Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42124
diff changeset
48 a tuple of functions (encoder, decoder, stream_reader, stream_writer)\n\
4bbbe0c55fa2 Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42124
diff changeset
49 (or a CodecInfo object).");
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
50
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 static
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
52 PyObject *codec_register(PyObject *self, PyObject *search_function)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 if (PyCodec_Register(search_function))
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
55 return NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
56
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
57 Py_RETURN_NONE;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
60 PyDoc_STRVAR(lookup__doc__,
42324
4bbbe0c55fa2 Merged revisions 56443-56466 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 42124
diff changeset
61 "lookup(encoding) -> CodecInfo\n\
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
62 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
63 Looks up a codec tuple in the Python codec registry and returns\n\
52260
c6688e9156b5 Merged revisions 70507-70508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 50975
diff changeset
64 a CodecInfo object.");
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
65
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 static
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
67 PyObject *codec_lookup(PyObject *self, PyObject *args)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 char *encoding;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
72 return NULL;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return _PyCodec_Lookup(encoding);
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
77 PyDoc_STRVAR(encode__doc__,
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
78 "encode(obj, [encoding[,errors]]) -> object\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
79 \n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
80 Encodes obj using the codec registered for encoding. encoding defaults\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
81 to the default encoding. errors may be given to set a different error\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
82 handling scheme. Default is 'strict' meaning that encoding errors raise\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
83 a ValueError. Other possible values are 'ignore', 'replace' and\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
84 'xmlcharrefreplace' as well as any other name registered with\n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
85 codecs.register_error that can handle ValueErrors.");
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
86
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
87 static PyObject *
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
88 codec_encode(PyObject *self, PyObject *args)
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
89 {
32602
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
90 const char *encoding = NULL;
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
91 const char *errors = NULL;
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
92 PyObject *v;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
93
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
94 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
95 return NULL;
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
96
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
97 if (encoding == NULL)
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
98 encoding = PyUnicode_GetDefaultEncoding();
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
99
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
100 /* Encode via the codec registry */
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
101 return PyCodec_Encode(v, encoding, errors);
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
102 }
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 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
105 "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
106 \n\
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
107 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
108 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
109 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
110 a ValueError. Other possible values are 'ignore' and 'replace'\n\
49493
bdf4da5d04ad merge from trunk
Benjamin Peterson <benjamin@python.org>
parents: 48683
diff changeset
111 as well as any other name registered with codecs.register_error that is\n\
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
112 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
113
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
114 static PyObject *
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
115 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
116 {
32602
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
117 const char *encoding = NULL;
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
118 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
119 PyObject *v;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
120
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
121 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
122 return NULL;
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
123
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
124 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
125 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
126
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
127 /* Decode via the codec registry */
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
128 return PyCodec_Decode(v, encoding, errors);
32572
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
129 }
8ea2cb1ec598 Add generic codecs.encode() and .decode() APIs that don't impose
Marc-André Lemburg <mal@egenix.com>
parents: 27680
diff changeset
130
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 /* --- Helpers ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 static
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 PyObject *codec_tuple(PyObject *unicode,
38453
29ae5e0fc348 Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents: 36501
diff changeset
135 Py_ssize_t len)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
137 PyObject *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 if (unicode == NULL)
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
139 return NULL;
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
140 v = Py_BuildValue("On", unicode, len);
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
141 Py_DECREF(unicode);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 return v;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
145 /* --- String codecs ------------------------------------------------------ */
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
146 static PyObject *
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
147 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
148 PyObject *args)
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
149 {
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
150 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
151 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
152 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
153
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
154 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
155 &data, &size, &errors))
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
156 return NULL;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
157 return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL),
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
158 size);
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
159 }
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
160
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
161 static PyObject *
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
162 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
163 PyObject *args)
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
164 {
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
165 static const char *hexdigits = "0123456789abcdef";
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
166 PyObject *str;
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
167 Py_ssize_t size;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
168 Py_ssize_t newsize;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
169 const char *errors = NULL;
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
170 PyObject *v;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
171
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
172 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
173 &PyBytes_Type, &str, &errors))
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
174 return NULL;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
175
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
176 size = PyBytes_GET_SIZE(str);
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
177 newsize = 4*size;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
178 if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
179 PyErr_SetString(PyExc_OverflowError,
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
180 "string is too large to encode");
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
181 return NULL;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
182 }
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
183 v = PyBytes_FromStringAndSize(NULL, newsize);
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
184
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
185 if (v == NULL) {
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
186 return NULL;
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
187 }
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
188 else {
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
189 register Py_ssize_t i;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
190 register char c;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
191 register char *p = PyBytes_AS_STRING(v);
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
192
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
193 for (i = 0; i < size; i++) {
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
194 /* There's at least enough room for a hex escape */
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
195 assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
196 c = PyBytes_AS_STRING(str)[i];
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
197 if (c == '\'' || c == '\\')
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
198 *p++ = '\\', *p++ = c;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
199 else if (c == '\t')
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
200 *p++ = '\\', *p++ = 't';
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
201 else if (c == '\n')
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
202 *p++ = '\\', *p++ = 'n';
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
203 else if (c == '\r')
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
204 *p++ = '\\', *p++ = 'r';
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
205 else if (c < ' ' || c >= 0x7f) {
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
206 *p++ = '\\';
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
207 *p++ = 'x';
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
208 *p++ = hexdigits[(c & 0xf0) >> 4];
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
209 *p++ = hexdigits[c & 0xf];
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
210 }
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
211 else
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
212 *p++ = c;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
213 }
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
214 *p = '\0';
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
215 if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
41769
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
216 return NULL;
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
217 }
b29d71d43c80 Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
Walter Dörwald <walter@livinglogic.de>
parents: 41587
diff changeset
218 }
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
219
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
220 return codec_tuple(v, PyBytes_Size(v));
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
221 }
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
222
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 /* --- Decoder ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
224
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 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
227 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 {
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
229 PyObject *obj;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
230 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
231 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
232 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
233
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
234 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
235 &obj, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
27680
b19aaaeb6d64 Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents: 25974
diff changeset
238 if (PyUnicode_Check(obj)) {
b19aaaeb6d64 Fix for [ 543344 ] Interpreter crashes when recoding; suggested
Marc-André Lemburg <mal@egenix.com>
parents: 25974
diff changeset
239 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
240 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
241 }
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
242 else {
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
243 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
244 return NULL;
35485
6b8c55877755 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 34707
diff changeset
245
6b8c55877755 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 34707
diff changeset
246 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
247 size);
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
248 }
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
250
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 static PyObject *
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
252 utf_7_decode(PyObject *self,
43933
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
253 PyObject *args)
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
254 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
255 Py_buffer pbuf;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
256 const char *errors = NULL;
43933
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
257 int final = 0;
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
258 Py_ssize_t consumed;
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
259 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
260
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
261 if (!PyArg_ParseTuple(args, "y*|zi:utf_7_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
262 &pbuf, &errors, &final))
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
263 return NULL;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
264 consumed = pbuf.len;
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
265
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
266 decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
267 final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
268 PyBuffer_Release(&pbuf);
43933
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
269 if (decoded == NULL)
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
270 return NULL;
9c4bf18e5d30 Merged revisions 59056-59076 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
271 return codec_tuple(decoded, consumed);
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
272 }
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
273
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
274 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 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
276 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
278 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 const char *errors = NULL;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
280 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
281 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
282 PyObject *decoded = 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
283
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
284 if (!PyArg_ParseTuple(args, "y*|zi:utf_8_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
285 &pbuf, &errors, &final))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
287 consumed = pbuf.len;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
288
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
289 decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
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
290 final ? NULL : &consumed);
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
291 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
292 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
293 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
294 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
295 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
296
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 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
299 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
301 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 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
304 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
305 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
306 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
307
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
308 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
309 &pbuf, &errors, &final))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
311 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
312 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
313 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
314 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
315 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
316 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
317 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
318 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
319
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 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
322 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
324 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 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
327 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
328 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
329 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
330
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
331 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_le_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
332 &pbuf, &errors, &final))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 return NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
334
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
335 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
336 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
337 &byteorder, final ? NULL : &consumed);
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
338 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
339 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
340 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
341 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
342 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 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
346 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
348 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 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
351 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
352 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
353 PyObject *decoded = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
354
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
355 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_be_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
356 &pbuf, &errors, &final))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
358
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
359 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
360 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
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
361 &byteorder, final ? NULL : &consumed);
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
362 PyBuffer_Release(&pbuf);
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
363 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
364 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
365 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
366 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 /* 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
369 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
370
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 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
372 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
373
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 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
378 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
380 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 int byteorder = 0;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 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
384 int final = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
385 Py_ssize_t consumed;
33428
57478a13fbf6 SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
Walter Dörwald <walter@livinglogic.de>
parents: 32602
diff changeset
386
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
387 if (!PyArg_ParseTuple(args, "y*|zii:utf_16_ex_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
388 &pbuf, &errors, &byteorder, &final))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
390 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
391 unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
392 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
393 PyBuffer_Release(&pbuf);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 if (unicode == NULL)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 return NULL;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
396 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 Py_DECREF(unicode);
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 return tuple;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
400
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 static PyObject *
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
402 utf_32_decode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
403 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
404 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
405 Py_buffer pbuf;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
406 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
407 int byteorder = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
408 int final = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
409 Py_ssize_t consumed;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
410 PyObject *decoded;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
411
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
412 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
413 &pbuf, &errors, &final))
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
414 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
415 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
416 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
417 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
418 PyBuffer_Release(&pbuf);
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
419 if (decoded == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
420 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
421 return codec_tuple(decoded, consumed);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
422 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
423
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
424 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
425 utf_32_le_decode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
426 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
427 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
428 Py_buffer pbuf;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
429 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
430 int byteorder = -1;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
431 int final = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
432 Py_ssize_t consumed;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
433 PyObject *decoded;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
434
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
435 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_le_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
436 &pbuf, &errors, &final))
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
437 return NULL;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
438 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
439 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
440 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
441 PyBuffer_Release(&pbuf);
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
442 if (decoded == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
443 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
444 return codec_tuple(decoded, consumed);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
445 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
446
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
447 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
448 utf_32_be_decode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
449 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
450 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
451 Py_buffer pbuf;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
452 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
453 int byteorder = 1;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
454 int final = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
455 Py_ssize_t consumed;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
456 PyObject *decoded;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
457
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
458 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_be_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
459 &pbuf, &errors, &final))
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
460 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
461 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
462 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
463 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
464 PyBuffer_Release(&pbuf);
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
465 if (decoded == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
466 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
467 return codec_tuple(decoded, consumed);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
468 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
469
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
470 /* This non-standard version also provides access to the byteorder
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
471 parameter of the builtin UTF-32 codec.
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
472
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
473 It returns a tuple (unicode, bytesread, byteorder) with byteorder
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
474 being the value in effect at the end of data.
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
475
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
476 */
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
477
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
478 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
479 utf_32_ex_decode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
480 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
481 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
482 Py_buffer pbuf;
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
483 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
484 int byteorder = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
485 PyObject *unicode, *tuple;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
486 int final = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
487 Py_ssize_t consumed;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
488
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
489 if (!PyArg_ParseTuple(args, "y*|zii:utf_32_ex_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
490 &pbuf, &errors, &byteorder, &final))
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
491 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
492 consumed = pbuf.len; /* This is overwritten unless final is true. */
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
493 unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
494 &byteorder, final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
495 PyBuffer_Release(&pbuf);
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
496 if (unicode == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
497 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
498 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
499 Py_DECREF(unicode);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
500 return tuple;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
501 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
502
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
503 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 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
505 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
507 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 const char *errors = NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
509 PyObject *unicode;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
510
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
511 if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
512 &pbuf, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
513 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
514
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
515 unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
516 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
517 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
518 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
519
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
520 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 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
522 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
524 Py_buffer pbuf;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 const char *errors = NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
526 PyObject *unicode;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
527
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
528 if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
529 &pbuf, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
531
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
532 unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
533 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
534 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
536
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 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
539 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
540 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
541 Py_buffer pbuf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
542 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 const char *errors = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
544
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
545 if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
546 &pbuf, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
548
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
549 unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
550 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
551 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
552 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
553
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 ascii_decode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
558 Py_buffer pbuf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
559 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
560 const char *errors = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
561
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
562 if (!PyArg_ParseTuple(args, "y*|z:ascii_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
563 &pbuf, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
565
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
566 unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
567 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
568 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
569 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
570
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 charmap_decode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
573 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
574 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
575 Py_buffer pbuf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
576 PyObject *unicode;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
577 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
578 PyObject *mapping = NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
579
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
580 if (!PyArg_ParseTuple(args, "y*|zO:charmap_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
581 &pbuf, &errors, &mapping))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 if (mapping == Py_None)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
584 mapping = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
585
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
586 unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
587 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
588 return codec_tuple(unicode, pbuf.len);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
590
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
591 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
592
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
593 static PyObject *
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
594 mbcs_decode(PyObject *self,
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
595 PyObject *args)
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
596 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
597 Py_buffer pbuf;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
598 const char *errors = NULL;
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
599 int final = 0;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
600 Py_ssize_t consumed;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
601 PyObject *decoded = NULL;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
602
50975
ec6f29608bf0 Merged revisions 68855 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49493
diff changeset
603 if (!PyArg_ParseTuple(args, "y*|zi:mbcs_decode",
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
604 &pbuf, &errors, &final))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 38673
diff changeset
605 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
606 consumed = pbuf.len;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
607
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
608 decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
609 final ? NULL : &consumed);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
610 PyBuffer_Release(&pbuf);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
611 if (decoded == NULL)
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
612 return NULL;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
613 return codec_tuple(decoded, consumed);
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
614 }
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
615
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
616 #endif /* MS_WINDOWS */
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
617
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 /* --- Encoder ------------------------------------------------------------ */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
619
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 readbuffer_encode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
623 {
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
624 Py_buffer pdata;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
625 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
626 Py_ssize_t size;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 const char *errors = NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
628 PyObject *result;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
629
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
630 if (!PyArg_ParseTuple(args, "s*|z:readbuffer_encode",
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
631 &pdata, &errors))
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 return NULL;
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
633 data = pdata.buf;
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
634 size = pdata.len;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
635
48683
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
636 result = PyBytes_FromStringAndSize(data, size);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
637 PyBuffer_Release(&pdata);
cd3b0b7fd8e1 Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
638 return codec_tuple(result, size);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
639 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
640
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 charbuffer_encode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
644 {
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
646 Py_ssize_t size;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
648
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 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
650 &data, &size, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
652
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
653 return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
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 *
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
657 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
658 PyObject *args)
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
659 {
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
660 PyObject *obj;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
661 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
662 const char *data;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35825
diff changeset
663 Py_ssize_t size;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
664
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
665 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
666 &obj, &errors))
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
667 return NULL;
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
668
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
669 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
670 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
671 size = PyUnicode_GET_DATA_SIZE(obj);
53859
63b23bd3904d Merged revisions 72404-72406 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52260
diff changeset
672 return codec_tuple(PyBytes_FromStringAndSize(data, size),
63b23bd3904d Merged revisions 72404-72406 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 52260
diff changeset
673 PyUnicode_GET_SIZE(obj));
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
674 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
675 else {
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
676 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
677 return NULL;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 43933
diff changeset
678 return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
14733
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
679 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
680 }
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
681
814f421e0326 Added a true unicode_internal_encode function and fixed the
Marc-André Lemburg <mal@egenix.com>
parents: 13828
diff changeset
682 static PyObject *
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
683 utf_7_encode(PyObject *self,
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
684 PyObject *args)
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
685 {
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
686 PyObject *str, *v;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
687 const char *errors = NULL;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
688
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
689 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
690 &str, &errors))
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
691 return NULL;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
692
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
693 str = PyUnicode_FromObject(str);
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
694 if (str == NULL)
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
695 return NULL;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
696 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
697 PyUnicode_GET_SIZE(str),
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
698 0,
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
699 0,
19998
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
700 errors),
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
701 PyUnicode_GET_SIZE(str));
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
702 Py_DECREF(str);
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
703 return v;
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
704 }
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
705
8a0c97453df4 Patch #435971: UTF-7 codec by Brian Quinlan.
Marc-André Lemburg <mal@egenix.com>
parents: 19343
diff changeset
706 static PyObject *
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 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
708 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
709 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
710 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
711 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
712
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
713 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
715 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
716
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
717 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
718 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
719 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
720 v = codec_tuple(PyUnicode_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
721 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
722 errors),
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
723 PyUnicode_GET_SIZE(str));
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
724 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
725 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
726 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
727
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
728 /* 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
729 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
730 which means: use the native byte order and prepend the data with a
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
731 BOM mark.
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
732
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
734
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 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
737 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
739 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 int byteorder = 0;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
742
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
743 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
744 &str, &errors, &byteorder))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
745 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
746
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
747 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
748 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
749 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
750 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
751 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
752 errors,
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
753 byteorder),
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
754 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
755 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
756 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
757 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
758
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
759 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 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
761 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
763 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
765
18139
354a4df09e38 Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents: 14733
diff changeset
766 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
767 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
769
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
770 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
771 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
772 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
773 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
774 PyUnicode_GET_SIZE(str),
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
775 errors,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
776 -1),
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
777 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
778 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
779 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
780 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
781
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
782 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
783 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
784 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
786 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
787 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
788
18139
354a4df09e38 Fix for bug [ #433047 ] missing args to PyArg_ParseTuple
Marc-André Lemburg <mal@egenix.com>
parents: 14733
diff changeset
789 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
790 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
791 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
792
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
793 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
794 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
795 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
796 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
797 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
798 errors,
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
799 +1),
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
800 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
801 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
802 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
804
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
805 /* This version provides access to the byteorder parameter of the
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
806 builtin UTF-32 codecs as optional third argument. It defaults to 0
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
807 which means: use the native byte order and prepend the data with a
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
808 BOM mark.
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
809
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
810 */
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
811
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
812 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
813 utf_32_encode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
814 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
815 {
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
816 PyObject *str, *v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
817 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
818 int byteorder = 0;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
819
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
820 if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode",
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
821 &str, &errors, &byteorder))
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
822 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
823
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
824 str = PyUnicode_FromObject(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
825 if (str == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
826 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
827 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
828 PyUnicode_GET_SIZE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
829 errors,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
830 byteorder),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
831 PyUnicode_GET_SIZE(str));
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
832 Py_DECREF(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
833 return v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
834 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
835
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
836 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
837 utf_32_le_encode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
838 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
839 {
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
840 PyObject *str, *v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
841 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
842
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
843 if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode",
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
844 &str, &errors))
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
845 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
846
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
847 str = PyUnicode_FromObject(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
848 if (str == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
849 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
850 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
851 PyUnicode_GET_SIZE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
852 errors,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
853 -1),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
854 PyUnicode_GET_SIZE(str));
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
855 Py_DECREF(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
856 return v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
857 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
858
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
859 static PyObject *
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
860 utf_32_be_encode(PyObject *self,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
861 PyObject *args)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
862 {
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
863 PyObject *str, *v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
864 const char *errors = NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
865
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
866 if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode",
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
867 &str, &errors))
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
868 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
869
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
870 str = PyUnicode_FromObject(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
871 if (str == NULL)
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
872 return NULL;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
873 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
874 PyUnicode_GET_SIZE(str),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
875 errors,
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
876 +1),
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
877 PyUnicode_GET_SIZE(str));
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
878 Py_DECREF(str);
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
879 return v;
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
880 }
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
881
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
882 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
883 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
884 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
885 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
886 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
887 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
888
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
889 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
890 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
891 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
892
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
893 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
894 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
895 return NULL;
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
896 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
897 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
898 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
899 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
900 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
901 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
902
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
904 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
905 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
907 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
909
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
910 if (!PyArg_ParseTuple(args, "O|z: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
911 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
912 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
913
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
914 str = PyUnicode_FromObject(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
915 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
916 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
917 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
918 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
919 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
920 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
921 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
922 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
923 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
924
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
925 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
926 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
927 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
928 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
929 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
930 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
931
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
932 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
933 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
934 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
935
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
936 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
937 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
938 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
939 v = codec_tuple(PyUnicode_EncodeLatin1(
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
940 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
941 PyUnicode_GET_SIZE(str),
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
942 errors),
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
943 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
944 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
945 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
946 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
947
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
948 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
949 ascii_encode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
950 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
951 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
952 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
953 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
954
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
955 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
956 &str, &errors))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
957 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
958
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
959 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
960 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
961 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
962 v = codec_tuple(PyUnicode_EncodeASCII(
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
963 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
964 PyUnicode_GET_SIZE(str),
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
965 errors),
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
966 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
967 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
968 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
969 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
970
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
971 static PyObject *
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
972 charmap_encode(PyObject *self,
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
973 PyObject *args)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
974 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
975 PyObject *str, *v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
976 const char *errors = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
977 PyObject *mapping = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
978
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
979 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
980 &str, &errors, &mapping))
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
981 return NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
982 if (mapping == Py_None)
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
983 mapping = NULL;
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
984
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
985 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
986 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
987 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
988 v = codec_tuple(PyUnicode_EncodeCharmap(
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
989 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
990 PyUnicode_GET_SIZE(str),
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
991 mapping,
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
992 errors),
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
993 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
994 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
995 return v;
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
996 }
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
997
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
998 static PyObject*
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
999 charmap_build(PyObject *self, PyObject *args)
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1000 {
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1001 PyObject *map;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1002 if (!PyArg_ParseTuple(args, "U:charmap_build", &map))
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1003 return NULL;
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1004 return PyUnicode_BuildEncodingMap(map);
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1005 }
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1006
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
1007 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1008
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1009 static PyObject *
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1010 mbcs_encode(PyObject *self,
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1011 PyObject *args)
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1012 {
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1013 PyObject *str, *v;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1014 const char *errors = NULL;
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1015
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1016 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1017 &str, &errors))
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1018 return NULL;
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1019
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1020 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
1021 if (str == NULL)
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1022 return NULL;
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1023 v = codec_tuple(PyUnicode_EncodeMBCS(
35825
cc17a582518a Whitespace cleanup.
Walter Dörwald <walter@livinglogic.de>
parents: 35485
diff changeset
1024 PyUnicode_AS_UNICODE(str),
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1025 PyUnicode_GET_SIZE(str),
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1026 errors),
13358
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1027 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
1028 Py_DECREF(str);
c8706e5a882f Modified the encode interfaces of all builtin codecs to accept
Marc-André Lemburg <mal@egenix.com>
parents: 12074
diff changeset
1029 return v;
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1030 }
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1031
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 21757
diff changeset
1032 #endif /* MS_WINDOWS */
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1033
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1034 /* --- 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
1035
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1036 PyDoc_STRVAR(register_error__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1037 "register_error(errors, handler)\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1038 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1039 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
1040 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
1041 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
1042 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
1043 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
1044
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1045 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
1046 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1047 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
1048 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
1049
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1050 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
1051 &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
1052 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
1053 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
1054 return NULL;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1055 Py_RETURN_NONE;
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1056 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1057
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1058 PyDoc_STRVAR(lookup_error__doc__,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1059 "lookup_error(errors) -> handler\n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1060 \n\
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1061 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
1062 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
1063
25091
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1064 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
1065 {
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1066 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
1067
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1068 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
1069 &name))
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1070 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
1071 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
1072 }
0337dad8403e PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents: 24808
diff changeset
1073
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1074 /* --- Module API --------------------------------------------------------- */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1075
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1076 static PyMethodDef _codecs_functions[] = {
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
1077 {"register", codec_register, METH_O,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1078 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
1079 {"lookup", codec_lookup, METH_VARARGS,
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1080 lookup__doc__},
32602
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
1081 {"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
1082 encode__doc__},
ab979ff8b02a Change some declarations from ``char *`` to ``const char *``. Also added
Brett Cannon <bcannon@gmail.com>
parents: 32572
diff changeset
1083 {"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
1084 decode__doc__},
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
1085 {"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
1086 {"escape_decode", escape_decode, METH_VARARGS},
21757
40631ae74b17 Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents: 19998
diff changeset
1087 {"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
1088 {"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
1089 {"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
1090 {"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
1091 {"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
1092 {"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
1093 {"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
1094 {"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
1095 {"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
1096 {"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
1097 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS},
42626
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1098 {"utf_32_encode", utf_32_encode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1099 {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1100 {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1101 {"utf_32_decode", utf_32_decode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1102 {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1103 {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS},
f1a2d51f1cab Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents: 42324
diff changeset
1104 {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS},
21757
40631ae74b17 Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents: 19998
diff changeset
1105 {"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
1106 {"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
1107 {"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
1108 {"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
1109 {"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
1110 {"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
1111 {"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
1112 {"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
1113 {"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
1114 {"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
1115 {"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
1116 {"charmap_decode", charmap_decode, METH_VARARGS},
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1117 {"charmap_build", charmap_build, METH_VARARGS},
21757
40631ae74b17 Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents: 19998
diff changeset
1118 {"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
1119 {"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
1120 #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
1121 {"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
1122 {"mbcs_decode", mbcs_decode, METH_VARARGS},
12074
65f35b73e350 Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 11980
diff changeset
1123 #endif
25974
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1124 {"register_error", register_error, METH_VARARGS,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1125 register_error__doc__},
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1126 {"lookup_error", lookup_error, METH_VARARGS,
040af9c736bb Add docstrings to register, lookup, register_error
Walter Dörwald <walter@livinglogic.de>
parents: 25091
diff changeset
1127 lookup_error__doc__},
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1128 {NULL, NULL} /* sentinel */
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1129 };
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1130
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1131 static struct PyModuleDef codecsmodule = {
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1132 PyModuleDef_HEAD_INIT,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1133 "_codecs",
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1134 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1135 -1,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1136 _codecs_functions,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1137 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1138 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1139 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1140 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1141 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1142
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24071
diff changeset
1143 PyMODINIT_FUNC
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1144 PyInit__codecs(void)
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1145 {
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
1146 return PyModule_Create(&codecsmodule);
11980
a9b5a31ff8cb Internal module _codecs -- Provides access to the codec registry and
Guido van Rossum <guido@python.org>
parents:
diff changeset
1147 }