/src/cpython/Modules/clinic/_codecsmodule.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_BadArgument() |
10 | | |
11 | | PyDoc_STRVAR(_codecs_register__doc__, |
12 | | "register($module, search_function, /)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Register a codec search function.\n" |
16 | | "\n" |
17 | | "Search functions are expected to take one argument, the encoding\n" |
18 | | "name in all lower case letters, and either return None, or a tuple\n" |
19 | | "of functions (encoder, decoder, stream_reader, stream_writer) (or\n" |
20 | | "a CodecInfo object)."); |
21 | | |
22 | | #define _CODECS_REGISTER_METHODDEF \ |
23 | | {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__}, |
24 | | |
25 | | PyDoc_STRVAR(_codecs_unregister__doc__, |
26 | | "unregister($module, search_function, /)\n" |
27 | | "--\n" |
28 | | "\n" |
29 | | "Unregister a codec search function and clear the registry\'s cache.\n" |
30 | | "\n" |
31 | | "If the search function is not registered, do nothing."); |
32 | | |
33 | | #define _CODECS_UNREGISTER_METHODDEF \ |
34 | | {"unregister", (PyCFunction)_codecs_unregister, METH_O, _codecs_unregister__doc__}, |
35 | | |
36 | | PyDoc_STRVAR(_codecs_lookup__doc__, |
37 | | "lookup($module, encoding, /)\n" |
38 | | "--\n" |
39 | | "\n" |
40 | | "Looks up a codec tuple in the Python codec registry and returns a CodecInfo object."); |
41 | | |
42 | | #define _CODECS_LOOKUP_METHODDEF \ |
43 | | {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__}, |
44 | | |
45 | | static PyObject * |
46 | | _codecs_lookup_impl(PyObject *module, const char *encoding); |
47 | | |
48 | | static PyObject * |
49 | | _codecs_lookup(PyObject *module, PyObject *arg) |
50 | 334k | { |
51 | 334k | PyObject *return_value = NULL; |
52 | 334k | const char *encoding; |
53 | | |
54 | 334k | if (!PyUnicode_Check(arg)) { |
55 | 0 | _PyArg_BadArgument("lookup", "argument", "str", arg); |
56 | 0 | goto exit; |
57 | 0 | } |
58 | 334k | Py_ssize_t encoding_length; |
59 | 334k | encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length); |
60 | 334k | if (encoding == NULL) { |
61 | 206 | goto exit; |
62 | 206 | } |
63 | 334k | if (strlen(encoding) != (size_t)encoding_length) { |
64 | 488 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
65 | 488 | goto exit; |
66 | 488 | } |
67 | 333k | return_value = _codecs_lookup_impl(module, encoding); |
68 | | |
69 | 334k | exit: |
70 | 334k | return return_value; |
71 | 333k | } |
72 | | |
73 | | PyDoc_STRVAR(_codecs_encode__doc__, |
74 | | "encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n" |
75 | | "--\n" |
76 | | "\n" |
77 | | "Encodes obj using the codec registered for encoding.\n" |
78 | | "\n" |
79 | | "The default encoding is \'utf-8\'. errors may be given to set a\n" |
80 | | "different error handling scheme. Default is \'strict\' meaning that\n" |
81 | | "encoding errors raise a ValueError. Other possible values are \'ignore\',\n" |
82 | | "\'replace\' and \'backslashreplace\' as well as any other name registered\n" |
83 | | "with codecs.register_error that can handle ValueErrors."); |
84 | | |
85 | | #define _CODECS_ENCODE_METHODDEF \ |
86 | | {"encode", _PyCFunction_CAST(_codecs_encode), METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__}, |
87 | | |
88 | | static PyObject * |
89 | | _codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding, |
90 | | const char *errors); |
91 | | |
92 | | static PyObject * |
93 | | _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
94 | 0 | { |
95 | 0 | PyObject *return_value = NULL; |
96 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
97 | |
|
98 | 0 | #define NUM_KEYWORDS 3 |
99 | 0 | static struct { |
100 | 0 | PyGC_Head _this_is_not_used; |
101 | 0 | PyObject_VAR_HEAD |
102 | 0 | Py_hash_t ob_hash; |
103 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
104 | 0 | } _kwtuple = { |
105 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
106 | 0 | .ob_hash = -1, |
107 | 0 | .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), }, |
108 | 0 | }; |
109 | 0 | #undef NUM_KEYWORDS |
110 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
111 | |
|
112 | | #else // !Py_BUILD_CORE |
113 | | # define KWTUPLE NULL |
114 | | #endif // !Py_BUILD_CORE |
115 | |
|
116 | 0 | static const char * const _keywords[] = {"obj", "encoding", "errors", NULL}; |
117 | 0 | static _PyArg_Parser _parser = { |
118 | 0 | .keywords = _keywords, |
119 | 0 | .fname = "encode", |
120 | 0 | .kwtuple = KWTUPLE, |
121 | 0 | }; |
122 | 0 | #undef KWTUPLE |
123 | 0 | PyObject *argsbuf[3]; |
124 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
125 | 0 | PyObject *obj; |
126 | 0 | const char *encoding = NULL; |
127 | 0 | const char *errors = NULL; |
128 | |
|
129 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
130 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
131 | 0 | if (!args) { |
132 | 0 | goto exit; |
133 | 0 | } |
134 | 0 | obj = args[0]; |
135 | 0 | if (!noptargs) { |
136 | 0 | goto skip_optional_pos; |
137 | 0 | } |
138 | 0 | if (args[1]) { |
139 | 0 | if (!PyUnicode_Check(args[1])) { |
140 | 0 | _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]); |
141 | 0 | goto exit; |
142 | 0 | } |
143 | 0 | Py_ssize_t encoding_length; |
144 | 0 | encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); |
145 | 0 | if (encoding == NULL) { |
146 | 0 | goto exit; |
147 | 0 | } |
148 | 0 | if (strlen(encoding) != (size_t)encoding_length) { |
149 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
150 | 0 | goto exit; |
151 | 0 | } |
152 | 0 | if (!--noptargs) { |
153 | 0 | goto skip_optional_pos; |
154 | 0 | } |
155 | 0 | } |
156 | 0 | if (!PyUnicode_Check(args[2])) { |
157 | 0 | _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]); |
158 | 0 | goto exit; |
159 | 0 | } |
160 | 0 | Py_ssize_t errors_length; |
161 | 0 | errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
162 | 0 | if (errors == NULL) { |
163 | 0 | goto exit; |
164 | 0 | } |
165 | 0 | if (strlen(errors) != (size_t)errors_length) { |
166 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
167 | 0 | goto exit; |
168 | 0 | } |
169 | 0 | skip_optional_pos: |
170 | 0 | return_value = _codecs_encode_impl(module, obj, encoding, errors); |
171 | |
|
172 | 0 | exit: |
173 | 0 | return return_value; |
174 | 0 | } |
175 | | |
176 | | PyDoc_STRVAR(_codecs_decode__doc__, |
177 | | "decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n" |
178 | | "--\n" |
179 | | "\n" |
180 | | "Decodes obj using the codec registered for encoding.\n" |
181 | | "\n" |
182 | | "Default encoding is \'utf-8\'. errors may be given to set a\n" |
183 | | "different error handling scheme. Default is \'strict\' meaning that\n" |
184 | | "encoding errors raise a ValueError. Other possible values are \'ignore\',\n" |
185 | | "\'replace\' and \'backslashreplace\' as well as any other name registered\n" |
186 | | "with codecs.register_error that can handle ValueErrors."); |
187 | | |
188 | | #define _CODECS_DECODE_METHODDEF \ |
189 | | {"decode", _PyCFunction_CAST(_codecs_decode), METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__}, |
190 | | |
191 | | static PyObject * |
192 | | _codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding, |
193 | | const char *errors); |
194 | | |
195 | | static PyObject * |
196 | | _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
197 | 0 | { |
198 | 0 | PyObject *return_value = NULL; |
199 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
200 | |
|
201 | 0 | #define NUM_KEYWORDS 3 |
202 | 0 | static struct { |
203 | 0 | PyGC_Head _this_is_not_used; |
204 | 0 | PyObject_VAR_HEAD |
205 | 0 | Py_hash_t ob_hash; |
206 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
207 | 0 | } _kwtuple = { |
208 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
209 | 0 | .ob_hash = -1, |
210 | 0 | .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), }, |
211 | 0 | }; |
212 | 0 | #undef NUM_KEYWORDS |
213 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
214 | |
|
215 | | #else // !Py_BUILD_CORE |
216 | | # define KWTUPLE NULL |
217 | | #endif // !Py_BUILD_CORE |
218 | |
|
219 | 0 | static const char * const _keywords[] = {"obj", "encoding", "errors", NULL}; |
220 | 0 | static _PyArg_Parser _parser = { |
221 | 0 | .keywords = _keywords, |
222 | 0 | .fname = "decode", |
223 | 0 | .kwtuple = KWTUPLE, |
224 | 0 | }; |
225 | 0 | #undef KWTUPLE |
226 | 0 | PyObject *argsbuf[3]; |
227 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
228 | 0 | PyObject *obj; |
229 | 0 | const char *encoding = NULL; |
230 | 0 | const char *errors = NULL; |
231 | |
|
232 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
233 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
234 | 0 | if (!args) { |
235 | 0 | goto exit; |
236 | 0 | } |
237 | 0 | obj = args[0]; |
238 | 0 | if (!noptargs) { |
239 | 0 | goto skip_optional_pos; |
240 | 0 | } |
241 | 0 | if (args[1]) { |
242 | 0 | if (!PyUnicode_Check(args[1])) { |
243 | 0 | _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]); |
244 | 0 | goto exit; |
245 | 0 | } |
246 | 0 | Py_ssize_t encoding_length; |
247 | 0 | encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); |
248 | 0 | if (encoding == NULL) { |
249 | 0 | goto exit; |
250 | 0 | } |
251 | 0 | if (strlen(encoding) != (size_t)encoding_length) { |
252 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
253 | 0 | goto exit; |
254 | 0 | } |
255 | 0 | if (!--noptargs) { |
256 | 0 | goto skip_optional_pos; |
257 | 0 | } |
258 | 0 | } |
259 | 0 | if (!PyUnicode_Check(args[2])) { |
260 | 0 | _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]); |
261 | 0 | goto exit; |
262 | 0 | } |
263 | 0 | Py_ssize_t errors_length; |
264 | 0 | errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
265 | 0 | if (errors == NULL) { |
266 | 0 | goto exit; |
267 | 0 | } |
268 | 0 | if (strlen(errors) != (size_t)errors_length) { |
269 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
270 | 0 | goto exit; |
271 | 0 | } |
272 | 0 | skip_optional_pos: |
273 | 0 | return_value = _codecs_decode_impl(module, obj, encoding, errors); |
274 | |
|
275 | 0 | exit: |
276 | 0 | return return_value; |
277 | 0 | } |
278 | | |
279 | | PyDoc_STRVAR(_codecs_escape_decode__doc__, |
280 | | "escape_decode($module, data, errors=None, /)\n" |
281 | | "--\n" |
282 | | "\n"); |
283 | | |
284 | | #define _CODECS_ESCAPE_DECODE_METHODDEF \ |
285 | | {"escape_decode", _PyCFunction_CAST(_codecs_escape_decode), METH_FASTCALL, _codecs_escape_decode__doc__}, |
286 | | |
287 | | static PyObject * |
288 | | _codecs_escape_decode_impl(PyObject *module, Py_buffer *data, |
289 | | const char *errors); |
290 | | |
291 | | static PyObject * |
292 | | _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
293 | 0 | { |
294 | 0 | PyObject *return_value = NULL; |
295 | 0 | Py_buffer data = {NULL, NULL}; |
296 | 0 | const char *errors = NULL; |
297 | |
|
298 | 0 | if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) { |
299 | 0 | goto exit; |
300 | 0 | } |
301 | 0 | if (PyUnicode_Check(args[0])) { |
302 | 0 | Py_ssize_t len; |
303 | 0 | const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
304 | 0 | if (ptr == NULL) { |
305 | 0 | goto exit; |
306 | 0 | } |
307 | 0 | if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
308 | 0 | goto exit; |
309 | 0 | } |
310 | 0 | } |
311 | 0 | else { /* any bytes-like object */ |
312 | 0 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
313 | 0 | goto exit; |
314 | 0 | } |
315 | 0 | } |
316 | 0 | if (nargs < 2) { |
317 | 0 | goto skip_optional; |
318 | 0 | } |
319 | 0 | if (args[1] == Py_None) { |
320 | 0 | errors = NULL; |
321 | 0 | } |
322 | 0 | else if (PyUnicode_Check(args[1])) { |
323 | 0 | Py_ssize_t errors_length; |
324 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
325 | 0 | if (errors == NULL) { |
326 | 0 | goto exit; |
327 | 0 | } |
328 | 0 | if (strlen(errors) != (size_t)errors_length) { |
329 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
330 | 0 | goto exit; |
331 | 0 | } |
332 | 0 | } |
333 | 0 | else { |
334 | 0 | _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]); |
335 | 0 | goto exit; |
336 | 0 | } |
337 | 0 | skip_optional: |
338 | 0 | return_value = _codecs_escape_decode_impl(module, &data, errors); |
339 | |
|
340 | 0 | exit: |
341 | | /* Cleanup for data */ |
342 | 0 | if (data.obj) { |
343 | 0 | PyBuffer_Release(&data); |
344 | 0 | } |
345 | |
|
346 | 0 | return return_value; |
347 | 0 | } |
348 | | |
349 | | PyDoc_STRVAR(_codecs_escape_encode__doc__, |
350 | | "escape_encode($module, data, errors=None, /)\n" |
351 | | "--\n" |
352 | | "\n"); |
353 | | |
354 | | #define _CODECS_ESCAPE_ENCODE_METHODDEF \ |
355 | | {"escape_encode", _PyCFunction_CAST(_codecs_escape_encode), METH_FASTCALL, _codecs_escape_encode__doc__}, |
356 | | |
357 | | static PyObject * |
358 | | _codecs_escape_encode_impl(PyObject *module, PyObject *data, |
359 | | const char *errors); |
360 | | |
361 | | static PyObject * |
362 | | _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
363 | 0 | { |
364 | 0 | PyObject *return_value = NULL; |
365 | 0 | PyObject *data; |
366 | 0 | const char *errors = NULL; |
367 | |
|
368 | 0 | if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) { |
369 | 0 | goto exit; |
370 | 0 | } |
371 | 0 | if (!PyBytes_Check(args[0])) { |
372 | 0 | _PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]); |
373 | 0 | goto exit; |
374 | 0 | } |
375 | 0 | data = args[0]; |
376 | 0 | if (nargs < 2) { |
377 | 0 | goto skip_optional; |
378 | 0 | } |
379 | 0 | if (args[1] == Py_None) { |
380 | 0 | errors = NULL; |
381 | 0 | } |
382 | 0 | else if (PyUnicode_Check(args[1])) { |
383 | 0 | Py_ssize_t errors_length; |
384 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
385 | 0 | if (errors == NULL) { |
386 | 0 | goto exit; |
387 | 0 | } |
388 | 0 | if (strlen(errors) != (size_t)errors_length) { |
389 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
390 | 0 | goto exit; |
391 | 0 | } |
392 | 0 | } |
393 | 0 | else { |
394 | 0 | _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]); |
395 | 0 | goto exit; |
396 | 0 | } |
397 | 0 | skip_optional: |
398 | 0 | return_value = _codecs_escape_encode_impl(module, data, errors); |
399 | |
|
400 | 0 | exit: |
401 | 0 | return return_value; |
402 | 0 | } |
403 | | |
404 | | PyDoc_STRVAR(_codecs_utf_7_decode__doc__, |
405 | | "utf_7_decode($module, data, errors=None, final=False, /)\n" |
406 | | "--\n" |
407 | | "\n"); |
408 | | |
409 | | #define _CODECS_UTF_7_DECODE_METHODDEF \ |
410 | | {"utf_7_decode", _PyCFunction_CAST(_codecs_utf_7_decode), METH_FASTCALL, _codecs_utf_7_decode__doc__}, |
411 | | |
412 | | static PyObject * |
413 | | _codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data, |
414 | | const char *errors, int final); |
415 | | |
416 | | static PyObject * |
417 | | _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
418 | 22.1k | { |
419 | 22.1k | PyObject *return_value = NULL; |
420 | 22.1k | Py_buffer data = {NULL, NULL}; |
421 | 22.1k | const char *errors = NULL; |
422 | 22.1k | int final = 0; |
423 | | |
424 | 22.1k | if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) { |
425 | 0 | goto exit; |
426 | 0 | } |
427 | 22.1k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
428 | 0 | goto exit; |
429 | 0 | } |
430 | 22.1k | if (nargs < 2) { |
431 | 0 | goto skip_optional; |
432 | 0 | } |
433 | 22.1k | if (args[1] == Py_None) { |
434 | 0 | errors = NULL; |
435 | 0 | } |
436 | 22.1k | else if (PyUnicode_Check(args[1])) { |
437 | 22.1k | Py_ssize_t errors_length; |
438 | 22.1k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
439 | 22.1k | if (errors == NULL) { |
440 | 0 | goto exit; |
441 | 0 | } |
442 | 22.1k | if (strlen(errors) != (size_t)errors_length) { |
443 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
444 | 0 | goto exit; |
445 | 0 | } |
446 | 22.1k | } |
447 | 0 | else { |
448 | 0 | _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]); |
449 | 0 | goto exit; |
450 | 0 | } |
451 | 22.1k | if (nargs < 3) { |
452 | 0 | goto skip_optional; |
453 | 0 | } |
454 | 22.1k | final = PyObject_IsTrue(args[2]); |
455 | 22.1k | if (final < 0) { |
456 | 0 | goto exit; |
457 | 0 | } |
458 | 22.1k | skip_optional: |
459 | 22.1k | return_value = _codecs_utf_7_decode_impl(module, &data, errors, final); |
460 | | |
461 | 22.1k | exit: |
462 | | /* Cleanup for data */ |
463 | 22.1k | if (data.obj) { |
464 | 22.1k | PyBuffer_Release(&data); |
465 | 22.1k | } |
466 | | |
467 | 22.1k | return return_value; |
468 | 22.1k | } |
469 | | |
470 | | PyDoc_STRVAR(_codecs_utf_8_decode__doc__, |
471 | | "utf_8_decode($module, data, errors=None, final=False, /)\n" |
472 | | "--\n" |
473 | | "\n"); |
474 | | |
475 | | #define _CODECS_UTF_8_DECODE_METHODDEF \ |
476 | | {"utf_8_decode", _PyCFunction_CAST(_codecs_utf_8_decode), METH_FASTCALL, _codecs_utf_8_decode__doc__}, |
477 | | |
478 | | static PyObject * |
479 | | _codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data, |
480 | | const char *errors, int final); |
481 | | |
482 | | static PyObject * |
483 | | _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
484 | 62.1k | { |
485 | 62.1k | PyObject *return_value = NULL; |
486 | 62.1k | Py_buffer data = {NULL, NULL}; |
487 | 62.1k | const char *errors = NULL; |
488 | 62.1k | int final = 0; |
489 | | |
490 | 62.1k | if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) { |
491 | 0 | goto exit; |
492 | 0 | } |
493 | 62.1k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
494 | 0 | goto exit; |
495 | 0 | } |
496 | 62.1k | if (nargs < 2) { |
497 | 0 | goto skip_optional; |
498 | 0 | } |
499 | 62.1k | if (args[1] == Py_None) { |
500 | 0 | errors = NULL; |
501 | 0 | } |
502 | 62.1k | else if (PyUnicode_Check(args[1])) { |
503 | 62.1k | Py_ssize_t errors_length; |
504 | 62.1k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
505 | 62.1k | if (errors == NULL) { |
506 | 0 | goto exit; |
507 | 0 | } |
508 | 62.1k | if (strlen(errors) != (size_t)errors_length) { |
509 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
510 | 0 | goto exit; |
511 | 0 | } |
512 | 62.1k | } |
513 | 0 | else { |
514 | 0 | _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]); |
515 | 0 | goto exit; |
516 | 0 | } |
517 | 62.1k | if (nargs < 3) { |
518 | 0 | goto skip_optional; |
519 | 0 | } |
520 | 62.1k | final = PyObject_IsTrue(args[2]); |
521 | 62.1k | if (final < 0) { |
522 | 0 | goto exit; |
523 | 0 | } |
524 | 62.1k | skip_optional: |
525 | 62.1k | return_value = _codecs_utf_8_decode_impl(module, &data, errors, final); |
526 | | |
527 | 62.1k | exit: |
528 | | /* Cleanup for data */ |
529 | 62.1k | if (data.obj) { |
530 | 62.1k | PyBuffer_Release(&data); |
531 | 62.1k | } |
532 | | |
533 | 62.1k | return return_value; |
534 | 62.1k | } |
535 | | |
536 | | PyDoc_STRVAR(_codecs_utf_16_decode__doc__, |
537 | | "utf_16_decode($module, data, errors=None, final=False, /)\n" |
538 | | "--\n" |
539 | | "\n"); |
540 | | |
541 | | #define _CODECS_UTF_16_DECODE_METHODDEF \ |
542 | | {"utf_16_decode", _PyCFunction_CAST(_codecs_utf_16_decode), METH_FASTCALL, _codecs_utf_16_decode__doc__}, |
543 | | |
544 | | static PyObject * |
545 | | _codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data, |
546 | | const char *errors, int final); |
547 | | |
548 | | static PyObject * |
549 | | _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
550 | 16.7k | { |
551 | 16.7k | PyObject *return_value = NULL; |
552 | 16.7k | Py_buffer data = {NULL, NULL}; |
553 | 16.7k | const char *errors = NULL; |
554 | 16.7k | int final = 0; |
555 | | |
556 | 16.7k | if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) { |
557 | 0 | goto exit; |
558 | 0 | } |
559 | 16.7k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
560 | 0 | goto exit; |
561 | 0 | } |
562 | 16.7k | if (nargs < 2) { |
563 | 0 | goto skip_optional; |
564 | 0 | } |
565 | 16.7k | if (args[1] == Py_None) { |
566 | 0 | errors = NULL; |
567 | 0 | } |
568 | 16.7k | else if (PyUnicode_Check(args[1])) { |
569 | 16.7k | Py_ssize_t errors_length; |
570 | 16.7k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
571 | 16.7k | if (errors == NULL) { |
572 | 0 | goto exit; |
573 | 0 | } |
574 | 16.7k | if (strlen(errors) != (size_t)errors_length) { |
575 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
576 | 0 | goto exit; |
577 | 0 | } |
578 | 16.7k | } |
579 | 0 | else { |
580 | 0 | _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]); |
581 | 0 | goto exit; |
582 | 0 | } |
583 | 16.7k | if (nargs < 3) { |
584 | 0 | goto skip_optional; |
585 | 0 | } |
586 | 16.7k | final = PyObject_IsTrue(args[2]); |
587 | 16.7k | if (final < 0) { |
588 | 0 | goto exit; |
589 | 0 | } |
590 | 16.7k | skip_optional: |
591 | 16.7k | return_value = _codecs_utf_16_decode_impl(module, &data, errors, final); |
592 | | |
593 | 16.7k | exit: |
594 | | /* Cleanup for data */ |
595 | 16.7k | if (data.obj) { |
596 | 16.7k | PyBuffer_Release(&data); |
597 | 16.7k | } |
598 | | |
599 | 16.7k | return return_value; |
600 | 16.7k | } |
601 | | |
602 | | PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__, |
603 | | "utf_16_le_decode($module, data, errors=None, final=False, /)\n" |
604 | | "--\n" |
605 | | "\n"); |
606 | | |
607 | | #define _CODECS_UTF_16_LE_DECODE_METHODDEF \ |
608 | | {"utf_16_le_decode", _PyCFunction_CAST(_codecs_utf_16_le_decode), METH_FASTCALL, _codecs_utf_16_le_decode__doc__}, |
609 | | |
610 | | static PyObject * |
611 | | _codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data, |
612 | | const char *errors, int final); |
613 | | |
614 | | static PyObject * |
615 | | _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
616 | 48 | { |
617 | 48 | PyObject *return_value = NULL; |
618 | 48 | Py_buffer data = {NULL, NULL}; |
619 | 48 | const char *errors = NULL; |
620 | 48 | int final = 0; |
621 | | |
622 | 48 | if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) { |
623 | 0 | goto exit; |
624 | 0 | } |
625 | 48 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
626 | 0 | goto exit; |
627 | 0 | } |
628 | 48 | if (nargs < 2) { |
629 | 0 | goto skip_optional; |
630 | 0 | } |
631 | 48 | if (args[1] == Py_None) { |
632 | 0 | errors = NULL; |
633 | 0 | } |
634 | 48 | else if (PyUnicode_Check(args[1])) { |
635 | 48 | Py_ssize_t errors_length; |
636 | 48 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
637 | 48 | if (errors == NULL) { |
638 | 0 | goto exit; |
639 | 0 | } |
640 | 48 | if (strlen(errors) != (size_t)errors_length) { |
641 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
642 | 0 | goto exit; |
643 | 0 | } |
644 | 48 | } |
645 | 0 | else { |
646 | 0 | _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]); |
647 | 0 | goto exit; |
648 | 0 | } |
649 | 48 | if (nargs < 3) { |
650 | 0 | goto skip_optional; |
651 | 0 | } |
652 | 48 | final = PyObject_IsTrue(args[2]); |
653 | 48 | if (final < 0) { |
654 | 0 | goto exit; |
655 | 0 | } |
656 | 48 | skip_optional: |
657 | 48 | return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final); |
658 | | |
659 | 48 | exit: |
660 | | /* Cleanup for data */ |
661 | 48 | if (data.obj) { |
662 | 48 | PyBuffer_Release(&data); |
663 | 48 | } |
664 | | |
665 | 48 | return return_value; |
666 | 48 | } |
667 | | |
668 | | PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__, |
669 | | "utf_16_be_decode($module, data, errors=None, final=False, /)\n" |
670 | | "--\n" |
671 | | "\n"); |
672 | | |
673 | | #define _CODECS_UTF_16_BE_DECODE_METHODDEF \ |
674 | | {"utf_16_be_decode", _PyCFunction_CAST(_codecs_utf_16_be_decode), METH_FASTCALL, _codecs_utf_16_be_decode__doc__}, |
675 | | |
676 | | static PyObject * |
677 | | _codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data, |
678 | | const char *errors, int final); |
679 | | |
680 | | static PyObject * |
681 | | _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
682 | 224 | { |
683 | 224 | PyObject *return_value = NULL; |
684 | 224 | Py_buffer data = {NULL, NULL}; |
685 | 224 | const char *errors = NULL; |
686 | 224 | int final = 0; |
687 | | |
688 | 224 | if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) { |
689 | 0 | goto exit; |
690 | 0 | } |
691 | 224 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
692 | 0 | goto exit; |
693 | 0 | } |
694 | 224 | if (nargs < 2) { |
695 | 0 | goto skip_optional; |
696 | 0 | } |
697 | 224 | if (args[1] == Py_None) { |
698 | 0 | errors = NULL; |
699 | 0 | } |
700 | 224 | else if (PyUnicode_Check(args[1])) { |
701 | 224 | Py_ssize_t errors_length; |
702 | 224 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
703 | 224 | if (errors == NULL) { |
704 | 0 | goto exit; |
705 | 0 | } |
706 | 224 | if (strlen(errors) != (size_t)errors_length) { |
707 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
708 | 0 | goto exit; |
709 | 0 | } |
710 | 224 | } |
711 | 0 | else { |
712 | 0 | _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]); |
713 | 0 | goto exit; |
714 | 0 | } |
715 | 224 | if (nargs < 3) { |
716 | 0 | goto skip_optional; |
717 | 0 | } |
718 | 224 | final = PyObject_IsTrue(args[2]); |
719 | 224 | if (final < 0) { |
720 | 0 | goto exit; |
721 | 0 | } |
722 | 224 | skip_optional: |
723 | 224 | return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final); |
724 | | |
725 | 224 | exit: |
726 | | /* Cleanup for data */ |
727 | 224 | if (data.obj) { |
728 | 224 | PyBuffer_Release(&data); |
729 | 224 | } |
730 | | |
731 | 224 | return return_value; |
732 | 224 | } |
733 | | |
734 | | PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__, |
735 | | "utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" |
736 | | " /)\n" |
737 | | "--\n" |
738 | | "\n"); |
739 | | |
740 | | #define _CODECS_UTF_16_EX_DECODE_METHODDEF \ |
741 | | {"utf_16_ex_decode", _PyCFunction_CAST(_codecs_utf_16_ex_decode), METH_FASTCALL, _codecs_utf_16_ex_decode__doc__}, |
742 | | |
743 | | static PyObject * |
744 | | _codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data, |
745 | | const char *errors, int byteorder, int final); |
746 | | |
747 | | static PyObject * |
748 | | _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
749 | 0 | { |
750 | 0 | PyObject *return_value = NULL; |
751 | 0 | Py_buffer data = {NULL, NULL}; |
752 | 0 | const char *errors = NULL; |
753 | 0 | int byteorder = 0; |
754 | 0 | int final = 0; |
755 | |
|
756 | 0 | if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) { |
757 | 0 | goto exit; |
758 | 0 | } |
759 | 0 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
760 | 0 | goto exit; |
761 | 0 | } |
762 | 0 | if (nargs < 2) { |
763 | 0 | goto skip_optional; |
764 | 0 | } |
765 | 0 | if (args[1] == Py_None) { |
766 | 0 | errors = NULL; |
767 | 0 | } |
768 | 0 | else if (PyUnicode_Check(args[1])) { |
769 | 0 | Py_ssize_t errors_length; |
770 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
771 | 0 | if (errors == NULL) { |
772 | 0 | goto exit; |
773 | 0 | } |
774 | 0 | if (strlen(errors) != (size_t)errors_length) { |
775 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
776 | 0 | goto exit; |
777 | 0 | } |
778 | 0 | } |
779 | 0 | else { |
780 | 0 | _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]); |
781 | 0 | goto exit; |
782 | 0 | } |
783 | 0 | if (nargs < 3) { |
784 | 0 | goto skip_optional; |
785 | 0 | } |
786 | 0 | byteorder = PyLong_AsInt(args[2]); |
787 | 0 | if (byteorder == -1 && PyErr_Occurred()) { |
788 | 0 | goto exit; |
789 | 0 | } |
790 | 0 | if (nargs < 4) { |
791 | 0 | goto skip_optional; |
792 | 0 | } |
793 | 0 | final = PyObject_IsTrue(args[3]); |
794 | 0 | if (final < 0) { |
795 | 0 | goto exit; |
796 | 0 | } |
797 | 0 | skip_optional: |
798 | 0 | return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final); |
799 | |
|
800 | 0 | exit: |
801 | | /* Cleanup for data */ |
802 | 0 | if (data.obj) { |
803 | 0 | PyBuffer_Release(&data); |
804 | 0 | } |
805 | |
|
806 | 0 | return return_value; |
807 | 0 | } |
808 | | |
809 | | PyDoc_STRVAR(_codecs_utf_32_decode__doc__, |
810 | | "utf_32_decode($module, data, errors=None, final=False, /)\n" |
811 | | "--\n" |
812 | | "\n"); |
813 | | |
814 | | #define _CODECS_UTF_32_DECODE_METHODDEF \ |
815 | | {"utf_32_decode", _PyCFunction_CAST(_codecs_utf_32_decode), METH_FASTCALL, _codecs_utf_32_decode__doc__}, |
816 | | |
817 | | static PyObject * |
818 | | _codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data, |
819 | | const char *errors, int final); |
820 | | |
821 | | static PyObject * |
822 | | _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
823 | 51.0k | { |
824 | 51.0k | PyObject *return_value = NULL; |
825 | 51.0k | Py_buffer data = {NULL, NULL}; |
826 | 51.0k | const char *errors = NULL; |
827 | 51.0k | int final = 0; |
828 | | |
829 | 51.0k | if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) { |
830 | 0 | goto exit; |
831 | 0 | } |
832 | 51.0k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
833 | 0 | goto exit; |
834 | 0 | } |
835 | 51.0k | if (nargs < 2) { |
836 | 0 | goto skip_optional; |
837 | 0 | } |
838 | 51.0k | if (args[1] == Py_None) { |
839 | 0 | errors = NULL; |
840 | 0 | } |
841 | 51.0k | else if (PyUnicode_Check(args[1])) { |
842 | 51.0k | Py_ssize_t errors_length; |
843 | 51.0k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
844 | 51.0k | if (errors == NULL) { |
845 | 0 | goto exit; |
846 | 0 | } |
847 | 51.0k | if (strlen(errors) != (size_t)errors_length) { |
848 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
849 | 0 | goto exit; |
850 | 0 | } |
851 | 51.0k | } |
852 | 0 | else { |
853 | 0 | _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]); |
854 | 0 | goto exit; |
855 | 0 | } |
856 | 51.0k | if (nargs < 3) { |
857 | 0 | goto skip_optional; |
858 | 0 | } |
859 | 51.0k | final = PyObject_IsTrue(args[2]); |
860 | 51.0k | if (final < 0) { |
861 | 0 | goto exit; |
862 | 0 | } |
863 | 51.0k | skip_optional: |
864 | 51.0k | return_value = _codecs_utf_32_decode_impl(module, &data, errors, final); |
865 | | |
866 | 51.0k | exit: |
867 | | /* Cleanup for data */ |
868 | 51.0k | if (data.obj) { |
869 | 51.0k | PyBuffer_Release(&data); |
870 | 51.0k | } |
871 | | |
872 | 51.0k | return return_value; |
873 | 51.0k | } |
874 | | |
875 | | PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__, |
876 | | "utf_32_le_decode($module, data, errors=None, final=False, /)\n" |
877 | | "--\n" |
878 | | "\n"); |
879 | | |
880 | | #define _CODECS_UTF_32_LE_DECODE_METHODDEF \ |
881 | | {"utf_32_le_decode", _PyCFunction_CAST(_codecs_utf_32_le_decode), METH_FASTCALL, _codecs_utf_32_le_decode__doc__}, |
882 | | |
883 | | static PyObject * |
884 | | _codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data, |
885 | | const char *errors, int final); |
886 | | |
887 | | static PyObject * |
888 | | _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
889 | 29 | { |
890 | 29 | PyObject *return_value = NULL; |
891 | 29 | Py_buffer data = {NULL, NULL}; |
892 | 29 | const char *errors = NULL; |
893 | 29 | int final = 0; |
894 | | |
895 | 29 | if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) { |
896 | 0 | goto exit; |
897 | 0 | } |
898 | 29 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
899 | 0 | goto exit; |
900 | 0 | } |
901 | 29 | if (nargs < 2) { |
902 | 0 | goto skip_optional; |
903 | 0 | } |
904 | 29 | if (args[1] == Py_None) { |
905 | 0 | errors = NULL; |
906 | 0 | } |
907 | 29 | else if (PyUnicode_Check(args[1])) { |
908 | 29 | Py_ssize_t errors_length; |
909 | 29 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
910 | 29 | if (errors == NULL) { |
911 | 0 | goto exit; |
912 | 0 | } |
913 | 29 | if (strlen(errors) != (size_t)errors_length) { |
914 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
915 | 0 | goto exit; |
916 | 0 | } |
917 | 29 | } |
918 | 0 | else { |
919 | 0 | _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]); |
920 | 0 | goto exit; |
921 | 0 | } |
922 | 29 | if (nargs < 3) { |
923 | 0 | goto skip_optional; |
924 | 0 | } |
925 | 29 | final = PyObject_IsTrue(args[2]); |
926 | 29 | if (final < 0) { |
927 | 0 | goto exit; |
928 | 0 | } |
929 | 29 | skip_optional: |
930 | 29 | return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final); |
931 | | |
932 | 29 | exit: |
933 | | /* Cleanup for data */ |
934 | 29 | if (data.obj) { |
935 | 29 | PyBuffer_Release(&data); |
936 | 29 | } |
937 | | |
938 | 29 | return return_value; |
939 | 29 | } |
940 | | |
941 | | PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__, |
942 | | "utf_32_be_decode($module, data, errors=None, final=False, /)\n" |
943 | | "--\n" |
944 | | "\n"); |
945 | | |
946 | | #define _CODECS_UTF_32_BE_DECODE_METHODDEF \ |
947 | | {"utf_32_be_decode", _PyCFunction_CAST(_codecs_utf_32_be_decode), METH_FASTCALL, _codecs_utf_32_be_decode__doc__}, |
948 | | |
949 | | static PyObject * |
950 | | _codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data, |
951 | | const char *errors, int final); |
952 | | |
953 | | static PyObject * |
954 | | _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
955 | 81 | { |
956 | 81 | PyObject *return_value = NULL; |
957 | 81 | Py_buffer data = {NULL, NULL}; |
958 | 81 | const char *errors = NULL; |
959 | 81 | int final = 0; |
960 | | |
961 | 81 | if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) { |
962 | 0 | goto exit; |
963 | 0 | } |
964 | 81 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
965 | 0 | goto exit; |
966 | 0 | } |
967 | 81 | if (nargs < 2) { |
968 | 0 | goto skip_optional; |
969 | 0 | } |
970 | 81 | if (args[1] == Py_None) { |
971 | 0 | errors = NULL; |
972 | 0 | } |
973 | 81 | else if (PyUnicode_Check(args[1])) { |
974 | 81 | Py_ssize_t errors_length; |
975 | 81 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
976 | 81 | if (errors == NULL) { |
977 | 0 | goto exit; |
978 | 0 | } |
979 | 81 | if (strlen(errors) != (size_t)errors_length) { |
980 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
981 | 0 | goto exit; |
982 | 0 | } |
983 | 81 | } |
984 | 0 | else { |
985 | 0 | _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]); |
986 | 0 | goto exit; |
987 | 0 | } |
988 | 81 | if (nargs < 3) { |
989 | 0 | goto skip_optional; |
990 | 0 | } |
991 | 81 | final = PyObject_IsTrue(args[2]); |
992 | 81 | if (final < 0) { |
993 | 0 | goto exit; |
994 | 0 | } |
995 | 81 | skip_optional: |
996 | 81 | return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final); |
997 | | |
998 | 81 | exit: |
999 | | /* Cleanup for data */ |
1000 | 81 | if (data.obj) { |
1001 | 81 | PyBuffer_Release(&data); |
1002 | 81 | } |
1003 | | |
1004 | 81 | return return_value; |
1005 | 81 | } |
1006 | | |
1007 | | PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__, |
1008 | | "utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" |
1009 | | " /)\n" |
1010 | | "--\n" |
1011 | | "\n"); |
1012 | | |
1013 | | #define _CODECS_UTF_32_EX_DECODE_METHODDEF \ |
1014 | | {"utf_32_ex_decode", _PyCFunction_CAST(_codecs_utf_32_ex_decode), METH_FASTCALL, _codecs_utf_32_ex_decode__doc__}, |
1015 | | |
1016 | | static PyObject * |
1017 | | _codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data, |
1018 | | const char *errors, int byteorder, int final); |
1019 | | |
1020 | | static PyObject * |
1021 | | _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1022 | 0 | { |
1023 | 0 | PyObject *return_value = NULL; |
1024 | 0 | Py_buffer data = {NULL, NULL}; |
1025 | 0 | const char *errors = NULL; |
1026 | 0 | int byteorder = 0; |
1027 | 0 | int final = 0; |
1028 | |
|
1029 | 0 | if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) { |
1030 | 0 | goto exit; |
1031 | 0 | } |
1032 | 0 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1033 | 0 | goto exit; |
1034 | 0 | } |
1035 | 0 | if (nargs < 2) { |
1036 | 0 | goto skip_optional; |
1037 | 0 | } |
1038 | 0 | if (args[1] == Py_None) { |
1039 | 0 | errors = NULL; |
1040 | 0 | } |
1041 | 0 | else if (PyUnicode_Check(args[1])) { |
1042 | 0 | Py_ssize_t errors_length; |
1043 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1044 | 0 | if (errors == NULL) { |
1045 | 0 | goto exit; |
1046 | 0 | } |
1047 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1048 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1049 | 0 | goto exit; |
1050 | 0 | } |
1051 | 0 | } |
1052 | 0 | else { |
1053 | 0 | _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]); |
1054 | 0 | goto exit; |
1055 | 0 | } |
1056 | 0 | if (nargs < 3) { |
1057 | 0 | goto skip_optional; |
1058 | 0 | } |
1059 | 0 | byteorder = PyLong_AsInt(args[2]); |
1060 | 0 | if (byteorder == -1 && PyErr_Occurred()) { |
1061 | 0 | goto exit; |
1062 | 0 | } |
1063 | 0 | if (nargs < 4) { |
1064 | 0 | goto skip_optional; |
1065 | 0 | } |
1066 | 0 | final = PyObject_IsTrue(args[3]); |
1067 | 0 | if (final < 0) { |
1068 | 0 | goto exit; |
1069 | 0 | } |
1070 | 0 | skip_optional: |
1071 | 0 | return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final); |
1072 | |
|
1073 | 0 | exit: |
1074 | | /* Cleanup for data */ |
1075 | 0 | if (data.obj) { |
1076 | 0 | PyBuffer_Release(&data); |
1077 | 0 | } |
1078 | |
|
1079 | 0 | return return_value; |
1080 | 0 | } |
1081 | | |
1082 | | PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__, |
1083 | | "unicode_escape_decode($module, data, errors=None, final=True, /)\n" |
1084 | | "--\n" |
1085 | | "\n"); |
1086 | | |
1087 | | #define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \ |
1088 | | {"unicode_escape_decode", _PyCFunction_CAST(_codecs_unicode_escape_decode), METH_FASTCALL, _codecs_unicode_escape_decode__doc__}, |
1089 | | |
1090 | | static PyObject * |
1091 | | _codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, |
1092 | | const char *errors, int final); |
1093 | | |
1094 | | static PyObject * |
1095 | | _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1096 | 545 | { |
1097 | 545 | PyObject *return_value = NULL; |
1098 | 545 | Py_buffer data = {NULL, NULL}; |
1099 | 545 | const char *errors = NULL; |
1100 | 545 | int final = 1; |
1101 | | |
1102 | 545 | if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 3)) { |
1103 | 0 | goto exit; |
1104 | 0 | } |
1105 | 545 | if (PyUnicode_Check(args[0])) { |
1106 | 0 | Py_ssize_t len; |
1107 | 0 | const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
1108 | 0 | if (ptr == NULL) { |
1109 | 0 | goto exit; |
1110 | 0 | } |
1111 | 0 | if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
1112 | 0 | goto exit; |
1113 | 0 | } |
1114 | 0 | } |
1115 | 545 | else { /* any bytes-like object */ |
1116 | 545 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1117 | 0 | goto exit; |
1118 | 0 | } |
1119 | 545 | } |
1120 | 545 | if (nargs < 2) { |
1121 | 545 | goto skip_optional; |
1122 | 545 | } |
1123 | 0 | if (args[1] == Py_None) { |
1124 | 0 | errors = NULL; |
1125 | 0 | } |
1126 | 0 | else if (PyUnicode_Check(args[1])) { |
1127 | 0 | Py_ssize_t errors_length; |
1128 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1129 | 0 | if (errors == NULL) { |
1130 | 0 | goto exit; |
1131 | 0 | } |
1132 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1133 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1134 | 0 | goto exit; |
1135 | 0 | } |
1136 | 0 | } |
1137 | 0 | else { |
1138 | 0 | _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]); |
1139 | 0 | goto exit; |
1140 | 0 | } |
1141 | 0 | if (nargs < 3) { |
1142 | 0 | goto skip_optional; |
1143 | 0 | } |
1144 | 0 | final = PyObject_IsTrue(args[2]); |
1145 | 0 | if (final < 0) { |
1146 | 0 | goto exit; |
1147 | 0 | } |
1148 | 545 | skip_optional: |
1149 | 545 | return_value = _codecs_unicode_escape_decode_impl(module, &data, errors, final); |
1150 | | |
1151 | 545 | exit: |
1152 | | /* Cleanup for data */ |
1153 | 545 | if (data.obj) { |
1154 | 545 | PyBuffer_Release(&data); |
1155 | 545 | } |
1156 | | |
1157 | 545 | return return_value; |
1158 | 545 | } |
1159 | | |
1160 | | PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__, |
1161 | | "raw_unicode_escape_decode($module, data, errors=None, final=True, /)\n" |
1162 | | "--\n" |
1163 | | "\n"); |
1164 | | |
1165 | | #define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \ |
1166 | | {"raw_unicode_escape_decode", _PyCFunction_CAST(_codecs_raw_unicode_escape_decode), METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__}, |
1167 | | |
1168 | | static PyObject * |
1169 | | _codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, |
1170 | | const char *errors, int final); |
1171 | | |
1172 | | static PyObject * |
1173 | | _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1174 | 112 | { |
1175 | 112 | PyObject *return_value = NULL; |
1176 | 112 | Py_buffer data = {NULL, NULL}; |
1177 | 112 | const char *errors = NULL; |
1178 | 112 | int final = 1; |
1179 | | |
1180 | 112 | if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 3)) { |
1181 | 0 | goto exit; |
1182 | 0 | } |
1183 | 112 | if (PyUnicode_Check(args[0])) { |
1184 | 0 | Py_ssize_t len; |
1185 | 0 | const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
1186 | 0 | if (ptr == NULL) { |
1187 | 0 | goto exit; |
1188 | 0 | } |
1189 | 0 | if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
1190 | 0 | goto exit; |
1191 | 0 | } |
1192 | 0 | } |
1193 | 112 | else { /* any bytes-like object */ |
1194 | 112 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1195 | 0 | goto exit; |
1196 | 0 | } |
1197 | 112 | } |
1198 | 112 | if (nargs < 2) { |
1199 | 112 | goto skip_optional; |
1200 | 112 | } |
1201 | 0 | if (args[1] == Py_None) { |
1202 | 0 | errors = NULL; |
1203 | 0 | } |
1204 | 0 | else if (PyUnicode_Check(args[1])) { |
1205 | 0 | Py_ssize_t errors_length; |
1206 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1207 | 0 | if (errors == NULL) { |
1208 | 0 | goto exit; |
1209 | 0 | } |
1210 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1211 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1212 | 0 | goto exit; |
1213 | 0 | } |
1214 | 0 | } |
1215 | 0 | else { |
1216 | 0 | _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]); |
1217 | 0 | goto exit; |
1218 | 0 | } |
1219 | 0 | if (nargs < 3) { |
1220 | 0 | goto skip_optional; |
1221 | 0 | } |
1222 | 0 | final = PyObject_IsTrue(args[2]); |
1223 | 0 | if (final < 0) { |
1224 | 0 | goto exit; |
1225 | 0 | } |
1226 | 112 | skip_optional: |
1227 | 112 | return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors, final); |
1228 | | |
1229 | 112 | exit: |
1230 | | /* Cleanup for data */ |
1231 | 112 | if (data.obj) { |
1232 | 112 | PyBuffer_Release(&data); |
1233 | 112 | } |
1234 | | |
1235 | 112 | return return_value; |
1236 | 112 | } |
1237 | | |
1238 | | PyDoc_STRVAR(_codecs_latin_1_decode__doc__, |
1239 | | "latin_1_decode($module, data, errors=None, /)\n" |
1240 | | "--\n" |
1241 | | "\n"); |
1242 | | |
1243 | | #define _CODECS_LATIN_1_DECODE_METHODDEF \ |
1244 | | {"latin_1_decode", _PyCFunction_CAST(_codecs_latin_1_decode), METH_FASTCALL, _codecs_latin_1_decode__doc__}, |
1245 | | |
1246 | | static PyObject * |
1247 | | _codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data, |
1248 | | const char *errors); |
1249 | | |
1250 | | static PyObject * |
1251 | | _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1252 | 4.09k | { |
1253 | 4.09k | PyObject *return_value = NULL; |
1254 | 4.09k | Py_buffer data = {NULL, NULL}; |
1255 | 4.09k | const char *errors = NULL; |
1256 | | |
1257 | 4.09k | if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) { |
1258 | 0 | goto exit; |
1259 | 0 | } |
1260 | 4.09k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1261 | 0 | goto exit; |
1262 | 0 | } |
1263 | 4.09k | if (nargs < 2) { |
1264 | 931 | goto skip_optional; |
1265 | 931 | } |
1266 | 3.16k | if (args[1] == Py_None) { |
1267 | 0 | errors = NULL; |
1268 | 0 | } |
1269 | 3.16k | else if (PyUnicode_Check(args[1])) { |
1270 | 3.16k | Py_ssize_t errors_length; |
1271 | 3.16k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1272 | 3.16k | if (errors == NULL) { |
1273 | 0 | goto exit; |
1274 | 0 | } |
1275 | 3.16k | if (strlen(errors) != (size_t)errors_length) { |
1276 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1277 | 0 | goto exit; |
1278 | 0 | } |
1279 | 3.16k | } |
1280 | 0 | else { |
1281 | 0 | _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]); |
1282 | 0 | goto exit; |
1283 | 0 | } |
1284 | 4.09k | skip_optional: |
1285 | 4.09k | return_value = _codecs_latin_1_decode_impl(module, &data, errors); |
1286 | | |
1287 | 4.09k | exit: |
1288 | | /* Cleanup for data */ |
1289 | 4.09k | if (data.obj) { |
1290 | 4.09k | PyBuffer_Release(&data); |
1291 | 4.09k | } |
1292 | | |
1293 | 4.09k | return return_value; |
1294 | 4.09k | } |
1295 | | |
1296 | | PyDoc_STRVAR(_codecs_ascii_decode__doc__, |
1297 | | "ascii_decode($module, data, errors=None, /)\n" |
1298 | | "--\n" |
1299 | | "\n"); |
1300 | | |
1301 | | #define _CODECS_ASCII_DECODE_METHODDEF \ |
1302 | | {"ascii_decode", _PyCFunction_CAST(_codecs_ascii_decode), METH_FASTCALL, _codecs_ascii_decode__doc__}, |
1303 | | |
1304 | | static PyObject * |
1305 | | _codecs_ascii_decode_impl(PyObject *module, Py_buffer *data, |
1306 | | const char *errors); |
1307 | | |
1308 | | static PyObject * |
1309 | | _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1310 | 22.0k | { |
1311 | 22.0k | PyObject *return_value = NULL; |
1312 | 22.0k | Py_buffer data = {NULL, NULL}; |
1313 | 22.0k | const char *errors = NULL; |
1314 | | |
1315 | 22.0k | if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) { |
1316 | 0 | goto exit; |
1317 | 0 | } |
1318 | 22.0k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1319 | 0 | goto exit; |
1320 | 0 | } |
1321 | 22.0k | if (nargs < 2) { |
1322 | 11.5k | goto skip_optional; |
1323 | 11.5k | } |
1324 | 10.5k | if (args[1] == Py_None) { |
1325 | 0 | errors = NULL; |
1326 | 0 | } |
1327 | 10.5k | else if (PyUnicode_Check(args[1])) { |
1328 | 10.5k | Py_ssize_t errors_length; |
1329 | 10.5k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1330 | 10.5k | if (errors == NULL) { |
1331 | 0 | goto exit; |
1332 | 0 | } |
1333 | 10.5k | if (strlen(errors) != (size_t)errors_length) { |
1334 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1335 | 0 | goto exit; |
1336 | 0 | } |
1337 | 10.5k | } |
1338 | 0 | else { |
1339 | 0 | _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]); |
1340 | 0 | goto exit; |
1341 | 0 | } |
1342 | 22.0k | skip_optional: |
1343 | 22.0k | return_value = _codecs_ascii_decode_impl(module, &data, errors); |
1344 | | |
1345 | 22.0k | exit: |
1346 | | /* Cleanup for data */ |
1347 | 22.0k | if (data.obj) { |
1348 | 22.0k | PyBuffer_Release(&data); |
1349 | 22.0k | } |
1350 | | |
1351 | 22.0k | return return_value; |
1352 | 22.0k | } |
1353 | | |
1354 | | PyDoc_STRVAR(_codecs_charmap_decode__doc__, |
1355 | | "charmap_decode($module, data, errors=None, mapping=None, /)\n" |
1356 | | "--\n" |
1357 | | "\n"); |
1358 | | |
1359 | | #define _CODECS_CHARMAP_DECODE_METHODDEF \ |
1360 | | {"charmap_decode", _PyCFunction_CAST(_codecs_charmap_decode), METH_FASTCALL, _codecs_charmap_decode__doc__}, |
1361 | | |
1362 | | static PyObject * |
1363 | | _codecs_charmap_decode_impl(PyObject *module, Py_buffer *data, |
1364 | | const char *errors, PyObject *mapping); |
1365 | | |
1366 | | static PyObject * |
1367 | | _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1368 | 655k | { |
1369 | 655k | PyObject *return_value = NULL; |
1370 | 655k | Py_buffer data = {NULL, NULL}; |
1371 | 655k | const char *errors = NULL; |
1372 | 655k | PyObject *mapping = Py_None; |
1373 | | |
1374 | 655k | if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) { |
1375 | 0 | goto exit; |
1376 | 0 | } |
1377 | 655k | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1378 | 0 | goto exit; |
1379 | 0 | } |
1380 | 655k | if (nargs < 2) { |
1381 | 21 | goto skip_optional; |
1382 | 21 | } |
1383 | 655k | if (args[1] == Py_None) { |
1384 | 0 | errors = NULL; |
1385 | 0 | } |
1386 | 655k | else if (PyUnicode_Check(args[1])) { |
1387 | 655k | Py_ssize_t errors_length; |
1388 | 655k | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1389 | 655k | if (errors == NULL) { |
1390 | 0 | goto exit; |
1391 | 0 | } |
1392 | 655k | if (strlen(errors) != (size_t)errors_length) { |
1393 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1394 | 0 | goto exit; |
1395 | 0 | } |
1396 | 655k | } |
1397 | 0 | else { |
1398 | 0 | _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]); |
1399 | 0 | goto exit; |
1400 | 0 | } |
1401 | 655k | if (nargs < 3) { |
1402 | 0 | goto skip_optional; |
1403 | 0 | } |
1404 | 655k | mapping = args[2]; |
1405 | 655k | skip_optional: |
1406 | 655k | return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping); |
1407 | | |
1408 | 655k | exit: |
1409 | | /* Cleanup for data */ |
1410 | 655k | if (data.obj) { |
1411 | 655k | PyBuffer_Release(&data); |
1412 | 655k | } |
1413 | | |
1414 | 655k | return return_value; |
1415 | 655k | } |
1416 | | |
1417 | | #if defined(MS_WINDOWS) |
1418 | | |
1419 | | PyDoc_STRVAR(_codecs_mbcs_decode__doc__, |
1420 | | "mbcs_decode($module, data, errors=None, final=False, /)\n" |
1421 | | "--\n" |
1422 | | "\n"); |
1423 | | |
1424 | | #define _CODECS_MBCS_DECODE_METHODDEF \ |
1425 | | {"mbcs_decode", _PyCFunction_CAST(_codecs_mbcs_decode), METH_FASTCALL, _codecs_mbcs_decode__doc__}, |
1426 | | |
1427 | | static PyObject * |
1428 | | _codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data, |
1429 | | const char *errors, int final); |
1430 | | |
1431 | | static PyObject * |
1432 | | _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1433 | | { |
1434 | | PyObject *return_value = NULL; |
1435 | | Py_buffer data = {NULL, NULL}; |
1436 | | const char *errors = NULL; |
1437 | | int final = 0; |
1438 | | |
1439 | | if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) { |
1440 | | goto exit; |
1441 | | } |
1442 | | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1443 | | goto exit; |
1444 | | } |
1445 | | if (nargs < 2) { |
1446 | | goto skip_optional; |
1447 | | } |
1448 | | if (args[1] == Py_None) { |
1449 | | errors = NULL; |
1450 | | } |
1451 | | else if (PyUnicode_Check(args[1])) { |
1452 | | Py_ssize_t errors_length; |
1453 | | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1454 | | if (errors == NULL) { |
1455 | | goto exit; |
1456 | | } |
1457 | | if (strlen(errors) != (size_t)errors_length) { |
1458 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1459 | | goto exit; |
1460 | | } |
1461 | | } |
1462 | | else { |
1463 | | _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]); |
1464 | | goto exit; |
1465 | | } |
1466 | | if (nargs < 3) { |
1467 | | goto skip_optional; |
1468 | | } |
1469 | | final = PyObject_IsTrue(args[2]); |
1470 | | if (final < 0) { |
1471 | | goto exit; |
1472 | | } |
1473 | | skip_optional: |
1474 | | return_value = _codecs_mbcs_decode_impl(module, &data, errors, final); |
1475 | | |
1476 | | exit: |
1477 | | /* Cleanup for data */ |
1478 | | if (data.obj) { |
1479 | | PyBuffer_Release(&data); |
1480 | | } |
1481 | | |
1482 | | return return_value; |
1483 | | } |
1484 | | |
1485 | | #endif /* defined(MS_WINDOWS) */ |
1486 | | |
1487 | | #if defined(MS_WINDOWS) |
1488 | | |
1489 | | PyDoc_STRVAR(_codecs_oem_decode__doc__, |
1490 | | "oem_decode($module, data, errors=None, final=False, /)\n" |
1491 | | "--\n" |
1492 | | "\n"); |
1493 | | |
1494 | | #define _CODECS_OEM_DECODE_METHODDEF \ |
1495 | | {"oem_decode", _PyCFunction_CAST(_codecs_oem_decode), METH_FASTCALL, _codecs_oem_decode__doc__}, |
1496 | | |
1497 | | static PyObject * |
1498 | | _codecs_oem_decode_impl(PyObject *module, Py_buffer *data, |
1499 | | const char *errors, int final); |
1500 | | |
1501 | | static PyObject * |
1502 | | _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1503 | | { |
1504 | | PyObject *return_value = NULL; |
1505 | | Py_buffer data = {NULL, NULL}; |
1506 | | const char *errors = NULL; |
1507 | | int final = 0; |
1508 | | |
1509 | | if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) { |
1510 | | goto exit; |
1511 | | } |
1512 | | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1513 | | goto exit; |
1514 | | } |
1515 | | if (nargs < 2) { |
1516 | | goto skip_optional; |
1517 | | } |
1518 | | if (args[1] == Py_None) { |
1519 | | errors = NULL; |
1520 | | } |
1521 | | else if (PyUnicode_Check(args[1])) { |
1522 | | Py_ssize_t errors_length; |
1523 | | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1524 | | if (errors == NULL) { |
1525 | | goto exit; |
1526 | | } |
1527 | | if (strlen(errors) != (size_t)errors_length) { |
1528 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1529 | | goto exit; |
1530 | | } |
1531 | | } |
1532 | | else { |
1533 | | _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]); |
1534 | | goto exit; |
1535 | | } |
1536 | | if (nargs < 3) { |
1537 | | goto skip_optional; |
1538 | | } |
1539 | | final = PyObject_IsTrue(args[2]); |
1540 | | if (final < 0) { |
1541 | | goto exit; |
1542 | | } |
1543 | | skip_optional: |
1544 | | return_value = _codecs_oem_decode_impl(module, &data, errors, final); |
1545 | | |
1546 | | exit: |
1547 | | /* Cleanup for data */ |
1548 | | if (data.obj) { |
1549 | | PyBuffer_Release(&data); |
1550 | | } |
1551 | | |
1552 | | return return_value; |
1553 | | } |
1554 | | |
1555 | | #endif /* defined(MS_WINDOWS) */ |
1556 | | |
1557 | | #if defined(MS_WINDOWS) |
1558 | | |
1559 | | PyDoc_STRVAR(_codecs_code_page_decode__doc__, |
1560 | | "code_page_decode($module, codepage, data, errors=None, final=False, /)\n" |
1561 | | "--\n" |
1562 | | "\n"); |
1563 | | |
1564 | | #define _CODECS_CODE_PAGE_DECODE_METHODDEF \ |
1565 | | {"code_page_decode", _PyCFunction_CAST(_codecs_code_page_decode), METH_FASTCALL, _codecs_code_page_decode__doc__}, |
1566 | | |
1567 | | static PyObject * |
1568 | | _codecs_code_page_decode_impl(PyObject *module, int codepage, |
1569 | | Py_buffer *data, const char *errors, int final); |
1570 | | |
1571 | | static PyObject * |
1572 | | _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1573 | | { |
1574 | | PyObject *return_value = NULL; |
1575 | | int codepage; |
1576 | | Py_buffer data = {NULL, NULL}; |
1577 | | const char *errors = NULL; |
1578 | | int final = 0; |
1579 | | |
1580 | | if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) { |
1581 | | goto exit; |
1582 | | } |
1583 | | codepage = PyLong_AsInt(args[0]); |
1584 | | if (codepage == -1 && PyErr_Occurred()) { |
1585 | | goto exit; |
1586 | | } |
1587 | | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
1588 | | goto exit; |
1589 | | } |
1590 | | if (nargs < 3) { |
1591 | | goto skip_optional; |
1592 | | } |
1593 | | if (args[2] == Py_None) { |
1594 | | errors = NULL; |
1595 | | } |
1596 | | else if (PyUnicode_Check(args[2])) { |
1597 | | Py_ssize_t errors_length; |
1598 | | errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
1599 | | if (errors == NULL) { |
1600 | | goto exit; |
1601 | | } |
1602 | | if (strlen(errors) != (size_t)errors_length) { |
1603 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1604 | | goto exit; |
1605 | | } |
1606 | | } |
1607 | | else { |
1608 | | _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]); |
1609 | | goto exit; |
1610 | | } |
1611 | | if (nargs < 4) { |
1612 | | goto skip_optional; |
1613 | | } |
1614 | | final = PyObject_IsTrue(args[3]); |
1615 | | if (final < 0) { |
1616 | | goto exit; |
1617 | | } |
1618 | | skip_optional: |
1619 | | return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final); |
1620 | | |
1621 | | exit: |
1622 | | /* Cleanup for data */ |
1623 | | if (data.obj) { |
1624 | | PyBuffer_Release(&data); |
1625 | | } |
1626 | | |
1627 | | return return_value; |
1628 | | } |
1629 | | |
1630 | | #endif /* defined(MS_WINDOWS) */ |
1631 | | |
1632 | | PyDoc_STRVAR(_codecs_readbuffer_encode__doc__, |
1633 | | "readbuffer_encode($module, data, errors=None, /)\n" |
1634 | | "--\n" |
1635 | | "\n"); |
1636 | | |
1637 | | #define _CODECS_READBUFFER_ENCODE_METHODDEF \ |
1638 | | {"readbuffer_encode", _PyCFunction_CAST(_codecs_readbuffer_encode), METH_FASTCALL, _codecs_readbuffer_encode__doc__}, |
1639 | | |
1640 | | static PyObject * |
1641 | | _codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data, |
1642 | | const char *errors); |
1643 | | |
1644 | | static PyObject * |
1645 | | _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1646 | 0 | { |
1647 | 0 | PyObject *return_value = NULL; |
1648 | 0 | Py_buffer data = {NULL, NULL}; |
1649 | 0 | const char *errors = NULL; |
1650 | |
|
1651 | 0 | if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) { |
1652 | 0 | goto exit; |
1653 | 0 | } |
1654 | 0 | if (PyUnicode_Check(args[0])) { |
1655 | 0 | Py_ssize_t len; |
1656 | 0 | const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len); |
1657 | 0 | if (ptr == NULL) { |
1658 | 0 | goto exit; |
1659 | 0 | } |
1660 | 0 | if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) { |
1661 | 0 | goto exit; |
1662 | 0 | } |
1663 | 0 | } |
1664 | 0 | else { /* any bytes-like object */ |
1665 | 0 | if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { |
1666 | 0 | goto exit; |
1667 | 0 | } |
1668 | 0 | } |
1669 | 0 | if (nargs < 2) { |
1670 | 0 | goto skip_optional; |
1671 | 0 | } |
1672 | 0 | if (args[1] == Py_None) { |
1673 | 0 | errors = NULL; |
1674 | 0 | } |
1675 | 0 | else if (PyUnicode_Check(args[1])) { |
1676 | 0 | Py_ssize_t errors_length; |
1677 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1678 | 0 | if (errors == NULL) { |
1679 | 0 | goto exit; |
1680 | 0 | } |
1681 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1682 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1683 | 0 | goto exit; |
1684 | 0 | } |
1685 | 0 | } |
1686 | 0 | else { |
1687 | 0 | _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]); |
1688 | 0 | goto exit; |
1689 | 0 | } |
1690 | 0 | skip_optional: |
1691 | 0 | return_value = _codecs_readbuffer_encode_impl(module, &data, errors); |
1692 | |
|
1693 | 0 | exit: |
1694 | | /* Cleanup for data */ |
1695 | 0 | if (data.obj) { |
1696 | 0 | PyBuffer_Release(&data); |
1697 | 0 | } |
1698 | |
|
1699 | 0 | return return_value; |
1700 | 0 | } |
1701 | | |
1702 | | PyDoc_STRVAR(_codecs_utf_7_encode__doc__, |
1703 | | "utf_7_encode($module, str, errors=None, /)\n" |
1704 | | "--\n" |
1705 | | "\n"); |
1706 | | |
1707 | | #define _CODECS_UTF_7_ENCODE_METHODDEF \ |
1708 | | {"utf_7_encode", _PyCFunction_CAST(_codecs_utf_7_encode), METH_FASTCALL, _codecs_utf_7_encode__doc__}, |
1709 | | |
1710 | | static PyObject * |
1711 | | _codecs_utf_7_encode_impl(PyObject *module, PyObject *str, |
1712 | | const char *errors); |
1713 | | |
1714 | | static PyObject * |
1715 | | _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1716 | 0 | { |
1717 | 0 | PyObject *return_value = NULL; |
1718 | 0 | PyObject *str; |
1719 | 0 | const char *errors = NULL; |
1720 | |
|
1721 | 0 | if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) { |
1722 | 0 | goto exit; |
1723 | 0 | } |
1724 | 0 | if (!PyUnicode_Check(args[0])) { |
1725 | 0 | _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]); |
1726 | 0 | goto exit; |
1727 | 0 | } |
1728 | 0 | str = args[0]; |
1729 | 0 | if (nargs < 2) { |
1730 | 0 | goto skip_optional; |
1731 | 0 | } |
1732 | 0 | if (args[1] == Py_None) { |
1733 | 0 | errors = NULL; |
1734 | 0 | } |
1735 | 0 | else if (PyUnicode_Check(args[1])) { |
1736 | 0 | Py_ssize_t errors_length; |
1737 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1738 | 0 | if (errors == NULL) { |
1739 | 0 | goto exit; |
1740 | 0 | } |
1741 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1742 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1743 | 0 | goto exit; |
1744 | 0 | } |
1745 | 0 | } |
1746 | 0 | else { |
1747 | 0 | _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]); |
1748 | 0 | goto exit; |
1749 | 0 | } |
1750 | 0 | skip_optional: |
1751 | 0 | return_value = _codecs_utf_7_encode_impl(module, str, errors); |
1752 | |
|
1753 | 0 | exit: |
1754 | 0 | return return_value; |
1755 | 0 | } |
1756 | | |
1757 | | PyDoc_STRVAR(_codecs_utf_8_encode__doc__, |
1758 | | "utf_8_encode($module, str, errors=None, /)\n" |
1759 | | "--\n" |
1760 | | "\n"); |
1761 | | |
1762 | | #define _CODECS_UTF_8_ENCODE_METHODDEF \ |
1763 | | {"utf_8_encode", _PyCFunction_CAST(_codecs_utf_8_encode), METH_FASTCALL, _codecs_utf_8_encode__doc__}, |
1764 | | |
1765 | | static PyObject * |
1766 | | _codecs_utf_8_encode_impl(PyObject *module, PyObject *str, |
1767 | | const char *errors); |
1768 | | |
1769 | | static PyObject * |
1770 | | _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1771 | 0 | { |
1772 | 0 | PyObject *return_value = NULL; |
1773 | 0 | PyObject *str; |
1774 | 0 | const char *errors = NULL; |
1775 | |
|
1776 | 0 | if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) { |
1777 | 0 | goto exit; |
1778 | 0 | } |
1779 | 0 | if (!PyUnicode_Check(args[0])) { |
1780 | 0 | _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]); |
1781 | 0 | goto exit; |
1782 | 0 | } |
1783 | 0 | str = args[0]; |
1784 | 0 | if (nargs < 2) { |
1785 | 0 | goto skip_optional; |
1786 | 0 | } |
1787 | 0 | if (args[1] == Py_None) { |
1788 | 0 | errors = NULL; |
1789 | 0 | } |
1790 | 0 | else if (PyUnicode_Check(args[1])) { |
1791 | 0 | Py_ssize_t errors_length; |
1792 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1793 | 0 | if (errors == NULL) { |
1794 | 0 | goto exit; |
1795 | 0 | } |
1796 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1797 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1798 | 0 | goto exit; |
1799 | 0 | } |
1800 | 0 | } |
1801 | 0 | else { |
1802 | 0 | _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]); |
1803 | 0 | goto exit; |
1804 | 0 | } |
1805 | 0 | skip_optional: |
1806 | 0 | return_value = _codecs_utf_8_encode_impl(module, str, errors); |
1807 | |
|
1808 | 0 | exit: |
1809 | 0 | return return_value; |
1810 | 0 | } |
1811 | | |
1812 | | PyDoc_STRVAR(_codecs_utf_16_encode__doc__, |
1813 | | "utf_16_encode($module, str, errors=None, byteorder=0, /)\n" |
1814 | | "--\n" |
1815 | | "\n"); |
1816 | | |
1817 | | #define _CODECS_UTF_16_ENCODE_METHODDEF \ |
1818 | | {"utf_16_encode", _PyCFunction_CAST(_codecs_utf_16_encode), METH_FASTCALL, _codecs_utf_16_encode__doc__}, |
1819 | | |
1820 | | static PyObject * |
1821 | | _codecs_utf_16_encode_impl(PyObject *module, PyObject *str, |
1822 | | const char *errors, int byteorder); |
1823 | | |
1824 | | static PyObject * |
1825 | | _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1826 | 0 | { |
1827 | 0 | PyObject *return_value = NULL; |
1828 | 0 | PyObject *str; |
1829 | 0 | const char *errors = NULL; |
1830 | 0 | int byteorder = 0; |
1831 | |
|
1832 | 0 | if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) { |
1833 | 0 | goto exit; |
1834 | 0 | } |
1835 | 0 | if (!PyUnicode_Check(args[0])) { |
1836 | 0 | _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]); |
1837 | 0 | goto exit; |
1838 | 0 | } |
1839 | 0 | str = args[0]; |
1840 | 0 | if (nargs < 2) { |
1841 | 0 | goto skip_optional; |
1842 | 0 | } |
1843 | 0 | if (args[1] == Py_None) { |
1844 | 0 | errors = NULL; |
1845 | 0 | } |
1846 | 0 | else if (PyUnicode_Check(args[1])) { |
1847 | 0 | Py_ssize_t errors_length; |
1848 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1849 | 0 | if (errors == NULL) { |
1850 | 0 | goto exit; |
1851 | 0 | } |
1852 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1853 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1854 | 0 | goto exit; |
1855 | 0 | } |
1856 | 0 | } |
1857 | 0 | else { |
1858 | 0 | _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]); |
1859 | 0 | goto exit; |
1860 | 0 | } |
1861 | 0 | if (nargs < 3) { |
1862 | 0 | goto skip_optional; |
1863 | 0 | } |
1864 | 0 | byteorder = PyLong_AsInt(args[2]); |
1865 | 0 | if (byteorder == -1 && PyErr_Occurred()) { |
1866 | 0 | goto exit; |
1867 | 0 | } |
1868 | 0 | skip_optional: |
1869 | 0 | return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder); |
1870 | |
|
1871 | 0 | exit: |
1872 | 0 | return return_value; |
1873 | 0 | } |
1874 | | |
1875 | | PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__, |
1876 | | "utf_16_le_encode($module, str, errors=None, /)\n" |
1877 | | "--\n" |
1878 | | "\n"); |
1879 | | |
1880 | | #define _CODECS_UTF_16_LE_ENCODE_METHODDEF \ |
1881 | | {"utf_16_le_encode", _PyCFunction_CAST(_codecs_utf_16_le_encode), METH_FASTCALL, _codecs_utf_16_le_encode__doc__}, |
1882 | | |
1883 | | static PyObject * |
1884 | | _codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str, |
1885 | | const char *errors); |
1886 | | |
1887 | | static PyObject * |
1888 | | _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1889 | 3.47k | { |
1890 | 3.47k | PyObject *return_value = NULL; |
1891 | 3.47k | PyObject *str; |
1892 | 3.47k | const char *errors = NULL; |
1893 | | |
1894 | 3.47k | if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) { |
1895 | 0 | goto exit; |
1896 | 0 | } |
1897 | 3.47k | if (!PyUnicode_Check(args[0])) { |
1898 | 0 | _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]); |
1899 | 0 | goto exit; |
1900 | 0 | } |
1901 | 3.47k | str = args[0]; |
1902 | 3.47k | if (nargs < 2) { |
1903 | 3.47k | goto skip_optional; |
1904 | 3.47k | } |
1905 | 0 | if (args[1] == Py_None) { |
1906 | 0 | errors = NULL; |
1907 | 0 | } |
1908 | 0 | else if (PyUnicode_Check(args[1])) { |
1909 | 0 | Py_ssize_t errors_length; |
1910 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1911 | 0 | if (errors == NULL) { |
1912 | 0 | goto exit; |
1913 | 0 | } |
1914 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1915 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1916 | 0 | goto exit; |
1917 | 0 | } |
1918 | 0 | } |
1919 | 0 | else { |
1920 | 0 | _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]); |
1921 | 0 | goto exit; |
1922 | 0 | } |
1923 | 3.47k | skip_optional: |
1924 | 3.47k | return_value = _codecs_utf_16_le_encode_impl(module, str, errors); |
1925 | | |
1926 | 3.47k | exit: |
1927 | 3.47k | return return_value; |
1928 | 3.47k | } |
1929 | | |
1930 | | PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__, |
1931 | | "utf_16_be_encode($module, str, errors=None, /)\n" |
1932 | | "--\n" |
1933 | | "\n"); |
1934 | | |
1935 | | #define _CODECS_UTF_16_BE_ENCODE_METHODDEF \ |
1936 | | {"utf_16_be_encode", _PyCFunction_CAST(_codecs_utf_16_be_encode), METH_FASTCALL, _codecs_utf_16_be_encode__doc__}, |
1937 | | |
1938 | | static PyObject * |
1939 | | _codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str, |
1940 | | const char *errors); |
1941 | | |
1942 | | static PyObject * |
1943 | | _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1944 | 3.65k | { |
1945 | 3.65k | PyObject *return_value = NULL; |
1946 | 3.65k | PyObject *str; |
1947 | 3.65k | const char *errors = NULL; |
1948 | | |
1949 | 3.65k | if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) { |
1950 | 0 | goto exit; |
1951 | 0 | } |
1952 | 3.65k | if (!PyUnicode_Check(args[0])) { |
1953 | 0 | _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]); |
1954 | 0 | goto exit; |
1955 | 0 | } |
1956 | 3.65k | str = args[0]; |
1957 | 3.65k | if (nargs < 2) { |
1958 | 3.65k | goto skip_optional; |
1959 | 3.65k | } |
1960 | 0 | if (args[1] == Py_None) { |
1961 | 0 | errors = NULL; |
1962 | 0 | } |
1963 | 0 | else if (PyUnicode_Check(args[1])) { |
1964 | 0 | Py_ssize_t errors_length; |
1965 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
1966 | 0 | if (errors == NULL) { |
1967 | 0 | goto exit; |
1968 | 0 | } |
1969 | 0 | if (strlen(errors) != (size_t)errors_length) { |
1970 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
1971 | 0 | goto exit; |
1972 | 0 | } |
1973 | 0 | } |
1974 | 0 | else { |
1975 | 0 | _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]); |
1976 | 0 | goto exit; |
1977 | 0 | } |
1978 | 3.65k | skip_optional: |
1979 | 3.65k | return_value = _codecs_utf_16_be_encode_impl(module, str, errors); |
1980 | | |
1981 | 3.65k | exit: |
1982 | 3.65k | return return_value; |
1983 | 3.65k | } |
1984 | | |
1985 | | PyDoc_STRVAR(_codecs_utf_32_encode__doc__, |
1986 | | "utf_32_encode($module, str, errors=None, byteorder=0, /)\n" |
1987 | | "--\n" |
1988 | | "\n"); |
1989 | | |
1990 | | #define _CODECS_UTF_32_ENCODE_METHODDEF \ |
1991 | | {"utf_32_encode", _PyCFunction_CAST(_codecs_utf_32_encode), METH_FASTCALL, _codecs_utf_32_encode__doc__}, |
1992 | | |
1993 | | static PyObject * |
1994 | | _codecs_utf_32_encode_impl(PyObject *module, PyObject *str, |
1995 | | const char *errors, int byteorder); |
1996 | | |
1997 | | static PyObject * |
1998 | | _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
1999 | 0 | { |
2000 | 0 | PyObject *return_value = NULL; |
2001 | 0 | PyObject *str; |
2002 | 0 | const char *errors = NULL; |
2003 | 0 | int byteorder = 0; |
2004 | |
|
2005 | 0 | if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) { |
2006 | 0 | goto exit; |
2007 | 0 | } |
2008 | 0 | if (!PyUnicode_Check(args[0])) { |
2009 | 0 | _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]); |
2010 | 0 | goto exit; |
2011 | 0 | } |
2012 | 0 | str = args[0]; |
2013 | 0 | if (nargs < 2) { |
2014 | 0 | goto skip_optional; |
2015 | 0 | } |
2016 | 0 | if (args[1] == Py_None) { |
2017 | 0 | errors = NULL; |
2018 | 0 | } |
2019 | 0 | else if (PyUnicode_Check(args[1])) { |
2020 | 0 | Py_ssize_t errors_length; |
2021 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2022 | 0 | if (errors == NULL) { |
2023 | 0 | goto exit; |
2024 | 0 | } |
2025 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2026 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2027 | 0 | goto exit; |
2028 | 0 | } |
2029 | 0 | } |
2030 | 0 | else { |
2031 | 0 | _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]); |
2032 | 0 | goto exit; |
2033 | 0 | } |
2034 | 0 | if (nargs < 3) { |
2035 | 0 | goto skip_optional; |
2036 | 0 | } |
2037 | 0 | byteorder = PyLong_AsInt(args[2]); |
2038 | 0 | if (byteorder == -1 && PyErr_Occurred()) { |
2039 | 0 | goto exit; |
2040 | 0 | } |
2041 | 0 | skip_optional: |
2042 | 0 | return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder); |
2043 | |
|
2044 | 0 | exit: |
2045 | 0 | return return_value; |
2046 | 0 | } |
2047 | | |
2048 | | PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__, |
2049 | | "utf_32_le_encode($module, str, errors=None, /)\n" |
2050 | | "--\n" |
2051 | | "\n"); |
2052 | | |
2053 | | #define _CODECS_UTF_32_LE_ENCODE_METHODDEF \ |
2054 | | {"utf_32_le_encode", _PyCFunction_CAST(_codecs_utf_32_le_encode), METH_FASTCALL, _codecs_utf_32_le_encode__doc__}, |
2055 | | |
2056 | | static PyObject * |
2057 | | _codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str, |
2058 | | const char *errors); |
2059 | | |
2060 | | static PyObject * |
2061 | | _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2062 | 0 | { |
2063 | 0 | PyObject *return_value = NULL; |
2064 | 0 | PyObject *str; |
2065 | 0 | const char *errors = NULL; |
2066 | |
|
2067 | 0 | if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) { |
2068 | 0 | goto exit; |
2069 | 0 | } |
2070 | 0 | if (!PyUnicode_Check(args[0])) { |
2071 | 0 | _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]); |
2072 | 0 | goto exit; |
2073 | 0 | } |
2074 | 0 | str = args[0]; |
2075 | 0 | if (nargs < 2) { |
2076 | 0 | goto skip_optional; |
2077 | 0 | } |
2078 | 0 | if (args[1] == Py_None) { |
2079 | 0 | errors = NULL; |
2080 | 0 | } |
2081 | 0 | else if (PyUnicode_Check(args[1])) { |
2082 | 0 | Py_ssize_t errors_length; |
2083 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2084 | 0 | if (errors == NULL) { |
2085 | 0 | goto exit; |
2086 | 0 | } |
2087 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2088 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2089 | 0 | goto exit; |
2090 | 0 | } |
2091 | 0 | } |
2092 | 0 | else { |
2093 | 0 | _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]); |
2094 | 0 | goto exit; |
2095 | 0 | } |
2096 | 0 | skip_optional: |
2097 | 0 | return_value = _codecs_utf_32_le_encode_impl(module, str, errors); |
2098 | |
|
2099 | 0 | exit: |
2100 | 0 | return return_value; |
2101 | 0 | } |
2102 | | |
2103 | | PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__, |
2104 | | "utf_32_be_encode($module, str, errors=None, /)\n" |
2105 | | "--\n" |
2106 | | "\n"); |
2107 | | |
2108 | | #define _CODECS_UTF_32_BE_ENCODE_METHODDEF \ |
2109 | | {"utf_32_be_encode", _PyCFunction_CAST(_codecs_utf_32_be_encode), METH_FASTCALL, _codecs_utf_32_be_encode__doc__}, |
2110 | | |
2111 | | static PyObject * |
2112 | | _codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str, |
2113 | | const char *errors); |
2114 | | |
2115 | | static PyObject * |
2116 | | _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2117 | 0 | { |
2118 | 0 | PyObject *return_value = NULL; |
2119 | 0 | PyObject *str; |
2120 | 0 | const char *errors = NULL; |
2121 | |
|
2122 | 0 | if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) { |
2123 | 0 | goto exit; |
2124 | 0 | } |
2125 | 0 | if (!PyUnicode_Check(args[0])) { |
2126 | 0 | _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]); |
2127 | 0 | goto exit; |
2128 | 0 | } |
2129 | 0 | str = args[0]; |
2130 | 0 | if (nargs < 2) { |
2131 | 0 | goto skip_optional; |
2132 | 0 | } |
2133 | 0 | if (args[1] == Py_None) { |
2134 | 0 | errors = NULL; |
2135 | 0 | } |
2136 | 0 | else if (PyUnicode_Check(args[1])) { |
2137 | 0 | Py_ssize_t errors_length; |
2138 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2139 | 0 | if (errors == NULL) { |
2140 | 0 | goto exit; |
2141 | 0 | } |
2142 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2143 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2144 | 0 | goto exit; |
2145 | 0 | } |
2146 | 0 | } |
2147 | 0 | else { |
2148 | 0 | _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]); |
2149 | 0 | goto exit; |
2150 | 0 | } |
2151 | 0 | skip_optional: |
2152 | 0 | return_value = _codecs_utf_32_be_encode_impl(module, str, errors); |
2153 | |
|
2154 | 0 | exit: |
2155 | 0 | return return_value; |
2156 | 0 | } |
2157 | | |
2158 | | PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__, |
2159 | | "unicode_escape_encode($module, str, errors=None, /)\n" |
2160 | | "--\n" |
2161 | | "\n"); |
2162 | | |
2163 | | #define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \ |
2164 | | {"unicode_escape_encode", _PyCFunction_CAST(_codecs_unicode_escape_encode), METH_FASTCALL, _codecs_unicode_escape_encode__doc__}, |
2165 | | |
2166 | | static PyObject * |
2167 | | _codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str, |
2168 | | const char *errors); |
2169 | | |
2170 | | static PyObject * |
2171 | | _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2172 | 330k | { |
2173 | 330k | PyObject *return_value = NULL; |
2174 | 330k | PyObject *str; |
2175 | 330k | const char *errors = NULL; |
2176 | | |
2177 | 330k | if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) { |
2178 | 0 | goto exit; |
2179 | 0 | } |
2180 | 330k | if (!PyUnicode_Check(args[0])) { |
2181 | 0 | _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]); |
2182 | 0 | goto exit; |
2183 | 0 | } |
2184 | 330k | str = args[0]; |
2185 | 330k | if (nargs < 2) { |
2186 | 330k | goto skip_optional; |
2187 | 330k | } |
2188 | 0 | if (args[1] == Py_None) { |
2189 | 0 | errors = NULL; |
2190 | 0 | } |
2191 | 0 | else if (PyUnicode_Check(args[1])) { |
2192 | 0 | Py_ssize_t errors_length; |
2193 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2194 | 0 | if (errors == NULL) { |
2195 | 0 | goto exit; |
2196 | 0 | } |
2197 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2198 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2199 | 0 | goto exit; |
2200 | 0 | } |
2201 | 0 | } |
2202 | 0 | else { |
2203 | 0 | _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]); |
2204 | 0 | goto exit; |
2205 | 0 | } |
2206 | 330k | skip_optional: |
2207 | 330k | return_value = _codecs_unicode_escape_encode_impl(module, str, errors); |
2208 | | |
2209 | 330k | exit: |
2210 | 330k | return return_value; |
2211 | 330k | } |
2212 | | |
2213 | | PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__, |
2214 | | "raw_unicode_escape_encode($module, str, errors=None, /)\n" |
2215 | | "--\n" |
2216 | | "\n"); |
2217 | | |
2218 | | #define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \ |
2219 | | {"raw_unicode_escape_encode", _PyCFunction_CAST(_codecs_raw_unicode_escape_encode), METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__}, |
2220 | | |
2221 | | static PyObject * |
2222 | | _codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str, |
2223 | | const char *errors); |
2224 | | |
2225 | | static PyObject * |
2226 | | _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2227 | 247k | { |
2228 | 247k | PyObject *return_value = NULL; |
2229 | 247k | PyObject *str; |
2230 | 247k | const char *errors = NULL; |
2231 | | |
2232 | 247k | if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) { |
2233 | 0 | goto exit; |
2234 | 0 | } |
2235 | 247k | if (!PyUnicode_Check(args[0])) { |
2236 | 0 | _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]); |
2237 | 0 | goto exit; |
2238 | 0 | } |
2239 | 247k | str = args[0]; |
2240 | 247k | if (nargs < 2) { |
2241 | 247k | goto skip_optional; |
2242 | 247k | } |
2243 | 0 | if (args[1] == Py_None) { |
2244 | 0 | errors = NULL; |
2245 | 0 | } |
2246 | 0 | else if (PyUnicode_Check(args[1])) { |
2247 | 0 | Py_ssize_t errors_length; |
2248 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2249 | 0 | if (errors == NULL) { |
2250 | 0 | goto exit; |
2251 | 0 | } |
2252 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2253 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2254 | 0 | goto exit; |
2255 | 0 | } |
2256 | 0 | } |
2257 | 0 | else { |
2258 | 0 | _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]); |
2259 | 0 | goto exit; |
2260 | 0 | } |
2261 | 247k | skip_optional: |
2262 | 247k | return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors); |
2263 | | |
2264 | 247k | exit: |
2265 | 247k | return return_value; |
2266 | 247k | } |
2267 | | |
2268 | | PyDoc_STRVAR(_codecs_latin_1_encode__doc__, |
2269 | | "latin_1_encode($module, str, errors=None, /)\n" |
2270 | | "--\n" |
2271 | | "\n"); |
2272 | | |
2273 | | #define _CODECS_LATIN_1_ENCODE_METHODDEF \ |
2274 | | {"latin_1_encode", _PyCFunction_CAST(_codecs_latin_1_encode), METH_FASTCALL, _codecs_latin_1_encode__doc__}, |
2275 | | |
2276 | | static PyObject * |
2277 | | _codecs_latin_1_encode_impl(PyObject *module, PyObject *str, |
2278 | | const char *errors); |
2279 | | |
2280 | | static PyObject * |
2281 | | _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2282 | 0 | { |
2283 | 0 | PyObject *return_value = NULL; |
2284 | 0 | PyObject *str; |
2285 | 0 | const char *errors = NULL; |
2286 | |
|
2287 | 0 | if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) { |
2288 | 0 | goto exit; |
2289 | 0 | } |
2290 | 0 | if (!PyUnicode_Check(args[0])) { |
2291 | 0 | _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]); |
2292 | 0 | goto exit; |
2293 | 0 | } |
2294 | 0 | str = args[0]; |
2295 | 0 | if (nargs < 2) { |
2296 | 0 | goto skip_optional; |
2297 | 0 | } |
2298 | 0 | if (args[1] == Py_None) { |
2299 | 0 | errors = NULL; |
2300 | 0 | } |
2301 | 0 | else if (PyUnicode_Check(args[1])) { |
2302 | 0 | Py_ssize_t errors_length; |
2303 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2304 | 0 | if (errors == NULL) { |
2305 | 0 | goto exit; |
2306 | 0 | } |
2307 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2308 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2309 | 0 | goto exit; |
2310 | 0 | } |
2311 | 0 | } |
2312 | 0 | else { |
2313 | 0 | _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]); |
2314 | 0 | goto exit; |
2315 | 0 | } |
2316 | 0 | skip_optional: |
2317 | 0 | return_value = _codecs_latin_1_encode_impl(module, str, errors); |
2318 | |
|
2319 | 0 | exit: |
2320 | 0 | return return_value; |
2321 | 0 | } |
2322 | | |
2323 | | PyDoc_STRVAR(_codecs_ascii_encode__doc__, |
2324 | | "ascii_encode($module, str, errors=None, /)\n" |
2325 | | "--\n" |
2326 | | "\n"); |
2327 | | |
2328 | | #define _CODECS_ASCII_ENCODE_METHODDEF \ |
2329 | | {"ascii_encode", _PyCFunction_CAST(_codecs_ascii_encode), METH_FASTCALL, _codecs_ascii_encode__doc__}, |
2330 | | |
2331 | | static PyObject * |
2332 | | _codecs_ascii_encode_impl(PyObject *module, PyObject *str, |
2333 | | const char *errors); |
2334 | | |
2335 | | static PyObject * |
2336 | | _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2337 | 0 | { |
2338 | 0 | PyObject *return_value = NULL; |
2339 | 0 | PyObject *str; |
2340 | 0 | const char *errors = NULL; |
2341 | |
|
2342 | 0 | if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) { |
2343 | 0 | goto exit; |
2344 | 0 | } |
2345 | 0 | if (!PyUnicode_Check(args[0])) { |
2346 | 0 | _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]); |
2347 | 0 | goto exit; |
2348 | 0 | } |
2349 | 0 | str = args[0]; |
2350 | 0 | if (nargs < 2) { |
2351 | 0 | goto skip_optional; |
2352 | 0 | } |
2353 | 0 | if (args[1] == Py_None) { |
2354 | 0 | errors = NULL; |
2355 | 0 | } |
2356 | 0 | else if (PyUnicode_Check(args[1])) { |
2357 | 0 | Py_ssize_t errors_length; |
2358 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2359 | 0 | if (errors == NULL) { |
2360 | 0 | goto exit; |
2361 | 0 | } |
2362 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2363 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2364 | 0 | goto exit; |
2365 | 0 | } |
2366 | 0 | } |
2367 | 0 | else { |
2368 | 0 | _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]); |
2369 | 0 | goto exit; |
2370 | 0 | } |
2371 | 0 | skip_optional: |
2372 | 0 | return_value = _codecs_ascii_encode_impl(module, str, errors); |
2373 | |
|
2374 | 0 | exit: |
2375 | 0 | return return_value; |
2376 | 0 | } |
2377 | | |
2378 | | PyDoc_STRVAR(_codecs_charmap_encode__doc__, |
2379 | | "charmap_encode($module, str, errors=None, mapping=None, /)\n" |
2380 | | "--\n" |
2381 | | "\n"); |
2382 | | |
2383 | | #define _CODECS_CHARMAP_ENCODE_METHODDEF \ |
2384 | | {"charmap_encode", _PyCFunction_CAST(_codecs_charmap_encode), METH_FASTCALL, _codecs_charmap_encode__doc__}, |
2385 | | |
2386 | | static PyObject * |
2387 | | _codecs_charmap_encode_impl(PyObject *module, PyObject *str, |
2388 | | const char *errors, PyObject *mapping); |
2389 | | |
2390 | | static PyObject * |
2391 | | _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2392 | 0 | { |
2393 | 0 | PyObject *return_value = NULL; |
2394 | 0 | PyObject *str; |
2395 | 0 | const char *errors = NULL; |
2396 | 0 | PyObject *mapping = Py_None; |
2397 | |
|
2398 | 0 | if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) { |
2399 | 0 | goto exit; |
2400 | 0 | } |
2401 | 0 | if (!PyUnicode_Check(args[0])) { |
2402 | 0 | _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]); |
2403 | 0 | goto exit; |
2404 | 0 | } |
2405 | 0 | str = args[0]; |
2406 | 0 | if (nargs < 2) { |
2407 | 0 | goto skip_optional; |
2408 | 0 | } |
2409 | 0 | if (args[1] == Py_None) { |
2410 | 0 | errors = NULL; |
2411 | 0 | } |
2412 | 0 | else if (PyUnicode_Check(args[1])) { |
2413 | 0 | Py_ssize_t errors_length; |
2414 | 0 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2415 | 0 | if (errors == NULL) { |
2416 | 0 | goto exit; |
2417 | 0 | } |
2418 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2419 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2420 | 0 | goto exit; |
2421 | 0 | } |
2422 | 0 | } |
2423 | 0 | else { |
2424 | 0 | _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]); |
2425 | 0 | goto exit; |
2426 | 0 | } |
2427 | 0 | if (nargs < 3) { |
2428 | 0 | goto skip_optional; |
2429 | 0 | } |
2430 | 0 | mapping = args[2]; |
2431 | 0 | skip_optional: |
2432 | 0 | return_value = _codecs_charmap_encode_impl(module, str, errors, mapping); |
2433 | |
|
2434 | 0 | exit: |
2435 | 0 | return return_value; |
2436 | 0 | } |
2437 | | |
2438 | | PyDoc_STRVAR(_codecs_charmap_build__doc__, |
2439 | | "charmap_build($module, map, /)\n" |
2440 | | "--\n" |
2441 | | "\n"); |
2442 | | |
2443 | | #define _CODECS_CHARMAP_BUILD_METHODDEF \ |
2444 | | {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__}, |
2445 | | |
2446 | | static PyObject * |
2447 | | _codecs_charmap_build_impl(PyObject *module, PyObject *map); |
2448 | | |
2449 | | static PyObject * |
2450 | | _codecs_charmap_build(PyObject *module, PyObject *arg) |
2451 | 136 | { |
2452 | 136 | PyObject *return_value = NULL; |
2453 | 136 | PyObject *map; |
2454 | | |
2455 | 136 | if (!PyUnicode_Check(arg)) { |
2456 | 0 | _PyArg_BadArgument("charmap_build", "argument", "str", arg); |
2457 | 0 | goto exit; |
2458 | 0 | } |
2459 | 136 | map = arg; |
2460 | 136 | return_value = _codecs_charmap_build_impl(module, map); |
2461 | | |
2462 | 136 | exit: |
2463 | 136 | return return_value; |
2464 | 136 | } |
2465 | | |
2466 | | #if defined(MS_WINDOWS) |
2467 | | |
2468 | | PyDoc_STRVAR(_codecs_mbcs_encode__doc__, |
2469 | | "mbcs_encode($module, str, errors=None, /)\n" |
2470 | | "--\n" |
2471 | | "\n"); |
2472 | | |
2473 | | #define _CODECS_MBCS_ENCODE_METHODDEF \ |
2474 | | {"mbcs_encode", _PyCFunction_CAST(_codecs_mbcs_encode), METH_FASTCALL, _codecs_mbcs_encode__doc__}, |
2475 | | |
2476 | | static PyObject * |
2477 | | _codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors); |
2478 | | |
2479 | | static PyObject * |
2480 | | _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2481 | | { |
2482 | | PyObject *return_value = NULL; |
2483 | | PyObject *str; |
2484 | | const char *errors = NULL; |
2485 | | |
2486 | | if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) { |
2487 | | goto exit; |
2488 | | } |
2489 | | if (!PyUnicode_Check(args[0])) { |
2490 | | _PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]); |
2491 | | goto exit; |
2492 | | } |
2493 | | str = args[0]; |
2494 | | if (nargs < 2) { |
2495 | | goto skip_optional; |
2496 | | } |
2497 | | if (args[1] == Py_None) { |
2498 | | errors = NULL; |
2499 | | } |
2500 | | else if (PyUnicode_Check(args[1])) { |
2501 | | Py_ssize_t errors_length; |
2502 | | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2503 | | if (errors == NULL) { |
2504 | | goto exit; |
2505 | | } |
2506 | | if (strlen(errors) != (size_t)errors_length) { |
2507 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2508 | | goto exit; |
2509 | | } |
2510 | | } |
2511 | | else { |
2512 | | _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]); |
2513 | | goto exit; |
2514 | | } |
2515 | | skip_optional: |
2516 | | return_value = _codecs_mbcs_encode_impl(module, str, errors); |
2517 | | |
2518 | | exit: |
2519 | | return return_value; |
2520 | | } |
2521 | | |
2522 | | #endif /* defined(MS_WINDOWS) */ |
2523 | | |
2524 | | #if defined(MS_WINDOWS) |
2525 | | |
2526 | | PyDoc_STRVAR(_codecs_oem_encode__doc__, |
2527 | | "oem_encode($module, str, errors=None, /)\n" |
2528 | | "--\n" |
2529 | | "\n"); |
2530 | | |
2531 | | #define _CODECS_OEM_ENCODE_METHODDEF \ |
2532 | | {"oem_encode", _PyCFunction_CAST(_codecs_oem_encode), METH_FASTCALL, _codecs_oem_encode__doc__}, |
2533 | | |
2534 | | static PyObject * |
2535 | | _codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors); |
2536 | | |
2537 | | static PyObject * |
2538 | | _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2539 | | { |
2540 | | PyObject *return_value = NULL; |
2541 | | PyObject *str; |
2542 | | const char *errors = NULL; |
2543 | | |
2544 | | if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) { |
2545 | | goto exit; |
2546 | | } |
2547 | | if (!PyUnicode_Check(args[0])) { |
2548 | | _PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]); |
2549 | | goto exit; |
2550 | | } |
2551 | | str = args[0]; |
2552 | | if (nargs < 2) { |
2553 | | goto skip_optional; |
2554 | | } |
2555 | | if (args[1] == Py_None) { |
2556 | | errors = NULL; |
2557 | | } |
2558 | | else if (PyUnicode_Check(args[1])) { |
2559 | | Py_ssize_t errors_length; |
2560 | | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
2561 | | if (errors == NULL) { |
2562 | | goto exit; |
2563 | | } |
2564 | | if (strlen(errors) != (size_t)errors_length) { |
2565 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2566 | | goto exit; |
2567 | | } |
2568 | | } |
2569 | | else { |
2570 | | _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]); |
2571 | | goto exit; |
2572 | | } |
2573 | | skip_optional: |
2574 | | return_value = _codecs_oem_encode_impl(module, str, errors); |
2575 | | |
2576 | | exit: |
2577 | | return return_value; |
2578 | | } |
2579 | | |
2580 | | #endif /* defined(MS_WINDOWS) */ |
2581 | | |
2582 | | #if defined(MS_WINDOWS) |
2583 | | |
2584 | | PyDoc_STRVAR(_codecs_code_page_encode__doc__, |
2585 | | "code_page_encode($module, code_page, str, errors=None, /)\n" |
2586 | | "--\n" |
2587 | | "\n"); |
2588 | | |
2589 | | #define _CODECS_CODE_PAGE_ENCODE_METHODDEF \ |
2590 | | {"code_page_encode", _PyCFunction_CAST(_codecs_code_page_encode), METH_FASTCALL, _codecs_code_page_encode__doc__}, |
2591 | | |
2592 | | static PyObject * |
2593 | | _codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str, |
2594 | | const char *errors); |
2595 | | |
2596 | | static PyObject * |
2597 | | _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2598 | | { |
2599 | | PyObject *return_value = NULL; |
2600 | | int code_page; |
2601 | | PyObject *str; |
2602 | | const char *errors = NULL; |
2603 | | |
2604 | | if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) { |
2605 | | goto exit; |
2606 | | } |
2607 | | code_page = PyLong_AsInt(args[0]); |
2608 | | if (code_page == -1 && PyErr_Occurred()) { |
2609 | | goto exit; |
2610 | | } |
2611 | | if (!PyUnicode_Check(args[1])) { |
2612 | | _PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]); |
2613 | | goto exit; |
2614 | | } |
2615 | | str = args[1]; |
2616 | | if (nargs < 3) { |
2617 | | goto skip_optional; |
2618 | | } |
2619 | | if (args[2] == Py_None) { |
2620 | | errors = NULL; |
2621 | | } |
2622 | | else if (PyUnicode_Check(args[2])) { |
2623 | | Py_ssize_t errors_length; |
2624 | | errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); |
2625 | | if (errors == NULL) { |
2626 | | goto exit; |
2627 | | } |
2628 | | if (strlen(errors) != (size_t)errors_length) { |
2629 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2630 | | goto exit; |
2631 | | } |
2632 | | } |
2633 | | else { |
2634 | | _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]); |
2635 | | goto exit; |
2636 | | } |
2637 | | skip_optional: |
2638 | | return_value = _codecs_code_page_encode_impl(module, code_page, str, errors); |
2639 | | |
2640 | | exit: |
2641 | | return return_value; |
2642 | | } |
2643 | | |
2644 | | #endif /* defined(MS_WINDOWS) */ |
2645 | | |
2646 | | PyDoc_STRVAR(_codecs_register_error__doc__, |
2647 | | "register_error($module, errors, handler, /)\n" |
2648 | | "--\n" |
2649 | | "\n" |
2650 | | "Register the specified error handler under the name errors.\n" |
2651 | | "\n" |
2652 | | "handler must be a callable object, that will be called with an exception\n" |
2653 | | "instance containing information about the location of the\n" |
2654 | | "encoding/decoding error and must return a (replacement, new position)\n" |
2655 | | "tuple."); |
2656 | | |
2657 | | #define _CODECS_REGISTER_ERROR_METHODDEF \ |
2658 | | {"register_error", _PyCFunction_CAST(_codecs_register_error), METH_FASTCALL, _codecs_register_error__doc__}, |
2659 | | |
2660 | | static PyObject * |
2661 | | _codecs_register_error_impl(PyObject *module, const char *errors, |
2662 | | PyObject *handler); |
2663 | | |
2664 | | static PyObject * |
2665 | | _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2666 | 0 | { |
2667 | 0 | PyObject *return_value = NULL; |
2668 | 0 | const char *errors; |
2669 | 0 | PyObject *handler; |
2670 | |
|
2671 | 0 | if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) { |
2672 | 0 | goto exit; |
2673 | 0 | } |
2674 | 0 | if (!PyUnicode_Check(args[0])) { |
2675 | 0 | _PyArg_BadArgument("register_error", "argument 1", "str", args[0]); |
2676 | 0 | goto exit; |
2677 | 0 | } |
2678 | 0 | Py_ssize_t errors_length; |
2679 | 0 | errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length); |
2680 | 0 | if (errors == NULL) { |
2681 | 0 | goto exit; |
2682 | 0 | } |
2683 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2684 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2685 | 0 | goto exit; |
2686 | 0 | } |
2687 | 0 | handler = args[1]; |
2688 | 0 | return_value = _codecs_register_error_impl(module, errors, handler); |
2689 | |
|
2690 | 0 | exit: |
2691 | 0 | return return_value; |
2692 | 0 | } |
2693 | | |
2694 | | PyDoc_STRVAR(_codecs__unregister_error__doc__, |
2695 | | "_unregister_error($module, errors, /)\n" |
2696 | | "--\n" |
2697 | | "\n" |
2698 | | "Un-register the specified error handler for the error handling `errors\'.\n" |
2699 | | "\n" |
2700 | | "Only custom error handlers can be un-registered. An exception is raised\n" |
2701 | | "if the error handling is a built-in one (e.g., \'strict\'), or if an error\n" |
2702 | | "occurs.\n" |
2703 | | "\n" |
2704 | | "Otherwise, this returns True if a custom handler has been successfully\n" |
2705 | | "un-registered, and False if no custom handler for the specified error\n" |
2706 | | "handling exists."); |
2707 | | |
2708 | | #define _CODECS__UNREGISTER_ERROR_METHODDEF \ |
2709 | | {"_unregister_error", (PyCFunction)_codecs__unregister_error, METH_O, _codecs__unregister_error__doc__}, |
2710 | | |
2711 | | static int |
2712 | | _codecs__unregister_error_impl(PyObject *module, const char *errors); |
2713 | | |
2714 | | static PyObject * |
2715 | | _codecs__unregister_error(PyObject *module, PyObject *arg) |
2716 | 0 | { |
2717 | 0 | PyObject *return_value = NULL; |
2718 | 0 | const char *errors; |
2719 | 0 | int _return_value; |
2720 | |
|
2721 | 0 | if (!PyUnicode_Check(arg)) { |
2722 | 0 | _PyArg_BadArgument("_unregister_error", "argument", "str", arg); |
2723 | 0 | goto exit; |
2724 | 0 | } |
2725 | 0 | Py_ssize_t errors_length; |
2726 | 0 | errors = PyUnicode_AsUTF8AndSize(arg, &errors_length); |
2727 | 0 | if (errors == NULL) { |
2728 | 0 | goto exit; |
2729 | 0 | } |
2730 | 0 | if (strlen(errors) != (size_t)errors_length) { |
2731 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2732 | 0 | goto exit; |
2733 | 0 | } |
2734 | 0 | _return_value = _codecs__unregister_error_impl(module, errors); |
2735 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
2736 | 0 | goto exit; |
2737 | 0 | } |
2738 | 0 | return_value = PyBool_FromLong((long)_return_value); |
2739 | |
|
2740 | 0 | exit: |
2741 | 0 | return return_value; |
2742 | 0 | } |
2743 | | |
2744 | | PyDoc_STRVAR(_codecs_lookup_error__doc__, |
2745 | | "lookup_error($module, name, /)\n" |
2746 | | "--\n" |
2747 | | "\n" |
2748 | | "lookup_error(errors) -> handler\n" |
2749 | | "\n" |
2750 | | "Return the error handler for the specified error handling name or raise\n" |
2751 | | "a LookupError, if no handler exists under this name."); |
2752 | | |
2753 | | #define _CODECS_LOOKUP_ERROR_METHODDEF \ |
2754 | | {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__}, |
2755 | | |
2756 | | static PyObject * |
2757 | | _codecs_lookup_error_impl(PyObject *module, const char *name); |
2758 | | |
2759 | | static PyObject * |
2760 | | _codecs_lookup_error(PyObject *module, PyObject *arg) |
2761 | 222 | { |
2762 | 222 | PyObject *return_value = NULL; |
2763 | 222 | const char *name; |
2764 | | |
2765 | 222 | if (!PyUnicode_Check(arg)) { |
2766 | 0 | _PyArg_BadArgument("lookup_error", "argument", "str", arg); |
2767 | 0 | goto exit; |
2768 | 0 | } |
2769 | 222 | Py_ssize_t name_length; |
2770 | 222 | name = PyUnicode_AsUTF8AndSize(arg, &name_length); |
2771 | 222 | if (name == NULL) { |
2772 | 0 | goto exit; |
2773 | 0 | } |
2774 | 222 | if (strlen(name) != (size_t)name_length) { |
2775 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
2776 | 0 | goto exit; |
2777 | 0 | } |
2778 | 222 | return_value = _codecs_lookup_error_impl(module, name); |
2779 | | |
2780 | 222 | exit: |
2781 | 222 | return return_value; |
2782 | 222 | } |
2783 | | |
2784 | | PyDoc_STRVAR(_codecs__normalize_encoding__doc__, |
2785 | | "_normalize_encoding($module, /, encoding)\n" |
2786 | | "--\n" |
2787 | | "\n" |
2788 | | "Normalize an encoding name *encoding*.\n" |
2789 | | "\n" |
2790 | | "Used for encodings.normalize_encoding. Does not convert to lower case."); |
2791 | | |
2792 | | #define _CODECS__NORMALIZE_ENCODING_METHODDEF \ |
2793 | | {"_normalize_encoding", _PyCFunction_CAST(_codecs__normalize_encoding), METH_FASTCALL|METH_KEYWORDS, _codecs__normalize_encoding__doc__}, |
2794 | | |
2795 | | static PyObject * |
2796 | | _codecs__normalize_encoding_impl(PyObject *module, PyObject *encoding); |
2797 | | |
2798 | | static PyObject * |
2799 | | _codecs__normalize_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2800 | 3.57k | { |
2801 | 3.57k | PyObject *return_value = NULL; |
2802 | 3.57k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2803 | | |
2804 | 3.57k | #define NUM_KEYWORDS 1 |
2805 | 3.57k | static struct { |
2806 | 3.57k | PyGC_Head _this_is_not_used; |
2807 | 3.57k | PyObject_VAR_HEAD |
2808 | 3.57k | Py_hash_t ob_hash; |
2809 | 3.57k | PyObject *ob_item[NUM_KEYWORDS]; |
2810 | 3.57k | } _kwtuple = { |
2811 | 3.57k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2812 | 3.57k | .ob_hash = -1, |
2813 | 3.57k | .ob_item = { &_Py_ID(encoding), }, |
2814 | 3.57k | }; |
2815 | 3.57k | #undef NUM_KEYWORDS |
2816 | 3.57k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2817 | | |
2818 | | #else // !Py_BUILD_CORE |
2819 | | # define KWTUPLE NULL |
2820 | | #endif // !Py_BUILD_CORE |
2821 | | |
2822 | 3.57k | static const char * const _keywords[] = {"encoding", NULL}; |
2823 | 3.57k | static _PyArg_Parser _parser = { |
2824 | 3.57k | .keywords = _keywords, |
2825 | 3.57k | .fname = "_normalize_encoding", |
2826 | 3.57k | .kwtuple = KWTUPLE, |
2827 | 3.57k | }; |
2828 | 3.57k | #undef KWTUPLE |
2829 | 3.57k | PyObject *argsbuf[1]; |
2830 | 3.57k | PyObject *encoding; |
2831 | | |
2832 | 3.57k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2833 | 3.57k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2834 | 3.57k | if (!args) { |
2835 | 0 | goto exit; |
2836 | 0 | } |
2837 | 3.57k | if (!PyUnicode_Check(args[0])) { |
2838 | 0 | _PyArg_BadArgument("_normalize_encoding", "argument 'encoding'", "str", args[0]); |
2839 | 0 | goto exit; |
2840 | 0 | } |
2841 | 3.57k | encoding = args[0]; |
2842 | 3.57k | return_value = _codecs__normalize_encoding_impl(module, encoding); |
2843 | | |
2844 | 3.57k | exit: |
2845 | 3.57k | return return_value; |
2846 | 3.57k | } |
2847 | | |
2848 | | #ifndef _CODECS_MBCS_DECODE_METHODDEF |
2849 | | #define _CODECS_MBCS_DECODE_METHODDEF |
2850 | | #endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */ |
2851 | | |
2852 | | #ifndef _CODECS_OEM_DECODE_METHODDEF |
2853 | | #define _CODECS_OEM_DECODE_METHODDEF |
2854 | | #endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */ |
2855 | | |
2856 | | #ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF |
2857 | | #define _CODECS_CODE_PAGE_DECODE_METHODDEF |
2858 | | #endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */ |
2859 | | |
2860 | | #ifndef _CODECS_MBCS_ENCODE_METHODDEF |
2861 | | #define _CODECS_MBCS_ENCODE_METHODDEF |
2862 | | #endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */ |
2863 | | |
2864 | | #ifndef _CODECS_OEM_ENCODE_METHODDEF |
2865 | | #define _CODECS_OEM_ENCODE_METHODDEF |
2866 | | #endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */ |
2867 | | |
2868 | | #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF |
2869 | | #define _CODECS_CODE_PAGE_ENCODE_METHODDEF |
2870 | | #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ |
2871 | | /*[clinic end generated code: output=505edef891a06329 input=a9049054013a1b77]*/ |