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

Delta Between Two Patch Sets: Modules/_codecsmodule.c

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

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