Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Modules/_codecsmodule.c

Issue 20173: Derby #4: Convert 53 sites to Argument Clinic across 5 files
Patch Set: Created 6 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* ------------------------------------------------------------------------ 1 /* ------------------------------------------------------------------------
2 2
3 _codecs -- Provides access to the codec registry and the builtin 3 _codecs -- Provides access to the codec registry and the builtin
4 codecs. 4 codecs.
5 5
6 This module should never be imported directly. The standard library 6 This module should never be imported directly. The standard library
7 module "codecs" wraps this builtin module for use within Python. 7 module "codecs" wraps this builtin module for use within Python.
8 8
9 The codec registry is accessible via: 9 The codec registry is accessible via:
10 10
(...skipping 23 matching lines...) Expand all
34 Copyright (c) Corporation for National Research Initiatives. 34 Copyright (c) Corporation for National Research Initiatives.
35 35
36 ------------------------------------------------------------------------ */ 36 ------------------------------------------------------------------------ */
37 37
38 #define PY_SSIZE_T_CLEAN 38 #define PY_SSIZE_T_CLEAN
39 #include "Python.h" 39 #include "Python.h"
40 40
41 #ifdef MS_WINDOWS 41 #ifdef MS_WINDOWS
42 #include <windows.h> 42 #include <windows.h>
43 #endif 43 #endif
44
45 /*[clinic input]
46 module _codecs
47 class _codecs.Codecs
48 [clinic start generated code]*/
49 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
44 50
45 /* --- Registry ----------------------------------------------------------- */ 51 /* --- Registry ----------------------------------------------------------- */
46 52
47 PyDoc_STRVAR(register__doc__, 53 PyDoc_STRVAR(register__doc__,
48 "register(search_function)\n\ 54 "register(search_function)\n\
49 \n\ 55 \n\
50 Register a codec search function. Search functions are expected to take\n\ 56 Register a codec search function. Search functions are expected to take\n\
51 one argument, the encoding name in all lower case letters, and return\n\ 57 one argument, the encoding name in all lower case letters, and return\n\
52 a tuple of functions (encoder, decoder, stream_reader, stream_writer)\n\ 58 a tuple of functions (encoder, decoder, stream_reader, stream_writer)\n\
53 (or a CodecInfo object)."); 59 (or a CodecInfo object).");
54 60
55 static 61 static
56 PyObject *codec_register(PyObject *self, PyObject *search_function) 62 PyObject *codec_register(PyObject *self, PyObject *search_function)
57 { 63 {
58 if (PyCodec_Register(search_function)) 64 if (PyCodec_Register(search_function))
59 return NULL; 65 return NULL;
60 66
61 Py_RETURN_NONE; 67 Py_RETURN_NONE;
62 } 68 }
63 69
64 PyDoc_STRVAR(lookup__doc__, 70 /*[clinic input]
65 "lookup(encoding) -> CodecInfo\n\ 71 _codecs.Codecs.lookup
66 \n\ 72 encoding: str
67 Looks up a codec tuple in the Python codec registry and returns\n\ 73 /
68 a CodecInfo object."); 74
69 75 Looks up an encoding.
70 static 76
71 PyObject *codec_lookup(PyObject *self, PyObject *args) 77 Looks up a codec tuple in the Python codec registry and returns a CodecInfo
72 { 78 object.
73 char *encoding; 79 [clinic start generated code]*/
74 80
75 if (!PyArg_ParseTuple(args, "s:lookup", &encoding)) 81 PyDoc_STRVAR(_codecs_Codecs_lookup__doc__,
76 return NULL; 82 "lookup(encoding)\n"
77 83 "Looks up an encoding.\n"
84 "\n"
85 "Looks up a codec tuple in the Python codec registry and returns a CodecInfo\n"
86 "object.");
87
88 #define _CODECS_CODECS_LOOKUP_METHODDEF \
89 {"lookup", (PyCFunction)_codecs_Codecs_lookup, METH_VARARGS, _codecs_Codecs_ lookup__doc__},
90
91 static PyObject *
92 _codecs_Codecs_lookup_impl(PyObject *self, const char *encoding);
93
94 static PyObject *
95 _codecs_Codecs_lookup(PyObject *self, PyObject *args)
96 {
97 PyObject *return_value = NULL;
98 const char *encoding;
99
100 if (!PyArg_ParseTuple(args,
101 "s:lookup",
102 &encoding))
103 goto exit;
104 return_value = _codecs_Codecs_lookup_impl(self, encoding);
105
106 exit:
107 return return_value;
108 }
109
110 static PyObject *
111 _codecs_Codecs_lookup_impl(PyObject *self, const char *encoding)
112 /*[clinic end generated code: checksum=b68ced685fd46f0cc233b29e343223b4eaac86d7] */
113 {
78 return _PyCodec_Lookup(encoding); 114 return _PyCodec_Lookup(encoding);
79 } 115 }
80 116
81 PyDoc_STRVAR(encode__doc__, 117 /*[clinic input]
82 "encode(obj, [encoding[,errors]]) -> object\n\ 118 _codecs.Codecs.encode
83 \n\ 119 obj: object
84 Encodes obj using the codec registered for encoding. encoding defaults\n\ 120 [
85 to the default encoding. errors may be given to set a different error\n\ 121 encoding: str
86 handling scheme. Default is 'strict' meaning that encoding errors raise\n\ 122 [
87 a ValueError. Other possible values are 'ignore', 'replace' and\n\ 123 errors: str
88 'xmlcharrefreplace' as well as any other name registered with\n\ 124 ]
89 codecs.register_error that can handle ValueErrors."); 125 ]
90 126 /
91 static PyObject * 127
92 codec_encode(PyObject *self, PyObject *args) 128 Encodes obj using the codec registered for encoding.
93 { 129
130 encoding defaults to the default encoding. errors may be given to set a
131 different error handling scheme. Default is 'strict' meaning that encoding
132 errors raise a ValueError. Other possible values are 'ignore', 'replace' and
133 'xmlcharrefreplace' as well as any other name registered with
134 codecs.register_error that can handle ValueErrors.
135 [clinic start generated code]*/
136
137 PyDoc_STRVAR(_codecs_Codecs_encode__doc__,
138 "encode(obj, [encoding, [errors]])\n"
139 "Encodes obj using the codec registered for encoding.\n"
140 "\n"
141 "encoding defaults to the default encoding. errors may be given to set a\n"
142 "different error handling scheme. Default is \'strict\' meaning that encoding\n"
143 "errors raise a ValueError. Other possible values are \'ignore\', \'replace\' an d\n"
144 "\'xmlcharrefreplace\' as well as any other name registered with\n"
145 "codecs.register_error that can handle ValueErrors.");
146
147 #define _CODECS_CODECS_ENCODE_METHODDEF \
148 {"encode", (PyCFunction)_codecs_Codecs_encode, METH_VARARGS, _codecs_Codecs_ encode__doc__},
149
150 static PyObject *
151 _codecs_Codecs_encode_impl(PyObject *self, PyObject *obj, int group_right_1, con st char *encoding, int group_right_2, const char *errors);
152
153 static PyObject *
154 _codecs_Codecs_encode(PyObject *self, PyObject *args)
155 {
156 PyObject *return_value = NULL;
157 PyObject *obj;
158 int group_right_1 = 0;
94 const char *encoding = NULL; 159 const char *encoding = NULL;
160 int group_right_2 = 0;
95 const char *errors = NULL; 161 const char *errors = NULL;
96 PyObject *v; 162
97 163 switch (PyTuple_Size(args)) {
98 if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors)) 164 case 1:
99 return NULL; 165 if (!PyArg_ParseTuple(args, "O:encode", &obj))
100 166 return NULL;
167 break;
168 case 2:
169 if (!PyArg_ParseTuple(args, "Os:encode", &obj, &encoding))
170 return NULL;
171 group_right_1 = 1;
172 break;
173 case 3:
174 if (!PyArg_ParseTuple(args, "Oss:encode", &obj, &encoding, &errors))
175 return NULL;
176 group_right_1 = 1;
177 group_right_2 = 1;
178 break;
179 default:
180 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.encode requires 1 t o 3 arguments");
181 return NULL;
182 }
183 return_value = _codecs_Codecs_encode_impl(self, obj, group_right_1, encoding , group_right_2, errors);
184
185 return return_value;
186 }
187
188 static PyObject *
189 _codecs_Codecs_encode_impl(PyObject *self, PyObject *obj, int group_right_1, con st char *encoding, int group_right_2, const char *errors)
190 /*[clinic end generated code: checksum=5e09245ea83ae503ab82e658194a8b11713f9087] */
191 {
101 if (encoding == NULL) 192 if (encoding == NULL)
102 encoding = PyUnicode_GetDefaultEncoding(); 193 encoding = PyUnicode_GetDefaultEncoding();
103 194
104 /* Encode via the codec registry */ 195 /* Encode via the codec registry */
105 return PyCodec_Encode(v, encoding, errors); 196 return PyCodec_Encode(obj, encoding, errors);
106 } 197 }
107 198
108 PyDoc_STRVAR(decode__doc__, 199 /*[clinic input]
109 "decode(obj, [encoding[,errors]]) -> object\n\ 200 _codecs.Codecs.decode
110 \n\ 201 obj: object
111 Decodes obj using the codec registered for encoding. encoding defaults\n\ 202 [
112 to the default encoding. errors may be given to set a different error\n\ 203 encoding: str
113 handling scheme. Default is 'strict' meaning that encoding errors raise\n\ 204 [
114 a ValueError. Other possible values are 'ignore' and 'replace'\n\ 205 errors: str
115 as well as any other name registered with codecs.register_error that is\n\ 206 ]
116 able to handle ValueErrors."); 207 ]
117 208 /
118 static PyObject * 209
119 codec_decode(PyObject *self, PyObject *args) 210 Decodes obj using the codec registered for encoding.
120 { 211
212 encoding defaults to the default encoding. errors may be given to set a
213 different error handling scheme. Default is 'strict' meaning that encoding
214 errors raise a ValueError. Other possible values are 'ignore' and 'replace'
215 as well as any other name registered with codecs.register_error that is
216 able to handle ValueErrors.
217 [clinic start generated code]*/
218
219 PyDoc_STRVAR(_codecs_Codecs_decode__doc__,
220 "decode(obj, [encoding, [errors]])\n"
221 "Decodes obj using the codec registered for encoding.\n"
222 "\n"
223 "encoding defaults to the default encoding. errors may be given to set a\n"
224 "different error handling scheme. Default is \'strict\' meaning that encoding\n"
225 "errors raise a ValueError. Other possible values are \'ignore\' and \'replace\' \n"
226 "as well as any other name registered with codecs.register_error that is\n"
227 "able to handle ValueErrors.");
228
229 #define _CODECS_CODECS_DECODE_METHODDEF \
230 {"decode", (PyCFunction)_codecs_Codecs_decode, METH_VARARGS, _codecs_Codecs_ decode__doc__},
231
232 static PyObject *
233 _codecs_Codecs_decode_impl(PyObject *self, PyObject *obj, int group_right_1, con st char *encoding, int group_right_2, const char *errors);
234
235 static PyObject *
236 _codecs_Codecs_decode(PyObject *self, PyObject *args)
237 {
238 PyObject *return_value = NULL;
239 PyObject *obj;
240 int group_right_1 = 0;
121 const char *encoding = NULL; 241 const char *encoding = NULL;
242 int group_right_2 = 0;
122 const char *errors = NULL; 243 const char *errors = NULL;
123 PyObject *v; 244
124 245 switch (PyTuple_Size(args)) {
125 if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors)) 246 case 1:
126 return NULL; 247 if (!PyArg_ParseTuple(args, "O:decode", &obj))
127 248 return NULL;
249 break;
250 case 2:
251 if (!PyArg_ParseTuple(args, "Os:decode", &obj, &encoding))
252 return NULL;
253 group_right_1 = 1;
254 break;
255 case 3:
256 if (!PyArg_ParseTuple(args, "Oss:decode", &obj, &encoding, &errors))
257 return NULL;
258 group_right_1 = 1;
259 group_right_2 = 1;
260 break;
261 default:
262 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.decode requires 1 t o 3 arguments");
263 return NULL;
264 }
265 return_value = _codecs_Codecs_decode_impl(self, obj, group_right_1, encoding , group_right_2, errors);
266
267 return return_value;
268 }
269
270 static PyObject *
271 _codecs_Codecs_decode_impl(PyObject *self, PyObject *obj, int group_right_1, con st char *encoding, int group_right_2, const char *errors)
272 /*[clinic end generated code: checksum=26e9991555f0b60c6eb70d7408b027d788a338d4] */
273 {
128 if (encoding == NULL) 274 if (encoding == NULL)
129 encoding = PyUnicode_GetDefaultEncoding(); 275 encoding = PyUnicode_GetDefaultEncoding();
130 276
131 /* Decode via the codec registry */ 277 /* Decode via the codec registry */
132 return PyCodec_Decode(v, encoding, errors); 278 return PyCodec_Decode(obj, encoding, errors);
133 } 279 }
134 280
135 /* --- Helpers ------------------------------------------------------------ */ 281 /* --- Helpers ------------------------------------------------------------ */
136 282
137 static 283 static
138 PyObject *codec_tuple(PyObject *unicode, 284 PyObject *codec_tuple(PyObject *unicode,
139 Py_ssize_t len) 285 Py_ssize_t len)
140 { 286 {
141 PyObject *v; 287 PyObject *v;
142 if (unicode == NULL) 288 if (unicode == NULL)
143 return NULL; 289 return NULL;
144 v = Py_BuildValue("On", unicode, len); 290 v = Py_BuildValue("On", unicode, len);
145 Py_DECREF(unicode); 291 Py_DECREF(unicode);
146 return v; 292 return v;
147 } 293 }
148 294
149 /* --- String codecs ------------------------------------------------------ */ 295 /* --- String codecs ------------------------------------------------------ */
296 /*[clinic input]
297 _codecs.Codecs.escape_decode
298 data: str(length=True)
299 [
300 errors: str(nullable=True)
301 ]
302 /
303 [clinic start generated code]*/
304
305 PyDoc_STRVAR(_codecs_Codecs_escape_decode__doc__,
306 "escape_decode(data, [errors])");
307
308 #define _CODECS_CODECS_ESCAPE_DECODE_METHODDEF \
309 {"escape_decode", (PyCFunction)_codecs_Codecs_escape_decode, METH_VARARGS, _ codecs_Codecs_escape_decode__doc__},
310
150 static PyObject * 311 static PyObject *
151 escape_decode(PyObject *self, 312 _codecs_Codecs_escape_decode_impl(PyObject *self, const char *data, Py_ssize_cle an_t data_length, int group_right_1, const char *errors);
152 PyObject *args) 313
314 static PyObject *
315 _codecs_Codecs_escape_decode(PyObject *self, PyObject *args)
153 { 316 {
317 PyObject *return_value = NULL;
318 const char *data;
319 Py_ssize_clean_t data_length;
320 int group_right_1 = 0;
154 const char *errors = NULL; 321 const char *errors = NULL;
155 const char *data;
156 Py_ssize_t size;
157 322
158 if (!PyArg_ParseTuple(args, "s#|z:escape_decode", 323 switch (PyTuple_Size(args)) {
159 &data, &size, &errors)) 324 case 1:
160 return NULL; 325 if (!PyArg_ParseTuple(args, "s#:escape_decode", &data, &data_length) )
161 return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL), 326 return NULL;
162 size); 327 break;
328 case 2:
329 if (!PyArg_ParseTuple(args, "s#z:escape_decode", &data, &data_length , &errors))
330 return NULL;
331 group_right_1 = 1;
332 break;
333 default:
334 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.escape_decode requi res 1 to 2 arguments");
335 return NULL;
336 }
337 return_value = _codecs_Codecs_escape_decode_impl(self, data, data_length, gr oup_right_1, errors);
338
339 return return_value;
163 } 340 }
164 341
165 static PyObject * 342 static PyObject *
166 escape_encode(PyObject *self, 343 _codecs_Codecs_escape_decode_impl(PyObject *self, const char *data, Py_ssize_cle an_t data_length, int group_right_1, const char *errors)
167 PyObject *args) 344 /*[clinic end generated code: checksum=2ac63e14d21c21cabf3f0cac826d6e02c16b4d8b] */
168 { 345 {
346 return codec_tuple(PyBytes_DecodeEscape(data, data_length, errors, 0, NULL),
347 data_length);
348 }
349
350 /*[clinic input]
351 _codecs.Codecs.escape_encode
352 str: object(subclass_of='&PyBytes_Type')
353 [
354 errors: str(nullable=True)
355 ]
356 /
357 [clinic start generated code]*/
358
359 PyDoc_STRVAR(_codecs_Codecs_escape_encode__doc__,
360 "escape_encode(str, [errors])");
361
362 #define _CODECS_CODECS_ESCAPE_ENCODE_METHODDEF \
363 {"escape_encode", (PyCFunction)_codecs_Codecs_escape_encode, METH_VARARGS, _ codecs_Codecs_escape_encode__doc__},
364
365 static PyObject *
366 _codecs_Codecs_escape_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors);
367
368 static PyObject *
369 _codecs_Codecs_escape_encode(PyObject *self, PyObject *args)
370 {
371 PyObject *return_value = NULL;
169 PyObject *str; 372 PyObject *str;
373 int group_right_1 = 0;
374 const char *errors = NULL;
375
376 switch (PyTuple_Size(args)) {
377 case 1:
378 if (!PyArg_ParseTuple(args, "O!:escape_encode", &PyBytes_Type, &str) )
379 return NULL;
380 break;
381 case 2:
382 if (!PyArg_ParseTuple(args, "O!z:escape_encode", &PyBytes_Type, &str , &errors))
383 return NULL;
384 group_right_1 = 1;
385 break;
386 default:
387 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.escape_encode requi res 1 to 2 arguments");
388 return NULL;
389 }
390 return_value = _codecs_Codecs_escape_encode_impl(self, str, group_right_1, e rrors);
391
392 return return_value;
393 }
394
395 static PyObject *
396 _codecs_Codecs_escape_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors)
397 /*[clinic end generated code: checksum=1825e81def2fe1c52abb6db205208cef0013cfc8] */
398 {
170 Py_ssize_t size; 399 Py_ssize_t size;
171 Py_ssize_t newsize; 400 Py_ssize_t newsize;
172 const char *errors = NULL;
173 PyObject *v; 401 PyObject *v;
174
175 if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
176 &PyBytes_Type, &str, &errors))
177 return NULL;
178 402
179 size = PyBytes_GET_SIZE(str); 403 size = PyBytes_GET_SIZE(str);
180 if (size > PY_SSIZE_T_MAX / 4) { 404 if (size > PY_SSIZE_T_MAX / 4) {
181 PyErr_SetString(PyExc_OverflowError, 405 PyErr_SetString(PyExc_OverflowError,
182 "string is too large to encode"); 406 "string is too large to encode");
183 return NULL; 407 return NULL;
184 } 408 }
185 newsize = 4*size; 409 newsize = 4*size;
186 v = PyBytes_FromStringAndSize(NULL, newsize); 410 v = PyBytes_FromStringAndSize(NULL, newsize);
187 411
(...skipping 29 matching lines...) Expand all
217 *p = '\0'; 441 *p = '\0';
218 if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) { 442 if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
219 return NULL; 443 return NULL;
220 } 444 }
221 } 445 }
222 446
223 return codec_tuple(v, size); 447 return codec_tuple(v, size);
224 } 448 }
225 449
226 /* --- Decoder ------------------------------------------------------------ */ 450 /* --- Decoder ------------------------------------------------------------ */
451 /*[clinic input]
452 _codecs.Codecs.unicode_internal_decode
453 obj: object
454 [
455 errors: str(nullable=True)
456 ]
457 /
458 [clinic start generated code]*/
459
460 PyDoc_STRVAR(_codecs_Codecs_unicode_internal_decode__doc__,
461 "unicode_internal_decode(obj, [errors])");
462
463 #define _CODECS_CODECS_UNICODE_INTERNAL_DECODE_METHODDEF \
464 {"unicode_internal_decode", (PyCFunction)_codecs_Codecs_unicode_internal_dec ode, METH_VARARGS, _codecs_Codecs_unicode_internal_decode__doc__},
227 465
228 static PyObject * 466 static PyObject *
229 unicode_internal_decode(PyObject *self, 467 _codecs_Codecs_unicode_internal_decode_impl(PyObject *self, PyObject *obj, int g roup_right_1, const char *errors);
230 PyObject *args) 468
469 static PyObject *
470 _codecs_Codecs_unicode_internal_decode(PyObject *self, PyObject *args)
231 { 471 {
472 PyObject *return_value = NULL;
232 PyObject *obj; 473 PyObject *obj;
474 int group_right_1 = 0;
233 const char *errors = NULL; 475 const char *errors = NULL;
476
477 switch (PyTuple_Size(args)) {
478 case 1:
479 if (!PyArg_ParseTuple(args, "O:unicode_internal_decode", &obj))
480 return NULL;
481 break;
482 case 2:
483 if (!PyArg_ParseTuple(args, "Oz:unicode_internal_decode", &obj, &err ors))
484 return NULL;
485 group_right_1 = 1;
486 break;
487 default:
488 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.unicode_internal_de code requires 1 to 2 arguments");
489 return NULL;
490 }
491 return_value = _codecs_Codecs_unicode_internal_decode_impl(self, obj, group_ right_1, errors);
492
493 return return_value;
494 }
495
496 static PyObject *
497 _codecs_Codecs_unicode_internal_decode_impl(PyObject *self, PyObject *obj, int g roup_right_1, const char *errors)
498 /*[clinic end generated code: checksum=71ea63c2d7d1b64a688913e0305dc98487e01956] */
499 {
234 const char *data; 500 const char *data;
235 Py_ssize_t size; 501 Py_ssize_t size;
236
237 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
238 &obj, &errors))
239 return NULL;
240 502
241 if (PyUnicode_Check(obj)) { 503 if (PyUnicode_Check(obj)) {
242 if (PyUnicode_READY(obj) < 0) 504 if (PyUnicode_READY(obj) < 0)
243 return NULL; 505 return NULL;
244 Py_INCREF(obj); 506 Py_INCREF(obj);
245 return codec_tuple(obj, PyUnicode_GET_LENGTH(obj)); 507 return codec_tuple(obj, PyUnicode_GET_LENGTH(obj));
246 } 508 }
247 else { 509 else {
248 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) 510 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
249 return NULL; 511 return NULL;
250 512
251 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors), 513 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
252 size); 514 size);
253 } 515 }
254 } 516 }
255 517
256 static PyObject * 518 /*[clinic input]
257 utf_7_decode(PyObject *self, 519 _codecs.Codecs.utf_7_decode
258 PyObject *args) 520 pbuf: Py_buffer
259 { 521 [
260 Py_buffer pbuf; 522 errors: str(nullable=True)
261 const char *errors = NULL; 523 [
262 int final = 0; 524 final: int = 0
263 Py_ssize_t consumed; 525 ]
526 ]
527 /
528 [clinic start generated code]*/
529
530 PyDoc_STRVAR(_codecs_Codecs_utf_7_decode__doc__,
531 "utf_7_decode(pbuf, [errors, [final=0]])");
532
533 #define _CODECS_CODECS_UTF_7_DECODE_METHODDEF \
534 {"utf_7_decode", (PyCFunction)_codecs_Codecs_utf_7_decode, METH_VARARGS, _co decs_Codecs_utf_7_decode__doc__},
535
536 static PyObject *
537 _codecs_Codecs_utf_7_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors, int group_right_2, int final);
538
539 static PyObject *
540 _codecs_Codecs_utf_7_decode(PyObject *self, PyObject *args)
541 {
542 PyObject *return_value = NULL;
543 Py_buffer pbuf = {NULL, NULL};
544 int group_right_1 = 0;
545 const char *errors = NULL;
546 int group_right_2 = 0;
547 int final = 0;
548
549 switch (PyTuple_Size(args)) {
550 case 1:
551 if (!PyArg_ParseTuple(args, "y*:utf_7_decode", &pbuf))
552 return NULL;
553 break;
554 case 2:
555 if (!PyArg_ParseTuple(args, "y*z:utf_7_decode", &pbuf, &errors))
556 return NULL;
557 group_right_1 = 1;
558 break;
559 case 3:
560 if (!PyArg_ParseTuple(args, "y*zi:utf_7_decode", &pbuf, &errors, &fi nal))
561 return NULL;
562 group_right_1 = 1;
563 group_right_2 = 1;
564 break;
565 default:
566 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_7_decode requir es 1 to 3 arguments");
567 return NULL;
568 }
569 return_value = _codecs_Codecs_utf_7_decode_impl(self, &pbuf, group_right_1, errors, group_right_2, final);
570
571 /* Cleanup for pbuf */
572 if (pbuf.obj)
573 PyBuffer_Release(&pbuf);
574
575 return return_value;
576 }
577
578 static PyObject *
579 _codecs_Codecs_utf_7_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors, int group_right_2, int final)
580 /*[clinic end generated code: checksum=55ae215e968f480805f4c949963e23817a34605f] */
581 {
582 Py_ssize_t consumed = pbuf->len;
264 PyObject *decoded = NULL; 583 PyObject *decoded = NULL;
265 584
266 if (!PyArg_ParseTuple(args, "y*|zi:utf_7_decode", 585 decoded = PyUnicode_DecodeUTF7Stateful(pbuf->buf, pbuf->len, errors,
267 &pbuf, &errors, &final))
268 return NULL;
269 consumed = pbuf.len;
270
271 decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
272 final ? NULL : &consumed); 586 final ? NULL : &consumed);
273 PyBuffer_Release(&pbuf); 587 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
274 if (decoded == NULL) 588 if (decoded == NULL)
275 return NULL; 589 return NULL;
276 return codec_tuple(decoded, consumed); 590 return codec_tuple(decoded, consumed);
277 } 591 }
278 592
279 static PyObject * 593 /*[clinic input]
280 utf_8_decode(PyObject *self, 594 _codecs.Codecs.utf_8_decode
281 PyObject *args) 595 pbuf: Py_buffer
282 { 596 [
283 Py_buffer pbuf; 597 errors: str(nullable=True)
284 const char *errors = NULL; 598 [
285 int final = 0; 599 final: int = 0
286 Py_ssize_t consumed; 600 ]
601 ]
602 /
603 [clinic start generated code]*/
604
605 PyDoc_STRVAR(_codecs_Codecs_utf_8_decode__doc__,
606 "utf_8_decode(pbuf, [errors, [final=0]])");
607
608 #define _CODECS_CODECS_UTF_8_DECODE_METHODDEF \
609 {"utf_8_decode", (PyCFunction)_codecs_Codecs_utf_8_decode, METH_VARARGS, _co decs_Codecs_utf_8_decode__doc__},
610
611 static PyObject *
612 _codecs_Codecs_utf_8_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors, int group_right_2, int final);
613
614 static PyObject *
615 _codecs_Codecs_utf_8_decode(PyObject *self, PyObject *args)
616 {
617 PyObject *return_value = NULL;
618 Py_buffer pbuf = {NULL, NULL};
619 int group_right_1 = 0;
620 const char *errors = NULL;
621 int group_right_2 = 0;
622 int final = 0;
623
624 switch (PyTuple_Size(args)) {
625 case 1:
626 if (!PyArg_ParseTuple(args, "y*:utf_8_decode", &pbuf))
627 return NULL;
628 break;
629 case 2:
630 if (!PyArg_ParseTuple(args, "y*z:utf_8_decode", &pbuf, &errors))
631 return NULL;
632 group_right_1 = 1;
633 break;
634 case 3:
635 if (!PyArg_ParseTuple(args, "y*zi:utf_8_decode", &pbuf, &errors, &fi nal))
636 return NULL;
637 group_right_1 = 1;
638 group_right_2 = 1;
639 break;
640 default:
641 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_8_decode requir es 1 to 3 arguments");
642 return NULL;
643 }
644 return_value = _codecs_Codecs_utf_8_decode_impl(self, &pbuf, group_right_1, errors, group_right_2, final);
645
646 /* Cleanup for pbuf */
647 if (pbuf.obj)
648 PyBuffer_Release(&pbuf);
649
650 return return_value;
651 }
652
653 static PyObject *
654 _codecs_Codecs_utf_8_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors, int group_right_2, int final)
655 /*[clinic end generated code: checksum=9e9ac13c3aa2323e0038e64e161ebfbac2b7223b] */
656 {
657 Py_ssize_t consumed = pbuf->len;
287 PyObject *decoded = NULL; 658 PyObject *decoded = NULL;
288 659
289 if (!PyArg_ParseTuple(args, "y*|zi:utf_8_decode", 660 decoded = PyUnicode_DecodeUTF8Stateful(pbuf->buf, pbuf->len, errors,
290 &pbuf, &errors, &final))
291 return NULL;
292 consumed = pbuf.len;
293
294 decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
295 final ? NULL : &consumed); 661 final ? NULL : &consumed);
296 PyBuffer_Release(&pbuf); 662 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the buffe
297 if (decoded == NULL) 663 if (decoded == NULL)
298 return NULL; 664 return NULL;
299 return codec_tuple(decoded, consumed); 665 return codec_tuple(decoded, consumed);
300 } 666 }
301 667
302 static PyObject * 668 /*[clinic input]
303 utf_16_decode(PyObject *self, 669 _codecs.Codecs.utf_16_decode
304 PyObject *args) 670 pbuf: Py_buffer
305 { 671 [
306 Py_buffer pbuf; 672 errors: str(nullable=True)
307 const char *errors = NULL; 673 [
674 final: int = 0
675 ]
676 ]
677 /
678 [clinic start generated code]*/
679
680 PyDoc_STRVAR(_codecs_Codecs_utf_16_decode__doc__,
681 "utf_16_decode(pbuf, [errors, [final=0]])");
682
683 #define _CODECS_CODECS_UTF_16_DECODE_METHODDEF \
684 {"utf_16_decode", (PyCFunction)_codecs_Codecs_utf_16_decode, METH_VARARGS, _ codecs_Codecs_utf_16_decode__doc__},
685
686 static PyObject *
687 _codecs_Codecs_utf_16_decode_impl(PyObject *self, Py_buffer *pbuf, int group_rig ht_1, const char *errors, int group_right_2, int final);
688
689 static PyObject *
690 _codecs_Codecs_utf_16_decode(PyObject *self, PyObject *args)
691 {
692 PyObject *return_value = NULL;
693 Py_buffer pbuf = {NULL, NULL};
694 int group_right_1 = 0;
695 const char *errors = NULL;
696 int group_right_2 = 0;
697 int final = 0;
698
699 switch (PyTuple_Size(args)) {
700 case 1:
701 if (!PyArg_ParseTuple(args, "y*:utf_16_decode", &pbuf))
702 return NULL;
703 break;
704 case 2:
705 if (!PyArg_ParseTuple(args, "y*z:utf_16_decode", &pbuf, &errors))
706 return NULL;
707 group_right_1 = 1;
708 break;
709 case 3:
710 if (!PyArg_ParseTuple(args, "y*zi:utf_16_decode", &pbuf, &errors, &f inal))
711 return NULL;
712 group_right_1 = 1;
713 group_right_2 = 1;
714 break;
715 default:
716 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_decode requi res 1 to 3 arguments");
717 return NULL;
718 }
719 return_value = _codecs_Codecs_utf_16_decode_impl(self, &pbuf, group_right_1, errors, group_right_2, final);
720
721 /* Cleanup for pbuf */
722 if (pbuf.obj)
723 PyBuffer_Release(&pbuf);
724
725 return return_value;
726 }
727
728 static PyObject *
729 _codecs_Codecs_utf_16_decode_impl(PyObject *self, Py_buffer *pbuf, int group_rig ht_1, const char *errors, int group_right_2, int final)
730 /*[clinic end generated code: checksum=59e4ef2baf52a76cd8628624df8523da2f6adbff] */
731 {
308 int byteorder = 0; 732 int byteorder = 0;
309 int final = 0;
310 Py_ssize_t consumed;
311 PyObject *decoded; 733 PyObject *decoded;
312 734 /* This is overwritten unless final is true. */
313 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_decode", 735 Py_ssize_t consumed = pbuf->len;
314 &pbuf, &errors, &final)) 736
315 return NULL; 737 decoded = PyUnicode_DecodeUTF16Stateful(pbuf->buf, pbuf->len, errors,
316 consumed = pbuf.len; /* This is overwritten unless final is true. */
317 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
318 &byteorder, final ? NULL : &consumed); 738 &byteorder, final ? NULL : &consumed);
319 PyBuffer_Release(&pbuf); 739 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
320 if (decoded == NULL) 740 if (decoded == NULL)
321 return NULL; 741 return NULL;
322 return codec_tuple(decoded, consumed); 742 return codec_tuple(decoded, consumed);
323 } 743 }
324 744
325 static PyObject * 745 /*[clinic input]
326 utf_16_le_decode(PyObject *self, 746 _codecs.Codecs.utf_16_le_decode
327 PyObject *args) 747 pbuf: Py_buffer
328 { 748 [
329 Py_buffer pbuf; 749 errors: str(nullable=True)
330 const char *errors = NULL; 750 [
751 final: int = 0
752 ]
753 ]
754 /
755 [clinic start generated code]*/
756
757 PyDoc_STRVAR(_codecs_Codecs_utf_16_le_decode__doc__,
758 "utf_16_le_decode(pbuf, [errors, [final=0]])");
759
760 #define _CODECS_CODECS_UTF_16_LE_DECODE_METHODDEF \
761 {"utf_16_le_decode", (PyCFunction)_codecs_Codecs_utf_16_le_decode, METH_VARA RGS, _codecs_Codecs_utf_16_le_decode__doc__},
762
763 static PyObject *
764 _codecs_Codecs_utf_16_le_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final);
765
766 static PyObject *
767 _codecs_Codecs_utf_16_le_decode(PyObject *self, PyObject *args)
768 {
769 PyObject *return_value = NULL;
770 Py_buffer pbuf = {NULL, NULL};
771 int group_right_1 = 0;
772 const char *errors = NULL;
773 int group_right_2 = 0;
774 int final = 0;
775
776 switch (PyTuple_Size(args)) {
777 case 1:
778 if (!PyArg_ParseTuple(args, "y*:utf_16_le_decode", &pbuf))
779 return NULL;
780 break;
781 case 2:
782 if (!PyArg_ParseTuple(args, "y*z:utf_16_le_decode", &pbuf, &errors))
783 return NULL;
784 group_right_1 = 1;
785 break;
786 case 3:
787 if (!PyArg_ParseTuple(args, "y*zi:utf_16_le_decode", &pbuf, &errors, &final))
788 return NULL;
789 group_right_1 = 1;
790 group_right_2 = 1;
791 break;
792 default:
793 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_le_decode re quires 1 to 3 arguments");
794 return NULL;
795 }
796 return_value = _codecs_Codecs_utf_16_le_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, final);
797
798 /* Cleanup for pbuf */
799 if (pbuf.obj)
800 PyBuffer_Release(&pbuf);
801
802 return return_value;
803 }
804
805 static PyObject *
806 _codecs_Codecs_utf_16_le_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final)
807 /*[clinic end generated code: checksum=47b76a3cd19f37458b16f07e087b0d6790f20104] */
808 {
331 int byteorder = -1; 809 int byteorder = -1;
332 int final = 0; 810 /* This is overwritten unless final is true. */
333 Py_ssize_t consumed; 811 Py_ssize_t consumed = pbuf->len;
334 PyObject *decoded = NULL; 812 PyObject *decoded = NULL;
335 813
336 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_le_decode", 814 decoded = PyUnicode_DecodeUTF16Stateful(pbuf->buf, pbuf->len, errors,
337 &pbuf, &errors, &final))
338 return NULL;
339
340 consumed = pbuf.len; /* This is overwritten unless final is true. */
341 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
342 &byteorder, final ? NULL : &consumed); 815 &byteorder, final ? NULL : &consumed);
343 PyBuffer_Release(&pbuf); 816 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
344 if (decoded == NULL) 817 if (decoded == NULL)
345 return NULL; 818 return NULL;
346 return codec_tuple(decoded, consumed); 819 return codec_tuple(decoded, consumed);
347 } 820 }
348 821
349 static PyObject * 822 /*[clinic input]
350 utf_16_be_decode(PyObject *self, 823 _codecs.Codecs.utf_16_be_decode
351 PyObject *args) 824 pbuf: Py_buffer
352 { 825 [
353 Py_buffer pbuf; 826 errors: str(nullable=True)
354 const char *errors = NULL; 827 [
828 final: int = 0
829 ]
830 ]
831 /
832 [clinic start generated code]*/
833
834 PyDoc_STRVAR(_codecs_Codecs_utf_16_be_decode__doc__,
835 "utf_16_be_decode(pbuf, [errors, [final=0]])");
836
837 #define _CODECS_CODECS_UTF_16_BE_DECODE_METHODDEF \
838 {"utf_16_be_decode", (PyCFunction)_codecs_Codecs_utf_16_be_decode, METH_VARA RGS, _codecs_Codecs_utf_16_be_decode__doc__},
839
840 static PyObject *
841 _codecs_Codecs_utf_16_be_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final);
842
843 static PyObject *
844 _codecs_Codecs_utf_16_be_decode(PyObject *self, PyObject *args)
845 {
846 PyObject *return_value = NULL;
847 Py_buffer pbuf = {NULL, NULL};
848 int group_right_1 = 0;
849 const char *errors = NULL;
850 int group_right_2 = 0;
851 int final = 0;
852
853 switch (PyTuple_Size(args)) {
854 case 1:
855 if (!PyArg_ParseTuple(args, "y*:utf_16_be_decode", &pbuf))
856 return NULL;
857 break;
858 case 2:
859 if (!PyArg_ParseTuple(args, "y*z:utf_16_be_decode", &pbuf, &errors))
860 return NULL;
861 group_right_1 = 1;
862 break;
863 case 3:
864 if (!PyArg_ParseTuple(args, "y*zi:utf_16_be_decode", &pbuf, &errors, &final))
865 return NULL;
866 group_right_1 = 1;
867 group_right_2 = 1;
868 break;
869 default:
870 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_be_decode re quires 1 to 3 arguments");
871 return NULL;
872 }
873 return_value = _codecs_Codecs_utf_16_be_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, final);
874
875 /* Cleanup for pbuf */
876 if (pbuf.obj)
877 PyBuffer_Release(&pbuf);
878
879 return return_value;
880 }
881
882 static PyObject *
883 _codecs_Codecs_utf_16_be_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final)
884 /*[clinic end generated code: checksum=90df345e0bc071a26d94e1b79ba51c90efa7e3e8] */
885 {
355 int byteorder = 1; 886 int byteorder = 1;
356 int final = 0; 887 /* This is overwritten unless final is true. */
357 Py_ssize_t consumed; 888 Py_ssize_t consumed = pbuf->len;
358 PyObject *decoded = NULL; 889 PyObject *decoded = NULL;
359 890
360 if (!PyArg_ParseTuple(args, "y*|zi:utf_16_be_decode", 891 decoded = PyUnicode_DecodeUTF16Stateful(pbuf->buf, pbuf->len, errors,
361 &pbuf, &errors, &final))
362 return NULL;
363
364 consumed = pbuf.len; /* This is overwritten unless final is true. */
365 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
366 &byteorder, final ? NULL : &consumed); 892 &byteorder, final ? NULL : &consumed);
367 PyBuffer_Release(&pbuf); 893 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
368 if (decoded == NULL) 894 if (decoded == NULL)
369 return NULL; 895 return NULL;
370 return codec_tuple(decoded, consumed); 896 return codec_tuple(decoded, consumed);
371 } 897 }
372 898
373 /* This non-standard version also provides access to the byteorder 899 /* This non-standard version also provides access to the byteorder
374 parameter of the builtin UTF-16 codec. 900 parameter of the builtin UTF-16 codec.
375 901
376 It returns a tuple (unicode, bytesread, byteorder) with byteorder 902 It returns a tuple (unicode, bytesread, byteorder) with byteorder
377 being the value in effect at the end of data. 903 being the value in effect at the end of data.
378 904
379 */ 905 */
906 /*[clinic input]
907 _codecs.Codecs.utf_16_ex_decode
908 pbuf: Py_buffer
909 [
910 errors: str(nullable=True)
911 [
912 byteorder: int = 0
913 [
914 final: int = 0
915 ]
916 ]
917 ]
918 /
919 [clinic start generated code]*/
920
921 PyDoc_STRVAR(_codecs_Codecs_utf_16_ex_decode__doc__,
922 "utf_16_ex_decode(pbuf, [errors, [byteorder=0, [final=0]]])");
923
924 #define _CODECS_CODECS_UTF_16_EX_DECODE_METHODDEF \
925 {"utf_16_ex_decode", (PyCFunction)_codecs_Codecs_utf_16_ex_decode, METH_VARA RGS, _codecs_Codecs_utf_16_ex_decode__doc__},
380 926
381 static PyObject * 927 static PyObject *
382 utf_16_ex_decode(PyObject *self, 928 _codecs_Codecs_utf_16_ex_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int byteorder, int group_right_3 , int final);
383 PyObject *args) 929
930 static PyObject *
931 _codecs_Codecs_utf_16_ex_decode(PyObject *self, PyObject *args)
384 { 932 {
385 Py_buffer pbuf; 933 PyObject *return_value = NULL;
934 Py_buffer pbuf = {NULL, NULL};
935 int group_right_1 = 0;
386 const char *errors = NULL; 936 const char *errors = NULL;
937 int group_right_2 = 0;
387 int byteorder = 0; 938 int byteorder = 0;
939 int group_right_3 = 0;
940 int final = 0;
941
942 switch (PyTuple_Size(args)) {
943 case 1:
944 if (!PyArg_ParseTuple(args, "y*:utf_16_ex_decode", &pbuf))
945 return NULL;
946 break;
947 case 2:
948 if (!PyArg_ParseTuple(args, "y*z:utf_16_ex_decode", &pbuf, &errors))
949 return NULL;
950 group_right_1 = 1;
951 break;
952 case 3:
953 if (!PyArg_ParseTuple(args, "y*zi:utf_16_ex_decode", &pbuf, &errors, &byteorder))
954 return NULL;
955 group_right_1 = 1;
956 group_right_2 = 1;
957 break;
958 case 4:
959 if (!PyArg_ParseTuple(args, "y*zii:utf_16_ex_decode", &pbuf, &errors , &byteorder, &final))
960 return NULL;
961 group_right_1 = 1;
962 group_right_2 = 1;
963 group_right_3 = 1;
964 break;
965 default:
966 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_ex_decode re quires 1 to 4 arguments");
967 return NULL;
968 }
969 return_value = _codecs_Codecs_utf_16_ex_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, byteorder, group_right_3, final);
970
971 /* Cleanup for pbuf */
972 if (pbuf.obj)
973 PyBuffer_Release(&pbuf);
974
975 return return_value;
976 }
977
978 static PyObject *
979 _codecs_Codecs_utf_16_ex_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int byteorder, int group_right_3 , int final)
980 /*[clinic end generated code: checksum=64c552405bb54fce83b025875ea578a24efc1d74] */
981 {
388 PyObject *unicode, *tuple; 982 PyObject *unicode, *tuple;
389 int final = 0; 983 /* This is overwritten unless final is true. */
390 Py_ssize_t consumed; 984 Py_ssize_t consumed = pbuf->len;
391 985
392 if (!PyArg_ParseTuple(args, "y*|zii:utf_16_ex_decode", 986 unicode = PyUnicode_DecodeUTF16Stateful(pbuf->buf, pbuf->len, errors,
393 &pbuf, &errors, &byteorder, &final))
394 return NULL;
395 consumed = pbuf.len; /* This is overwritten unless final is true. */
396 unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
397 &byteorder, final ? NULL : &consumed); 987 &byteorder, final ? NULL : &consumed);
398 PyBuffer_Release(&pbuf); 988 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
399 if (unicode == NULL) 989 if (unicode == NULL)
400 return NULL; 990 return NULL;
401 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); 991 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
402 Py_DECREF(unicode); 992 Py_DECREF(unicode);
403 return tuple; 993 return tuple;
404 } 994 }
405 995
406 static PyObject * 996 /*[clinic input]
407 utf_32_decode(PyObject *self, 997 _codecs.Codecs.utf_32_decode
408 PyObject *args) 998 pbuf: Py_buffer
409 { 999 [
410 Py_buffer pbuf; 1000 errors: str(nullable=True)
1001 [
1002 final: int = 0
1003 ]
1004 ]
1005 /
1006 [clinic start generated code]*/
1007
1008 PyDoc_STRVAR(_codecs_Codecs_utf_32_decode__doc__,
1009 "utf_32_decode(pbuf, [errors, [final=0]])");
1010
1011 #define _CODECS_CODECS_UTF_32_DECODE_METHODDEF \
1012 {"utf_32_decode", (PyCFunction)_codecs_Codecs_utf_32_decode, METH_VARARGS, _ codecs_Codecs_utf_32_decode__doc__},
1013
1014 static PyObject *
1015 _codecs_Codecs_utf_32_decode_impl(PyObject *self, Py_buffer *pbuf, int group_rig ht_1, const char *errors, int group_right_2, int final);
1016
1017 static PyObject *
1018 _codecs_Codecs_utf_32_decode(PyObject *self, PyObject *args)
1019 {
1020 PyObject *return_value = NULL;
1021 Py_buffer pbuf = {NULL, NULL};
1022 int group_right_1 = 0;
411 const char *errors = NULL; 1023 const char *errors = NULL;
1024 int group_right_2 = 0;
1025 int final = 0;
1026
1027 switch (PyTuple_Size(args)) {
1028 case 1:
1029 if (!PyArg_ParseTuple(args, "y*:utf_32_decode", &pbuf))
1030 return NULL;
1031 break;
1032 case 2:
1033 if (!PyArg_ParseTuple(args, "y*z:utf_32_decode", &pbuf, &errors))
1034 return NULL;
1035 group_right_1 = 1;
1036 break;
1037 case 3:
1038 if (!PyArg_ParseTuple(args, "y*zi:utf_32_decode", &pbuf, &errors, &f inal))
1039 return NULL;
1040 group_right_1 = 1;
1041 group_right_2 = 1;
1042 break;
1043 default:
1044 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_decode requi res 1 to 3 arguments");
1045 return NULL;
1046 }
1047 return_value = _codecs_Codecs_utf_32_decode_impl(self, &pbuf, group_right_1, errors, group_right_2, final);
1048
1049 /* Cleanup for pbuf */
1050 if (pbuf.obj)
1051 PyBuffer_Release(&pbuf);
1052
1053 return return_value;
1054 }
1055
1056 static PyObject *
1057 _codecs_Codecs_utf_32_decode_impl(PyObject *self, Py_buffer *pbuf, int group_rig ht_1, const char *errors, int group_right_2, int final)
1058 /*[clinic end generated code: checksum=bc5da0d82ec133876b0218ba496cfb1b583fdf11] */
1059 {
412 int byteorder = 0; 1060 int byteorder = 0;
413 int final = 0; 1061 /* This is overwritten unless final is true. */
414 Py_ssize_t consumed; 1062 Py_ssize_t consumed = pbuf->len;
415 PyObject *decoded; 1063 PyObject *decoded;
416 1064
417 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_decode", 1065 decoded = PyUnicode_DecodeUTF32Stateful(pbuf->buf, pbuf->len, errors,
418 &pbuf, &errors, &final))
419 return NULL;
420 consumed = pbuf.len; /* This is overwritten unless final is true. */
421 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
422 &byteorder, final ? NULL : &consumed); 1066 &byteorder, final ? NULL : &consumed);
423 PyBuffer_Release(&pbuf); 1067 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
424 if (decoded == NULL) 1068 if (decoded == NULL)
425 return NULL; 1069 return NULL;
426 return codec_tuple(decoded, consumed); 1070 return codec_tuple(decoded, consumed);
427 } 1071 }
428 1072
429 static PyObject * 1073 /*[clinic input]
430 utf_32_le_decode(PyObject *self, 1074 _codecs.Codecs.utf_32_le_decode
431 PyObject *args) 1075 pbuf: Py_buffer
432 { 1076 [
433 Py_buffer pbuf; 1077 errors: str(nullable=True)
1078 [
1079 final: int = 0
1080 ]
1081 ]
1082 /
1083 [clinic start generated code]*/
1084
1085 PyDoc_STRVAR(_codecs_Codecs_utf_32_le_decode__doc__,
1086 "utf_32_le_decode(pbuf, [errors, [final=0]])");
1087
1088 #define _CODECS_CODECS_UTF_32_LE_DECODE_METHODDEF \
1089 {"utf_32_le_decode", (PyCFunction)_codecs_Codecs_utf_32_le_decode, METH_VARA RGS, _codecs_Codecs_utf_32_le_decode__doc__},
1090
1091 static PyObject *
1092 _codecs_Codecs_utf_32_le_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final);
1093
1094 static PyObject *
1095 _codecs_Codecs_utf_32_le_decode(PyObject *self, PyObject *args)
1096 {
1097 PyObject *return_value = NULL;
1098 Py_buffer pbuf = {NULL, NULL};
1099 int group_right_1 = 0;
434 const char *errors = NULL; 1100 const char *errors = NULL;
1101 int group_right_2 = 0;
1102 int final = 0;
1103
1104 switch (PyTuple_Size(args)) {
1105 case 1:
1106 if (!PyArg_ParseTuple(args, "y*:utf_32_le_decode", &pbuf))
1107 return NULL;
1108 break;
1109 case 2:
1110 if (!PyArg_ParseTuple(args, "y*z:utf_32_le_decode", &pbuf, &errors))
1111 return NULL;
1112 group_right_1 = 1;
1113 break;
1114 case 3:
1115 if (!PyArg_ParseTuple(args, "y*zi:utf_32_le_decode", &pbuf, &errors, &final))
1116 return NULL;
1117 group_right_1 = 1;
1118 group_right_2 = 1;
1119 break;
1120 default:
1121 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_le_decode re quires 1 to 3 arguments");
1122 return NULL;
1123 }
1124 return_value = _codecs_Codecs_utf_32_le_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, final);
1125
1126 /* Cleanup for pbuf */
1127 if (pbuf.obj)
1128 PyBuffer_Release(&pbuf);
1129
1130 return return_value;
1131 }
1132
1133 static PyObject *
1134 _codecs_Codecs_utf_32_le_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final)
1135 /*[clinic end generated code: checksum=70ef9bfe9a4ddd0f05176c390e5cf73bf0c5ce50] */
1136 {
435 int byteorder = -1; 1137 int byteorder = -1;
436 int final = 0; 1138 /* This is overwritten unless final is true. */
437 Py_ssize_t consumed; 1139 Py_ssize_t consumed = pbuf->len;
438 PyObject *decoded; 1140 PyObject *decoded;
439 1141
440 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_le_decode", 1142 decoded = PyUnicode_DecodeUTF32Stateful(pbuf->buf, pbuf->len, errors,
441 &pbuf, &errors, &final))
442 return NULL;
443 consumed = pbuf.len; /* This is overwritten unless final is true. */
444 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
445 &byteorder, final ? NULL : &consumed); 1143 &byteorder, final ? NULL : &consumed);
446 PyBuffer_Release(&pbuf); 1144 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
447 if (decoded == NULL) 1145 if (decoded == NULL)
448 return NULL; 1146 return NULL;
449 return codec_tuple(decoded, consumed); 1147 return codec_tuple(decoded, consumed);
450 } 1148 }
451 1149
452 static PyObject * 1150 /*[clinic input]
453 utf_32_be_decode(PyObject *self, 1151 _codecs.Codecs.utf_32_be_decode
454 PyObject *args) 1152 pbuf: Py_buffer
455 { 1153 [
456 Py_buffer pbuf; 1154 errors: str(nullable=True)
1155 [
1156 final: int = 0
1157 ]
1158 ]
1159 /
1160 [clinic start generated code]*/
1161
1162 PyDoc_STRVAR(_codecs_Codecs_utf_32_be_decode__doc__,
1163 "utf_32_be_decode(pbuf, [errors, [final=0]])");
1164
1165 #define _CODECS_CODECS_UTF_32_BE_DECODE_METHODDEF \
1166 {"utf_32_be_decode", (PyCFunction)_codecs_Codecs_utf_32_be_decode, METH_VARA RGS, _codecs_Codecs_utf_32_be_decode__doc__},
1167
1168 static PyObject *
1169 _codecs_Codecs_utf_32_be_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final);
1170
1171 static PyObject *
1172 _codecs_Codecs_utf_32_be_decode(PyObject *self, PyObject *args)
1173 {
1174 PyObject *return_value = NULL;
1175 Py_buffer pbuf = {NULL, NULL};
1176 int group_right_1 = 0;
457 const char *errors = NULL; 1177 const char *errors = NULL;
1178 int group_right_2 = 0;
1179 int final = 0;
1180
1181 switch (PyTuple_Size(args)) {
1182 case 1:
1183 if (!PyArg_ParseTuple(args, "y*:utf_32_be_decode", &pbuf))
1184 return NULL;
1185 break;
1186 case 2:
1187 if (!PyArg_ParseTuple(args, "y*z:utf_32_be_decode", &pbuf, &errors))
1188 return NULL;
1189 group_right_1 = 1;
1190 break;
1191 case 3:
1192 if (!PyArg_ParseTuple(args, "y*zi:utf_32_be_decode", &pbuf, &errors, &final))
1193 return NULL;
1194 group_right_1 = 1;
1195 group_right_2 = 1;
1196 break;
1197 default:
1198 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_be_decode re quires 1 to 3 arguments");
1199 return NULL;
1200 }
1201 return_value = _codecs_Codecs_utf_32_be_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, final);
1202
1203 /* Cleanup for pbuf */
1204 if (pbuf.obj)
1205 PyBuffer_Release(&pbuf);
1206
1207 return return_value;
1208 }
1209
1210 static PyObject *
1211 _codecs_Codecs_utf_32_be_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int final)
1212 /*[clinic end generated code: checksum=82192b2f2263cdc196ed6be884fc3148d811a9c6] */
1213 {
458 int byteorder = 1; 1214 int byteorder = 1;
459 int final = 0; 1215 /* This is overwritten unless final is true. */
460 Py_ssize_t consumed; 1216 Py_ssize_t consumed = pbuf->len;
461 PyObject *decoded; 1217 PyObject *decoded;
462 1218
463 if (!PyArg_ParseTuple(args, "y*|zi:utf_32_be_decode", 1219 decoded = PyUnicode_DecodeUTF32Stateful(pbuf->buf, pbuf->len, errors,
464 &pbuf, &errors, &final))
465 return NULL;
466 consumed = pbuf.len; /* This is overwritten unless final is true. */
467 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
468 &byteorder, final ? NULL : &consumed); 1220 &byteorder, final ? NULL : &consumed);
469 PyBuffer_Release(&pbuf); 1221 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
470 if (decoded == NULL) 1222 if (decoded == NULL)
471 return NULL; 1223 return NULL;
472 return codec_tuple(decoded, consumed); 1224 return codec_tuple(decoded, consumed);
473 } 1225 }
474 1226
475 /* This non-standard version also provides access to the byteorder 1227 /* This non-standard version also provides access to the byteorder
476 parameter of the builtin UTF-32 codec. 1228 parameter of the builtin UTF-32 codec.
477 1229
478 It returns a tuple (unicode, bytesread, byteorder) with byteorder 1230 It returns a tuple (unicode, bytesread, byteorder) with byteorder
479 being the value in effect at the end of data. 1231 being the value in effect at the end of data.
480 1232
481 */ 1233 */
1234 /*[clinic input]
1235 _codecs.Codecs.utf_32_ex_decode
1236 pbuf: Py_buffer
1237 [
1238 errors: str(nullable=True)
1239 [
1240 byteorder: int = 0
1241 [
1242 final: int = 0
1243 ]
1244 ]
1245 ]
1246 /
1247 [clinic start generated code]*/
1248
1249 PyDoc_STRVAR(_codecs_Codecs_utf_32_ex_decode__doc__,
1250 "utf_32_ex_decode(pbuf, [errors, [byteorder=0, [final=0]]])");
1251
1252 #define _CODECS_CODECS_UTF_32_EX_DECODE_METHODDEF \
1253 {"utf_32_ex_decode", (PyCFunction)_codecs_Codecs_utf_32_ex_decode, METH_VARA RGS, _codecs_Codecs_utf_32_ex_decode__doc__},
482 1254
483 static PyObject * 1255 static PyObject *
484 utf_32_ex_decode(PyObject *self, 1256 _codecs_Codecs_utf_32_ex_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int byteorder, int group_right_3 , int final);
485 PyObject *args) 1257
1258 static PyObject *
1259 _codecs_Codecs_utf_32_ex_decode(PyObject *self, PyObject *args)
486 { 1260 {
487 Py_buffer pbuf; 1261 PyObject *return_value = NULL;
1262 Py_buffer pbuf = {NULL, NULL};
1263 int group_right_1 = 0;
488 const char *errors = NULL; 1264 const char *errors = NULL;
1265 int group_right_2 = 0;
489 int byteorder = 0; 1266 int byteorder = 0;
1267 int group_right_3 = 0;
1268 int final = 0;
1269
1270 switch (PyTuple_Size(args)) {
1271 case 1:
1272 if (!PyArg_ParseTuple(args, "y*:utf_32_ex_decode", &pbuf))
1273 return NULL;
1274 break;
1275 case 2:
1276 if (!PyArg_ParseTuple(args, "y*z:utf_32_ex_decode", &pbuf, &errors))
1277 return NULL;
1278 group_right_1 = 1;
1279 break;
1280 case 3:
1281 if (!PyArg_ParseTuple(args, "y*zi:utf_32_ex_decode", &pbuf, &errors, &byteorder))
1282 return NULL;
1283 group_right_1 = 1;
1284 group_right_2 = 1;
1285 break;
1286 case 4:
1287 if (!PyArg_ParseTuple(args, "y*zii:utf_32_ex_decode", &pbuf, &errors , &byteorder, &final))
1288 return NULL;
1289 group_right_1 = 1;
1290 group_right_2 = 1;
1291 group_right_3 = 1;
1292 break;
1293 default:
1294 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_ex_decode re quires 1 to 4 arguments");
1295 return NULL;
1296 }
1297 return_value = _codecs_Codecs_utf_32_ex_decode_impl(self, &pbuf, group_right _1, errors, group_right_2, byteorder, group_right_3, final);
1298
1299 /* Cleanup for pbuf */
1300 if (pbuf.obj)
1301 PyBuffer_Release(&pbuf);
1302
1303 return return_value;
1304 }
1305
1306 static PyObject *
1307 _codecs_Codecs_utf_32_ex_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ right_1, const char *errors, int group_right_2, int byteorder, int group_right_3 , int final)
1308 /*[clinic end generated code: checksum=693fca9c1b64c1cf6111feb86c0c0eb31b934857] */
1309 {
490 PyObject *unicode, *tuple; 1310 PyObject *unicode, *tuple;
491 int final = 0; 1311 Py_ssize_t consumed = pbuf->len;
492 Py_ssize_t consumed;
493 1312
494 if (!PyArg_ParseTuple(args, "y*|zii:utf_32_ex_decode", 1313 unicode = PyUnicode_DecodeUTF32Stateful(pbuf->buf, pbuf->len, errors,
495 &pbuf, &errors, &byteorder, &final))
496 return NULL;
497 consumed = pbuf.len; /* This is overwritten unless final is true. */
498 unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
499 &byteorder, final ? NULL : &consumed); 1314 &byteorder, final ? NULL : &consumed);
500 PyBuffer_Release(&pbuf); 1315 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
501 if (unicode == NULL) 1316 if (unicode == NULL)
502 return NULL; 1317 return NULL;
503 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); 1318 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
504 Py_DECREF(unicode); 1319 Py_DECREF(unicode);
505 return tuple; 1320 return tuple;
506 } 1321 }
507 1322
508 static PyObject * 1323 /*[clinic input]
509 unicode_escape_decode(PyObject *self, 1324 _codecs.Codecs.unicode_escape_decode
510 PyObject *args) 1325 pbuf: Py_buffer(types='str bytes bytearray buffer')
511 { 1326 [
512 Py_buffer pbuf; 1327 errors: str(nullable=True)
513 const char *errors = NULL; 1328 ]
514 PyObject *unicode; 1329 /
515 1330 [clinic start generated code]*/
516 if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode", 1331
517 &pbuf, &errors)) 1332 PyDoc_STRVAR(_codecs_Codecs_unicode_escape_decode__doc__,
518 return NULL; 1333 "unicode_escape_decode(pbuf, [errors])");
519 1334
520 unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors); 1335 #define _CODECS_CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \
521 PyBuffer_Release(&pbuf); 1336 {"unicode_escape_decode", (PyCFunction)_codecs_Codecs_unicode_escape_decode, METH_VARARGS, _codecs_Codecs_unicode_escape_decode__doc__},
522 return codec_tuple(unicode, pbuf.len); 1337
523 } 1338 static PyObject *
524 1339 _codecs_Codecs_unicode_escape_decode_impl(PyObject *self, Py_buffer *pbuf, int g roup_right_1, const char *errors);
525 static PyObject * 1340
526 raw_unicode_escape_decode(PyObject *self, 1341 static PyObject *
527 PyObject *args) 1342 _codecs_Codecs_unicode_escape_decode(PyObject *self, PyObject *args)
528 { 1343 {
529 Py_buffer pbuf; 1344 PyObject *return_value = NULL;
530 const char *errors = NULL; 1345 Py_buffer pbuf = {NULL, NULL};
1346 int group_right_1 = 0;
1347 const char *errors = NULL;
1348
1349 switch (PyTuple_Size(args)) {
1350 case 1:
1351 if (!PyArg_ParseTuple(args, "s*:unicode_escape_decode", &pbuf))
1352 return NULL;
1353 break;
1354 case 2:
1355 if (!PyArg_ParseTuple(args, "s*z:unicode_escape_decode", &pbuf, &err ors))
1356 return NULL;
1357 group_right_1 = 1;
1358 break;
1359 default:
1360 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.unicode_escape_deco de requires 1 to 2 arguments");
1361 return NULL;
1362 }
1363 return_value = _codecs_Codecs_unicode_escape_decode_impl(self, &pbuf, group_ right_1, errors);
1364
1365 /* Cleanup for pbuf */
1366 if (pbuf.obj)
1367 PyBuffer_Release(&pbuf);
1368
1369 return return_value;
1370 }
1371
1372 static PyObject *
1373 _codecs_Codecs_unicode_escape_decode_impl(PyObject *self, Py_buffer *pbuf, int g roup_right_1, const char *errors)
1374 /*[clinic end generated code: checksum=b77ca0eed0c140f6e422c8b10f1a8ecf20cd9746] */
1375 {
531 PyObject *unicode; 1376 PyObject *unicode;
532 1377
533 if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode", 1378 unicode = PyUnicode_DecodeUnicodeEscape(pbuf->buf, pbuf->len, errors);
534 &pbuf, &errors)) 1379 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
535 return NULL; 1380 return codec_tuple(unicode, pbuf->len);
536 1381 }
537 unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors); 1382
538 PyBuffer_Release(&pbuf); 1383 /*[clinic input]
539 return codec_tuple(unicode, pbuf.len); 1384 _codecs.Codecs.raw_unicode_escape_decode
540 } 1385 pbuf: Py_buffer(types='str bytes bytearray buffer')
541 1386 [
542 static PyObject * 1387 errors: str(nullable=True)
543 latin_1_decode(PyObject *self, 1388 ]
544 PyObject *args) 1389 /
545 { 1390 [clinic start generated code]*/
546 Py_buffer pbuf; 1391
1392 PyDoc_STRVAR(_codecs_Codecs_raw_unicode_escape_decode__doc__,
1393 "raw_unicode_escape_decode(pbuf, [errors])");
1394
1395 #define _CODECS_CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \
1396 {"raw_unicode_escape_decode", (PyCFunction)_codecs_Codecs_raw_unicode_escape _decode, METH_VARARGS, _codecs_Codecs_raw_unicode_escape_decode__doc__},
1397
1398 static PyObject *
1399 _codecs_Codecs_raw_unicode_escape_decode_impl(PyObject *self, Py_buffer *pbuf, i nt group_right_1, const char *errors);
1400
1401 static PyObject *
1402 _codecs_Codecs_raw_unicode_escape_decode(PyObject *self, PyObject *args)
1403 {
1404 PyObject *return_value = NULL;
1405 Py_buffer pbuf = {NULL, NULL};
1406 int group_right_1 = 0;
1407 const char *errors = NULL;
1408
1409 switch (PyTuple_Size(args)) {
1410 case 1:
1411 if (!PyArg_ParseTuple(args, "s*:raw_unicode_escape_decode", &pbuf))
1412 return NULL;
1413 break;
1414 case 2:
1415 if (!PyArg_ParseTuple(args, "s*z:raw_unicode_escape_decode", &pbuf, &errors))
1416 return NULL;
1417 group_right_1 = 1;
1418 break;
1419 default:
1420 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.raw_unicode_escape_ decode requires 1 to 2 arguments");
1421 return NULL;
1422 }
1423 return_value = _codecs_Codecs_raw_unicode_escape_decode_impl(self, &pbuf, gr oup_right_1, errors);
1424
1425 /* Cleanup for pbuf */
1426 if (pbuf.obj)
1427 PyBuffer_Release(&pbuf);
1428
1429 return return_value;
1430 }
1431
1432 static PyObject *
1433 _codecs_Codecs_raw_unicode_escape_decode_impl(PyObject *self, Py_buffer *pbuf, i nt group_right_1, const char *errors)
1434 /*[clinic end generated code: checksum=4d9f594d2a64f0f5a90d5fb6dd4837f07d1e4060] */
1435 {
547 PyObject *unicode; 1436 PyObject *unicode;
548 const char *errors = NULL; 1437
549 1438 unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf->buf, pbuf->len, errors);
550 if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode", 1439 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
551 &pbuf, &errors)) 1440 return codec_tuple(unicode, pbuf->len);
552 return NULL; 1441 }
553 1442
554 unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors); 1443 /*[clinic input]
555 PyBuffer_Release(&pbuf); 1444 _codecs.Codecs.latin_1_decode
556 return codec_tuple(unicode, pbuf.len); 1445 pbuf: Py_buffer
557 } 1446 [
558 1447 errors: str(nullable=True)
559 static PyObject * 1448 ]
560 ascii_decode(PyObject *self, 1449 /
561 PyObject *args) 1450 [clinic start generated code]*/
562 { 1451
563 Py_buffer pbuf; 1452 PyDoc_STRVAR(_codecs_Codecs_latin_1_decode__doc__,
1453 "latin_1_decode(pbuf, [errors])");
1454
1455 #define _CODECS_CODECS_LATIN_1_DECODE_METHODDEF \
1456 {"latin_1_decode", (PyCFunction)_codecs_Codecs_latin_1_decode, METH_VARARGS, _codecs_Codecs_latin_1_decode__doc__},
1457
1458 static PyObject *
1459 _codecs_Codecs_latin_1_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ri ght_1, const char *errors);
1460
1461 static PyObject *
1462 _codecs_Codecs_latin_1_decode(PyObject *self, PyObject *args)
1463 {
1464 PyObject *return_value = NULL;
1465 Py_buffer pbuf = {NULL, NULL};
1466 int group_right_1 = 0;
1467 const char *errors = NULL;
1468
1469 switch (PyTuple_Size(args)) {
1470 case 1:
1471 if (!PyArg_ParseTuple(args, "y*:latin_1_decode", &pbuf))
1472 return NULL;
1473 break;
1474 case 2:
1475 if (!PyArg_ParseTuple(args, "y*z:latin_1_decode", &pbuf, &errors))
1476 return NULL;
1477 group_right_1 = 1;
1478 break;
1479 default:
1480 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.latin_1_decode requ ires 1 to 2 arguments");
1481 return NULL;
1482 }
1483 return_value = _codecs_Codecs_latin_1_decode_impl(self, &pbuf, group_right_1 , errors);
1484
1485 /* Cleanup for pbuf */
1486 if (pbuf.obj)
1487 PyBuffer_Release(&pbuf);
1488
1489 return return_value;
1490 }
1491
1492 static PyObject *
1493 _codecs_Codecs_latin_1_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ri ght_1, const char *errors)
1494 /*[clinic end generated code: checksum=468bf8d720098557e9e04922296809a672f3c21c] */
1495 {
564 PyObject *unicode; 1496 PyObject *unicode;
565 const char *errors = NULL; 1497
566 1498 unicode = PyUnicode_DecodeLatin1(pbuf->buf, pbuf->len, errors);
567 if (!PyArg_ParseTuple(args, "y*|z:ascii_decode", 1499 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
568 &pbuf, &errors)) 1500 return codec_tuple(unicode, pbuf->len);
569 return NULL; 1501 }
570 1502
571 unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors); 1503 /*[clinic input]
572 PyBuffer_Release(&pbuf); 1504 _codecs.Codecs.ascii_decode
573 return codec_tuple(unicode, pbuf.len); 1505 pbuf: Py_buffer
574 } 1506 [
575 1507 errors: str(nullable=True)
576 static PyObject * 1508 ]
577 charmap_decode(PyObject *self, 1509 /
578 PyObject *args) 1510 [clinic start generated code]*/
579 { 1511
580 Py_buffer pbuf; 1512 PyDoc_STRVAR(_codecs_Codecs_ascii_decode__doc__,
1513 "ascii_decode(pbuf, [errors])");
1514
1515 #define _CODECS_CODECS_ASCII_DECODE_METHODDEF \
1516 {"ascii_decode", (PyCFunction)_codecs_Codecs_ascii_decode, METH_VARARGS, _co decs_Codecs_ascii_decode__doc__},
1517
1518 static PyObject *
1519 _codecs_Codecs_ascii_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors);
1520
1521 static PyObject *
1522 _codecs_Codecs_ascii_decode(PyObject *self, PyObject *args)
1523 {
1524 PyObject *return_value = NULL;
1525 Py_buffer pbuf = {NULL, NULL};
1526 int group_right_1 = 0;
1527 const char *errors = NULL;
1528
1529 switch (PyTuple_Size(args)) {
1530 case 1:
1531 if (!PyArg_ParseTuple(args, "y*:ascii_decode", &pbuf))
1532 return NULL;
1533 break;
1534 case 2:
1535 if (!PyArg_ParseTuple(args, "y*z:ascii_decode", &pbuf, &errors))
1536 return NULL;
1537 group_right_1 = 1;
1538 break;
1539 default:
1540 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.ascii_decode requir es 1 to 2 arguments");
1541 return NULL;
1542 }
1543 return_value = _codecs_Codecs_ascii_decode_impl(self, &pbuf, group_right_1, errors);
1544
1545 /* Cleanup for pbuf */
1546 if (pbuf.obj)
1547 PyBuffer_Release(&pbuf);
1548
1549 return return_value;
1550 }
1551
1552 static PyObject *
1553 _codecs_Codecs_ascii_decode_impl(PyObject *self, Py_buffer *pbuf, int group_righ t_1, const char *errors)
1554 /*[clinic end generated code: checksum=71aea27a479823c89b959bd37c6f68e624baf4eb] */
1555 {
581 PyObject *unicode; 1556 PyObject *unicode;
582 const char *errors = NULL; 1557
583 PyObject *mapping = NULL; 1558 unicode = PyUnicode_DecodeASCII(pbuf->buf, pbuf->len, errors);
584 1559 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
585 if (!PyArg_ParseTuple(args, "y*|zO:charmap_decode", 1560 return codec_tuple(unicode, pbuf->len);
586 &pbuf, &errors, &mapping)) 1561 }
587 return NULL; 1562
1563 /*[clinic input]
1564 _codecs.Codecs.charmap_decode
1565 pbuf: Py_buffer
1566 [
1567 errors: str(nullable=True)
1568 [
1569 mapping: object = None
1570 ]
1571 ]
1572 /
1573 [clinic start generated code]*/
1574
1575 PyDoc_STRVAR(_codecs_Codecs_charmap_decode__doc__,
1576 "charmap_decode(pbuf, [errors, [mapping=None]])");
1577
1578 #define _CODECS_CODECS_CHARMAP_DECODE_METHODDEF \
1579 {"charmap_decode", (PyCFunction)_codecs_Codecs_charmap_decode, METH_VARARGS, _codecs_Codecs_charmap_decode__doc__},
1580
1581 static PyObject *
1582 _codecs_Codecs_charmap_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ri ght_1, const char *errors, int group_right_2, PyObject *mapping);
1583
1584 static PyObject *
1585 _codecs_Codecs_charmap_decode(PyObject *self, PyObject *args)
1586 {
1587 PyObject *return_value = NULL;
1588 Py_buffer pbuf = {NULL, NULL};
1589 int group_right_1 = 0;
1590 const char *errors = NULL;
1591 int group_right_2 = 0;
1592 PyObject *mapping = Py_None;
1593
1594 switch (PyTuple_Size(args)) {
1595 case 1:
1596 if (!PyArg_ParseTuple(args, "y*:charmap_decode", &pbuf))
1597 return NULL;
1598 break;
1599 case 2:
1600 if (!PyArg_ParseTuple(args, "y*z:charmap_decode", &pbuf, &errors))
1601 return NULL;
1602 group_right_1 = 1;
1603 break;
1604 case 3:
1605 if (!PyArg_ParseTuple(args, "y*zO:charmap_decode", &pbuf, &errors, & mapping))
1606 return NULL;
1607 group_right_1 = 1;
1608 group_right_2 = 1;
1609 break;
1610 default:
1611 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.charmap_decode requ ires 1 to 3 arguments");
1612 return NULL;
1613 }
1614 return_value = _codecs_Codecs_charmap_decode_impl(self, &pbuf, group_right_1 , errors, group_right_2, mapping);
1615
1616 /* Cleanup for pbuf */
1617 if (pbuf.obj)
1618 PyBuffer_Release(&pbuf);
1619
1620 return return_value;
1621 }
1622
1623 static PyObject *
1624 _codecs_Codecs_charmap_decode_impl(PyObject *self, Py_buffer *pbuf, int group_ri ght_1, const char *errors, int group_right_2, PyObject *mapping)
1625 /*[clinic end generated code: checksum=34aa3f6eaa0943384294a8c1948c9a7bba26663c] */
1626 {
1627 PyObject *unicode;
1628
588 if (mapping == Py_None) 1629 if (mapping == Py_None)
589 mapping = NULL; 1630 mapping = NULL;
590 1631
591 unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors); 1632 unicode = PyUnicode_DecodeCharmap(pbuf->buf, pbuf->len, mapping, errors);
592 PyBuffer_Release(&pbuf); 1633 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
593 return codec_tuple(unicode, pbuf.len); 1634 return codec_tuple(unicode, pbuf->len);
594 } 1635 }
595 1636
596 #ifdef HAVE_MBCS 1637 #ifdef HAVE_MBCS
597 1638
598 static PyObject * 1639 /*[clinic input]
599 mbcs_decode(PyObject *self, 1640 _codecs.Codecs.mbcs_decode
600 PyObject *args) 1641 pbuf: Py_buffer
601 { 1642 [
602 Py_buffer pbuf; 1643 errors: str(nullable=True)
603 const char *errors = NULL; 1644 [
1645 final: int = 0
1646 ]
1647 ]
1648 /
1649 [clinic start generated code]*/
1650
1651 PyDoc_STRVAR(_codecs_Codecs_mbcs_decode__doc__,
1652 "mbcs_decode(pbuf, [errors, [final=0]])");
1653
1654 #define _CODECS_CODECS_MBCS_DECODE_METHODDEF \
1655 {"mbcs_decode", (PyCFunction)_codecs_Codecs_mbcs_decode, METH_VARARGS, _code cs_Codecs_mbcs_decode__doc__},
1656
1657 static PyObject *
1658 _codecs_Codecs_mbcs_decode_impl(PyObject *self, Py_buffer *pbuf, int group_right _1, const char *errors, int group_right_2, int final);
1659
1660 static PyObject *
1661 _codecs_Codecs_mbcs_decode(PyObject *self, PyObject *args)
1662 {
1663 PyObject *return_value = NULL;
1664 Py_buffer pbuf = {NULL, NULL};
1665 int group_right_1 = 0;
1666 const char *errors = NULL;
1667 int group_right_2 = 0;
604 int final = 0; 1668 int final = 0;
605 Py_ssize_t consumed; 1669
1670 switch (PyTuple_Size(args)) {
1671 case 1:
1672 if (!PyArg_ParseTuple(args, "y*:mbcs_decode", &pbuf))
1673 return NULL;
1674 break;
1675 case 2:
1676 if (!PyArg_ParseTuple(args, "y*z:mbcs_decode", &pbuf, &errors))
1677 return NULL;
1678 group_right_1 = 1;
1679 break;
1680 case 3:
1681 if (!PyArg_ParseTuple(args, "y*zi:mbcs_decode", &pbuf, &errors, &fin al))
1682 return NULL;
1683 group_right_1 = 1;
1684 group_right_2 = 1;
1685 break;
1686 default:
1687 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.mbcs_decode require s 1 to 3 arguments");
1688 return NULL;
1689 }
1690 return_value = _codecs_Codecs_mbcs_decode_impl(self, &pbuf, group_right_1, e rrors, group_right_2, final);
1691
1692 /* Cleanup for pbuf */
1693 if (pbuf.obj)
1694 PyBuffer_Release(&pbuf);
1695
1696 return return_value;
1697 }
1698
1699 static PyObject *
1700 _codecs_Codecs_mbcs_decode_impl(PyObject *self, Py_buffer *pbuf, int group_right _1, const char *errors, int group_right_2, int final)
1701 /*[clinic end generated code: checksum=dc2f5295b119004d628f5ebc50dd6241096b0624] */
1702 {
1703 Py_ssize_t consumed = pbuf->len;
606 PyObject *decoded = NULL; 1704 PyObject *decoded = NULL;
607 1705
608 if (!PyArg_ParseTuple(args, "y*|zi:mbcs_decode",
609 &pbuf, &errors, &final))
610 return NULL;
611 consumed = pbuf.len; 1706 consumed = pbuf.len;
612 1707
613 decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors, 1708 decoded = PyUnicode_DecodeMBCSStateful(pbuf->buf, pbuf->len, errors,
614 final ? NULL : &consumed); 1709 final ? NULL : &consumed);
615 PyBuffer_Release(&pbuf); 1710 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
616 if (decoded == NULL) 1711 if (decoded == NULL)
617 return NULL; 1712 return NULL;
618 return codec_tuple(decoded, consumed); 1713 return codec_tuple(decoded, consumed);
619 } 1714 }
620 1715
621 static PyObject * 1716 /*[clinic input]
622 code_page_decode(PyObject *self, 1717 _codecs.Codecs.code_page_decode
623 PyObject *args) 1718 codepage: int
624 { 1719 pbuf: Py_buffer
625 Py_buffer pbuf; 1720 [
626 const char *errors = NULL; 1721 errors: str(nullable=True)
1722 [
1723 final: int = 0
1724 ]
1725 ]
1726 /
1727 [clinic start generated code]*/
1728
1729 PyDoc_STRVAR(_codecs_Codecs_code_page_decode__doc__,
1730 "code_page_decode(codepage, pbuf, [errors, [final=0]])");
1731
1732 #define _CODECS_CODECS_CODE_PAGE_DECODE_METHODDEF \
1733 {"code_page_decode", (PyCFunction)_codecs_Codecs_code_page_decode, METH_VARA RGS, _codecs_Codecs_code_page_decode__doc__},
1734
1735 static PyObject *
1736 _codecs_Codecs_code_page_decode_impl(PyObject *self, int codepage, Py_buffer *pb uf, int group_right_1, const char *errors, int group_right_2, int final);
1737
1738 static PyObject *
1739 _codecs_Codecs_code_page_decode(PyObject *self, PyObject *args)
1740 {
1741 PyObject *return_value = NULL;
1742 int codepage;
1743 Py_buffer pbuf = {NULL, NULL};
1744 int group_right_1 = 0;
1745 const char *errors = NULL;
1746 int group_right_2 = 0;
627 int final = 0; 1747 int final = 0;
628 Py_ssize_t consumed; 1748
1749 switch (PyTuple_Size(args)) {
1750 case 2:
1751 if (!PyArg_ParseTuple(args, "iy*:code_page_decode", &codepage, &pbuf ))
1752 return NULL;
1753 break;
1754 case 3:
1755 if (!PyArg_ParseTuple(args, "iy*z:code_page_decode", &codepage, &pbu f, &errors))
1756 return NULL;
1757 group_right_1 = 1;
1758 break;
1759 case 4:
1760 if (!PyArg_ParseTuple(args, "iy*zi:code_page_decode", &codepage, &pb uf, &errors, &final))
1761 return NULL;
1762 group_right_1 = 1;
1763 group_right_2 = 1;
1764 break;
1765 default:
1766 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.code_page_decode re quires 2 to 4 arguments");
1767 return NULL;
1768 }
1769 return_value = _codecs_Codecs_code_page_decode_impl(self, codepage, &pbuf, g roup_right_1, errors, group_right_2, final);
1770
1771 /* Cleanup for pbuf */
1772 if (pbuf.obj)
1773 PyBuffer_Release(&pbuf);
1774
1775 return return_value;
1776 }
1777
1778 static PyObject *
1779 _codecs_Codecs_code_page_decode_impl(PyObject *self, int codepage, Py_buffer *pb uf, int group_right_1, const char *errors, int group_right_2, int final)
1780 /*[clinic end generated code: checksum=3ffd032d9d767326789b7e35ac4dfa96585f9b37] */
1781 {
1782 Py_ssize_t consumed = pbuf->len;
629 PyObject *decoded = NULL; 1783 PyObject *decoded = NULL;
630 int code_page;
631
632 if (!PyArg_ParseTuple(args, "iy*|zi:code_page_decode",
633 &code_page, &pbuf, &errors, &final))
634 return NULL;
635 consumed = pbuf.len;
636 1784
637 decoded = PyUnicode_DecodeCodePageStateful(code_page, 1785 decoded = PyUnicode_DecodeCodePageStateful(code_page,
638 pbuf.buf, pbuf.len, errors, 1786 pbuf->buf, pbuf->len, errors,
639 final ? NULL : &consumed); 1787 final ? NULL : &consumed);
640 PyBuffer_Release(&pbuf); 1788 PyBuffer_Release(pbuf);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
641 if (decoded == NULL) 1789 if (decoded == NULL)
642 return NULL; 1790 return NULL;
643 return codec_tuple(decoded, consumed); 1791 return codec_tuple(decoded, consumed);
644 } 1792 }
645 1793
646 #endif /* HAVE_MBCS */ 1794 #endif /* HAVE_MBCS */
647 1795
648 /* --- Encoder ------------------------------------------------------------ */ 1796 /* --- Encoder ------------------------------------------------------------ */
649 1797
1798 /*[clinic input]
1799 _codecs.Codecs.readbuffer_encode
1800 pdata: Py_buffer(types='str bytes bytearray buffer')
1801 [
1802 errors: str(nullable=True)
1803 ]
1804 /
1805 [clinic start generated code]*/
1806
1807 PyDoc_STRVAR(_codecs_Codecs_readbuffer_encode__doc__,
1808 "readbuffer_encode(pdata, [errors])");
1809
1810 #define _CODECS_CODECS_READBUFFER_ENCODE_METHODDEF \
1811 {"readbuffer_encode", (PyCFunction)_codecs_Codecs_readbuffer_encode, METH_VA RARGS, _codecs_Codecs_readbuffer_encode__doc__},
1812
650 static PyObject * 1813 static PyObject *
651 readbuffer_encode(PyObject *self, 1814 _codecs_Codecs_readbuffer_encode_impl(PyObject *self, Py_buffer *pdata, int grou p_right_1, const char *errors);
652 PyObject *args) 1815
1816 static PyObject *
1817 _codecs_Codecs_readbuffer_encode(PyObject *self, PyObject *args)
653 { 1818 {
654 Py_buffer pdata; 1819 PyObject *return_value = NULL;
655 const char *data; 1820 Py_buffer pdata = {NULL, NULL};
656 Py_ssize_t size; 1821 int group_right_1 = 0;
657 const char *errors = NULL; 1822 const char *errors = NULL;
658 PyObject *result;
659 1823
660 if (!PyArg_ParseTuple(args, "s*|z:readbuffer_encode", 1824 switch (PyTuple_Size(args)) {
661 &pdata, &errors)) 1825 case 1:
662 return NULL; 1826 if (!PyArg_ParseTuple(args, "s*:readbuffer_encode", &pdata))
663 data = pdata.buf; 1827 return NULL;
664 size = pdata.len; 1828 break;
1829 case 2:
1830 if (!PyArg_ParseTuple(args, "s*z:readbuffer_encode", &pdata, &errors ))
1831 return NULL;
1832 group_right_1 = 1;
1833 break;
1834 default:
1835 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.readbuffer_encode r equires 1 to 2 arguments");
1836 return NULL;
1837 }
1838 return_value = _codecs_Codecs_readbuffer_encode_impl(self, &pdata, group_rig ht_1, errors);
665 1839
666 result = PyBytes_FromStringAndSize(data, size); 1840 /* Cleanup for pdata */
667 PyBuffer_Release(&pdata); 1841 if (pdata.obj)
1842 PyBuffer_Release(&pdata);
1843
1844 return return_value;
1845 }
1846
1847 static PyObject *
1848 _codecs_Codecs_readbuffer_encode_impl(PyObject *self, Py_buffer *pdata, int grou p_right_1, const char *errors)
1849 /*[clinic end generated code: checksum=7b0e61e4071750fd661cdb8de8f4d57ebc2c0dee] */
1850 {
1851 const char *data = pdata->buf;
1852 Py_ssize_t size = pdata->len;
1853 PyObject *result = PyBytes_FromStringAndSize(data, size);
1854
1855 PyBuffer_Release(pdata);
larry 2014/01/19 10:59:35 This is a bug. Argument Clinic releases the Py_bu
668 return codec_tuple(result, size); 1856 return codec_tuple(result, size);
669 } 1857 }
670 1858
1859 /*[clinic input]
1860 _codecs.Codecs.unicode_internal_encode
1861 obj: object
1862 [
1863 errors: str(nullable=True)
1864 ]
1865 /
1866 [clinic start generated code]*/
1867
1868 PyDoc_STRVAR(_codecs_Codecs_unicode_internal_encode__doc__,
1869 "unicode_internal_encode(obj, [errors])");
1870
1871 #define _CODECS_CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF \
1872 {"unicode_internal_encode", (PyCFunction)_codecs_Codecs_unicode_internal_enc ode, METH_VARARGS, _codecs_Codecs_unicode_internal_encode__doc__},
1873
671 static PyObject * 1874 static PyObject *
672 unicode_internal_encode(PyObject *self, 1875 _codecs_Codecs_unicode_internal_encode_impl(PyObject *self, PyObject *obj, int g roup_right_1, const char *errors);
673 PyObject *args) 1876
1877 static PyObject *
1878 _codecs_Codecs_unicode_internal_encode(PyObject *self, PyObject *args)
674 { 1879 {
1880 PyObject *return_value = NULL;
675 PyObject *obj; 1881 PyObject *obj;
1882 int group_right_1 = 0;
676 const char *errors = NULL; 1883 const char *errors = NULL;
1884
1885 switch (PyTuple_Size(args)) {
1886 case 1:
1887 if (!PyArg_ParseTuple(args, "O:unicode_internal_encode", &obj))
1888 return NULL;
1889 break;
1890 case 2:
1891 if (!PyArg_ParseTuple(args, "Oz:unicode_internal_encode", &obj, &err ors))
1892 return NULL;
1893 group_right_1 = 1;
1894 break;
1895 default:
1896 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.unicode_internal_en code requires 1 to 2 arguments");
1897 return NULL;
1898 }
1899 return_value = _codecs_Codecs_unicode_internal_encode_impl(self, obj, group_ right_1, errors);
1900
1901 return return_value;
1902 }
1903
1904 static PyObject *
1905 _codecs_Codecs_unicode_internal_encode_impl(PyObject *self, PyObject *obj, int g roup_right_1, const char *errors)
1906 /*[clinic end generated code: checksum=19efdb7139fcc2ed2cc2e57d914cac27aeab43e0] */
1907 {
677 const char *data; 1908 const char *data;
678 Py_ssize_t len, size; 1909 Py_ssize_t len, size;
679 1910
680 if (PyErr_WarnEx(PyExc_DeprecationWarning, 1911 if (PyErr_WarnEx(PyExc_DeprecationWarning,
681 "unicode_internal codec has been deprecated", 1912 "unicode_internal codec has been deprecated",
682 1)) 1913 1))
683 return NULL;
684
685 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
686 &obj, &errors))
687 return NULL; 1914 return NULL;
688 1915
689 if (PyUnicode_Check(obj)) { 1916 if (PyUnicode_Check(obj)) {
690 Py_UNICODE *u; 1917 Py_UNICODE *u;
691 1918
692 if (PyUnicode_READY(obj) < 0) 1919 if (PyUnicode_READY(obj) < 0)
693 return NULL; 1920 return NULL;
694 1921
695 u = PyUnicode_AsUnicodeAndSize(obj, &len); 1922 u = PyUnicode_AsUnicodeAndSize(obj, &len);
696 if (u == NULL) 1923 if (u == NULL)
697 return NULL; 1924 return NULL;
698 if (len > PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) 1925 if (len > PY_SSIZE_T_MAX / sizeof(Py_UNICODE))
699 return PyErr_NoMemory(); 1926 return PyErr_NoMemory();
700 size = len * sizeof(Py_UNICODE); 1927 size = len * sizeof(Py_UNICODE);
701 return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size), 1928 return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size),
702 PyUnicode_GET_LENGTH(obj)); 1929 PyUnicode_GET_LENGTH(obj));
703 } 1930 }
704 else { 1931 else {
705 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) 1932 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
706 return NULL; 1933 return NULL;
707 return codec_tuple(PyBytes_FromStringAndSize(data, size), size); 1934 return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
708 } 1935 }
709 } 1936 }
710 1937
1938 /*[clinic input]
1939 _codecs.Codecs.utf_7_encode
1940 str: object
1941 [
1942 errors: str(nullable=True)
1943 ]
1944 /
1945 [clinic start generated code]*/
1946
1947 PyDoc_STRVAR(_codecs_Codecs_utf_7_encode__doc__,
1948 "utf_7_encode(str, [errors])");
1949
1950 #define _CODECS_CODECS_UTF_7_ENCODE_METHODDEF \
1951 {"utf_7_encode", (PyCFunction)_codecs_Codecs_utf_7_encode, METH_VARARGS, _co decs_Codecs_utf_7_encode__doc__},
1952
711 static PyObject * 1953 static PyObject *
712 utf_7_encode(PyObject *self, 1954 _codecs_Codecs_utf_7_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors);
713 PyObject *args) 1955
1956 static PyObject *
1957 _codecs_Codecs_utf_7_encode(PyObject *self, PyObject *args)
714 { 1958 {
715 PyObject *str, *v; 1959 PyObject *return_value = NULL;
1960 PyObject *str;
1961 int group_right_1 = 0;
716 const char *errors = NULL; 1962 const char *errors = NULL;
717 1963
718 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", 1964 switch (PyTuple_Size(args)) {
719 &str, &errors)) 1965 case 1:
720 return NULL; 1966 if (!PyArg_ParseTuple(args, "O:utf_7_encode", &str))
1967 return NULL;
1968 break;
1969 case 2:
1970 if (!PyArg_ParseTuple(args, "Oz:utf_7_encode", &str, &errors))
1971 return NULL;
1972 group_right_1 = 1;
1973 break;
1974 default:
1975 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_7_encode requir es 1 to 2 arguments");
1976 return NULL;
1977 }
1978 return_value = _codecs_Codecs_utf_7_encode_impl(self, str, group_right_1, er rors);
1979
1980 return return_value;
1981 }
1982
1983 static PyObject *
1984 _codecs_Codecs_utf_7_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors)
1985 /*[clinic end generated code: checksum=e8806f9456a8449b514fbd097067cff45008d28a] */
1986 {
1987 PyObject *v;
721 1988
722 str = PyUnicode_FromObject(str); 1989 str = PyUnicode_FromObject(str);
723 if (str == NULL || PyUnicode_READY(str) < 0) { 1990 if (str == NULL || PyUnicode_READY(str) < 0) {
724 Py_XDECREF(str); 1991 Py_XDECREF(str);
725 return NULL; 1992 return NULL;
726 } 1993 }
727 v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), 1994 v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors),
728 PyUnicode_GET_LENGTH(str)); 1995 PyUnicode_GET_LENGTH(str));
729 Py_DECREF(str); 1996 Py_DECREF(str);
730 return v; 1997 return v;
731 } 1998 }
732 1999
2000 /*[clinic input]
2001 _codecs.Codecs.utf_8_encode
2002 str: object
2003 [
2004 errors: str(nullable=True)
2005 ]
2006 /
2007 [clinic start generated code]*/
2008
2009 PyDoc_STRVAR(_codecs_Codecs_utf_8_encode__doc__,
2010 "utf_8_encode(str, [errors])");
2011
2012 #define _CODECS_CODECS_UTF_8_ENCODE_METHODDEF \
2013 {"utf_8_encode", (PyCFunction)_codecs_Codecs_utf_8_encode, METH_VARARGS, _co decs_Codecs_utf_8_encode__doc__},
2014
733 static PyObject * 2015 static PyObject *
734 utf_8_encode(PyObject *self, 2016 _codecs_Codecs_utf_8_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors);
735 PyObject *args) 2017
2018 static PyObject *
2019 _codecs_Codecs_utf_8_encode(PyObject *self, PyObject *args)
736 { 2020 {
737 PyObject *str, *v; 2021 PyObject *return_value = NULL;
2022 PyObject *str;
2023 int group_right_1 = 0;
738 const char *errors = NULL; 2024 const char *errors = NULL;
739 2025
740 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode", 2026 switch (PyTuple_Size(args)) {
741 &str, &errors)) 2027 case 1:
742 return NULL; 2028 if (!PyArg_ParseTuple(args, "O:utf_8_encode", &str))
2029 return NULL;
2030 break;
2031 case 2:
2032 if (!PyArg_ParseTuple(args, "Oz:utf_8_encode", &str, &errors))
2033 return NULL;
2034 group_right_1 = 1;
2035 break;
2036 default:
2037 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_8_encode requir es 1 to 2 arguments");
2038 return NULL;
2039 }
2040 return_value = _codecs_Codecs_utf_8_encode_impl(self, str, group_right_1, er rors);
2041
2042 return return_value;
2043 }
2044
2045 static PyObject *
2046 _codecs_Codecs_utf_8_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors)
2047 /*[clinic end generated code: checksum=0166a55bda0daf434ec7c29afcf8057820e3e930] */
2048 {
2049 PyObject *v;
743 2050
744 str = PyUnicode_FromObject(str); 2051 str = PyUnicode_FromObject(str);
745 if (str == NULL || PyUnicode_READY(str) < 0) { 2052 if (str == NULL || PyUnicode_READY(str) < 0) {
746 Py_XDECREF(str); 2053 Py_XDECREF(str);
747 return NULL; 2054 return NULL;
748 } 2055 }
749 v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors), 2056 v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors),
750 PyUnicode_GET_LENGTH(str)); 2057 PyUnicode_GET_LENGTH(str));
751 Py_DECREF(str); 2058 Py_DECREF(str);
752 return v; 2059 return v;
753 } 2060 }
754 2061
755 /* This version provides access to the byteorder parameter of the 2062 /* This version provides access to the byteorder parameter of the
756 builtin UTF-16 codecs as optional third argument. It defaults to 0 2063 builtin UTF-16 codecs as optional third argument. It defaults to 0
757 which means: use the native byte order and prepend the data with a 2064 which means: use the native byte order and prepend the data with a
758 BOM mark. 2065 BOM mark.
759 2066
760 */ 2067 */
761 2068
2069 /*[clinic input]
2070 _codecs.Codecs.utf_16_encode
2071 str: object
2072 [
2073 errors: str(nullable=True)
2074 [
2075 byteorder: int = 0
2076 ]
2077 ]
2078 /
2079 [clinic start generated code]*/
2080
2081 PyDoc_STRVAR(_codecs_Codecs_utf_16_encode__doc__,
2082 "utf_16_encode(str, [errors, [byteorder=0]])");
2083
2084 #define _CODECS_CODECS_UTF_16_ENCODE_METHODDEF \
2085 {"utf_16_encode", (PyCFunction)_codecs_Codecs_utf_16_encode, METH_VARARGS, _ codecs_Codecs_utf_16_encode__doc__},
2086
762 static PyObject * 2087 static PyObject *
763 utf_16_encode(PyObject *self, 2088 _codecs_Codecs_utf_16_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors, int group_right_2, int byteorder);
764 PyObject *args) 2089
2090 static PyObject *
2091 _codecs_Codecs_utf_16_encode(PyObject *self, PyObject *args)
765 { 2092 {
766 PyObject *str, *v; 2093 PyObject *return_value = NULL;
2094 PyObject *str;
2095 int group_right_1 = 0;
767 const char *errors = NULL; 2096 const char *errors = NULL;
2097 int group_right_2 = 0;
768 int byteorder = 0; 2098 int byteorder = 0;
769 2099
770 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", 2100 switch (PyTuple_Size(args)) {
771 &str, &errors, &byteorder)) 2101 case 1:
772 return NULL; 2102 if (!PyArg_ParseTuple(args, "O:utf_16_encode", &str))
2103 return NULL;
2104 break;
2105 case 2:
2106 if (!PyArg_ParseTuple(args, "Oz:utf_16_encode", &str, &errors))
2107 return NULL;
2108 group_right_1 = 1;
2109 break;
2110 case 3:
2111 if (!PyArg_ParseTuple(args, "Ozi:utf_16_encode", &str, &errors, &byt eorder))
2112 return NULL;
2113 group_right_1 = 1;
2114 group_right_2 = 1;
2115 break;
2116 default:
2117 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_encode requi res 1 to 3 arguments");
2118 return NULL;
2119 }
2120 return_value = _codecs_Codecs_utf_16_encode_impl(self, str, group_right_1, e rrors, group_right_2, byteorder);
2121
2122 return return_value;
2123 }
2124
2125 static PyObject *
2126 _codecs_Codecs_utf_16_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors, int group_right_2, int byteorder)
2127 /*[clinic end generated code: checksum=6dfd84bbe81e21021754ec75a9e45eaf1fcf54bf] */
2128 {
2129 PyObject *v;
773 2130
774 str = PyUnicode_FromObject(str); 2131 str = PyUnicode_FromObject(str);
775 if (str == NULL || PyUnicode_READY(str) < 0) { 2132 if (str == NULL || PyUnicode_READY(str) < 0) {
776 Py_XDECREF(str); 2133 Py_XDECREF(str);
777 return NULL; 2134 return NULL;
778 } 2135 }
779 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), 2136 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder),
780 PyUnicode_GET_LENGTH(str)); 2137 PyUnicode_GET_LENGTH(str));
781 Py_DECREF(str); 2138 Py_DECREF(str);
782 return v; 2139 return v;
783 } 2140 }
784 2141
2142 /*[clinic input]
2143 _codecs.Codecs.utf_16_le_encode
2144 str: object
2145 [
2146 errors: str(nullable=True)
2147 ]
2148 /
2149 [clinic start generated code]*/
2150
2151 PyDoc_STRVAR(_codecs_Codecs_utf_16_le_encode__doc__,
2152 "utf_16_le_encode(str, [errors])");
2153
2154 #define _CODECS_CODECS_UTF_16_LE_ENCODE_METHODDEF \
2155 {"utf_16_le_encode", (PyCFunction)_codecs_Codecs_utf_16_le_encode, METH_VARA RGS, _codecs_Codecs_utf_16_le_encode__doc__},
2156
785 static PyObject * 2157 static PyObject *
786 utf_16_le_encode(PyObject *self, 2158 _codecs_Codecs_utf_16_le_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors);
787 PyObject *args) 2159
2160 static PyObject *
2161 _codecs_Codecs_utf_16_le_encode(PyObject *self, PyObject *args)
788 { 2162 {
789 PyObject *str, *v; 2163 PyObject *return_value = NULL;
2164 PyObject *str;
2165 int group_right_1 = 0;
790 const char *errors = NULL; 2166 const char *errors = NULL;
791 2167
792 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", 2168 switch (PyTuple_Size(args)) {
793 &str, &errors)) 2169 case 1:
794 return NULL; 2170 if (!PyArg_ParseTuple(args, "O:utf_16_le_encode", &str))
2171 return NULL;
2172 break;
2173 case 2:
2174 if (!PyArg_ParseTuple(args, "Oz:utf_16_le_encode", &str, &errors))
2175 return NULL;
2176 group_right_1 = 1;
2177 break;
2178 default:
2179 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_le_encode re quires 1 to 2 arguments");
2180 return NULL;
2181 }
2182 return_value = _codecs_Codecs_utf_16_le_encode_impl(self, str, group_right_1 , errors);
2183
2184 return return_value;
2185 }
2186
2187 static PyObject *
2188 _codecs_Codecs_utf_16_le_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors)
2189 /*[clinic end generated code: checksum=d1df6209b7e67b93eb87076368ace9155a58c28e] */
2190 {
2191 PyObject *v;
795 2192
796 str = PyUnicode_FromObject(str); 2193 str = PyUnicode_FromObject(str);
797 if (str == NULL || PyUnicode_READY(str) < 0) { 2194 if (str == NULL || PyUnicode_READY(str) < 0) {
798 Py_XDECREF(str); 2195 Py_XDECREF(str);
799 return NULL; 2196 return NULL;
800 } 2197 }
801 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), 2198 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1),
802 PyUnicode_GET_LENGTH(str)); 2199 PyUnicode_GET_LENGTH(str));
803 Py_DECREF(str); 2200 Py_DECREF(str);
804 return v; 2201 return v;
805 } 2202 }
806 2203
2204 /*[clinic input]
2205 _codecs.Codecs.utf_16_be_encode
2206 str: object
2207 [
2208 errors: str(nullable=True)
2209 ]
2210 /
2211 [clinic start generated code]*/
2212
2213 PyDoc_STRVAR(_codecs_Codecs_utf_16_be_encode__doc__,
2214 "utf_16_be_encode(str, [errors])");
2215
2216 #define _CODECS_CODECS_UTF_16_BE_ENCODE_METHODDEF \
2217 {"utf_16_be_encode", (PyCFunction)_codecs_Codecs_utf_16_be_encode, METH_VARA RGS, _codecs_Codecs_utf_16_be_encode__doc__},
2218
807 static PyObject * 2219 static PyObject *
808 utf_16_be_encode(PyObject *self, 2220 _codecs_Codecs_utf_16_be_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors);
809 PyObject *args) 2221
2222 static PyObject *
2223 _codecs_Codecs_utf_16_be_encode(PyObject *self, PyObject *args)
810 { 2224 {
811 PyObject *str, *v; 2225 PyObject *return_value = NULL;
2226 PyObject *str;
2227 int group_right_1 = 0;
812 const char *errors = NULL; 2228 const char *errors = NULL;
813 2229
814 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", 2230 switch (PyTuple_Size(args)) {
815 &str, &errors)) 2231 case 1:
816 return NULL; 2232 if (!PyArg_ParseTuple(args, "O:utf_16_be_encode", &str))
2233 return NULL;
2234 break;
2235 case 2:
2236 if (!PyArg_ParseTuple(args, "Oz:utf_16_be_encode", &str, &errors))
2237 return NULL;
2238 group_right_1 = 1;
2239 break;
2240 default:
2241 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_16_be_encode re quires 1 to 2 arguments");
2242 return NULL;
2243 }
2244 return_value = _codecs_Codecs_utf_16_be_encode_impl(self, str, group_right_1 , errors);
2245
2246 return return_value;
2247 }
2248
2249 static PyObject *
2250 _codecs_Codecs_utf_16_be_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors)
2251 /*[clinic end generated code: checksum=b999bb3a4967df4509ba0b1b0685d3b4fabeb26d] */
2252 {
2253 PyObject *v;
817 2254
818 str = PyUnicode_FromObject(str); 2255 str = PyUnicode_FromObject(str);
819 if (str == NULL || PyUnicode_READY(str) < 0) { 2256 if (str == NULL || PyUnicode_READY(str) < 0) {
820 Py_XDECREF(str); 2257 Py_XDECREF(str);
821 return NULL; 2258 return NULL;
822 } 2259 }
823 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), 2260 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1),
824 PyUnicode_GET_LENGTH(str)); 2261 PyUnicode_GET_LENGTH(str));
825 Py_DECREF(str); 2262 Py_DECREF(str);
826 return v; 2263 return v;
827 } 2264 }
828 2265
829 /* This version provides access to the byteorder parameter of the 2266 /* This version provides access to the byteorder parameter of the
830 builtin UTF-32 codecs as optional third argument. It defaults to 0 2267 builtin UTF-32 codecs as optional third argument. It defaults to 0
831 which means: use the native byte order and prepend the data with a 2268 which means: use the native byte order and prepend the data with a
832 BOM mark. 2269 BOM mark.
833 2270
834 */ 2271 */
835 2272
2273 /*[clinic input]
2274 _codecs.Codecs.utf_32_encode
2275 str: object
2276 [
2277 errors: str(nullable=True)
2278 [
2279 byteorder: int = 0
2280 ]
2281 ]
2282 /
2283 [clinic start generated code]*/
2284
2285 PyDoc_STRVAR(_codecs_Codecs_utf_32_encode__doc__,
2286 "utf_32_encode(str, [errors, [byteorder=0]])");
2287
2288 #define _CODECS_CODECS_UTF_32_ENCODE_METHODDEF \
2289 {"utf_32_encode", (PyCFunction)_codecs_Codecs_utf_32_encode, METH_VARARGS, _ codecs_Codecs_utf_32_encode__doc__},
2290
836 static PyObject * 2291 static PyObject *
837 utf_32_encode(PyObject *self, 2292 _codecs_Codecs_utf_32_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors, int group_right_2, int byteorder);
838 PyObject *args) 2293
2294 static PyObject *
2295 _codecs_Codecs_utf_32_encode(PyObject *self, PyObject *args)
839 { 2296 {
840 PyObject *str, *v; 2297 PyObject *return_value = NULL;
2298 PyObject *str;
2299 int group_right_1 = 0;
841 const char *errors = NULL; 2300 const char *errors = NULL;
2301 int group_right_2 = 0;
842 int byteorder = 0; 2302 int byteorder = 0;
843 2303
844 if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", 2304 switch (PyTuple_Size(args)) {
845 &str, &errors, &byteorder)) 2305 case 1:
846 return NULL; 2306 if (!PyArg_ParseTuple(args, "O:utf_32_encode", &str))
2307 return NULL;
2308 break;
2309 case 2:
2310 if (!PyArg_ParseTuple(args, "Oz:utf_32_encode", &str, &errors))
2311 return NULL;
2312 group_right_1 = 1;
2313 break;
2314 case 3:
2315 if (!PyArg_ParseTuple(args, "Ozi:utf_32_encode", &str, &errors, &byt eorder))
2316 return NULL;
2317 group_right_1 = 1;
2318 group_right_2 = 1;
2319 break;
2320 default:
2321 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_encode requi res 1 to 3 arguments");
2322 return NULL;
2323 }
2324 return_value = _codecs_Codecs_utf_32_encode_impl(self, str, group_right_1, e rrors, group_right_2, byteorder);
2325
2326 return return_value;
2327 }
2328
2329 static PyObject *
2330 _codecs_Codecs_utf_32_encode_impl(PyObject *self, PyObject *str, int group_right _1, const char *errors, int group_right_2, int byteorder)
2331 /*[clinic end generated code: checksum=95bce5eae0e1726ea41a3b0037c8c9d3f67aa098] */
2332 {
2333 PyObject *v;
847 2334
848 str = PyUnicode_FromObject(str); 2335 str = PyUnicode_FromObject(str);
849 if (str == NULL || PyUnicode_READY(str) < 0) { 2336 if (str == NULL || PyUnicode_READY(str) < 0) {
850 Py_XDECREF(str); 2337 Py_XDECREF(str);
851 return NULL; 2338 return NULL;
852 } 2339 }
853 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), 2340 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder),
854 PyUnicode_GET_LENGTH(str)); 2341 PyUnicode_GET_LENGTH(str));
855 Py_DECREF(str); 2342 Py_DECREF(str);
856 return v; 2343 return v;
857 } 2344 }
858 2345
2346 /*[clinic input]
2347 _codecs.Codecs.utf_32_le_encode
2348 str: object
2349 [
2350 errors: str(nullable=True)
2351 ]
2352 /
2353 [clinic start generated code]*/
2354
2355 PyDoc_STRVAR(_codecs_Codecs_utf_32_le_encode__doc__,
2356 "utf_32_le_encode(str, [errors])");
2357
2358 #define _CODECS_CODECS_UTF_32_LE_ENCODE_METHODDEF \
2359 {"utf_32_le_encode", (PyCFunction)_codecs_Codecs_utf_32_le_encode, METH_VARA RGS, _codecs_Codecs_utf_32_le_encode__doc__},
2360
859 static PyObject * 2361 static PyObject *
860 utf_32_le_encode(PyObject *self, 2362 _codecs_Codecs_utf_32_le_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors);
861 PyObject *args) 2363
2364 static PyObject *
2365 _codecs_Codecs_utf_32_le_encode(PyObject *self, PyObject *args)
862 { 2366 {
863 PyObject *str, *v; 2367 PyObject *return_value = NULL;
2368 PyObject *str;
2369 int group_right_1 = 0;
864 const char *errors = NULL; 2370 const char *errors = NULL;
865 2371
866 if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", 2372 switch (PyTuple_Size(args)) {
867 &str, &errors)) 2373 case 1:
868 return NULL; 2374 if (!PyArg_ParseTuple(args, "O:utf_32_le_encode", &str))
2375 return NULL;
2376 break;
2377 case 2:
2378 if (!PyArg_ParseTuple(args, "Oz:utf_32_le_encode", &str, &errors))
2379 return NULL;
2380 group_right_1 = 1;
2381 break;
2382 default:
2383 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_le_encode re quires 1 to 2 arguments");
2384 return NULL;
2385 }
2386 return_value = _codecs_Codecs_utf_32_le_encode_impl(self, str, group_right_1 , errors);
2387
2388 return return_value;
2389 }
2390
2391 static PyObject *
2392 _codecs_Codecs_utf_32_le_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors)
2393 /*[clinic end generated code: checksum=211158cd66e13ddb41cf41c21232712b24a6d2c0] */
2394 {
2395 PyObject *v;
869 2396
870 str = PyUnicode_FromObject(str); 2397 str = PyUnicode_FromObject(str);
871 if (str == NULL || PyUnicode_READY(str) < 0) { 2398 if (str == NULL || PyUnicode_READY(str) < 0) {
872 Py_XDECREF(str); 2399 Py_XDECREF(str);
873 return NULL; 2400 return NULL;
874 } 2401 }
875 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), 2402 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1),
876 PyUnicode_GET_LENGTH(str)); 2403 PyUnicode_GET_LENGTH(str));
877 Py_DECREF(str); 2404 Py_DECREF(str);
878 return v; 2405 return v;
879 } 2406 }
880 2407
2408 /*[clinic input]
2409 _codecs.Codecs.utf_32_be_encode
2410 str: object
2411 [
2412 errors: str(nullable=True)
2413 ]
2414 /
2415 [clinic start generated code]*/
2416
2417 PyDoc_STRVAR(_codecs_Codecs_utf_32_be_encode__doc__,
2418 "utf_32_be_encode(str, [errors])");
2419
2420 #define _CODECS_CODECS_UTF_32_BE_ENCODE_METHODDEF \
2421 {"utf_32_be_encode", (PyCFunction)_codecs_Codecs_utf_32_be_encode, METH_VARA RGS, _codecs_Codecs_utf_32_be_encode__doc__},
2422
881 static PyObject * 2423 static PyObject *
882 utf_32_be_encode(PyObject *self, 2424 _codecs_Codecs_utf_32_be_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors);
883 PyObject *args) 2425
2426 static PyObject *
2427 _codecs_Codecs_utf_32_be_encode(PyObject *self, PyObject *args)
884 { 2428 {
885 PyObject *str, *v; 2429 PyObject *return_value = NULL;
2430 PyObject *str;
2431 int group_right_1 = 0;
886 const char *errors = NULL; 2432 const char *errors = NULL;
887 2433
888 if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", 2434 switch (PyTuple_Size(args)) {
889 &str, &errors)) 2435 case 1:
890 return NULL; 2436 if (!PyArg_ParseTuple(args, "O:utf_32_be_encode", &str))
2437 return NULL;
2438 break;
2439 case 2:
2440 if (!PyArg_ParseTuple(args, "Oz:utf_32_be_encode", &str, &errors))
2441 return NULL;
2442 group_right_1 = 1;
2443 break;
2444 default:
2445 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.utf_32_be_encode re quires 1 to 2 arguments");
2446 return NULL;
2447 }
2448 return_value = _codecs_Codecs_utf_32_be_encode_impl(self, str, group_right_1 , errors);
2449
2450 return return_value;
2451 }
2452
2453 static PyObject *
2454 _codecs_Codecs_utf_32_be_encode_impl(PyObject *self, PyObject *str, int group_ri ght_1, const char *errors)
2455 /*[clinic end generated code: checksum=f4f360e27584752de8f391612c0d3856ac5f631d] */
2456 {
2457 PyObject *v;
891 2458
892 str = PyUnicode_FromObject(str); 2459 str = PyUnicode_FromObject(str);
893 if (str == NULL || PyUnicode_READY(str) < 0) { 2460 if (str == NULL || PyUnicode_READY(str) < 0) {
894 Py_XDECREF(str); 2461 Py_XDECREF(str);
895 return NULL; 2462 return NULL;
896 } 2463 }
897 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), 2464 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1),
898 PyUnicode_GET_LENGTH(str)); 2465 PyUnicode_GET_LENGTH(str));
899 Py_DECREF(str); 2466 Py_DECREF(str);
900 return v; 2467 return v;
901 } 2468 }
902 2469
2470 /*[clinic input]
2471 _codecs.Codecs.unicode_escape_encode
2472 str: object
2473 [
2474 errors: str(nullable=True)
2475 ]
2476 /
2477 [clinic start generated code]*/
2478
2479 PyDoc_STRVAR(_codecs_Codecs_unicode_escape_encode__doc__,
2480 "unicode_escape_encode(str, [errors])");
2481
2482 #define _CODECS_CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \
2483 {"unicode_escape_encode", (PyCFunction)_codecs_Codecs_unicode_escape_encode, METH_VARARGS, _codecs_Codecs_unicode_escape_encode__doc__},
2484
903 static PyObject * 2485 static PyObject *
904 unicode_escape_encode(PyObject *self, 2486 _codecs_Codecs_unicode_escape_encode_impl(PyObject *self, PyObject *str, int gro up_right_1, const char *errors);
905 PyObject *args) 2487
2488 static PyObject *
2489 _codecs_Codecs_unicode_escape_encode(PyObject *self, PyObject *args)
906 { 2490 {
907 PyObject *str, *v; 2491 PyObject *return_value = NULL;
2492 PyObject *str;
2493 int group_right_1 = 0;
908 const char *errors = NULL; 2494 const char *errors = NULL;
909 2495
910 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", 2496 switch (PyTuple_Size(args)) {
911 &str, &errors)) 2497 case 1:
912 return NULL; 2498 if (!PyArg_ParseTuple(args, "O:unicode_escape_encode", &str))
2499 return NULL;
2500 break;
2501 case 2:
2502 if (!PyArg_ParseTuple(args, "Oz:unicode_escape_encode", &str, &error s))
2503 return NULL;
2504 group_right_1 = 1;
2505 break;
2506 default:
2507 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.unicode_escape_enco de requires 1 to 2 arguments");
2508 return NULL;
2509 }
2510 return_value = _codecs_Codecs_unicode_escape_encode_impl(self, str, group_ri ght_1, errors);
2511
2512 return return_value;
2513 }
2514
2515 static PyObject *
2516 _codecs_Codecs_unicode_escape_encode_impl(PyObject *self, PyObject *str, int gro up_right_1, const char *errors)
2517 /*[clinic end generated code: checksum=606f44f27f41c96420c5918de31951c425308c39] */
2518 {
2519 PyObject *v;
913 2520
914 str = PyUnicode_FromObject(str); 2521 str = PyUnicode_FromObject(str);
915 if (str == NULL || PyUnicode_READY(str) < 0) { 2522 if (str == NULL || PyUnicode_READY(str) < 0) {
916 Py_XDECREF(str); 2523 Py_XDECREF(str);
917 return NULL; 2524 return NULL;
918 } 2525 }
919 v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str), 2526 v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str),
920 PyUnicode_GET_LENGTH(str)); 2527 PyUnicode_GET_LENGTH(str));
921 Py_DECREF(str); 2528 Py_DECREF(str);
922 return v; 2529 return v;
923 } 2530 }
924 2531
2532 /*[clinic input]
2533 _codecs.Codecs.raw_unicode_escape_encode
2534 str: object
2535 [
2536 errors: str(nullable=True)
2537 ]
2538 /
2539 [clinic start generated code]*/
2540
2541 PyDoc_STRVAR(_codecs_Codecs_raw_unicode_escape_encode__doc__,
2542 "raw_unicode_escape_encode(str, [errors])");
2543
2544 #define _CODECS_CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \
2545 {"raw_unicode_escape_encode", (PyCFunction)_codecs_Codecs_raw_unicode_escape _encode, METH_VARARGS, _codecs_Codecs_raw_unicode_escape_encode__doc__},
2546
925 static PyObject * 2547 static PyObject *
926 raw_unicode_escape_encode(PyObject *self, 2548 _codecs_Codecs_raw_unicode_escape_encode_impl(PyObject *self, PyObject *str, int group_right_1, const char *errors);
927 PyObject *args) 2549
2550 static PyObject *
2551 _codecs_Codecs_raw_unicode_escape_encode(PyObject *self, PyObject *args)
928 { 2552 {
929 PyObject *str, *v; 2553 PyObject *return_value = NULL;
2554 PyObject *str;
2555 int group_right_1 = 0;
930 const char *errors = NULL; 2556 const char *errors = NULL;
931 2557
932 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", 2558 switch (PyTuple_Size(args)) {
933 &str, &errors)) 2559 case 1:
934 return NULL; 2560 if (!PyArg_ParseTuple(args, "O:raw_unicode_escape_encode", &str))
2561 return NULL;
2562 break;
2563 case 2:
2564 if (!PyArg_ParseTuple(args, "Oz:raw_unicode_escape_encode", &str, &e rrors))
2565 return NULL;
2566 group_right_1 = 1;
2567 break;
2568 default:
2569 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.raw_unicode_escape_ encode requires 1 to 2 arguments");
2570 return NULL;
2571 }
2572 return_value = _codecs_Codecs_raw_unicode_escape_encode_impl(self, str, grou p_right_1, errors);
2573
2574 return return_value;
2575 }
2576
2577 static PyObject *
2578 _codecs_Codecs_raw_unicode_escape_encode_impl(PyObject *self, PyObject *str, int group_right_1, const char *errors)
2579 /*[clinic end generated code: checksum=71322526bde049be177d1cb0c224af1d542cea22] */
2580 {
2581 PyObject *v;
935 2582
936 str = PyUnicode_FromObject(str); 2583 str = PyUnicode_FromObject(str);
937 if (str == NULL || PyUnicode_READY(str) < 0) { 2584 if (str == NULL || PyUnicode_READY(str) < 0) {
938 Py_XDECREF(str); 2585 Py_XDECREF(str);
939 return NULL; 2586 return NULL;
940 } 2587 }
941 v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), 2588 v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str),
942 PyUnicode_GET_LENGTH(str)); 2589 PyUnicode_GET_LENGTH(str));
943 Py_DECREF(str); 2590 Py_DECREF(str);
944 return v; 2591 return v;
945 } 2592 }
946 2593
2594 /*[clinic input]
2595 _codecs.Codecs.latin_1_encode
2596 str: object
2597 [
2598 errors: str(nullable=True)
2599 ]
2600 /
2601 [clinic start generated code]*/
2602
2603 PyDoc_STRVAR(_codecs_Codecs_latin_1_encode__doc__,
2604 "latin_1_encode(str, [errors])");
2605
2606 #define _CODECS_CODECS_LATIN_1_ENCODE_METHODDEF \
2607 {"latin_1_encode", (PyCFunction)_codecs_Codecs_latin_1_encode, METH_VARARGS, _codecs_Codecs_latin_1_encode__doc__},
2608
947 static PyObject * 2609 static PyObject *
948 latin_1_encode(PyObject *self, 2610 _codecs_Codecs_latin_1_encode_impl(PyObject *self, PyObject *str, int group_righ t_1, const char *errors);
949 PyObject *args) 2611
2612 static PyObject *
2613 _codecs_Codecs_latin_1_encode(PyObject *self, PyObject *args)
950 { 2614 {
951 PyObject *str, *v; 2615 PyObject *return_value = NULL;
2616 PyObject *str;
2617 int group_right_1 = 0;
952 const char *errors = NULL; 2618 const char *errors = NULL;
953 2619
954 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", 2620 switch (PyTuple_Size(args)) {
955 &str, &errors)) 2621 case 1:
956 return NULL; 2622 if (!PyArg_ParseTuple(args, "O:latin_1_encode", &str))
2623 return NULL;
2624 break;
2625 case 2:
2626 if (!PyArg_ParseTuple(args, "Oz:latin_1_encode", &str, &errors))
2627 return NULL;
2628 group_right_1 = 1;
2629 break;
2630 default:
2631 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.latin_1_encode requ ires 1 to 2 arguments");
2632 return NULL;
2633 }
2634 return_value = _codecs_Codecs_latin_1_encode_impl(self, str, group_right_1, errors);
2635
2636 return return_value;
2637 }
2638
2639 static PyObject *
2640 _codecs_Codecs_latin_1_encode_impl(PyObject *self, PyObject *str, int group_righ t_1, const char *errors)
2641 /*[clinic end generated code: checksum=7b73f06986d320799647494fb73c9f606f95ff53] */
2642 {
2643 PyObject *v;
957 2644
958 str = PyUnicode_FromObject(str); 2645 str = PyUnicode_FromObject(str);
959 if (str == NULL || PyUnicode_READY(str) < 0) { 2646 if (str == NULL || PyUnicode_READY(str) < 0) {
960 Py_XDECREF(str); 2647 Py_XDECREF(str);
961 return NULL; 2648 return NULL;
962 } 2649 }
963 v = codec_tuple(_PyUnicode_AsLatin1String(str, errors), 2650 v = codec_tuple(_PyUnicode_AsLatin1String(str, errors),
964 PyUnicode_GET_LENGTH(str)); 2651 PyUnicode_GET_LENGTH(str));
965 Py_DECREF(str); 2652 Py_DECREF(str);
966 return v; 2653 return v;
967 } 2654 }
968 2655
2656 /*[clinic input]
2657 _codecs.Codecs.ascii_encode
2658 str: object
2659 [
2660 errors: str(nullable=True)
2661 ]
2662 /
2663 [clinic start generated code]*/
2664
2665 PyDoc_STRVAR(_codecs_Codecs_ascii_encode__doc__,
2666 "ascii_encode(str, [errors])");
2667
2668 #define _CODECS_CODECS_ASCII_ENCODE_METHODDEF \
2669 {"ascii_encode", (PyCFunction)_codecs_Codecs_ascii_encode, METH_VARARGS, _co decs_Codecs_ascii_encode__doc__},
2670
969 static PyObject * 2671 static PyObject *
970 ascii_encode(PyObject *self, 2672 _codecs_Codecs_ascii_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors);
971 PyObject *args) 2673
2674 static PyObject *
2675 _codecs_Codecs_ascii_encode(PyObject *self, PyObject *args)
972 { 2676 {
973 PyObject *str, *v; 2677 PyObject *return_value = NULL;
2678 PyObject *str;
2679 int group_right_1 = 0;
974 const char *errors = NULL; 2680 const char *errors = NULL;
975 2681
976 if (!PyArg_ParseTuple(args, "O|z:ascii_encode", 2682 switch (PyTuple_Size(args)) {
977 &str, &errors)) 2683 case 1:
978 return NULL; 2684 if (!PyArg_ParseTuple(args, "O:ascii_encode", &str))
2685 return NULL;
2686 break;
2687 case 2:
2688 if (!PyArg_ParseTuple(args, "Oz:ascii_encode", &str, &errors))
2689 return NULL;
2690 group_right_1 = 1;
2691 break;
2692 default:
2693 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.ascii_encode requir es 1 to 2 arguments");
2694 return NULL;
2695 }
2696 return_value = _codecs_Codecs_ascii_encode_impl(self, str, group_right_1, er rors);
2697
2698 return return_value;
2699 }
2700
2701 static PyObject *
2702 _codecs_Codecs_ascii_encode_impl(PyObject *self, PyObject *str, int group_right_ 1, const char *errors)
2703 /*[clinic end generated code: checksum=7dce795060ed9de4a012740ff404d23ad3417cbf] */
2704 {
2705 PyObject *v;
979 2706
980 str = PyUnicode_FromObject(str); 2707 str = PyUnicode_FromObject(str);
981 if (str == NULL || PyUnicode_READY(str) < 0) { 2708 if (str == NULL || PyUnicode_READY(str) < 0) {
982 Py_XDECREF(str); 2709 Py_XDECREF(str);
983 return NULL; 2710 return NULL;
984 } 2711 }
985 v = codec_tuple(_PyUnicode_AsASCIIString(str, errors), 2712 v = codec_tuple(_PyUnicode_AsASCIIString(str, errors),
986 PyUnicode_GET_LENGTH(str)); 2713 PyUnicode_GET_LENGTH(str));
987 Py_DECREF(str); 2714 Py_DECREF(str);
988 return v; 2715 return v;
989 } 2716 }
990 2717
2718 /*[clinic input]
2719 _codecs.Codecs.charmap_encode
2720 str: object
2721 [
2722 errors: str(nullable=True)
2723 [
2724 mapping: object = None
2725 ]
2726 ]
2727 /
2728 [clinic start generated code]*/
2729
2730 PyDoc_STRVAR(_codecs_Codecs_charmap_encode__doc__,
2731 "charmap_encode(str, [errors, [mapping=None]])");
2732
2733 #define _CODECS_CODECS_CHARMAP_ENCODE_METHODDEF \
2734 {"charmap_encode", (PyCFunction)_codecs_Codecs_charmap_encode, METH_VARARGS, _codecs_Codecs_charmap_encode__doc__},
2735
991 static PyObject * 2736 static PyObject *
992 charmap_encode(PyObject *self, 2737 _codecs_Codecs_charmap_encode_impl(PyObject *self, PyObject *str, int group_righ t_1, const char *errors, int group_right_2, PyObject *mapping);
993 PyObject *args) 2738
2739 static PyObject *
2740 _codecs_Codecs_charmap_encode(PyObject *self, PyObject *args)
994 { 2741 {
995 PyObject *str, *v; 2742 PyObject *return_value = NULL;
2743 PyObject *str;
2744 int group_right_1 = 0;
996 const char *errors = NULL; 2745 const char *errors = NULL;
997 PyObject *mapping = NULL; 2746 int group_right_2 = 0;
2747 PyObject *mapping = Py_None;
998 2748
999 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", 2749 switch (PyTuple_Size(args)) {
1000 &str, &errors, &mapping)) 2750 case 1:
1001 return NULL; 2751 if (!PyArg_ParseTuple(args, "O:charmap_encode", &str))
2752 return NULL;
2753 break;
2754 case 2:
2755 if (!PyArg_ParseTuple(args, "Oz:charmap_encode", &str, &errors))
2756 return NULL;
2757 group_right_1 = 1;
2758 break;
2759 case 3:
2760 if (!PyArg_ParseTuple(args, "OzO:charmap_encode", &str, &errors, &ma pping))
2761 return NULL;
2762 group_right_1 = 1;
2763 group_right_2 = 1;
2764 break;
2765 default:
2766 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.charmap_encode requ ires 1 to 3 arguments");
2767 return NULL;
2768 }
2769 return_value = _codecs_Codecs_charmap_encode_impl(self, str, group_right_1, errors, group_right_2, mapping);
2770
2771 return return_value;
2772 }
2773
2774 static PyObject *
2775 _codecs_Codecs_charmap_encode_impl(PyObject *self, PyObject *str, int group_righ t_1, const char *errors, int group_right_2, PyObject *mapping)
2776 /*[clinic end generated code: checksum=cb386acf850159e17e2b30528fa0a4d2e6d1c809] */
2777 {
2778 PyObject *v;
2779
1002 if (mapping == Py_None) 2780 if (mapping == Py_None)
1003 mapping = NULL; 2781 mapping = NULL;
1004 2782
1005 str = PyUnicode_FromObject(str); 2783 str = PyUnicode_FromObject(str);
1006 if (str == NULL || PyUnicode_READY(str) < 0) { 2784 if (str == NULL || PyUnicode_READY(str) < 0) {
1007 Py_XDECREF(str); 2785 Py_XDECREF(str);
1008 return NULL; 2786 return NULL;
1009 } 2787 }
1010 v = codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors), 2788 v = codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors),
1011 PyUnicode_GET_LENGTH(str)); 2789 PyUnicode_GET_LENGTH(str));
1012 Py_DECREF(str); 2790 Py_DECREF(str);
1013 return v; 2791 return v;
1014 } 2792 }
1015 2793
1016 static PyObject* 2794 /*[clinic input]
1017 charmap_build(PyObject *self, PyObject *args) 2795 _codecs.Codecs.charmap_build
2796 map: unicode
2797 /
2798 [clinic start generated code]*/
2799
2800 PyDoc_STRVAR(_codecs_Codecs_charmap_build__doc__,
2801 "charmap_build(map)");
2802
2803 #define _CODECS_CODECS_CHARMAP_BUILD_METHODDEF \
2804 {"charmap_build", (PyCFunction)_codecs_Codecs_charmap_build, METH_VARARGS, _ codecs_Codecs_charmap_build__doc__},
2805
2806 static PyObject *
2807 _codecs_Codecs_charmap_build_impl(PyObject *self, PyObject *map);
2808
2809 static PyObject *
2810 _codecs_Codecs_charmap_build(PyObject *self, PyObject *args)
1018 { 2811 {
2812 PyObject *return_value = NULL;
1019 PyObject *map; 2813 PyObject *map;
1020 if (!PyArg_ParseTuple(args, "U:charmap_build", &map)) 2814
1021 return NULL; 2815 if (!PyArg_ParseTuple(args,
2816 "U:charmap_build",
2817 &map))
2818 goto exit;
2819 return_value = _codecs_Codecs_charmap_build_impl(self, map);
2820
2821 exit:
2822 return return_value;
2823 }
2824
2825 static PyObject *
2826 _codecs_Codecs_charmap_build_impl(PyObject *self, PyObject *map)
2827 /*[clinic end generated code: checksum=a80038590a254024bf45acd290b3b5ea4695c8f7] */
2828 {
1022 return PyUnicode_BuildEncodingMap(map); 2829 return PyUnicode_BuildEncodingMap(map);
1023 } 2830 }
1024 2831
1025 #ifdef HAVE_MBCS 2832 #ifdef HAVE_MBCS
1026 2833
2834 /*[clinic input]
2835 _codecs.Codecs.mbcs_encode
2836 str: object
2837 [
2838 errors: str(nullable=True)
2839 ]
2840 /
2841 [clinic start generated code]*/
2842
2843 PyDoc_STRVAR(_codecs_Codecs_mbcs_encode__doc__,
2844 "mbcs_encode(str, [errors])");
2845
2846 #define _CODECS_CODECS_MBCS_ENCODE_METHODDEF \
2847 {"mbcs_encode", (PyCFunction)_codecs_Codecs_mbcs_encode, METH_VARARGS, _code cs_Codecs_mbcs_encode__doc__},
2848
1027 static PyObject * 2849 static PyObject *
1028 mbcs_encode(PyObject *self, 2850 _codecs_Codecs_mbcs_encode_impl(PyObject *self, PyObject *str, int group_right_1 , const char *errors);
1029 PyObject *args) 2851
2852 static PyObject *
2853 _codecs_Codecs_mbcs_encode(PyObject *self, PyObject *args)
1030 { 2854 {
1031 PyObject *str, *v; 2855 PyObject *return_value = NULL;
2856 PyObject *str;
2857 int group_right_1 = 0;
1032 const char *errors = NULL; 2858 const char *errors = NULL;
1033 2859
1034 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", 2860 switch (PyTuple_Size(args)) {
1035 &str, &errors)) 2861 case 1:
1036 return NULL; 2862 if (!PyArg_ParseTuple(args, "O:mbcs_encode", &str))
2863 return NULL;
2864 break;
2865 case 2:
2866 if (!PyArg_ParseTuple(args, "Oz:mbcs_encode", &str, &errors))
2867 return NULL;
2868 group_right_1 = 1;
2869 break;
2870 default:
2871 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.mbcs_encode require s 1 to 2 arguments");
2872 return NULL;
2873 }
2874 return_value = _codecs_Codecs_mbcs_encode_impl(self, str, group_right_1, err ors);
2875
2876 return return_value;
2877 }
2878
2879 static PyObject *
2880 _codecs_Codecs_mbcs_encode_impl(PyObject *self, PyObject *str, int group_right_1 , const char *errors)
2881 /*[clinic end generated code: checksum=1c89fd3be1247aaecc1d17bd0fd3c4132f8fa45e] */
2882 {
2883 PyObject *v;
1037 2884
1038 str = PyUnicode_FromObject(str); 2885 str = PyUnicode_FromObject(str);
1039 if (str == NULL || PyUnicode_READY(str) < 0) { 2886 if (str == NULL || PyUnicode_READY(str) < 0) {
1040 Py_XDECREF(str); 2887 Py_XDECREF(str);
1041 return NULL; 2888 return NULL;
1042 } 2889 }
1043 v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), 2890 v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors),
1044 PyUnicode_GET_LENGTH(str)); 2891 PyUnicode_GET_LENGTH(str));
1045 Py_DECREF(str); 2892 Py_DECREF(str);
1046 return v; 2893 return v;
1047 } 2894 }
1048 2895
2896 /*[clinic input]
2897 _codecs.Codecs.code_page_encode
2898 code_page: int
2899 str: object
2900 [
2901 errors: str(nullable=True)
2902 ]
2903 /
2904 [clinic start generated code]*/
2905
2906 PyDoc_STRVAR(_codecs_Codecs_code_page_encode__doc__,
2907 "code_page_encode(code_page, str, [errors])");
2908
2909 #define _CODECS_CODECS_CODE_PAGE_ENCODE_METHODDEF \
2910 {"code_page_encode", (PyCFunction)_codecs_Codecs_code_page_encode, METH_VARA RGS, _codecs_Codecs_code_page_encode__doc__},
2911
1049 static PyObject * 2912 static PyObject *
1050 code_page_encode(PyObject *self, 2913 _codecs_Codecs_code_page_encode_impl(PyObject *self, int code_page, PyObject *st r, int group_right_1, const char *errors);
1051 PyObject *args) 2914
2915 static PyObject *
2916 _codecs_Codecs_code_page_encode(PyObject *self, PyObject *args)
1052 { 2917 {
1053 PyObject *str, *v; 2918 PyObject *return_value = NULL;
2919 int code_page;
2920 PyObject *str;
2921 int group_right_1 = 0;
1054 const char *errors = NULL; 2922 const char *errors = NULL;
1055 int code_page;
1056 2923
1057 if (!PyArg_ParseTuple(args, "iO|z:code_page_encode", 2924 switch (PyTuple_Size(args)) {
1058 &code_page, &str, &errors)) 2925 case 2:
1059 return NULL; 2926 if (!PyArg_ParseTuple(args, "iO:code_page_encode", &code_page, &str) )
2927 return NULL;
2928 break;
2929 case 3:
2930 if (!PyArg_ParseTuple(args, "iOz:code_page_encode", &code_page, &str , &errors))
2931 return NULL;
2932 group_right_1 = 1;
2933 break;
2934 default:
2935 PyErr_SetString(PyExc_TypeError, "_codecs.Codecs.code_page_encode re quires 2 to 3 arguments");
2936 return NULL;
2937 }
2938 return_value = _codecs_Codecs_code_page_encode_impl(self, code_page, str, gr oup_right_1, errors);
2939
2940 return return_value;
2941 }
2942
2943 static PyObject *
2944 _codecs_Codecs_code_page_encode_impl(PyObject *self, int code_page, PyObject *st r, int group_right_1, const char *errors)
2945 /*[clinic end generated code: checksum=dd0a2b0c37f9740a3aae914b8bf089d7af12f8da] */
2946 {
2947 PyObject *v;
1060 2948
1061 str = PyUnicode_FromObject(str); 2949 str = PyUnicode_FromObject(str);
1062 if (str == NULL || PyUnicode_READY(str) < 0) { 2950 if (str == NULL || PyUnicode_READY(str) < 0) {
1063 Py_XDECREF(str); 2951 Py_XDECREF(str);
1064 return NULL; 2952 return NULL;
1065 } 2953 }
1066 v = codec_tuple(PyUnicode_EncodeCodePage(code_page, 2954 v = codec_tuple(PyUnicode_EncodeCodePage(code_page,
1067 str, 2955 str,
1068 errors), 2956 errors),
1069 PyUnicode_GET_LENGTH(str)); 2957 PyUnicode_GET_LENGTH(str));
1070 Py_DECREF(str); 2958 Py_DECREF(str);
1071 return v; 2959 return v;
1072 } 2960 }
1073 2961
1074 #endif /* HAVE_MBCS */ 2962 #endif /* HAVE_MBCS */
1075 2963
1076 /* --- Error handler registry --------------------------------------------- */ 2964 /* --- Error handler registry --------------------------------------------- */
1077 2965
1078 PyDoc_STRVAR(register_error__doc__, 2966 /*[clinic input]
1079 "register_error(errors, handler)\n\ 2967 _codecs.Codecs.register_error
1080 \n\ 2968 name: str
1081 Register the specified error handler under the name\n\ 2969 handler: object
1082 errors. handler must be a callable object, that\n\ 2970 /
1083 will be called with an exception instance containing\n\
1084 information about the location of the encoding/decoding\n\
1085 error and must return a (replacement, new position) tuple.");
1086 2971
1087 static PyObject *register_error(PyObject *self, PyObject *args) 2972 Register the specified error handler.
2973
2974 Register the specified error handler under the name errors. handler must be a
2975 callable object, that will be called with an exception instance containing
2976 information about the location of the encoding/decoding error and must return a
2977 (replacement, new position) tuple.
2978 [clinic start generated code]*/
2979
2980 PyDoc_STRVAR(_codecs_Codecs_register_error__doc__,
2981 "register_error(name, handler)\n"
2982 "Register the specified error handler.\n"
2983 "\n"
2984 "Register the specified error handler under the name errors. handler must be a\n "
2985 "callable object, that will be called with an exception instance containing\n"
2986 "information about the location of the encoding/decoding error and must return a \n"
2987 "(replacement, new position) tuple.");
2988
2989 #define _CODECS_CODECS_REGISTER_ERROR_METHODDEF \
2990 {"register_error", (PyCFunction)_codecs_Codecs_register_error, METH_VARARGS, _codecs_Codecs_register_error__doc__},
2991
2992 static PyObject *
2993 _codecs_Codecs_register_error_impl(PyObject *self, const char *name, PyObject *h andler);
2994
2995 static PyObject *
2996 _codecs_Codecs_register_error(PyObject *self, PyObject *args)
1088 { 2997 {
2998 PyObject *return_value = NULL;
1089 const char *name; 2999 const char *name;
1090 PyObject *handler; 3000 PyObject *handler;
1091 3001
1092 if (!PyArg_ParseTuple(args, "sO:register_error", 3002 if (!PyArg_ParseTuple(args,
1093 &name, &handler)) 3003 "sO:register_error",
1094 return NULL; 3004 &name, &handler))
3005 goto exit;
3006 return_value = _codecs_Codecs_register_error_impl(self, name, handler);
3007
3008 exit:
3009 return return_value;
3010 }
3011
3012 static PyObject *
3013 _codecs_Codecs_register_error_impl(PyObject *self, const char *name, PyObject *h andler)
3014 /*[clinic end generated code: checksum=2f69fc4cacfab945ede1263f21f3522bd6a6e776] */
3015 {
1095 if (PyCodec_RegisterError(name, handler)) 3016 if (PyCodec_RegisterError(name, handler))
1096 return NULL; 3017 return NULL;
1097 Py_RETURN_NONE; 3018 Py_RETURN_NONE;
1098 } 3019 }
1099 3020
1100 PyDoc_STRVAR(lookup_error__doc__, 3021 /*[clinic input]
1101 "lookup_error(errors) -> handler\n\ 3022 _codecs.Codecs.lookup_error
1102 \n\ 3023 name: str
1103 Return the error handler for the specified error handling name\n\ 3024 /
1104 or raise a LookupError, if no handler exists under this name.");
1105 3025
1106 static PyObject *lookup_error(PyObject *self, PyObject *args) 3026 Return the error handler.
3027
3028 Return the error handler for the specified error handling name or raise a
3029 LookupError, if no handler exists under this name.
3030 [clinic start generated code]*/
3031
3032 PyDoc_STRVAR(_codecs_Codecs_lookup_error__doc__,
3033 "lookup_error(name)\n"
3034 "Return the error handler.\n"
3035 "\n"
3036 "Return the error handler for the specified error handling name or raise a\n"
3037 "LookupError, if no handler exists under this name.");
3038
3039 #define _CODECS_CODECS_LOOKUP_ERROR_METHODDEF \
3040 {"lookup_error", (PyCFunction)_codecs_Codecs_lookup_error, METH_VARARGS, _co decs_Codecs_lookup_error__doc__},
3041
3042 static PyObject *
3043 _codecs_Codecs_lookup_error_impl(PyObject *self, const char *name);
3044
3045 static PyObject *
3046 _codecs_Codecs_lookup_error(PyObject *self, PyObject *args)
1107 { 3047 {
3048 PyObject *return_value = NULL;
1108 const char *name; 3049 const char *name;
1109 3050
1110 if (!PyArg_ParseTuple(args, "s:lookup_error", 3051 if (!PyArg_ParseTuple(args,
1111 &name)) 3052 "s:lookup_error",
1112 return NULL; 3053 &name))
3054 goto exit;
3055 return_value = _codecs_Codecs_lookup_error_impl(self, name);
3056
3057 exit:
3058 return return_value;
3059 }
3060
3061 static PyObject *
3062 _codecs_Codecs_lookup_error_impl(PyObject *self, const char *name)
3063 /*[clinic end generated code: checksum=baf3de5707dfd143b51a672e6d6931d0850756a8] */
3064 {
1113 return PyCodec_LookupError(name); 3065 return PyCodec_LookupError(name);
1114 } 3066 }
1115 3067
1116 /* --- Module API --------------------------------------------------------- */ 3068 /* --- Module API --------------------------------------------------------- */
1117 3069
1118 static PyMethodDef _codecs_functions[] = { 3070 static PyMethodDef _codecs_functions[] = {
1119 {"register", codec_register, METH_O, 3071 {"register", codec_register, METH_O,
1120 register__doc__}, 3072 register__doc__},
1121 {"lookup", codec_lookup, METH_VARARGS, 3073 _CODECS_CODECS_LOOKUP_METHODDEF
1122 lookup__doc__}, 3074 _CODECS_CODECS_ENCODE_METHODDEF
1123 {"encode", codec_encode, METH_VARARGS, 3075 _CODECS_CODECS_DECODE_METHODDEF
1124 encode__doc__}, 3076 _CODECS_CODECS_ESCAPE_DECODE_METHODDEF
1125 {"decode", codec_decode, METH_VARARGS, 3077 _CODECS_CODECS_ESCAPE_ENCODE_METHODDEF
1126 decode__doc__}, 3078 _CODECS_CODECS_UTF_8_ENCODE_METHODDEF
1127 {"escape_encode", escape_encode, METH_VARARGS}, 3079 _CODECS_CODECS_UTF_8_DECODE_METHODDEF
1128 {"escape_decode", escape_decode, METH_VARARGS}, 3080 _CODECS_CODECS_UTF_7_ENCODE_METHODDEF
1129 {"utf_8_encode", utf_8_encode, METH_VARARGS}, 3081 _CODECS_CODECS_UTF_7_DECODE_METHODDEF
1130 {"utf_8_decode", utf_8_decode, METH_VARARGS}, 3082 _CODECS_CODECS_UTF_16_ENCODE_METHODDEF
1131 {"utf_7_encode", utf_7_encode, METH_VARARGS}, 3083 _CODECS_CODECS_UTF_16_LE_ENCODE_METHODDEF
1132 {"utf_7_decode", utf_7_decode, METH_VARARGS}, 3084 _CODECS_CODECS_UTF_16_BE_ENCODE_METHODDEF
1133 {"utf_16_encode", utf_16_encode, METH_VARARGS}, 3085 _CODECS_CODECS_UTF_16_DECODE_METHODDEF
1134 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS}, 3086 _CODECS_CODECS_UTF_16_LE_DECODE_METHODDEF
1135 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS}, 3087 _CODECS_CODECS_UTF_16_BE_DECODE_METHODDEF
1136 {"utf_16_decode", utf_16_decode, METH_VARARGS}, 3088 _CODECS_CODECS_UTF_16_EX_DECODE_METHODDEF
1137 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS}, 3089 _CODECS_CODECS_UTF_32_ENCODE_METHODDEF
1138 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS}, 3090 _CODECS_CODECS_UTF_32_LE_ENCODE_METHODDEF
1139 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS}, 3091 _CODECS_CODECS_UTF_32_BE_ENCODE_METHODDEF
1140 {"utf_32_encode", utf_32_encode, METH_VARARGS}, 3092 _CODECS_CODECS_UTF_32_DECODE_METHODDEF
1141 {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS}, 3093 _CODECS_CODECS_UTF_32_LE_DECODE_METHODDEF
1142 {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS}, 3094 _CODECS_CODECS_UTF_32_BE_DECODE_METHODDEF
1143 {"utf_32_decode", utf_32_decode, METH_VARARGS}, 3095 _CODECS_CODECS_UTF_32_EX_DECODE_METHODDEF
1144 {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS}, 3096 _CODECS_CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF
1145 {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS}, 3097 _CODECS_CODECS_UNICODE_ESCAPE_DECODE_METHODDEF
1146 {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS}, 3098 _CODECS_CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF
1147 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS}, 3099 _CODECS_CODECS_UNICODE_INTERNAL_DECODE_METHODDEF
1148 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS}, 3100 _CODECS_CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF
1149 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS}, 3101 _CODECS_CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF
1150 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS}, 3102 _CODECS_CODECS_LATIN_1_ENCODE_METHODDEF
1151 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS}, 3103 _CODECS_CODECS_LATIN_1_DECODE_METHODDEF
1152 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS}, 3104 _CODECS_CODECS_ASCII_ENCODE_METHODDEF
1153 {"latin_1_encode", latin_1_encode, METH_VARARGS}, 3105 _CODECS_CODECS_ASCII_DECODE_METHODDEF
1154 {"latin_1_decode", latin_1_decode, METH_VARARGS}, 3106 _CODECS_CODECS_CHARMAP_ENCODE_METHODDEF
1155 {"ascii_encode", ascii_encode, METH_VARARGS}, 3107 _CODECS_CODECS_CHARMAP_DECODE_METHODDEF
1156 {"ascii_decode", ascii_decode, METH_VARARGS}, 3108 _CODECS_CODECS_CHARMAP_BUILD_METHODDEF
1157 {"charmap_encode", charmap_encode, METH_VARARGS}, 3109 _CODECS_CODECS_READBUFFER_ENCODE_METHODDEF
1158 {"charmap_decode", charmap_decode, METH_VARARGS},
1159 {"charmap_build", charmap_build, METH_VARARGS},
1160 {"readbuffer_encode", readbuffer_encode, METH_VARARGS},
1161 #ifdef HAVE_MBCS 3110 #ifdef HAVE_MBCS
1162 {"mbcs_encode", mbcs_encode, METH_VARARGS}, 3111 _CODECS_CODECS_MBCS_ENCODE_METHODDEF
1163 {"mbcs_decode", mbcs_decode, METH_VARARGS}, 3112 _CODECS_CODECS_MBCS_DECODE_METHODDEF
1164 {"code_page_encode", code_page_encode, METH_VARARGS}, 3113 _CODECS_CODECS_CODE_PAGE_ENCODE_METHODDEF
1165 {"code_page_decode", code_page_decode, METH_VARARGS}, 3114 _CODECS_CODECS_CODE_PAGE_DECODE_METHODDEF
1166 #endif 3115 #endif
1167 {"register_error", register_error, METH_VARARGS, 3116 _CODECS_CODECS_REGISTER_ERROR_METHODDEF
1168 register_error__doc__}, 3117 _CODECS_CODECS_LOOKUP_ERROR_METHODDEF
1169 {"lookup_error", lookup_error, METH_VARARGS,
1170 lookup_error__doc__},
1171 {NULL, NULL} /* sentinel */ 3118 {NULL, NULL} /* sentinel */
1172 }; 3119 };
1173 3120
1174 static struct PyModuleDef codecsmodule = { 3121 static struct PyModuleDef codecsmodule = {
1175 PyModuleDef_HEAD_INIT, 3122 PyModuleDef_HEAD_INIT,
1176 "_codecs", 3123 "_codecs",
1177 NULL, 3124 NULL,
1178 -1, 3125 -1,
1179 _codecs_functions, 3126 _codecs_functions,
1180 NULL, 3127 NULL,
1181 NULL, 3128 NULL,
1182 NULL, 3129 NULL,
1183 NULL 3130 NULL
1184 }; 3131 };
1185 3132
1186 PyMODINIT_FUNC 3133 PyMODINIT_FUNC
1187 PyInit__codecs(void) 3134 PyInit__codecs(void)
1188 { 3135 {
1189 return PyModule_Create(&codecsmodule); 3136 return PyModule_Create(&codecsmodule);
1190 } 3137 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+