blob: be1d2f70cf1b5edceba41a56b8a1ec89770aa2e4 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03005PyDoc_STRVAR(_codecs_register__doc__,
6"register($module, search_function, /)\n"
7"--\n"
8"\n"
9"Register a codec search function.\n"
10"\n"
11"Search functions are expected to take one argument, the encoding name in\n"
12"all lower case letters, and either return None, or a tuple of functions\n"
13"(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object).");
14
15#define _CODECS_REGISTER_METHODDEF \
16 {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__},
17
18PyDoc_STRVAR(_codecs_lookup__doc__,
19"lookup($module, encoding, /)\n"
20"--\n"
21"\n"
22"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.");
23
24#define _CODECS_LOOKUP_METHODDEF \
25 {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__},
26
27static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030028_codecs_lookup_impl(PyObject *module, const char *encoding);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030029
30static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030031_codecs_lookup(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030032{
33 PyObject *return_value = NULL;
34 const char *encoding;
35
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020036 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +020037 _PyArg_BadArgument("lookup", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020038 goto exit;
39 }
40 Py_ssize_t encoding_length;
41 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
42 if (encoding == NULL) {
43 goto exit;
44 }
45 if (strlen(encoding) != (size_t)encoding_length) {
46 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030049 return_value = _codecs_lookup_impl(module, encoding);
50
51exit:
52 return return_value;
53}
54
55PyDoc_STRVAR(_codecs_encode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +030056"encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030057"--\n"
58"\n"
59"Encodes obj using the codec registered for encoding.\n"
60"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +030061"The default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030062"different error handling scheme. Default is \'strict\' meaning that encoding\n"
63"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
64"and \'backslashreplace\' as well as any other name registered with\n"
65"codecs.register_error that can handle ValueErrors.");
66
67#define _CODECS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020068 {"encode", (PyCFunction)(void(*)(void))_codecs_encode, METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030069
70static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030071_codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030072 const char *errors);
73
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075_codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020079 static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
80 PyObject *argsbuf[3];
81 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030082 PyObject *obj;
83 const char *encoding = NULL;
84 const char *errors = NULL;
85
Serhiy Storchaka31913912019-03-14 10:32:22 +020086 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
87 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030088 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030089 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020090 obj = args[0];
91 if (!noptargs) {
92 goto skip_optional_pos;
93 }
94 if (args[1]) {
95 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +020096 _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]);
Serhiy Storchaka31913912019-03-14 10:32:22 +020097 goto exit;
98 }
99 Py_ssize_t encoding_length;
100 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
101 if (encoding == NULL) {
102 goto exit;
103 }
104 if (strlen(encoding) != (size_t)encoding_length) {
105 PyErr_SetString(PyExc_ValueError, "embedded null character");
106 goto exit;
107 }
108 if (!--noptargs) {
109 goto skip_optional_pos;
110 }
111 }
112 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200113 _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200114 goto exit;
115 }
116 Py_ssize_t errors_length;
117 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
118 if (errors == NULL) {
119 goto exit;
120 }
121 if (strlen(errors) != (size_t)errors_length) {
122 PyErr_SetString(PyExc_ValueError, "embedded null character");
123 goto exit;
124 }
125skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300126 return_value = _codecs_encode_impl(module, obj, encoding, errors);
127
128exit:
129 return return_value;
130}
131
132PyDoc_STRVAR(_codecs_decode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300133"decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300134"--\n"
135"\n"
136"Decodes obj using the codec registered for encoding.\n"
137"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300138"Default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300139"different error handling scheme. Default is \'strict\' meaning that encoding\n"
140"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
141"and \'backslashreplace\' as well as any other name registered with\n"
142"codecs.register_error that can handle ValueErrors.");
143
144#define _CODECS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200145 {"decode", (PyCFunction)(void(*)(void))_codecs_decode, METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300146
147static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300148_codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300149 const char *errors);
150
151static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200152_codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300153{
154 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300155 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200156 static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
157 PyObject *argsbuf[3];
158 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300159 PyObject *obj;
160 const char *encoding = NULL;
161 const char *errors = NULL;
162
Serhiy Storchaka31913912019-03-14 10:32:22 +0200163 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
164 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300165 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300166 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200167 obj = args[0];
168 if (!noptargs) {
169 goto skip_optional_pos;
170 }
171 if (args[1]) {
172 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200173 _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200174 goto exit;
175 }
176 Py_ssize_t encoding_length;
177 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
178 if (encoding == NULL) {
179 goto exit;
180 }
181 if (strlen(encoding) != (size_t)encoding_length) {
182 PyErr_SetString(PyExc_ValueError, "embedded null character");
183 goto exit;
184 }
185 if (!--noptargs) {
186 goto skip_optional_pos;
187 }
188 }
189 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200190 _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200191 goto exit;
192 }
193 Py_ssize_t errors_length;
194 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
195 if (errors == NULL) {
196 goto exit;
197 }
198 if (strlen(errors) != (size_t)errors_length) {
199 PyErr_SetString(PyExc_ValueError, "embedded null character");
200 goto exit;
201 }
202skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300203 return_value = _codecs_decode_impl(module, obj, encoding, errors);
204
205exit:
206 return return_value;
207}
208
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300209PyDoc_STRVAR(_codecs__forget_codec__doc__,
210"_forget_codec($module, encoding, /)\n"
211"--\n"
212"\n"
213"Purge the named codec from the internal codec lookup cache");
214
215#define _CODECS__FORGET_CODEC_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300216 {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_O, _codecs__forget_codec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219_codecs__forget_codec_impl(PyObject *module, const char *encoding);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220
221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300222_codecs__forget_codec(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300223{
224 PyObject *return_value = NULL;
225 const char *encoding;
226
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200227 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200228 _PyArg_BadArgument("_forget_codec", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200229 goto exit;
230 }
231 Py_ssize_t encoding_length;
232 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
233 if (encoding == NULL) {
234 goto exit;
235 }
236 if (strlen(encoding) != (size_t)encoding_length) {
237 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240 return_value = _codecs__forget_codec_impl(module, encoding);
241
242exit:
243 return return_value;
244}
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300245
246PyDoc_STRVAR(_codecs_escape_decode__doc__,
247"escape_decode($module, data, errors=None, /)\n"
248"--\n"
249"\n");
250
251#define _CODECS_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200252 {"escape_decode", (PyCFunction)(void(*)(void))_codecs_escape_decode, METH_FASTCALL, _codecs_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300253
254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300255_codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300256 const char *errors);
257
258static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200259_codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300260{
261 PyObject *return_value = NULL;
262 Py_buffer data = {NULL, NULL};
263 const char *errors = NULL;
264
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200265 if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100266 goto exit;
267 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200268 if (PyUnicode_Check(args[0])) {
269 Py_ssize_t len;
270 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
271 if (ptr == NULL) {
272 goto exit;
273 }
274 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
275 }
276 else { /* any bytes-like object */
277 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
278 goto exit;
279 }
280 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200281 _PyArg_BadArgument("escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200282 goto exit;
283 }
284 }
285 if (nargs < 2) {
286 goto skip_optional;
287 }
288 if (args[1] == Py_None) {
289 errors = NULL;
290 }
291 else if (PyUnicode_Check(args[1])) {
292 Py_ssize_t errors_length;
293 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
294 if (errors == NULL) {
295 goto exit;
296 }
297 if (strlen(errors) != (size_t)errors_length) {
298 PyErr_SetString(PyExc_ValueError, "embedded null character");
299 goto exit;
300 }
301 }
302 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200303 _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200304 goto exit;
305 }
306skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300307 return_value = _codecs_escape_decode_impl(module, &data, errors);
308
309exit:
310 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300311 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300312 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300313 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300314
315 return return_value;
316}
317
318PyDoc_STRVAR(_codecs_escape_encode__doc__,
319"escape_encode($module, data, errors=None, /)\n"
320"--\n"
321"\n");
322
323#define _CODECS_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200324 {"escape_encode", (PyCFunction)(void(*)(void))_codecs_escape_encode, METH_FASTCALL, _codecs_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300325
326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300327_codecs_escape_encode_impl(PyObject *module, PyObject *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300328 const char *errors);
329
330static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200331_codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300332{
333 PyObject *return_value = NULL;
334 PyObject *data;
335 const char *errors = NULL;
336
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200337 if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100338 goto exit;
339 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200340 if (!PyBytes_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200341 _PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200342 goto exit;
343 }
344 data = args[0];
345 if (nargs < 2) {
346 goto skip_optional;
347 }
348 if (args[1] == Py_None) {
349 errors = NULL;
350 }
351 else if (PyUnicode_Check(args[1])) {
352 Py_ssize_t errors_length;
353 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
354 if (errors == NULL) {
355 goto exit;
356 }
357 if (strlen(errors) != (size_t)errors_length) {
358 PyErr_SetString(PyExc_ValueError, "embedded null character");
359 goto exit;
360 }
361 }
362 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200363 _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200364 goto exit;
365 }
366skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300367 return_value = _codecs_escape_encode_impl(module, data, errors);
368
369exit:
370 return return_value;
371}
372
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300373PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
374"utf_7_decode($module, data, errors=None, final=False, /)\n"
375"--\n"
376"\n");
377
378#define _CODECS_UTF_7_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200379 {"utf_7_decode", (PyCFunction)(void(*)(void))_codecs_utf_7_decode, METH_FASTCALL, _codecs_utf_7_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300380
381static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300382_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300383 const char *errors, int final);
384
385static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200386_codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300387{
388 PyObject *return_value = NULL;
389 Py_buffer data = {NULL, NULL};
390 const char *errors = NULL;
391 int final = 0;
392
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200393 if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100394 goto exit;
395 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200396 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
397 goto exit;
398 }
399 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200400 _PyArg_BadArgument("utf_7_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200401 goto exit;
402 }
403 if (nargs < 2) {
404 goto skip_optional;
405 }
406 if (args[1] == Py_None) {
407 errors = NULL;
408 }
409 else if (PyUnicode_Check(args[1])) {
410 Py_ssize_t errors_length;
411 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
412 if (errors == NULL) {
413 goto exit;
414 }
415 if (strlen(errors) != (size_t)errors_length) {
416 PyErr_SetString(PyExc_ValueError, "embedded null character");
417 goto exit;
418 }
419 }
420 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200421 _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200422 goto exit;
423 }
424 if (nargs < 3) {
425 goto skip_optional;
426 }
427 if (PyFloat_Check(args[2])) {
428 PyErr_SetString(PyExc_TypeError,
429 "integer argument expected, got float" );
430 goto exit;
431 }
432 final = _PyLong_AsInt(args[2]);
433 if (final == -1 && PyErr_Occurred()) {
434 goto exit;
435 }
436skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300437 return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
438
439exit:
440 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300441 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300442 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300443 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300444
445 return return_value;
446}
447
448PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
449"utf_8_decode($module, data, errors=None, final=False, /)\n"
450"--\n"
451"\n");
452
453#define _CODECS_UTF_8_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200454 {"utf_8_decode", (PyCFunction)(void(*)(void))_codecs_utf_8_decode, METH_FASTCALL, _codecs_utf_8_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300455
456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300457_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300458 const char *errors, int final);
459
460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200461_codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300462{
463 PyObject *return_value = NULL;
464 Py_buffer data = {NULL, NULL};
465 const char *errors = NULL;
466 int final = 0;
467
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200468 if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100469 goto exit;
470 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200471 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
472 goto exit;
473 }
474 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200475 _PyArg_BadArgument("utf_8_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200476 goto exit;
477 }
478 if (nargs < 2) {
479 goto skip_optional;
480 }
481 if (args[1] == Py_None) {
482 errors = NULL;
483 }
484 else if (PyUnicode_Check(args[1])) {
485 Py_ssize_t errors_length;
486 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
487 if (errors == NULL) {
488 goto exit;
489 }
490 if (strlen(errors) != (size_t)errors_length) {
491 PyErr_SetString(PyExc_ValueError, "embedded null character");
492 goto exit;
493 }
494 }
495 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200496 _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200497 goto exit;
498 }
499 if (nargs < 3) {
500 goto skip_optional;
501 }
502 if (PyFloat_Check(args[2])) {
503 PyErr_SetString(PyExc_TypeError,
504 "integer argument expected, got float" );
505 goto exit;
506 }
507 final = _PyLong_AsInt(args[2]);
508 if (final == -1 && PyErr_Occurred()) {
509 goto exit;
510 }
511skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300512 return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
513
514exit:
515 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300516 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300517 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300518 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300519
520 return return_value;
521}
522
523PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
524"utf_16_decode($module, data, errors=None, final=False, /)\n"
525"--\n"
526"\n");
527
528#define _CODECS_UTF_16_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200529 {"utf_16_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_decode, METH_FASTCALL, _codecs_utf_16_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300530
531static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300532_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300533 const char *errors, int final);
534
535static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200536_codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300537{
538 PyObject *return_value = NULL;
539 Py_buffer data = {NULL, NULL};
540 const char *errors = NULL;
541 int final = 0;
542
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200543 if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100544 goto exit;
545 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200546 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
547 goto exit;
548 }
549 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200550 _PyArg_BadArgument("utf_16_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200551 goto exit;
552 }
553 if (nargs < 2) {
554 goto skip_optional;
555 }
556 if (args[1] == Py_None) {
557 errors = NULL;
558 }
559 else if (PyUnicode_Check(args[1])) {
560 Py_ssize_t errors_length;
561 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
562 if (errors == NULL) {
563 goto exit;
564 }
565 if (strlen(errors) != (size_t)errors_length) {
566 PyErr_SetString(PyExc_ValueError, "embedded null character");
567 goto exit;
568 }
569 }
570 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200571 _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200572 goto exit;
573 }
574 if (nargs < 3) {
575 goto skip_optional;
576 }
577 if (PyFloat_Check(args[2])) {
578 PyErr_SetString(PyExc_TypeError,
579 "integer argument expected, got float" );
580 goto exit;
581 }
582 final = _PyLong_AsInt(args[2]);
583 if (final == -1 && PyErr_Occurred()) {
584 goto exit;
585 }
586skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300587 return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
588
589exit:
590 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300591 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300592 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300593 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300594
595 return return_value;
596}
597
598PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
599"utf_16_le_decode($module, data, errors=None, final=False, /)\n"
600"--\n"
601"\n");
602
603#define _CODECS_UTF_16_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200604 {"utf_16_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_decode, METH_FASTCALL, _codecs_utf_16_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300605
606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300607_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300608 const char *errors, int final);
609
610static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200611_codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300612{
613 PyObject *return_value = NULL;
614 Py_buffer data = {NULL, NULL};
615 const char *errors = NULL;
616 int final = 0;
617
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200618 if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100619 goto exit;
620 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200621 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
622 goto exit;
623 }
624 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200625 _PyArg_BadArgument("utf_16_le_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200626 goto exit;
627 }
628 if (nargs < 2) {
629 goto skip_optional;
630 }
631 if (args[1] == Py_None) {
632 errors = NULL;
633 }
634 else if (PyUnicode_Check(args[1])) {
635 Py_ssize_t errors_length;
636 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
637 if (errors == NULL) {
638 goto exit;
639 }
640 if (strlen(errors) != (size_t)errors_length) {
641 PyErr_SetString(PyExc_ValueError, "embedded null character");
642 goto exit;
643 }
644 }
645 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200646 _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200647 goto exit;
648 }
649 if (nargs < 3) {
650 goto skip_optional;
651 }
652 if (PyFloat_Check(args[2])) {
653 PyErr_SetString(PyExc_TypeError,
654 "integer argument expected, got float" );
655 goto exit;
656 }
657 final = _PyLong_AsInt(args[2]);
658 if (final == -1 && PyErr_Occurred()) {
659 goto exit;
660 }
661skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300662 return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
663
664exit:
665 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300666 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300667 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300668 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300669
670 return return_value;
671}
672
673PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
674"utf_16_be_decode($module, data, errors=None, final=False, /)\n"
675"--\n"
676"\n");
677
678#define _CODECS_UTF_16_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200679 {"utf_16_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_decode, METH_FASTCALL, _codecs_utf_16_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300680
681static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300682_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300683 const char *errors, int final);
684
685static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200686_codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300687{
688 PyObject *return_value = NULL;
689 Py_buffer data = {NULL, NULL};
690 const char *errors = NULL;
691 int final = 0;
692
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200693 if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100694 goto exit;
695 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200696 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
697 goto exit;
698 }
699 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200700 _PyArg_BadArgument("utf_16_be_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200701 goto exit;
702 }
703 if (nargs < 2) {
704 goto skip_optional;
705 }
706 if (args[1] == Py_None) {
707 errors = NULL;
708 }
709 else if (PyUnicode_Check(args[1])) {
710 Py_ssize_t errors_length;
711 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
712 if (errors == NULL) {
713 goto exit;
714 }
715 if (strlen(errors) != (size_t)errors_length) {
716 PyErr_SetString(PyExc_ValueError, "embedded null character");
717 goto exit;
718 }
719 }
720 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200721 _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200722 goto exit;
723 }
724 if (nargs < 3) {
725 goto skip_optional;
726 }
727 if (PyFloat_Check(args[2])) {
728 PyErr_SetString(PyExc_TypeError,
729 "integer argument expected, got float" );
730 goto exit;
731 }
732 final = _PyLong_AsInt(args[2]);
733 if (final == -1 && PyErr_Occurred()) {
734 goto exit;
735 }
736skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300737 return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
738
739exit:
740 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300741 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300742 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300743 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300744
745 return return_value;
746}
747
748PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
749"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
750" /)\n"
751"--\n"
752"\n");
753
754#define _CODECS_UTF_16_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200755 {"utf_16_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_ex_decode, METH_FASTCALL, _codecs_utf_16_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300756
757static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300758_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300759 const char *errors, int byteorder, int final);
760
761static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200762_codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300763{
764 PyObject *return_value = NULL;
765 Py_buffer data = {NULL, NULL};
766 const char *errors = NULL;
767 int byteorder = 0;
768 int final = 0;
769
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200770 if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100771 goto exit;
772 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200773 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
774 goto exit;
775 }
776 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200777 _PyArg_BadArgument("utf_16_ex_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200778 goto exit;
779 }
780 if (nargs < 2) {
781 goto skip_optional;
782 }
783 if (args[1] == Py_None) {
784 errors = NULL;
785 }
786 else if (PyUnicode_Check(args[1])) {
787 Py_ssize_t errors_length;
788 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
789 if (errors == NULL) {
790 goto exit;
791 }
792 if (strlen(errors) != (size_t)errors_length) {
793 PyErr_SetString(PyExc_ValueError, "embedded null character");
794 goto exit;
795 }
796 }
797 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200798 _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200799 goto exit;
800 }
801 if (nargs < 3) {
802 goto skip_optional;
803 }
804 if (PyFloat_Check(args[2])) {
805 PyErr_SetString(PyExc_TypeError,
806 "integer argument expected, got float" );
807 goto exit;
808 }
809 byteorder = _PyLong_AsInt(args[2]);
810 if (byteorder == -1 && PyErr_Occurred()) {
811 goto exit;
812 }
813 if (nargs < 4) {
814 goto skip_optional;
815 }
816 if (PyFloat_Check(args[3])) {
817 PyErr_SetString(PyExc_TypeError,
818 "integer argument expected, got float" );
819 goto exit;
820 }
821 final = _PyLong_AsInt(args[3]);
822 if (final == -1 && PyErr_Occurred()) {
823 goto exit;
824 }
825skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300826 return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
827
828exit:
829 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300830 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300831 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300832 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300833
834 return return_value;
835}
836
837PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
838"utf_32_decode($module, data, errors=None, final=False, /)\n"
839"--\n"
840"\n");
841
842#define _CODECS_UTF_32_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200843 {"utf_32_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_decode, METH_FASTCALL, _codecs_utf_32_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300844
845static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300846_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300847 const char *errors, int final);
848
849static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200850_codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300851{
852 PyObject *return_value = NULL;
853 Py_buffer data = {NULL, NULL};
854 const char *errors = NULL;
855 int final = 0;
856
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200857 if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100858 goto exit;
859 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200860 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
861 goto exit;
862 }
863 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200864 _PyArg_BadArgument("utf_32_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200865 goto exit;
866 }
867 if (nargs < 2) {
868 goto skip_optional;
869 }
870 if (args[1] == Py_None) {
871 errors = NULL;
872 }
873 else if (PyUnicode_Check(args[1])) {
874 Py_ssize_t errors_length;
875 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
876 if (errors == NULL) {
877 goto exit;
878 }
879 if (strlen(errors) != (size_t)errors_length) {
880 PyErr_SetString(PyExc_ValueError, "embedded null character");
881 goto exit;
882 }
883 }
884 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200885 _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200886 goto exit;
887 }
888 if (nargs < 3) {
889 goto skip_optional;
890 }
891 if (PyFloat_Check(args[2])) {
892 PyErr_SetString(PyExc_TypeError,
893 "integer argument expected, got float" );
894 goto exit;
895 }
896 final = _PyLong_AsInt(args[2]);
897 if (final == -1 && PyErr_Occurred()) {
898 goto exit;
899 }
900skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300901 return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
902
903exit:
904 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300905 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300906 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300907 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300908
909 return return_value;
910}
911
912PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
913"utf_32_le_decode($module, data, errors=None, final=False, /)\n"
914"--\n"
915"\n");
916
917#define _CODECS_UTF_32_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200918 {"utf_32_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_decode, METH_FASTCALL, _codecs_utf_32_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300919
920static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300921_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300922 const char *errors, int final);
923
924static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200925_codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300926{
927 PyObject *return_value = NULL;
928 Py_buffer data = {NULL, NULL};
929 const char *errors = NULL;
930 int final = 0;
931
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200932 if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100933 goto exit;
934 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200935 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
936 goto exit;
937 }
938 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200939 _PyArg_BadArgument("utf_32_le_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200940 goto exit;
941 }
942 if (nargs < 2) {
943 goto skip_optional;
944 }
945 if (args[1] == Py_None) {
946 errors = NULL;
947 }
948 else if (PyUnicode_Check(args[1])) {
949 Py_ssize_t errors_length;
950 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
951 if (errors == NULL) {
952 goto exit;
953 }
954 if (strlen(errors) != (size_t)errors_length) {
955 PyErr_SetString(PyExc_ValueError, "embedded null character");
956 goto exit;
957 }
958 }
959 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200960 _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200961 goto exit;
962 }
963 if (nargs < 3) {
964 goto skip_optional;
965 }
966 if (PyFloat_Check(args[2])) {
967 PyErr_SetString(PyExc_TypeError,
968 "integer argument expected, got float" );
969 goto exit;
970 }
971 final = _PyLong_AsInt(args[2]);
972 if (final == -1 && PyErr_Occurred()) {
973 goto exit;
974 }
975skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300976 return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
977
978exit:
979 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300980 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300981 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300982 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300983
984 return return_value;
985}
986
987PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
988"utf_32_be_decode($module, data, errors=None, final=False, /)\n"
989"--\n"
990"\n");
991
992#define _CODECS_UTF_32_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200993 {"utf_32_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_decode, METH_FASTCALL, _codecs_utf_32_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300994
995static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300996_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300997 const char *errors, int final);
998
999static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001000_codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001001{
1002 PyObject *return_value = NULL;
1003 Py_buffer data = {NULL, NULL};
1004 const char *errors = NULL;
1005 int final = 0;
1006
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001007 if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001008 goto exit;
1009 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001010 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1011 goto exit;
1012 }
1013 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001014 _PyArg_BadArgument("utf_32_be_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001015 goto exit;
1016 }
1017 if (nargs < 2) {
1018 goto skip_optional;
1019 }
1020 if (args[1] == Py_None) {
1021 errors = NULL;
1022 }
1023 else if (PyUnicode_Check(args[1])) {
1024 Py_ssize_t errors_length;
1025 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1026 if (errors == NULL) {
1027 goto exit;
1028 }
1029 if (strlen(errors) != (size_t)errors_length) {
1030 PyErr_SetString(PyExc_ValueError, "embedded null character");
1031 goto exit;
1032 }
1033 }
1034 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001035 _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001036 goto exit;
1037 }
1038 if (nargs < 3) {
1039 goto skip_optional;
1040 }
1041 if (PyFloat_Check(args[2])) {
1042 PyErr_SetString(PyExc_TypeError,
1043 "integer argument expected, got float" );
1044 goto exit;
1045 }
1046 final = _PyLong_AsInt(args[2]);
1047 if (final == -1 && PyErr_Occurred()) {
1048 goto exit;
1049 }
1050skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001051 return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
1052
1053exit:
1054 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001055 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001056 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001057 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001058
1059 return return_value;
1060}
1061
1062PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
1063"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
1064" /)\n"
1065"--\n"
1066"\n");
1067
1068#define _CODECS_UTF_32_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001069 {"utf_32_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_ex_decode, METH_FASTCALL, _codecs_utf_32_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001070
1071static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001072_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001073 const char *errors, int byteorder, int final);
1074
1075static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001076_codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001077{
1078 PyObject *return_value = NULL;
1079 Py_buffer data = {NULL, NULL};
1080 const char *errors = NULL;
1081 int byteorder = 0;
1082 int final = 0;
1083
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001084 if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001085 goto exit;
1086 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001087 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1088 goto exit;
1089 }
1090 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001091 _PyArg_BadArgument("utf_32_ex_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001092 goto exit;
1093 }
1094 if (nargs < 2) {
1095 goto skip_optional;
1096 }
1097 if (args[1] == Py_None) {
1098 errors = NULL;
1099 }
1100 else if (PyUnicode_Check(args[1])) {
1101 Py_ssize_t errors_length;
1102 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1103 if (errors == NULL) {
1104 goto exit;
1105 }
1106 if (strlen(errors) != (size_t)errors_length) {
1107 PyErr_SetString(PyExc_ValueError, "embedded null character");
1108 goto exit;
1109 }
1110 }
1111 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001112 _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001113 goto exit;
1114 }
1115 if (nargs < 3) {
1116 goto skip_optional;
1117 }
1118 if (PyFloat_Check(args[2])) {
1119 PyErr_SetString(PyExc_TypeError,
1120 "integer argument expected, got float" );
1121 goto exit;
1122 }
1123 byteorder = _PyLong_AsInt(args[2]);
1124 if (byteorder == -1 && PyErr_Occurred()) {
1125 goto exit;
1126 }
1127 if (nargs < 4) {
1128 goto skip_optional;
1129 }
1130 if (PyFloat_Check(args[3])) {
1131 PyErr_SetString(PyExc_TypeError,
1132 "integer argument expected, got float" );
1133 goto exit;
1134 }
1135 final = _PyLong_AsInt(args[3]);
1136 if (final == -1 && PyErr_Occurred()) {
1137 goto exit;
1138 }
1139skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001140 return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1141
1142exit:
1143 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001144 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001145 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001146 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001147
1148 return return_value;
1149}
1150
1151PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
1152"unicode_escape_decode($module, data, errors=None, /)\n"
1153"--\n"
1154"\n");
1155
1156#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001157 {"unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_decode, METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001158
1159static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001160_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001161 const char *errors);
1162
1163static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001164_codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001165{
1166 PyObject *return_value = NULL;
1167 Py_buffer data = {NULL, NULL};
1168 const char *errors = NULL;
1169
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001170 if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001171 goto exit;
1172 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001173 if (PyUnicode_Check(args[0])) {
1174 Py_ssize_t len;
1175 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1176 if (ptr == NULL) {
1177 goto exit;
1178 }
1179 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1180 }
1181 else { /* any bytes-like object */
1182 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1183 goto exit;
1184 }
1185 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001186 _PyArg_BadArgument("unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001187 goto exit;
1188 }
1189 }
1190 if (nargs < 2) {
1191 goto skip_optional;
1192 }
1193 if (args[1] == Py_None) {
1194 errors = NULL;
1195 }
1196 else if (PyUnicode_Check(args[1])) {
1197 Py_ssize_t errors_length;
1198 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1199 if (errors == NULL) {
1200 goto exit;
1201 }
1202 if (strlen(errors) != (size_t)errors_length) {
1203 PyErr_SetString(PyExc_ValueError, "embedded null character");
1204 goto exit;
1205 }
1206 }
1207 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001208 _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001209 goto exit;
1210 }
1211skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001212 return_value = _codecs_unicode_escape_decode_impl(module, &data, errors);
1213
1214exit:
1215 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001216 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001217 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001218 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001219
1220 return return_value;
1221}
1222
1223PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
1224"raw_unicode_escape_decode($module, data, errors=None, /)\n"
1225"--\n"
1226"\n");
1227
1228#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001229 {"raw_unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_decode, METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001230
1231static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001232_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001233 const char *errors);
1234
1235static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001236_codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001237{
1238 PyObject *return_value = NULL;
1239 Py_buffer data = {NULL, NULL};
1240 const char *errors = NULL;
1241
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001242 if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001243 goto exit;
1244 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001245 if (PyUnicode_Check(args[0])) {
1246 Py_ssize_t len;
1247 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1248 if (ptr == NULL) {
1249 goto exit;
1250 }
1251 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1252 }
1253 else { /* any bytes-like object */
1254 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1255 goto exit;
1256 }
1257 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001258 _PyArg_BadArgument("raw_unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001259 goto exit;
1260 }
1261 }
1262 if (nargs < 2) {
1263 goto skip_optional;
1264 }
1265 if (args[1] == Py_None) {
1266 errors = NULL;
1267 }
1268 else if (PyUnicode_Check(args[1])) {
1269 Py_ssize_t errors_length;
1270 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1271 if (errors == NULL) {
1272 goto exit;
1273 }
1274 if (strlen(errors) != (size_t)errors_length) {
1275 PyErr_SetString(PyExc_ValueError, "embedded null character");
1276 goto exit;
1277 }
1278 }
1279 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001280 _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001281 goto exit;
1282 }
1283skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001284 return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors);
1285
1286exit:
1287 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001288 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001289 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001290 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001291
1292 return return_value;
1293}
1294
1295PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
1296"latin_1_decode($module, data, errors=None, /)\n"
1297"--\n"
1298"\n");
1299
1300#define _CODECS_LATIN_1_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001301 {"latin_1_decode", (PyCFunction)(void(*)(void))_codecs_latin_1_decode, METH_FASTCALL, _codecs_latin_1_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001302
1303static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001304_codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001305 const char *errors);
1306
1307static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001308_codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001309{
1310 PyObject *return_value = NULL;
1311 Py_buffer data = {NULL, NULL};
1312 const char *errors = NULL;
1313
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001314 if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001315 goto exit;
1316 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001317 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1318 goto exit;
1319 }
1320 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001321 _PyArg_BadArgument("latin_1_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001322 goto exit;
1323 }
1324 if (nargs < 2) {
1325 goto skip_optional;
1326 }
1327 if (args[1] == Py_None) {
1328 errors = NULL;
1329 }
1330 else if (PyUnicode_Check(args[1])) {
1331 Py_ssize_t errors_length;
1332 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1333 if (errors == NULL) {
1334 goto exit;
1335 }
1336 if (strlen(errors) != (size_t)errors_length) {
1337 PyErr_SetString(PyExc_ValueError, "embedded null character");
1338 goto exit;
1339 }
1340 }
1341 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001342 _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001343 goto exit;
1344 }
1345skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001346 return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1347
1348exit:
1349 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001350 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001351 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001352 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001353
1354 return return_value;
1355}
1356
1357PyDoc_STRVAR(_codecs_ascii_decode__doc__,
1358"ascii_decode($module, data, errors=None, /)\n"
1359"--\n"
1360"\n");
1361
1362#define _CODECS_ASCII_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001363 {"ascii_decode", (PyCFunction)(void(*)(void))_codecs_ascii_decode, METH_FASTCALL, _codecs_ascii_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001364
1365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001366_codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001367 const char *errors);
1368
1369static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001370_codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001371{
1372 PyObject *return_value = NULL;
1373 Py_buffer data = {NULL, NULL};
1374 const char *errors = NULL;
1375
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001376 if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001377 goto exit;
1378 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001379 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1380 goto exit;
1381 }
1382 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001383 _PyArg_BadArgument("ascii_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001384 goto exit;
1385 }
1386 if (nargs < 2) {
1387 goto skip_optional;
1388 }
1389 if (args[1] == Py_None) {
1390 errors = NULL;
1391 }
1392 else if (PyUnicode_Check(args[1])) {
1393 Py_ssize_t errors_length;
1394 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1395 if (errors == NULL) {
1396 goto exit;
1397 }
1398 if (strlen(errors) != (size_t)errors_length) {
1399 PyErr_SetString(PyExc_ValueError, "embedded null character");
1400 goto exit;
1401 }
1402 }
1403 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001404 _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001405 goto exit;
1406 }
1407skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001408 return_value = _codecs_ascii_decode_impl(module, &data, errors);
1409
1410exit:
1411 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001412 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001413 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001414 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001415
1416 return return_value;
1417}
1418
1419PyDoc_STRVAR(_codecs_charmap_decode__doc__,
1420"charmap_decode($module, data, errors=None, mapping=None, /)\n"
1421"--\n"
1422"\n");
1423
1424#define _CODECS_CHARMAP_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001425 {"charmap_decode", (PyCFunction)(void(*)(void))_codecs_charmap_decode, METH_FASTCALL, _codecs_charmap_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001426
1427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001428_codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001429 const char *errors, PyObject *mapping);
1430
1431static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001432_codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001433{
1434 PyObject *return_value = NULL;
1435 Py_buffer data = {NULL, NULL};
1436 const char *errors = NULL;
1437 PyObject *mapping = NULL;
1438
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001439 if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001440 goto exit;
1441 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001442 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1443 goto exit;
1444 }
1445 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001446 _PyArg_BadArgument("charmap_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001447 goto exit;
1448 }
1449 if (nargs < 2) {
1450 goto skip_optional;
1451 }
1452 if (args[1] == Py_None) {
1453 errors = NULL;
1454 }
1455 else if (PyUnicode_Check(args[1])) {
1456 Py_ssize_t errors_length;
1457 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1458 if (errors == NULL) {
1459 goto exit;
1460 }
1461 if (strlen(errors) != (size_t)errors_length) {
1462 PyErr_SetString(PyExc_ValueError, "embedded null character");
1463 goto exit;
1464 }
1465 }
1466 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001467 _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001468 goto exit;
1469 }
1470 if (nargs < 3) {
1471 goto skip_optional;
1472 }
1473 mapping = args[2];
1474skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001475 return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1476
1477exit:
1478 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001479 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001480 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001481 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001482
1483 return return_value;
1484}
1485
Steve Dowercc16be82016-09-08 10:35:16 -07001486#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001487
1488PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
1489"mbcs_decode($module, data, errors=None, final=False, /)\n"
1490"--\n"
1491"\n");
1492
1493#define _CODECS_MBCS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001494 {"mbcs_decode", (PyCFunction)(void(*)(void))_codecs_mbcs_decode, METH_FASTCALL, _codecs_mbcs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001498 const char *errors, int final);
1499
1500static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001501_codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001502{
1503 PyObject *return_value = NULL;
1504 Py_buffer data = {NULL, NULL};
1505 const char *errors = NULL;
1506 int final = 0;
1507
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001508 if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001509 goto exit;
1510 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001511 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1512 goto exit;
1513 }
1514 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001515 _PyArg_BadArgument("mbcs_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001516 goto exit;
1517 }
1518 if (nargs < 2) {
1519 goto skip_optional;
1520 }
1521 if (args[1] == Py_None) {
1522 errors = NULL;
1523 }
1524 else if (PyUnicode_Check(args[1])) {
1525 Py_ssize_t errors_length;
1526 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1527 if (errors == NULL) {
1528 goto exit;
1529 }
1530 if (strlen(errors) != (size_t)errors_length) {
1531 PyErr_SetString(PyExc_ValueError, "embedded null character");
1532 goto exit;
1533 }
1534 }
1535 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001536 _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001537 goto exit;
1538 }
1539 if (nargs < 3) {
1540 goto skip_optional;
1541 }
1542 if (PyFloat_Check(args[2])) {
1543 PyErr_SetString(PyExc_TypeError,
1544 "integer argument expected, got float" );
1545 goto exit;
1546 }
1547 final = _PyLong_AsInt(args[2]);
1548 if (final == -1 && PyErr_Occurred()) {
1549 goto exit;
1550 }
1551skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001552 return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
1553
1554exit:
1555 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001556 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001557 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001558 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001559
1560 return return_value;
1561}
1562
Steve Dowercc16be82016-09-08 10:35:16 -07001563#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001564
Steve Dowercc16be82016-09-08 10:35:16 -07001565#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001566
Steve Dowerf5aba582016-09-06 19:42:27 -07001567PyDoc_STRVAR(_codecs_oem_decode__doc__,
1568"oem_decode($module, data, errors=None, final=False, /)\n"
1569"--\n"
1570"\n");
1571
1572#define _CODECS_OEM_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001573 {"oem_decode", (PyCFunction)(void(*)(void))_codecs_oem_decode, METH_FASTCALL, _codecs_oem_decode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07001574
1575static PyObject *
1576_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
1577 const char *errors, int final);
1578
1579static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001580_codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07001581{
1582 PyObject *return_value = NULL;
1583 Py_buffer data = {NULL, NULL};
1584 const char *errors = NULL;
1585 int final = 0;
1586
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001587 if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001588 goto exit;
1589 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001590 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1591 goto exit;
1592 }
1593 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001594 _PyArg_BadArgument("oem_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001595 goto exit;
1596 }
1597 if (nargs < 2) {
1598 goto skip_optional;
1599 }
1600 if (args[1] == Py_None) {
1601 errors = NULL;
1602 }
1603 else if (PyUnicode_Check(args[1])) {
1604 Py_ssize_t errors_length;
1605 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1606 if (errors == NULL) {
1607 goto exit;
1608 }
1609 if (strlen(errors) != (size_t)errors_length) {
1610 PyErr_SetString(PyExc_ValueError, "embedded null character");
1611 goto exit;
1612 }
1613 }
1614 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001615 _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001616 goto exit;
1617 }
1618 if (nargs < 3) {
1619 goto skip_optional;
1620 }
1621 if (PyFloat_Check(args[2])) {
1622 PyErr_SetString(PyExc_TypeError,
1623 "integer argument expected, got float" );
1624 goto exit;
1625 }
1626 final = _PyLong_AsInt(args[2]);
1627 if (final == -1 && PyErr_Occurred()) {
1628 goto exit;
1629 }
1630skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07001631 return_value = _codecs_oem_decode_impl(module, &data, errors, final);
1632
1633exit:
1634 /* Cleanup for data */
1635 if (data.obj) {
1636 PyBuffer_Release(&data);
1637 }
1638
1639 return return_value;
1640}
1641
Steve Dowercc16be82016-09-08 10:35:16 -07001642#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07001643
Steve Dowercc16be82016-09-08 10:35:16 -07001644#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07001645
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001646PyDoc_STRVAR(_codecs_code_page_decode__doc__,
1647"code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
1648"--\n"
1649"\n");
1650
1651#define _CODECS_CODE_PAGE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001652 {"code_page_decode", (PyCFunction)(void(*)(void))_codecs_code_page_decode, METH_FASTCALL, _codecs_code_page_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001653
1654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001655_codecs_code_page_decode_impl(PyObject *module, int codepage,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001656 Py_buffer *data, const char *errors, int final);
1657
1658static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001659_codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001660{
1661 PyObject *return_value = NULL;
1662 int codepage;
1663 Py_buffer data = {NULL, NULL};
1664 const char *errors = NULL;
1665 int final = 0;
1666
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001667 if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001668 goto exit;
1669 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001670 if (PyFloat_Check(args[0])) {
1671 PyErr_SetString(PyExc_TypeError,
1672 "integer argument expected, got float" );
1673 goto exit;
1674 }
1675 codepage = _PyLong_AsInt(args[0]);
1676 if (codepage == -1 && PyErr_Occurred()) {
1677 goto exit;
1678 }
1679 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
1680 goto exit;
1681 }
1682 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001683 _PyArg_BadArgument("code_page_decode", "argument 2", "contiguous buffer", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001684 goto exit;
1685 }
1686 if (nargs < 3) {
1687 goto skip_optional;
1688 }
1689 if (args[2] == Py_None) {
1690 errors = NULL;
1691 }
1692 else if (PyUnicode_Check(args[2])) {
1693 Py_ssize_t errors_length;
1694 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
1695 if (errors == NULL) {
1696 goto exit;
1697 }
1698 if (strlen(errors) != (size_t)errors_length) {
1699 PyErr_SetString(PyExc_ValueError, "embedded null character");
1700 goto exit;
1701 }
1702 }
1703 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001704 _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001705 goto exit;
1706 }
1707 if (nargs < 4) {
1708 goto skip_optional;
1709 }
1710 if (PyFloat_Check(args[3])) {
1711 PyErr_SetString(PyExc_TypeError,
1712 "integer argument expected, got float" );
1713 goto exit;
1714 }
1715 final = _PyLong_AsInt(args[3]);
1716 if (final == -1 && PyErr_Occurred()) {
1717 goto exit;
1718 }
1719skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001720 return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
1721
1722exit:
1723 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001724 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001725 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001726 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001727
1728 return return_value;
1729}
1730
Steve Dowercc16be82016-09-08 10:35:16 -07001731#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001732
1733PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
1734"readbuffer_encode($module, data, errors=None, /)\n"
1735"--\n"
1736"\n");
1737
1738#define _CODECS_READBUFFER_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001739 {"readbuffer_encode", (PyCFunction)(void(*)(void))_codecs_readbuffer_encode, METH_FASTCALL, _codecs_readbuffer_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001740
1741static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001742_codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001743 const char *errors);
1744
1745static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001746_codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001747{
1748 PyObject *return_value = NULL;
1749 Py_buffer data = {NULL, NULL};
1750 const char *errors = NULL;
1751
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001752 if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001753 goto exit;
1754 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001755 if (PyUnicode_Check(args[0])) {
1756 Py_ssize_t len;
1757 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1758 if (ptr == NULL) {
1759 goto exit;
1760 }
1761 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1762 }
1763 else { /* any bytes-like object */
1764 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1765 goto exit;
1766 }
1767 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001768 _PyArg_BadArgument("readbuffer_encode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001769 goto exit;
1770 }
1771 }
1772 if (nargs < 2) {
1773 goto skip_optional;
1774 }
1775 if (args[1] == Py_None) {
1776 errors = NULL;
1777 }
1778 else if (PyUnicode_Check(args[1])) {
1779 Py_ssize_t errors_length;
1780 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1781 if (errors == NULL) {
1782 goto exit;
1783 }
1784 if (strlen(errors) != (size_t)errors_length) {
1785 PyErr_SetString(PyExc_ValueError, "embedded null character");
1786 goto exit;
1787 }
1788 }
1789 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001790 _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001791 goto exit;
1792 }
1793skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001794 return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1795
1796exit:
1797 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001798 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001799 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001800 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001801
1802 return return_value;
1803}
1804
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001805PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
1806"utf_7_encode($module, str, errors=None, /)\n"
1807"--\n"
1808"\n");
1809
1810#define _CODECS_UTF_7_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001811 {"utf_7_encode", (PyCFunction)(void(*)(void))_codecs_utf_7_encode, METH_FASTCALL, _codecs_utf_7_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001812
1813static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001814_codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001815 const char *errors);
1816
1817static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001818_codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001819{
1820 PyObject *return_value = NULL;
1821 PyObject *str;
1822 const char *errors = NULL;
1823
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001824 if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001825 goto exit;
1826 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001827 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001828 _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001829 goto exit;
1830 }
1831 if (PyUnicode_READY(args[0]) == -1) {
1832 goto exit;
1833 }
1834 str = args[0];
1835 if (nargs < 2) {
1836 goto skip_optional;
1837 }
1838 if (args[1] == Py_None) {
1839 errors = NULL;
1840 }
1841 else if (PyUnicode_Check(args[1])) {
1842 Py_ssize_t errors_length;
1843 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1844 if (errors == NULL) {
1845 goto exit;
1846 }
1847 if (strlen(errors) != (size_t)errors_length) {
1848 PyErr_SetString(PyExc_ValueError, "embedded null character");
1849 goto exit;
1850 }
1851 }
1852 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001853 _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001854 goto exit;
1855 }
1856skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001857 return_value = _codecs_utf_7_encode_impl(module, str, errors);
1858
1859exit:
1860 return return_value;
1861}
1862
1863PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
1864"utf_8_encode($module, str, errors=None, /)\n"
1865"--\n"
1866"\n");
1867
1868#define _CODECS_UTF_8_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001869 {"utf_8_encode", (PyCFunction)(void(*)(void))_codecs_utf_8_encode, METH_FASTCALL, _codecs_utf_8_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001870
1871static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001872_codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001873 const char *errors);
1874
1875static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001876_codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001877{
1878 PyObject *return_value = NULL;
1879 PyObject *str;
1880 const char *errors = NULL;
1881
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001882 if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001883 goto exit;
1884 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001885 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001886 _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001887 goto exit;
1888 }
1889 if (PyUnicode_READY(args[0]) == -1) {
1890 goto exit;
1891 }
1892 str = args[0];
1893 if (nargs < 2) {
1894 goto skip_optional;
1895 }
1896 if (args[1] == Py_None) {
1897 errors = NULL;
1898 }
1899 else if (PyUnicode_Check(args[1])) {
1900 Py_ssize_t errors_length;
1901 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1902 if (errors == NULL) {
1903 goto exit;
1904 }
1905 if (strlen(errors) != (size_t)errors_length) {
1906 PyErr_SetString(PyExc_ValueError, "embedded null character");
1907 goto exit;
1908 }
1909 }
1910 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001911 _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001912 goto exit;
1913 }
1914skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001915 return_value = _codecs_utf_8_encode_impl(module, str, errors);
1916
1917exit:
1918 return return_value;
1919}
1920
1921PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
1922"utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
1923"--\n"
1924"\n");
1925
1926#define _CODECS_UTF_16_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001927 {"utf_16_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_encode, METH_FASTCALL, _codecs_utf_16_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001928
1929static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001930_codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001931 const char *errors, int byteorder);
1932
1933static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001934_codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001935{
1936 PyObject *return_value = NULL;
1937 PyObject *str;
1938 const char *errors = NULL;
1939 int byteorder = 0;
1940
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001941 if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001942 goto exit;
1943 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001944 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001945 _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001946 goto exit;
1947 }
1948 if (PyUnicode_READY(args[0]) == -1) {
1949 goto exit;
1950 }
1951 str = args[0];
1952 if (nargs < 2) {
1953 goto skip_optional;
1954 }
1955 if (args[1] == Py_None) {
1956 errors = NULL;
1957 }
1958 else if (PyUnicode_Check(args[1])) {
1959 Py_ssize_t errors_length;
1960 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1961 if (errors == NULL) {
1962 goto exit;
1963 }
1964 if (strlen(errors) != (size_t)errors_length) {
1965 PyErr_SetString(PyExc_ValueError, "embedded null character");
1966 goto exit;
1967 }
1968 }
1969 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001970 _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001971 goto exit;
1972 }
1973 if (nargs < 3) {
1974 goto skip_optional;
1975 }
1976 if (PyFloat_Check(args[2])) {
1977 PyErr_SetString(PyExc_TypeError,
1978 "integer argument expected, got float" );
1979 goto exit;
1980 }
1981 byteorder = _PyLong_AsInt(args[2]);
1982 if (byteorder == -1 && PyErr_Occurred()) {
1983 goto exit;
1984 }
1985skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001986 return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
1987
1988exit:
1989 return return_value;
1990}
1991
1992PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
1993"utf_16_le_encode($module, str, errors=None, /)\n"
1994"--\n"
1995"\n");
1996
1997#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001998 {"utf_16_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_encode, METH_FASTCALL, _codecs_utf_16_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001999
2000static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002001_codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002002 const char *errors);
2003
2004static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002005_codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002006{
2007 PyObject *return_value = NULL;
2008 PyObject *str;
2009 const char *errors = NULL;
2010
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002011 if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002012 goto exit;
2013 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002014 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002015 _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002016 goto exit;
2017 }
2018 if (PyUnicode_READY(args[0]) == -1) {
2019 goto exit;
2020 }
2021 str = args[0];
2022 if (nargs < 2) {
2023 goto skip_optional;
2024 }
2025 if (args[1] == Py_None) {
2026 errors = NULL;
2027 }
2028 else if (PyUnicode_Check(args[1])) {
2029 Py_ssize_t errors_length;
2030 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2031 if (errors == NULL) {
2032 goto exit;
2033 }
2034 if (strlen(errors) != (size_t)errors_length) {
2035 PyErr_SetString(PyExc_ValueError, "embedded null character");
2036 goto exit;
2037 }
2038 }
2039 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002040 _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002041 goto exit;
2042 }
2043skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002044 return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
2045
2046exit:
2047 return return_value;
2048}
2049
2050PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
2051"utf_16_be_encode($module, str, errors=None, /)\n"
2052"--\n"
2053"\n");
2054
2055#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002056 {"utf_16_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_encode, METH_FASTCALL, _codecs_utf_16_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002057
2058static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002059_codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002060 const char *errors);
2061
2062static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002063_codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002064{
2065 PyObject *return_value = NULL;
2066 PyObject *str;
2067 const char *errors = NULL;
2068
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002069 if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002070 goto exit;
2071 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002072 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002073 _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002074 goto exit;
2075 }
2076 if (PyUnicode_READY(args[0]) == -1) {
2077 goto exit;
2078 }
2079 str = args[0];
2080 if (nargs < 2) {
2081 goto skip_optional;
2082 }
2083 if (args[1] == Py_None) {
2084 errors = NULL;
2085 }
2086 else if (PyUnicode_Check(args[1])) {
2087 Py_ssize_t errors_length;
2088 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2089 if (errors == NULL) {
2090 goto exit;
2091 }
2092 if (strlen(errors) != (size_t)errors_length) {
2093 PyErr_SetString(PyExc_ValueError, "embedded null character");
2094 goto exit;
2095 }
2096 }
2097 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002098 _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002099 goto exit;
2100 }
2101skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002102 return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
2103
2104exit:
2105 return return_value;
2106}
2107
2108PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
2109"utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
2110"--\n"
2111"\n");
2112
2113#define _CODECS_UTF_32_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002114 {"utf_32_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_encode, METH_FASTCALL, _codecs_utf_32_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002115
2116static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002117_codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002118 const char *errors, int byteorder);
2119
2120static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002121_codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002122{
2123 PyObject *return_value = NULL;
2124 PyObject *str;
2125 const char *errors = NULL;
2126 int byteorder = 0;
2127
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002128 if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002129 goto exit;
2130 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002131 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002132 _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002133 goto exit;
2134 }
2135 if (PyUnicode_READY(args[0]) == -1) {
2136 goto exit;
2137 }
2138 str = args[0];
2139 if (nargs < 2) {
2140 goto skip_optional;
2141 }
2142 if (args[1] == Py_None) {
2143 errors = NULL;
2144 }
2145 else if (PyUnicode_Check(args[1])) {
2146 Py_ssize_t errors_length;
2147 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2148 if (errors == NULL) {
2149 goto exit;
2150 }
2151 if (strlen(errors) != (size_t)errors_length) {
2152 PyErr_SetString(PyExc_ValueError, "embedded null character");
2153 goto exit;
2154 }
2155 }
2156 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002157 _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002158 goto exit;
2159 }
2160 if (nargs < 3) {
2161 goto skip_optional;
2162 }
2163 if (PyFloat_Check(args[2])) {
2164 PyErr_SetString(PyExc_TypeError,
2165 "integer argument expected, got float" );
2166 goto exit;
2167 }
2168 byteorder = _PyLong_AsInt(args[2]);
2169 if (byteorder == -1 && PyErr_Occurred()) {
2170 goto exit;
2171 }
2172skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002173 return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2174
2175exit:
2176 return return_value;
2177}
2178
2179PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
2180"utf_32_le_encode($module, str, errors=None, /)\n"
2181"--\n"
2182"\n");
2183
2184#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002185 {"utf_32_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_encode, METH_FASTCALL, _codecs_utf_32_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002186
2187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002188_codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002189 const char *errors);
2190
2191static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002192_codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002193{
2194 PyObject *return_value = NULL;
2195 PyObject *str;
2196 const char *errors = NULL;
2197
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002198 if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002199 goto exit;
2200 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002201 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002202 _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002203 goto exit;
2204 }
2205 if (PyUnicode_READY(args[0]) == -1) {
2206 goto exit;
2207 }
2208 str = args[0];
2209 if (nargs < 2) {
2210 goto skip_optional;
2211 }
2212 if (args[1] == Py_None) {
2213 errors = NULL;
2214 }
2215 else if (PyUnicode_Check(args[1])) {
2216 Py_ssize_t errors_length;
2217 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2218 if (errors == NULL) {
2219 goto exit;
2220 }
2221 if (strlen(errors) != (size_t)errors_length) {
2222 PyErr_SetString(PyExc_ValueError, "embedded null character");
2223 goto exit;
2224 }
2225 }
2226 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002227 _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002228 goto exit;
2229 }
2230skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002231 return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2232
2233exit:
2234 return return_value;
2235}
2236
2237PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
2238"utf_32_be_encode($module, str, errors=None, /)\n"
2239"--\n"
2240"\n");
2241
2242#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002243 {"utf_32_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_encode, METH_FASTCALL, _codecs_utf_32_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002244
2245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002246_codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002247 const char *errors);
2248
2249static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002250_codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002251{
2252 PyObject *return_value = NULL;
2253 PyObject *str;
2254 const char *errors = NULL;
2255
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002256 if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002257 goto exit;
2258 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002259 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002260 _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002261 goto exit;
2262 }
2263 if (PyUnicode_READY(args[0]) == -1) {
2264 goto exit;
2265 }
2266 str = args[0];
2267 if (nargs < 2) {
2268 goto skip_optional;
2269 }
2270 if (args[1] == Py_None) {
2271 errors = NULL;
2272 }
2273 else if (PyUnicode_Check(args[1])) {
2274 Py_ssize_t errors_length;
2275 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2276 if (errors == NULL) {
2277 goto exit;
2278 }
2279 if (strlen(errors) != (size_t)errors_length) {
2280 PyErr_SetString(PyExc_ValueError, "embedded null character");
2281 goto exit;
2282 }
2283 }
2284 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002285 _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002286 goto exit;
2287 }
2288skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002289 return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2290
2291exit:
2292 return return_value;
2293}
2294
2295PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
2296"unicode_escape_encode($module, str, errors=None, /)\n"
2297"--\n"
2298"\n");
2299
2300#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002301 {"unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_encode, METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002302
2303static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002304_codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002305 const char *errors);
2306
2307static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002308_codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002309{
2310 PyObject *return_value = NULL;
2311 PyObject *str;
2312 const char *errors = NULL;
2313
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002314 if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002315 goto exit;
2316 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002317 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002318 _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002319 goto exit;
2320 }
2321 if (PyUnicode_READY(args[0]) == -1) {
2322 goto exit;
2323 }
2324 str = args[0];
2325 if (nargs < 2) {
2326 goto skip_optional;
2327 }
2328 if (args[1] == Py_None) {
2329 errors = NULL;
2330 }
2331 else if (PyUnicode_Check(args[1])) {
2332 Py_ssize_t errors_length;
2333 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2334 if (errors == NULL) {
2335 goto exit;
2336 }
2337 if (strlen(errors) != (size_t)errors_length) {
2338 PyErr_SetString(PyExc_ValueError, "embedded null character");
2339 goto exit;
2340 }
2341 }
2342 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002343 _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002344 goto exit;
2345 }
2346skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002347 return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2348
2349exit:
2350 return return_value;
2351}
2352
2353PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
2354"raw_unicode_escape_encode($module, str, errors=None, /)\n"
2355"--\n"
2356"\n");
2357
2358#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002359 {"raw_unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_encode, METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002360
2361static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002362_codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002363 const char *errors);
2364
2365static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002366_codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002367{
2368 PyObject *return_value = NULL;
2369 PyObject *str;
2370 const char *errors = NULL;
2371
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002372 if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002373 goto exit;
2374 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002375 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002376 _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002377 goto exit;
2378 }
2379 if (PyUnicode_READY(args[0]) == -1) {
2380 goto exit;
2381 }
2382 str = args[0];
2383 if (nargs < 2) {
2384 goto skip_optional;
2385 }
2386 if (args[1] == Py_None) {
2387 errors = NULL;
2388 }
2389 else if (PyUnicode_Check(args[1])) {
2390 Py_ssize_t errors_length;
2391 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2392 if (errors == NULL) {
2393 goto exit;
2394 }
2395 if (strlen(errors) != (size_t)errors_length) {
2396 PyErr_SetString(PyExc_ValueError, "embedded null character");
2397 goto exit;
2398 }
2399 }
2400 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002401 _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002402 goto exit;
2403 }
2404skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002405 return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2406
2407exit:
2408 return return_value;
2409}
2410
2411PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
2412"latin_1_encode($module, str, errors=None, /)\n"
2413"--\n"
2414"\n");
2415
2416#define _CODECS_LATIN_1_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002417 {"latin_1_encode", (PyCFunction)(void(*)(void))_codecs_latin_1_encode, METH_FASTCALL, _codecs_latin_1_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002418
2419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002420_codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002421 const char *errors);
2422
2423static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002424_codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002425{
2426 PyObject *return_value = NULL;
2427 PyObject *str;
2428 const char *errors = NULL;
2429
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002430 if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002431 goto exit;
2432 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002433 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002434 _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002435 goto exit;
2436 }
2437 if (PyUnicode_READY(args[0]) == -1) {
2438 goto exit;
2439 }
2440 str = args[0];
2441 if (nargs < 2) {
2442 goto skip_optional;
2443 }
2444 if (args[1] == Py_None) {
2445 errors = NULL;
2446 }
2447 else if (PyUnicode_Check(args[1])) {
2448 Py_ssize_t errors_length;
2449 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2450 if (errors == NULL) {
2451 goto exit;
2452 }
2453 if (strlen(errors) != (size_t)errors_length) {
2454 PyErr_SetString(PyExc_ValueError, "embedded null character");
2455 goto exit;
2456 }
2457 }
2458 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002459 _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002460 goto exit;
2461 }
2462skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002463 return_value = _codecs_latin_1_encode_impl(module, str, errors);
2464
2465exit:
2466 return return_value;
2467}
2468
2469PyDoc_STRVAR(_codecs_ascii_encode__doc__,
2470"ascii_encode($module, str, errors=None, /)\n"
2471"--\n"
2472"\n");
2473
2474#define _CODECS_ASCII_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002475 {"ascii_encode", (PyCFunction)(void(*)(void))_codecs_ascii_encode, METH_FASTCALL, _codecs_ascii_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002476
2477static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002478_codecs_ascii_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002479 const char *errors);
2480
2481static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002482_codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002483{
2484 PyObject *return_value = NULL;
2485 PyObject *str;
2486 const char *errors = NULL;
2487
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002488 if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002489 goto exit;
2490 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002491 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002492 _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002493 goto exit;
2494 }
2495 if (PyUnicode_READY(args[0]) == -1) {
2496 goto exit;
2497 }
2498 str = args[0];
2499 if (nargs < 2) {
2500 goto skip_optional;
2501 }
2502 if (args[1] == Py_None) {
2503 errors = NULL;
2504 }
2505 else if (PyUnicode_Check(args[1])) {
2506 Py_ssize_t errors_length;
2507 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2508 if (errors == NULL) {
2509 goto exit;
2510 }
2511 if (strlen(errors) != (size_t)errors_length) {
2512 PyErr_SetString(PyExc_ValueError, "embedded null character");
2513 goto exit;
2514 }
2515 }
2516 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002517 _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002518 goto exit;
2519 }
2520skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002521 return_value = _codecs_ascii_encode_impl(module, str, errors);
2522
2523exit:
2524 return return_value;
2525}
2526
2527PyDoc_STRVAR(_codecs_charmap_encode__doc__,
2528"charmap_encode($module, str, errors=None, mapping=None, /)\n"
2529"--\n"
2530"\n");
2531
2532#define _CODECS_CHARMAP_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002533 {"charmap_encode", (PyCFunction)(void(*)(void))_codecs_charmap_encode, METH_FASTCALL, _codecs_charmap_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002534
2535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002536_codecs_charmap_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002537 const char *errors, PyObject *mapping);
2538
2539static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002540_codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002541{
2542 PyObject *return_value = NULL;
2543 PyObject *str;
2544 const char *errors = NULL;
2545 PyObject *mapping = NULL;
2546
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002547 if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002548 goto exit;
2549 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002550 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002551 _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002552 goto exit;
2553 }
2554 if (PyUnicode_READY(args[0]) == -1) {
2555 goto exit;
2556 }
2557 str = args[0];
2558 if (nargs < 2) {
2559 goto skip_optional;
2560 }
2561 if (args[1] == Py_None) {
2562 errors = NULL;
2563 }
2564 else if (PyUnicode_Check(args[1])) {
2565 Py_ssize_t errors_length;
2566 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2567 if (errors == NULL) {
2568 goto exit;
2569 }
2570 if (strlen(errors) != (size_t)errors_length) {
2571 PyErr_SetString(PyExc_ValueError, "embedded null character");
2572 goto exit;
2573 }
2574 }
2575 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002576 _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002577 goto exit;
2578 }
2579 if (nargs < 3) {
2580 goto skip_optional;
2581 }
2582 mapping = args[2];
2583skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002584 return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2585
2586exit:
2587 return return_value;
2588}
2589
2590PyDoc_STRVAR(_codecs_charmap_build__doc__,
2591"charmap_build($module, map, /)\n"
2592"--\n"
2593"\n");
2594
2595#define _CODECS_CHARMAP_BUILD_METHODDEF \
2596 {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
2597
2598static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002599_codecs_charmap_build_impl(PyObject *module, PyObject *map);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002600
2601static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002602_codecs_charmap_build(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002603{
2604 PyObject *return_value = NULL;
2605 PyObject *map;
2606
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002607 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002608 _PyArg_BadArgument("charmap_build", "argument", "str", arg);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002609 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002610 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002611 if (PyUnicode_READY(arg) == -1) {
2612 goto exit;
2613 }
2614 map = arg;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002615 return_value = _codecs_charmap_build_impl(module, map);
2616
2617exit:
2618 return return_value;
2619}
2620
Steve Dowercc16be82016-09-08 10:35:16 -07002621#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002622
2623PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
2624"mbcs_encode($module, str, errors=None, /)\n"
2625"--\n"
2626"\n");
2627
2628#define _CODECS_MBCS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002629 {"mbcs_encode", (PyCFunction)(void(*)(void))_codecs_mbcs_encode, METH_FASTCALL, _codecs_mbcs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002630
2631static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002632_codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002633
2634static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002635_codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002636{
2637 PyObject *return_value = NULL;
2638 PyObject *str;
2639 const char *errors = NULL;
2640
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002641 if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002642 goto exit;
2643 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002644 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002645 _PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002646 goto exit;
2647 }
2648 if (PyUnicode_READY(args[0]) == -1) {
2649 goto exit;
2650 }
2651 str = args[0];
2652 if (nargs < 2) {
2653 goto skip_optional;
2654 }
2655 if (args[1] == Py_None) {
2656 errors = NULL;
2657 }
2658 else if (PyUnicode_Check(args[1])) {
2659 Py_ssize_t errors_length;
2660 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2661 if (errors == NULL) {
2662 goto exit;
2663 }
2664 if (strlen(errors) != (size_t)errors_length) {
2665 PyErr_SetString(PyExc_ValueError, "embedded null character");
2666 goto exit;
2667 }
2668 }
2669 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002670 _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002671 goto exit;
2672 }
2673skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002674 return_value = _codecs_mbcs_encode_impl(module, str, errors);
2675
2676exit:
2677 return return_value;
2678}
2679
Steve Dowercc16be82016-09-08 10:35:16 -07002680#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002681
Steve Dowercc16be82016-09-08 10:35:16 -07002682#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002683
Steve Dowerf5aba582016-09-06 19:42:27 -07002684PyDoc_STRVAR(_codecs_oem_encode__doc__,
2685"oem_encode($module, str, errors=None, /)\n"
2686"--\n"
2687"\n");
2688
2689#define _CODECS_OEM_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002690 {"oem_encode", (PyCFunction)(void(*)(void))_codecs_oem_encode, METH_FASTCALL, _codecs_oem_encode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07002691
2692static PyObject *
2693_codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
2694
2695static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002696_codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07002697{
2698 PyObject *return_value = NULL;
2699 PyObject *str;
2700 const char *errors = NULL;
2701
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002702 if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002703 goto exit;
2704 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002705 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002706 _PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002707 goto exit;
2708 }
2709 if (PyUnicode_READY(args[0]) == -1) {
2710 goto exit;
2711 }
2712 str = args[0];
2713 if (nargs < 2) {
2714 goto skip_optional;
2715 }
2716 if (args[1] == Py_None) {
2717 errors = NULL;
2718 }
2719 else if (PyUnicode_Check(args[1])) {
2720 Py_ssize_t errors_length;
2721 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2722 if (errors == NULL) {
2723 goto exit;
2724 }
2725 if (strlen(errors) != (size_t)errors_length) {
2726 PyErr_SetString(PyExc_ValueError, "embedded null character");
2727 goto exit;
2728 }
2729 }
2730 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002731 _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002732 goto exit;
2733 }
2734skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07002735 return_value = _codecs_oem_encode_impl(module, str, errors);
2736
2737exit:
2738 return return_value;
2739}
2740
Steve Dowercc16be82016-09-08 10:35:16 -07002741#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07002742
Steve Dowercc16be82016-09-08 10:35:16 -07002743#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07002744
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002745PyDoc_STRVAR(_codecs_code_page_encode__doc__,
2746"code_page_encode($module, code_page, str, errors=None, /)\n"
2747"--\n"
2748"\n");
2749
2750#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002751 {"code_page_encode", (PyCFunction)(void(*)(void))_codecs_code_page_encode, METH_FASTCALL, _codecs_code_page_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002752
2753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002754_codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
2755 const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002756
2757static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002758_codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002759{
2760 PyObject *return_value = NULL;
2761 int code_page;
2762 PyObject *str;
2763 const char *errors = NULL;
2764
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002765 if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002766 goto exit;
2767 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002768 if (PyFloat_Check(args[0])) {
2769 PyErr_SetString(PyExc_TypeError,
2770 "integer argument expected, got float" );
2771 goto exit;
2772 }
2773 code_page = _PyLong_AsInt(args[0]);
2774 if (code_page == -1 && PyErr_Occurred()) {
2775 goto exit;
2776 }
2777 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002778 _PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002779 goto exit;
2780 }
2781 if (PyUnicode_READY(args[1]) == -1) {
2782 goto exit;
2783 }
2784 str = args[1];
2785 if (nargs < 3) {
2786 goto skip_optional;
2787 }
2788 if (args[2] == Py_None) {
2789 errors = NULL;
2790 }
2791 else if (PyUnicode_Check(args[2])) {
2792 Py_ssize_t errors_length;
2793 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
2794 if (errors == NULL) {
2795 goto exit;
2796 }
2797 if (strlen(errors) != (size_t)errors_length) {
2798 PyErr_SetString(PyExc_ValueError, "embedded null character");
2799 goto exit;
2800 }
2801 }
2802 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002803 _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002804 goto exit;
2805 }
2806skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002807 return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
2808
2809exit:
2810 return return_value;
2811}
2812
Steve Dowercc16be82016-09-08 10:35:16 -07002813#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002814
2815PyDoc_STRVAR(_codecs_register_error__doc__,
2816"register_error($module, errors, handler, /)\n"
2817"--\n"
2818"\n"
2819"Register the specified error handler under the name errors.\n"
2820"\n"
2821"handler must be a callable object, that will be called with an exception\n"
2822"instance containing information about the location of the encoding/decoding\n"
2823"error and must return a (replacement, new position) tuple.");
2824
2825#define _CODECS_REGISTER_ERROR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002826 {"register_error", (PyCFunction)(void(*)(void))_codecs_register_error, METH_FASTCALL, _codecs_register_error__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002827
2828static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002829_codecs_register_error_impl(PyObject *module, const char *errors,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002830 PyObject *handler);
2831
2832static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002833_codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002834{
2835 PyObject *return_value = NULL;
2836 const char *errors;
2837 PyObject *handler;
2838
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002839 if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002840 goto exit;
2841 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002842 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002843 _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002844 goto exit;
2845 }
2846 Py_ssize_t errors_length;
2847 errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2848 if (errors == NULL) {
2849 goto exit;
2850 }
2851 if (strlen(errors) != (size_t)errors_length) {
2852 PyErr_SetString(PyExc_ValueError, "embedded null character");
2853 goto exit;
2854 }
2855 handler = args[1];
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002856 return_value = _codecs_register_error_impl(module, errors, handler);
2857
2858exit:
2859 return return_value;
2860}
2861
2862PyDoc_STRVAR(_codecs_lookup_error__doc__,
2863"lookup_error($module, name, /)\n"
2864"--\n"
2865"\n"
2866"lookup_error(errors) -> handler\n"
2867"\n"
2868"Return the error handler for the specified error handling name or raise a\n"
2869"LookupError, if no handler exists under this name.");
2870
2871#define _CODECS_LOOKUP_ERROR_METHODDEF \
2872 {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
2873
2874static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002875_codecs_lookup_error_impl(PyObject *module, const char *name);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002876
2877static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002878_codecs_lookup_error(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002879{
2880 PyObject *return_value = NULL;
2881 const char *name;
2882
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002883 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002884 _PyArg_BadArgument("lookup_error", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002885 goto exit;
2886 }
2887 Py_ssize_t name_length;
2888 name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2889 if (name == NULL) {
2890 goto exit;
2891 }
2892 if (strlen(name) != (size_t)name_length) {
2893 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002894 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002895 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002896 return_value = _codecs_lookup_error_impl(module, name);
2897
2898exit:
2899 return return_value;
2900}
2901
2902#ifndef _CODECS_MBCS_DECODE_METHODDEF
2903 #define _CODECS_MBCS_DECODE_METHODDEF
2904#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
2905
Steve Dowerf5aba582016-09-06 19:42:27 -07002906#ifndef _CODECS_OEM_DECODE_METHODDEF
2907 #define _CODECS_OEM_DECODE_METHODDEF
2908#endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
2909
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002910#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
2911 #define _CODECS_CODE_PAGE_DECODE_METHODDEF
2912#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
2913
2914#ifndef _CODECS_MBCS_ENCODE_METHODDEF
2915 #define _CODECS_MBCS_ENCODE_METHODDEF
2916#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
2917
Steve Dowerf5aba582016-09-06 19:42:27 -07002918#ifndef _CODECS_OEM_ENCODE_METHODDEF
2919 #define _CODECS_OEM_ENCODE_METHODDEF
2920#endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
2921
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002922#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
2923 #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
2924#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002925/*[clinic end generated code: output=59726a305e4ec24a input=a9049054013a1b77]*/