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

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 5 years, 2 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 Encodes obj using the codec registered for encoding. 97 Encodes obj using the codec registered for encoding.
98 98
99 encoding defaults to the default encoding. errors may be given to set a 99 encoding defaults to the default encoding. errors may be given to set a
100 different error handling scheme. Default is 'strict' meaning that encoding 100 different error handling scheme. Default is 'strict' meaning that encoding
101 errors raise a ValueError. Other possible values are 'ignore', 'replace' 101 errors raise a ValueError. Other possible values are 'ignore', 'replace'
102 and 'xmlcharrefreplace' as well as any other name registered with 102 and 'xmlcharrefreplace' as well as any other name registered with
103 codecs.register_error that can handle ValueErrors. 103 codecs.register_error that can handle ValueErrors.
104 [clinic start generated code]*/ 104 [clinic start generated code]*/
105 105
106 static PyObject * 106 static PyObject *
107 _codecs_encode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, co nst char *errors) 107 _codecs_encode_impl(PyModuleDef *module, PyObject *obj, const char *encoding,
108 /*[clinic end generated code: output=0662bb9f1c3506e5 input=cb1f62cf8d9e2a2c]*/ 108 const char *errors)
109 /*[clinic end generated code: output=5c073f62249c8d7c input=cb1f62cf8d9e2a2c]*/
109 { 110 {
110 if (encoding == NULL) 111 if (encoding == NULL)
111 encoding = PyUnicode_GetDefaultEncoding(); 112 encoding = PyUnicode_GetDefaultEncoding();
112 113
113 /* Encode via the codec registry */ 114 /* Encode via the codec registry */
114 return PyCodec_Encode(obj, encoding, errors); 115 return PyCodec_Encode(obj, encoding, errors);
115 } 116 }
116 117
117 /*[clinic input] 118 /*[clinic input]
118 _codecs.decode 119 _codecs.decode
119 obj: object 120 obj: object
120 encoding: str(c_default="NULL") = "utf-8" 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
121 errors: str(c_default="NULL") = "strict" 122 errors: str(c_default="NULL") = "strict"
122 123
123 Decodes obj using the codec registered for encoding. 124 Decodes obj using the codec registered for encoding.
124 125
125 encoding defaults to the default encoding. errors may be given to set a 126 encoding defaults to the default encoding. errors may be given to set a
126 different error handling scheme. Default is 'strict' meaning that encoding 127 different error handling scheme. Default is 'strict' meaning that encoding
127 errors raise a ValueError. Other possible values are 'ignore' and 'replace' 128 errors raise a ValueError. Other possible values are 'ignore' and 'replace'
128 as well as any other name registered with codecs.register_error that is able 129 as well as any other name registered with codecs.register_error that is able
129 to handle ValueErrors. 130 to handle ValueErrors.
130 [clinic start generated code]*/ 131 [clinic start generated code]*/
131 132
132 static PyObject * 133 static PyObject *
133 _codecs_decode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, co nst char *errors) 134 _codecs_decode_impl(PyModuleDef *module, PyObject *obj, const char *encoding,
134 /*[clinic end generated code: output=ba495029b811ab57 input=6e095980ea74fd98]*/ 135 const char *errors)
136 /*[clinic end generated code: output=c81cbf6189a7f878 input=9d04293156021886]*/
135 { 137 {
136 if (encoding == NULL) 138 if (encoding == NULL)
137 encoding = PyUnicode_GetDefaultEncoding(); 139 encoding = PyUnicode_GetDefaultEncoding();
138 140
139 /* Decode via the codec registry */ 141 /* Decode via the codec registry */
140 return PyCodec_Decode(obj, encoding, errors); 142 return PyCodec_Decode(obj, encoding, errors);
141 } 143 }
142 144
143 /* --- Helpers ------------------------------------------------------------ */ 145 /* --- Helpers ------------------------------------------------------------ */
144 146
(...skipping 21 matching lines...) Expand all
166 Py_ssize_t len) 168 Py_ssize_t len)
167 { 169 {
168 if (decoded == NULL) 170 if (decoded == NULL)
169 return NULL; 171 return NULL;
170 return Py_BuildValue("Nn", decoded, len); 172 return Py_BuildValue("Nn", decoded, len);
171 } 173 }
172 174
173 /* --- String codecs ------------------------------------------------------ */ 175 /* --- String codecs ------------------------------------------------------ */
174 /*[clinic input] 176 /*[clinic input]
175 _codecs.escape_decode 177 _codecs.escape_decode
176 data: Py_buffer(types='str bytes bytearray buffer') 178 data: Py_buffer(types={'str', 'buffer'})
177 errors: str(nullable=True) = NULL 179 errors: str(nullable=True) = NULL
178 / 180 /
179 [clinic start generated code]*/ 181 [clinic start generated code]*/
180 182
181 static PyObject * 183 static PyObject *
182 _codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data, const char *err ors) 184 _codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data,
183 /*[clinic end generated code: output=300a12d7135db0d6 input=40afdd7eb681507a]*/ 185 const char *errors)
186 /*[clinic end generated code: output=648fa3e78d03e658 input=f373087451274bbb]*/
184 { 187 {
185 PyObject *decoded = PyBytes_DecodeEscape(data->buf, data->len, 188 PyObject *decoded = PyBytes_DecodeEscape(data->buf, data->len,
186 errors, 0, NULL); 189 errors, 0, NULL);
187 return codec_tuple(decoded, data->len); 190 return codec_tuple(decoded, data->len);
188 } 191 }
189 192
190 /*[clinic input] 193 /*[clinic input]
191 _codecs.escape_encode 194 _codecs.escape_encode
192 data: 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!"
193 errors: str(nullable=True) = NULL 196 errors: str(nullable=True) = NULL
194 / 197 /
195 [clinic start generated code]*/ 198 [clinic start generated code]*/
196 199
197 static PyObject * 200 static PyObject *
198 _codecs_escape_encode_impl(PyModuleDef *module, PyObject *data, const char *erro rs) 201 _codecs_escape_encode_impl(PyModuleDef *module, PyObject *data,
199 /*[clinic end generated code: output=97ec47579ed9dd40 input=995ec13d87247ec7]*/ 202 const char *errors)
203 /*[clinic end generated code: output=fcd6f34fe4111c50 input=995ec13d87247ec7]*/
200 { 204 {
201 Py_ssize_t size; 205 Py_ssize_t size;
202 Py_ssize_t newsize; 206 Py_ssize_t newsize;
203 PyObject *v; 207 PyObject *v;
204 208
205 size = PyBytes_GET_SIZE(data); 209 size = PyBytes_GET_SIZE(data);
206 if (size > PY_SSIZE_T_MAX / 4) { 210 if (size > PY_SSIZE_T_MAX / 4) {
207 PyErr_SetString(PyExc_OverflowError, 211 PyErr_SetString(PyExc_OverflowError,
208 "string is too large to encode"); 212 "string is too large to encode");
209 return NULL; 213 return NULL;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 255
252 /* --- Decoder ------------------------------------------------------------ */ 256 /* --- Decoder ------------------------------------------------------------ */
253 /*[clinic input] 257 /*[clinic input]
254 _codecs.unicode_internal_decode 258 _codecs.unicode_internal_decode
255 obj: object 259 obj: object
256 errors: str(nullable=True) = NULL 260 errors: str(nullable=True) = NULL
257 / 261 /
258 [clinic start generated code]*/ 262 [clinic start generated code]*/
259 263
260 static PyObject * 264 static PyObject *
261 _codecs_unicode_internal_decode_impl(PyModuleDef *module, PyObject *obj, const c har *errors) 265 _codecs_unicode_internal_decode_impl(PyModuleDef *module, PyObject *obj,
262 /*[clinic end generated code: output=bd707b3de38091d9 input=71d1d53c6ea4f0fc]*/ 266 const char *errors)
267 /*[clinic end generated code: output=9fe47c2cd8807d92 input=71d1d53c6ea4f0fc]*/
263 { 268 {
264 if (PyUnicode_Check(obj)) { 269 if (PyUnicode_Check(obj)) {
265 if (PyUnicode_READY(obj) < 0) 270 if (PyUnicode_READY(obj) < 0)
266 return NULL; 271 return NULL;
267 Py_INCREF(obj); 272 Py_INCREF(obj);
268 return codec_tuple(obj, PyUnicode_GET_LENGTH(obj)); 273 return codec_tuple(obj, PyUnicode_GET_LENGTH(obj));
269 } 274 }
270 else { 275 else {
271 Py_buffer view; 276 Py_buffer view;
272 PyObject *result; 277 PyObject *result;
(...skipping 10 matching lines...) Expand all
283 288
284 /*[clinic input] 289 /*[clinic input]
285 _codecs.utf_7_decode 290 _codecs.utf_7_decode
286 data: Py_buffer 291 data: Py_buffer
287 errors: str(nullable=True) = NULL 292 errors: str(nullable=True) = NULL
288 final: int(c_default="0") = False 293 final: int(c_default="0") = False
289 / 294 /
290 [clinic start generated code]*/ 295 [clinic start generated code]*/
291 296
292 static PyObject * 297 static PyObject *
293 _codecs_utf_7_decode_impl(PyModuleDef *module, Py_buffer *data, const char *erro rs, int final) 298 _codecs_utf_7_decode_impl(PyModuleDef *module, Py_buffer *data,
294 /*[clinic end generated code: output=43e1112766a1e987 input=8fd0241dcc559fe8]*/ 299 const char *errors, int final)
300 /*[clinic end generated code: output=ca945e907e72e827 input=8fd0241dcc559fe8]*/
295 { 301 {
296 Py_ssize_t consumed = data->len; 302 Py_ssize_t consumed = data->len;
297 PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len, 303 PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len,
298 errors, 304 errors,
299 final ? NULL : &consumed); 305 final ? NULL : &consumed);
300 return codec_tuple(decoded, consumed); 306 return codec_tuple(decoded, consumed);
301 } 307 }
302 308
303 /*[clinic input] 309 /*[clinic input]
304 _codecs.utf_8_decode 310 _codecs.utf_8_decode
305 data: Py_buffer 311 data: Py_buffer
306 errors: str(nullable=True) = NULL 312 errors: str(nullable=True) = NULL
307 final: int(c_default="0") = False 313 final: int(c_default="0") = False
308 / 314 /
309 [clinic start generated code]*/ 315 [clinic start generated code]*/
310 316
311 static PyObject * 317 static PyObject *
312 _codecs_utf_8_decode_impl(PyModuleDef *module, Py_buffer *data, const char *erro rs, int final) 318 _codecs_utf_8_decode_impl(PyModuleDef *module, Py_buffer *data,
313 /*[clinic end generated code: output=4c66b62c7ce685a7 input=709f25fbc3cd9a3e]*/ 319 const char *errors, int final)
320 /*[clinic end generated code: output=7309f9ff4ef5c9b6 input=709f25fbc3cd9a3e]*/
314 { 321 {
315 Py_ssize_t consumed = data->len; 322 Py_ssize_t consumed = data->len;
316 PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len, 323 PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len,
317 errors, 324 errors,
318 final ? NULL : &consumed); 325 final ? NULL : &consumed);
319 return codec_tuple(decoded, consumed); 326 return codec_tuple(decoded, consumed);
320 } 327 }
321 328
322 /*[clinic input] 329 /*[clinic input]
323 _codecs.utf_16_decode 330 _codecs.utf_16_decode
324 data: Py_buffer 331 data: Py_buffer
325 errors: str(nullable=True) = NULL 332 errors: str(nullable=True) = NULL
326 final: int(c_default="0") = False 333 final: int(c_default="0") = False
327 / 334 /
328 [clinic start generated code]*/ 335 [clinic start generated code]*/
329 336
330 static PyObject * 337 static PyObject *
331 _codecs_utf_16_decode_impl(PyModuleDef *module, Py_buffer *data, const char *err ors, int final) 338 _codecs_utf_16_decode_impl(PyModuleDef *module, Py_buffer *data,
332 /*[clinic end generated code: output=cb95e943c37604ed input=81678c8535585915]*/ 339 const char *errors, int final)
340 /*[clinic end generated code: output=8d2fa0507d9bef2c input=81678c8535585915]*/
333 { 341 {
334 int byteorder = 0; 342 int byteorder = 0;
335 /* This is overwritten unless final is true. */ 343 /* This is overwritten unless final is true. */
336 Py_ssize_t consumed = data->len; 344 Py_ssize_t consumed = data->len;
337 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, 345 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len,
338 errors, &byteorder, 346 errors, &byteorder,
339 final ? NULL : &consumed); 347 final ? NULL : &consumed);
340 return codec_tuple(decoded, consumed); 348 return codec_tuple(decoded, consumed);
341 } 349 }
342 350
343 /*[clinic input] 351 /*[clinic input]
344 _codecs.utf_16_le_decode 352 _codecs.utf_16_le_decode
345 data: Py_buffer 353 data: Py_buffer
346 errors: str(nullable=True) = NULL 354 errors: str(nullable=True) = NULL
347 final: int(c_default="0") = False 355 final: int(c_default="0") = False
348 / 356 /
349 [clinic start generated code]*/ 357 [clinic start generated code]*/
350 358
351 static PyObject * 359 static PyObject *
352 _codecs_utf_16_le_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int final) 360 _codecs_utf_16_le_decode_impl(PyModuleDef *module, Py_buffer *data,
353 /*[clinic end generated code: output=b8066ebafa08b9b8 input=006e53be083b6777]*/ 361 const char *errors, int final)
362 /*[clinic end generated code: output=4fd621515ef4ce18 input=006e53be083b6777]*/
354 { 363 {
355 int byteorder = -1; 364 int byteorder = -1;
356 /* This is overwritten unless final is true. */ 365 /* This is overwritten unless final is true. */
357 Py_ssize_t consumed = data->len; 366 Py_ssize_t consumed = data->len;
358 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, 367 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len,
359 errors, &byteorder, 368 errors, &byteorder,
360 final ? NULL : &consumed); 369 final ? NULL : &consumed);
361 return codec_tuple(decoded, consumed); 370 return codec_tuple(decoded, consumed);
362 } 371 }
363 372
364 /*[clinic input] 373 /*[clinic input]
365 _codecs.utf_16_be_decode 374 _codecs.utf_16_be_decode
366 data: Py_buffer 375 data: Py_buffer
367 errors: str(nullable=True) = NULL 376 errors: str(nullable=True) = NULL
368 final: int(c_default="0") = False 377 final: int(c_default="0") = False
369 / 378 /
370 [clinic start generated code]*/ 379 [clinic start generated code]*/
371 380
372 static PyObject * 381 static PyObject *
373 _codecs_utf_16_be_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int final) 382 _codecs_utf_16_be_decode_impl(PyModuleDef *module, Py_buffer *data,
374 /*[clinic end generated code: output=f685253b80a5555b input=d9490ad0f74140f3]*/ 383 const char *errors, int final)
384 /*[clinic end generated code: output=792f4eacb3e1fa05 input=d9490ad0f74140f3]*/
375 { 385 {
376 int byteorder = 1; 386 int byteorder = 1;
377 /* This is overwritten unless final is true. */ 387 /* This is overwritten unless final is true. */
378 Py_ssize_t consumed = data->len; 388 Py_ssize_t consumed = data->len;
379 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, 389 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len,
380 errors, &byteorder, 390 errors, &byteorder,
381 final ? NULL : &consumed); 391 final ? NULL : &consumed);
382 return codec_tuple(decoded, consumed); 392 return codec_tuple(decoded, consumed);
383 } 393 }
384 394
385 /* This non-standard version also provides access to the byteorder 395 /* This non-standard version also provides access to the byteorder
386 parameter of the builtin UTF-16 codec. 396 parameter of the builtin UTF-16 codec.
387 397
388 It returns a tuple (unicode, bytesread, byteorder) with byteorder 398 It returns a tuple (unicode, bytesread, byteorder) with byteorder
389 being the value in effect at the end of data. 399 being the value in effect at the end of data.
390 400
391 */ 401 */
392 /*[clinic input] 402 /*[clinic input]
393 _codecs.utf_16_ex_decode 403 _codecs.utf_16_ex_decode
394 data: Py_buffer 404 data: Py_buffer
395 errors: str(nullable=True) = NULL 405 errors: str(nullable=True) = NULL
396 byteorder: int = 0 406 byteorder: int = 0
397 final: int(c_default="0") = False 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
398 / 408 /
399 [clinic start generated code]*/ 409 [clinic start generated code]*/
400 410
401 static PyObject * 411 static PyObject *
402 _codecs_utf_16_ex_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int byteorder, int final) 412 _codecs_utf_16_ex_decode_impl(PyModuleDef *module, Py_buffer *data,
403 /*[clinic end generated code: output=16c608e33b828a6c input=56a16c35944e4668]*/ 413 const char *errors, int byteorder, int final)
414 /*[clinic end generated code: output=f136a186dc2defa0 input=56a16c35944e4668]*/
404 { 415 {
405 /* This is overwritten unless final is true. */ 416 /* This is overwritten unless final is true. */
406 Py_ssize_t consumed = data->len; 417 Py_ssize_t consumed = data->len;
407 418
408 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, 419 PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len,
409 errors, &byteorder, 420 errors, &byteorder,
410 final ? NULL : &consumed); 421 final ? NULL : &consumed);
411 if (decoded == NULL) 422 if (decoded == NULL)
412 return NULL; 423 return NULL;
413 return Py_BuildValue("Nni", decoded, consumed, byteorder); 424 return Py_BuildValue("Nni", decoded, consumed, byteorder);
414 } 425 }
415 426
416 /*[clinic input] 427 /*[clinic input]
417 _codecs.utf_32_decode 428 _codecs.utf_32_decode
418 data: Py_buffer 429 data: Py_buffer
419 errors: str(nullable=True) = NULL 430 errors: str(nullable=True) = NULL
420 final: int(c_default="0") = False 431 final: int(c_default="0") = False
421 / 432 /
422 [clinic start generated code]*/ 433 [clinic start generated code]*/
423 434
424 static PyObject * 435 static PyObject *
425 _codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data, const char *err ors, int final) 436 _codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data,
426 /*[clinic end generated code: output=f0c809ec525c8d69 input=778f09d112c84716]*/ 437 const char *errors, int final)
438 /*[clinic end generated code: output=b7635e55857e8efb input=778f09d112c84716]*/
427 { 439 {
428 int byteorder = 0; 440 int byteorder = 0;
429 /* This is overwritten unless final is true. */ 441 /* This is overwritten unless final is true. */
430 Py_ssize_t consumed = data->len; 442 Py_ssize_t consumed = data->len;
431 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, 443 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
432 errors, &byteorder, 444 errors, &byteorder,
433 final ? NULL : &consumed); 445 final ? NULL : &consumed);
434 return codec_tuple(decoded, consumed); 446 return codec_tuple(decoded, consumed);
435 } 447 }
436 448
437 /*[clinic input] 449 /*[clinic input]
438 _codecs.utf_32_le_decode 450 _codecs.utf_32_le_decode
439 data: Py_buffer 451 data: Py_buffer
440 errors: str(nullable=True) = NULL 452 errors: str(nullable=True) = NULL
441 final: int(c_default="0") = False 453 final: int(c_default="0") = False
442 / 454 /
443 [clinic start generated code]*/ 455 [clinic start generated code]*/
444 456
445 static PyObject * 457 static PyObject *
446 _codecs_utf_32_le_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int final) 458 _codecs_utf_32_le_decode_impl(PyModuleDef *module, Py_buffer *data,
447 /*[clinic end generated code: output=405dd1513f8c8d0b input=7a398c6cadca231f]*/ 459 const char *errors, int final)
460 /*[clinic end generated code: output=a79d1787d8ddf988 input=7a398c6cadca231f]*/
448 { 461 {
449 int byteorder = -1; 462 int byteorder = -1;
450 /* This is overwritten unless final is true. */ 463 /* This is overwritten unless final is true. */
451 Py_ssize_t consumed = data->len; 464 Py_ssize_t consumed = data->len;
452 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, 465 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
453 errors, &byteorder, 466 errors, &byteorder,
454 final ? NULL : &consumed); 467 final ? NULL : &consumed);
455 return codec_tuple(decoded, consumed); 468 return codec_tuple(decoded, consumed);
456 } 469 }
457 470
458 /*[clinic input] 471 /*[clinic input]
459 _codecs.utf_32_be_decode 472 _codecs.utf_32_be_decode
460 data: Py_buffer 473 data: Py_buffer
461 errors: str(nullable=True) = NULL 474 errors: str(nullable=True) = NULL
462 final: int(c_default="0") = False 475 final: int(c_default="0") = False
463 / 476 /
464 [clinic start generated code]*/ 477 [clinic start generated code]*/
465 478
466 static PyObject * 479 static PyObject *
467 _codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int final) 480 _codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data,
468 /*[clinic end generated code: output=24febf529888e0b8 input=573fb3c3b8ac000d]*/ 481 const char *errors, int final)
482 /*[clinic end generated code: output=a8356b0f36779981 input=573fb3c3b8ac000d]*/
469 { 483 {
470 int byteorder = 1; 484 int byteorder = 1;
471 /* This is overwritten unless final is true. */ 485 /* This is overwritten unless final is true. */
472 Py_ssize_t consumed = data->len; 486 Py_ssize_t consumed = data->len;
473 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, 487 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
474 errors, &byteorder, 488 errors, &byteorder,
475 final ? NULL : &consumed); 489 final ? NULL : &consumed);
476 return codec_tuple(decoded, consumed); 490 return codec_tuple(decoded, consumed);
477 } 491 }
478 492
479 /* This non-standard version also provides access to the byteorder 493 /* This non-standard version also provides access to the byteorder
480 parameter of the builtin UTF-32 codec. 494 parameter of the builtin UTF-32 codec.
481 495
482 It returns a tuple (unicode, bytesread, byteorder) with byteorder 496 It returns a tuple (unicode, bytesread, byteorder) with byteorder
483 being the value in effect at the end of data. 497 being the value in effect at the end of data.
484 498
485 */ 499 */
486 /*[clinic input] 500 /*[clinic input]
487 _codecs.utf_32_ex_decode 501 _codecs.utf_32_ex_decode
488 data: Py_buffer 502 data: Py_buffer
489 errors: str(nullable=True) = NULL 503 errors: str(nullable=True) = NULL
490 byteorder: int = 0 504 byteorder: int = 0
491 final: int(c_default="0") = False 505 final: int(c_default="0") = False
492 / 506 /
493 [clinic start generated code]*/ 507 [clinic start generated code]*/
494 508
495 static PyObject * 509 static PyObject *
496 _codecs_utf_32_ex_decode_impl(PyModuleDef *module, Py_buffer *data, const char * errors, int byteorder, int final) 510 _codecs_utf_32_ex_decode_impl(PyModuleDef *module, Py_buffer *data,
497 /*[clinic end generated code: output=3aa867c23cbf1e72 input=56c2fd15274e69a0]*/ 511 const char *errors, int byteorder, int final)
512 /*[clinic end generated code: output=ab8c70977c1992f5 input=56c2fd15274e69a0]*/
498 { 513 {
499 Py_ssize_t consumed = data->len; 514 Py_ssize_t consumed = data->len;
500 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, 515 PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
501 errors, &byteorder, 516 errors, &byteorder,
502 final ? NULL : &consumed); 517 final ? NULL : &consumed);
503 if (decoded == NULL) 518 if (decoded == NULL)
504 return NULL; 519 return NULL;
505 return Py_BuildValue("Nni", decoded, consumed, byteorder); 520 return Py_BuildValue("Nni", decoded, consumed, byteorder);
506 } 521 }
507 522
508 /*[clinic input] 523 /*[clinic input]
509 _codecs.unicode_escape_decode 524 _codecs.unicode_escape_decode
510 data: Py_buffer(types='str bytes bytearray buffer') 525 data: Py_buffer(types={'str', 'buffer'})
511 errors: str(nullable=True) = NULL 526 errors: str(nullable=True) = NULL
512 / 527 /
513 [clinic start generated code]*/ 528 [clinic start generated code]*/
514 529
515 static PyObject * 530 static PyObject *
516 _codecs_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, const c har *errors) 531 _codecs_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data,
517 /*[clinic end generated code: output=84def09dc1178ab4 input=e6cf9b15356033bf]*/ 532 const char *errors)
533 /*[clinic end generated code: output=d1aa63f2620c4999 input=80f2ff60014d65c4]*/
518 { 534 {
519 PyObject *decoded = PyUnicode_DecodeUnicodeEscape(data->buf, data->len, 535 PyObject *decoded = PyUnicode_DecodeUnicodeEscape(data->buf, data->len,
520 errors); 536 errors);
521 return codec_tuple(decoded, data->len); 537 return codec_tuple(decoded, data->len);
522 } 538 }
523 539
524 /*[clinic input] 540 /*[clinic input]
525 _codecs.raw_unicode_escape_decode 541 _codecs.raw_unicode_escape_decode
526 data: Py_buffer(types='str bytes bytearray buffer') 542 data: Py_buffer(types={'str', 'buffer'})
527 errors: str(nullable=True) = NULL 543 errors: str(nullable=True) = NULL
528 / 544 /
529 [clinic start generated code]*/ 545 [clinic start generated code]*/
530 546
531 static PyObject * 547 static PyObject *
532 _codecs_raw_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, con st char *errors) 548 _codecs_raw_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data,
533 /*[clinic end generated code: output=ea5de256e10fad48 input=8ac951eae7f7f989]*/ 549 const char *errors)
550 /*[clinic end generated code: output=0bf96cc182d81379 input=ef77c7ab98ee2c60]*/
534 { 551 {
535 PyObject *decoded = PyUnicode_DecodeRawUnicodeEscape(data->buf, data->len, 552 PyObject *decoded = PyUnicode_DecodeRawUnicodeEscape(data->buf, data->len,
536 errors); 553 errors);
537 return codec_tuple(decoded, data->len); 554 return codec_tuple(decoded, data->len);
538 } 555 }
539 556
540 /*[clinic input] 557 /*[clinic input]
541 _codecs.latin_1_decode 558 _codecs.latin_1_decode
542 data: Py_buffer 559 data: Py_buffer
543 errors: str(nullable=True) = NULL 560 errors: str(nullable=True) = NULL
544 / 561 /
545 [clinic start generated code]*/ 562 [clinic start generated code]*/
546 563
547 static PyObject * 564 static PyObject *
548 _codecs_latin_1_decode_impl(PyModuleDef *module, Py_buffer *data, const char *er rors) 565 _codecs_latin_1_decode_impl(PyModuleDef *module, Py_buffer *data,
549 /*[clinic end generated code: output=9f460c6755979903 input=2ad8439a94444119]*/ 566 const char *errors)
567 /*[clinic end generated code: output=66b916f5055aaf13 input=2ad8439a94444119]*/
550 { 568 {
551 PyObject *decoded = PyUnicode_DecodeLatin1(data->buf, data->len, errors); 569 PyObject *decoded = PyUnicode_DecodeLatin1(data->buf, data->len, errors);
552 return codec_tuple(decoded, data->len); 570 return codec_tuple(decoded, data->len);
553 } 571 }
554 572
555 /*[clinic input] 573 /*[clinic input]
556 _codecs.ascii_decode 574 _codecs.ascii_decode
557 data: Py_buffer 575 data: Py_buffer
558 errors: str(nullable=True) = NULL 576 errors: str(nullable=True) = NULL
559 / 577 /
560 [clinic start generated code]*/ 578 [clinic start generated code]*/
561 579
562 static PyObject * 580 static PyObject *
563 _codecs_ascii_decode_impl(PyModuleDef *module, Py_buffer *data, const char *erro rs) 581 _codecs_ascii_decode_impl(PyModuleDef *module, Py_buffer *data,
564 /*[clinic end generated code: output=e57a04a8833400cc input=0bfd2dd60e3e0152]*/ 582 const char *errors)
583 /*[clinic end generated code: output=7f213a1b5cdafc65 input=0bfd2dd60e3e0152]*/
565 { 584 {
566 PyObject *decoded = PyUnicode_DecodeASCII(data->buf, data->len, errors); 585 PyObject *decoded = PyUnicode_DecodeASCII(data->buf, data->len, errors);
567 return codec_tuple(decoded, data->len); 586 return codec_tuple(decoded, data->len);
568 } 587 }
569 588
570 /*[clinic input] 589 /*[clinic input]
571 _codecs.charmap_decode 590 _codecs.charmap_decode
572 data: Py_buffer 591 data: Py_buffer
573 errors: str(nullable=True) = NULL 592 errors: str(nullable=True) = NULL
574 mapping: object = NULL 593 mapping: object = NULL
575 / 594 /
576 [clinic start generated code]*/ 595 [clinic start generated code]*/
577 596
578 static PyObject * 597 static PyObject *
579 _codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data, const char *er rors, PyObject *mapping) 598 _codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data,
580 /*[clinic end generated code: output=2a3b7be5ed83a5d8 input=bf5ab0388adeac8e]*/ 599 const char *errors, PyObject *mapping)
600 /*[clinic end generated code: output=87d27f365098bbae input=bf5ab0388adeac8e]*/
581 { 601 {
582 PyObject *decoded; 602 PyObject *decoded;
583 603
584 if (mapping == Py_None) 604 if (mapping == Py_None)
585 mapping = NULL; 605 mapping = NULL;
586 606
587 decoded = PyUnicode_DecodeCharmap(data->buf, data->len, mapping, errors); 607 decoded = PyUnicode_DecodeCharmap(data->buf, data->len, mapping, errors);
588 return codec_tuple(decoded, data->len); 608 return codec_tuple(decoded, data->len);
589 } 609 }
590 610
591 #ifdef HAVE_MBCS 611 #ifdef HAVE_MBCS
592 612
593 /*[clinic input] 613 /*[clinic input]
594 _codecs.mbcs_decode 614 _codecs.mbcs_decode
595 data: Py_buffer 615 data: Py_buffer
596 errors: str(nullable=True) = NULL 616 errors: str(nullable=True) = NULL
597 final: int(c_default="0") = False 617 final: int(c_default="0") = False
598 / 618 /
599 [clinic start generated code]*/ 619 [clinic start generated code]*/
600 620
601 static PyObject * 621 static PyObject *
602 _codecs_mbcs_decode_impl(PyModuleDef *module, Py_buffer *data, const char *error s, int final) 622 _codecs_mbcs_decode_impl(PyModuleDef *module, Py_buffer *data,
603 /*[clinic end generated code: output=aeb7d16803a466ce input=48841d508b7bacee]*/ 623 const char *errors, int final)
624 /*[clinic end generated code: output=0ebaf3a5b20e53fa input=48841d508b7bacee]*/
604 { 625 {
605 Py_ssize_t consumed = data->len; 626 Py_ssize_t consumed = data->len;
606 PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len, 627 PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len,
607 errors, final ? NULL : &consumed); 628 errors, final ? NULL : &consumed);
608 return codec_tuple(decoded, consumed); 629 return codec_tuple(decoded, consumed);
609 } 630 }
610 631
611 /*[clinic input] 632 /*[clinic input]
612 _codecs.code_page_decode 633 _codecs.code_page_decode
613 codepage: int 634 codepage: int
614 data: Py_buffer 635 data: Py_buffer
615 errors: str(nullable=True) = NULL 636 errors: str(nullable=True) = NULL
616 final: int(c_default="0") = False 637 final: int(c_default="0") = False
617 / 638 /
618 [clinic start generated code]*/ 639 [clinic start generated code]*/
619 640
620 static PyObject * 641 static PyObject *
621 _codecs_code_page_decode_impl(PyModuleDef *module, int codepage, Py_buffer *data , const char *errors, int final) 642 _codecs_code_page_decode_impl(PyModuleDef *module, int codepage,
622 /*[clinic end generated code: output=419f9cef0a3bb271 input=74f589867f3429ce]*/ 643 Py_buffer *data, const char *errors, int final)
644 /*[clinic end generated code: output=4318e3d9971e31ba input=74f589867f3429ce]*/
623 { 645 {
624 Py_ssize_t consumed = data->len; 646 Py_ssize_t consumed = data->len;
625 PyObject *decoded = PyUnicode_DecodeCodePageStateful(code_page, 647 PyObject *decoded = PyUnicode_DecodeCodePageStateful(code_page,
626 data->buf, data->len, 648 data->buf, data->len,
627 errors, 649 errors,
628 final ? NULL : &consume d); 650 final ? NULL : &consume d);
629 return codec_tuple(decoded, consumed); 651 return codec_tuple(decoded, consumed);
630 } 652 }
631 653
632 #endif /* HAVE_MBCS */ 654 #endif /* HAVE_MBCS */
633 655
634 /* --- Encoder ------------------------------------------------------------ */ 656 /* --- Encoder ------------------------------------------------------------ */
635 657
636 /*[clinic input] 658 /*[clinic input]
637 _codecs.readbuffer_encode 659 _codecs.readbuffer_encode
638 data: Py_buffer(types='str bytes bytearray buffer') 660 data: Py_buffer(types={'str', 'buffer'})
639 errors: str(nullable=True) = NULL 661 errors: str(nullable=True) = NULL
640 / 662 /
641 [clinic start generated code]*/ 663 [clinic start generated code]*/
642 664
643 static PyObject * 665 static PyObject *
644 _codecs_readbuffer_encode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) 666 _codecs_readbuffer_encode_impl(PyModuleDef *module, Py_buffer *data,
645 /*[clinic end generated code: output=add770b377370b6e input=2ab3d649599cec57]*/ 667 const char *errors)
668 /*[clinic end generated code: output=319cc24083299859 input=fc35dc93718e670d]*/
646 { 669 {
647 PyObject *result = PyBytes_FromStringAndSize(data->buf, data->len); 670 PyObject *result = PyBytes_FromStringAndSize(data->buf, data->len);
648 return codec_tuple(result, data->len); 671 return codec_tuple(result, data->len);
649 } 672 }
650 673
651 /*[clinic input] 674 /*[clinic input]
652 _codecs.unicode_internal_encode 675 _codecs.unicode_internal_encode
653 obj: object 676 obj: object
654 errors: str(nullable=True) = NULL 677 errors: str(nullable=True) = NULL
655 / 678 /
656 [clinic start generated code]*/ 679 [clinic start generated code]*/
657 680
658 static PyObject * 681 static PyObject *
659 _codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj, const c har *errors) 682 _codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj,
660 /*[clinic end generated code: output=880a7415536bff52 input=61192dad1fce371f]*/ 683 const char *errors)
684 /*[clinic end generated code: output=be08457068ad503b input=61192dad1fce371f]*/
661 { 685 {
662 if (PyErr_WarnEx(PyExc_DeprecationWarning, 686 if (PyErr_WarnEx(PyExc_DeprecationWarning,
663 "unicode_internal codec has been deprecated", 687 "unicode_internal codec has been deprecated",
664 1)) 688 1))
665 return NULL; 689 return NULL;
666 690
667 if (PyUnicode_Check(obj)) { 691 if (PyUnicode_Check(obj)) {
668 Py_UNICODE *u; 692 Py_UNICODE *u;
669 Py_ssize_t len, size; 693 Py_ssize_t len, size;
670 694
(...skipping 22 matching lines...) Expand all
693 } 717 }
694 718
695 /*[clinic input] 719 /*[clinic input]
696 _codecs.utf_7_encode 720 _codecs.utf_7_encode
697 str: object 721 str: object
698 errors: str(nullable=True) = NULL 722 errors: str(nullable=True) = NULL
699 / 723 /
700 [clinic start generated code]*/ 724 [clinic start generated code]*/
701 725
702 static PyObject * 726 static PyObject *
703 _codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str, const char *errors ) 727 _codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str,
704 /*[clinic end generated code: output=061f316ae18c1427 input=802ba3f495219bbc]*/ 728 const char *errors)
729 /*[clinic end generated code: output=a7accc496a32b759 input=802ba3f495219bbc]*/
705 { 730 {
706 PyObject *v; 731 PyObject *v;
707 732
708 str = PyUnicode_FromObject(str); 733 str = PyUnicode_FromObject(str);
709 if (str == NULL || PyUnicode_READY(str) < 0) { 734 if (str == NULL || PyUnicode_READY(str) < 0) {
710 Py_XDECREF(str); 735 Py_XDECREF(str);
711 return NULL; 736 return NULL;
712 } 737 }
713 v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), 738 v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors),
714 PyUnicode_GET_LENGTH(str)); 739 PyUnicode_GET_LENGTH(str));
715 Py_DECREF(str); 740 Py_DECREF(str);
716 return v; 741 return v;
717 } 742 }
718 743
719 /*[clinic input] 744 /*[clinic input]
720 _codecs.utf_8_encode 745 _codecs.utf_8_encode
721 str: object 746 str: object
722 errors: str(nullable=True) = NULL 747 errors: str(nullable=True) = NULL
723 / 748 /
724 [clinic start generated code]*/ 749 [clinic start generated code]*/
725 750
726 static PyObject * 751 static PyObject *
727 _codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str, const char *errors ) 752 _codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str,
728 /*[clinic end generated code: output=0842e04321f57d0f input=5c283859a2a90bf7]*/ 753 const char *errors)
754 /*[clinic end generated code: output=ec831d80e7aedede input=5c283859a2a90bf7]*/
729 { 755 {
730 PyObject *v; 756 PyObject *v;
731 757
732 str = PyUnicode_FromObject(str); 758 str = PyUnicode_FromObject(str);
733 if (str == NULL || PyUnicode_READY(str) < 0) { 759 if (str == NULL || PyUnicode_READY(str) < 0) {
734 Py_XDECREF(str); 760 Py_XDECREF(str);
735 return NULL; 761 return NULL;
736 } 762 }
737 v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors), 763 v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors),
738 PyUnicode_GET_LENGTH(str)); 764 PyUnicode_GET_LENGTH(str));
(...skipping 10 matching lines...) Expand all
749 775
750 /*[clinic input] 776 /*[clinic input]
751 _codecs.utf_16_encode 777 _codecs.utf_16_encode
752 str: object 778 str: object
753 errors: str(nullable=True) = NULL 779 errors: str(nullable=True) = NULL
754 byteorder: int = 0 780 byteorder: int = 0
755 / 781 /
756 [clinic start generated code]*/ 782 [clinic start generated code]*/
757 783
758 static PyObject * 784 static PyObject *
759 _codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str, const char *error s, int byteorder) 785 _codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str,
760 /*[clinic end generated code: output=a5bb3352c1825683 input=ed850025591019db]*/ 786 const char *errors, int byteorder)
787 /*[clinic end generated code: output=93ac58e960a9ee4d input=ed850025591019db]*/
761 { 788 {
762 PyObject *v; 789 PyObject *v;
763 790
764 str = PyUnicode_FromObject(str); 791 str = PyUnicode_FromObject(str);
765 if (str == NULL || PyUnicode_READY(str) < 0) { 792 if (str == NULL || PyUnicode_READY(str) < 0) {
766 Py_XDECREF(str); 793 Py_XDECREF(str);
767 return NULL; 794 return NULL;
768 } 795 }
769 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), 796 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder),
770 PyUnicode_GET_LENGTH(str)); 797 PyUnicode_GET_LENGTH(str));
771 Py_DECREF(str); 798 Py_DECREF(str);
772 return v; 799 return v;
773 } 800 }
774 801
775 /*[clinic input] 802 /*[clinic input]
776 _codecs.utf_16_le_encode 803 _codecs.utf_16_le_encode
777 str: object 804 str: object
778 errors: str(nullable=True) = NULL 805 errors: str(nullable=True) = NULL
779 / 806 /
780 [clinic start generated code]*/ 807 [clinic start generated code]*/
781 808
782 static PyObject * 809 static PyObject *
783 _codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str, const char *er rors) 810 _codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str,
784 /*[clinic end generated code: output=0c526b4d37936db1 input=950fcf919f117cb7]*/ 811 const char *errors)
812 /*[clinic end generated code: output=422bedb8da34fb66 input=950fcf919f117cb7]*/
785 { 813 {
786 PyObject *v; 814 PyObject *v;
787 815
788 str = PyUnicode_FromObject(str); 816 str = PyUnicode_FromObject(str);
789 if (str == NULL || PyUnicode_READY(str) < 0) { 817 if (str == NULL || PyUnicode_READY(str) < 0) {
790 Py_XDECREF(str); 818 Py_XDECREF(str);
791 return NULL; 819 return NULL;
792 } 820 }
793 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), 821 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1),
794 PyUnicode_GET_LENGTH(str)); 822 PyUnicode_GET_LENGTH(str));
795 Py_DECREF(str); 823 Py_DECREF(str);
796 return v; 824 return v;
797 } 825 }
798 826
799 /*[clinic input] 827 /*[clinic input]
800 _codecs.utf_16_be_encode 828 _codecs.utf_16_be_encode
801 str: object 829 str: object
802 errors: str(nullable=True) = NULL 830 errors: str(nullable=True) = NULL
803 / 831 /
804 [clinic start generated code]*/ 832 [clinic start generated code]*/
805 833
806 static PyObject * 834 static PyObject *
807 _codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str, const char *er rors) 835 _codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str,
808 /*[clinic end generated code: output=817e6bba3d9f99fe input=65a55a23d2a1e18d]*/ 836 const char *errors)
837 /*[clinic end generated code: output=3aa7ee9502acdd77 input=65a55a23d2a1e18d]*/
809 { 838 {
810 PyObject *v; 839 PyObject *v;
811 840
812 str = PyUnicode_FromObject(str); 841 str = PyUnicode_FromObject(str);
813 if (str == NULL || PyUnicode_READY(str) < 0) { 842 if (str == NULL || PyUnicode_READY(str) < 0) {
814 Py_XDECREF(str); 843 Py_XDECREF(str);
815 return NULL; 844 return NULL;
816 } 845 }
817 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), 846 v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1),
818 PyUnicode_GET_LENGTH(str)); 847 PyUnicode_GET_LENGTH(str));
(...skipping 10 matching lines...) Expand all
829 858
830 /*[clinic input] 859 /*[clinic input]
831 _codecs.utf_32_encode 860 _codecs.utf_32_encode
832 str: object 861 str: object
833 errors: str(nullable=True) = NULL 862 errors: str(nullable=True) = NULL
834 byteorder: int = 0 863 byteorder: int = 0
835 / 864 /
836 [clinic start generated code]*/ 865 [clinic start generated code]*/
837 866
838 static PyObject * 867 static PyObject *
839 _codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str, const char *error s, int byteorder) 868 _codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str,
840 /*[clinic end generated code: output=2ed436c6159df625 input=452ef1b8f0b8c3d5]*/ 869 const char *errors, int byteorder)
870 /*[clinic end generated code: output=3e7d5a003b02baed input=452ef1b8f0b8c3d5]*/
841 { 871 {
842 PyObject *v; 872 PyObject *v;
843 873
844 str = PyUnicode_FromObject(str); 874 str = PyUnicode_FromObject(str);
845 if (str == NULL || PyUnicode_READY(str) < 0) { 875 if (str == NULL || PyUnicode_READY(str) < 0) {
846 Py_XDECREF(str); 876 Py_XDECREF(str);
847 return NULL; 877 return NULL;
848 } 878 }
849 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), 879 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder),
850 PyUnicode_GET_LENGTH(str)); 880 PyUnicode_GET_LENGTH(str));
851 Py_DECREF(str); 881 Py_DECREF(str);
852 return v; 882 return v;
853 } 883 }
854 884
855 /*[clinic input] 885 /*[clinic input]
856 _codecs.utf_32_le_encode 886 _codecs.utf_32_le_encode
857 str: object 887 str: object
858 errors: str(nullable=True) = NULL 888 errors: str(nullable=True) = NULL
859 / 889 /
860 [clinic start generated code]*/ 890 [clinic start generated code]*/
861 891
862 static PyObject * 892 static PyObject *
863 _codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str, const char *er rors) 893 _codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str,
864 /*[clinic end generated code: output=f1de99147eb63a8b input=a8e2cc9b4dbf40d9]*/ 894 const char *errors)
895 /*[clinic end generated code: output=5dda641cd33dbfc2 input=a8e2cc9b4dbf40d9]*/
865 { 896 {
866 PyObject *v; 897 PyObject *v;
867 898
868 str = PyUnicode_FromObject(str); 899 str = PyUnicode_FromObject(str);
869 if (str == NULL || PyUnicode_READY(str) < 0) { 900 if (str == NULL || PyUnicode_READY(str) < 0) {
870 Py_XDECREF(str); 901 Py_XDECREF(str);
871 return NULL; 902 return NULL;
872 } 903 }
873 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), 904 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1),
874 PyUnicode_GET_LENGTH(str)); 905 PyUnicode_GET_LENGTH(str));
875 Py_DECREF(str); 906 Py_DECREF(str);
876 return v; 907 return v;
877 } 908 }
878 909
879 /*[clinic input] 910 /*[clinic input]
880 _codecs.utf_32_be_encode 911 _codecs.utf_32_be_encode
881 str: object 912 str: object
882 errors: str(nullable=True) = NULL 913 errors: str(nullable=True) = NULL
883 / 914 /
884 [clinic start generated code]*/ 915 [clinic start generated code]*/
885 916
886 static PyObject * 917 static PyObject *
887 _codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str, const char *er rors) 918 _codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str,
888 /*[clinic end generated code: output=a8a3276bc70f5543 input=cef51fb9de6a04b3]*/ 919 const char *errors)
920 /*[clinic end generated code: output=ccca8b44d91a7c7a input=cef51fb9de6a04b3]*/
889 { 921 {
890 PyObject *v; 922 PyObject *v;
891 923
892 str = PyUnicode_FromObject(str); 924 str = PyUnicode_FromObject(str);
893 if (str == NULL || PyUnicode_READY(str) < 0) { 925 if (str == NULL || PyUnicode_READY(str) < 0) {
894 Py_XDECREF(str); 926 Py_XDECREF(str);
895 return NULL; 927 return NULL;
896 } 928 }
897 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), 929 v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1),
898 PyUnicode_GET_LENGTH(str)); 930 PyUnicode_GET_LENGTH(str));
899 Py_DECREF(str); 931 Py_DECREF(str);
900 return v; 932 return v;
901 } 933 }
902 934
903 /*[clinic input] 935 /*[clinic input]
904 _codecs.unicode_escape_encode 936 _codecs.unicode_escape_encode
905 str: object 937 str: object
906 errors: str(nullable=True) = NULL 938 errors: str(nullable=True) = NULL
907 / 939 /
908 [clinic start generated code]*/ 940 [clinic start generated code]*/
909 941
910 static PyObject * 942 static PyObject *
911 _codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const cha r *errors) 943 _codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str,
912 /*[clinic end generated code: output=b966c98c8f66f373 input=a9b4d66329b51e5b]*/ 944 const char *errors)
945 /*[clinic end generated code: output=389f23d2b8f8d80b input=a9b4d66329b51e5b]*/
913 { 946 {
914 PyObject *v; 947 PyObject *v;
915 948
916 str = PyUnicode_FromObject(str); 949 str = PyUnicode_FromObject(str);
917 if (str == NULL || PyUnicode_READY(str) < 0) { 950 if (str == NULL || PyUnicode_READY(str) < 0) {
918 Py_XDECREF(str); 951 Py_XDECREF(str);
919 return NULL; 952 return NULL;
920 } 953 }
921 v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str), 954 v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str),
922 PyUnicode_GET_LENGTH(str)); 955 PyUnicode_GET_LENGTH(str));
923 Py_DECREF(str); 956 Py_DECREF(str);
924 return v; 957 return v;
925 } 958 }
926 959
927 /*[clinic input] 960 /*[clinic input]
928 _codecs.raw_unicode_escape_encode 961 _codecs.raw_unicode_escape_encode
929 str: object 962 str: object
930 errors: str(nullable=True) = NULL 963 errors: str(nullable=True) = NULL
931 / 964 /
932 [clinic start generated code]*/ 965 [clinic start generated code]*/
933 966
934 static PyObject * 967 static PyObject *
935 _codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) 968 _codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str,
936 /*[clinic end generated code: output=bd93a964bfc0066c input=022a856c6bbac275]*/ 969 const char *errors)
970 /*[clinic end generated code: output=fec4e39d6ec37a62 input=022a856c6bbac275]*/
937 { 971 {
938 PyObject *v; 972 PyObject *v;
939 973
940 str = PyUnicode_FromObject(str); 974 str = PyUnicode_FromObject(str);
941 if (str == NULL || PyUnicode_READY(str) < 0) { 975 if (str == NULL || PyUnicode_READY(str) < 0) {
942 Py_XDECREF(str); 976 Py_XDECREF(str);
943 return NULL; 977 return NULL;
944 } 978 }
945 v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), 979 v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str),
946 PyUnicode_GET_LENGTH(str)); 980 PyUnicode_GET_LENGTH(str));
947 Py_DECREF(str); 981 Py_DECREF(str);
948 return v; 982 return v;
949 } 983 }
950 984
951 /*[clinic input] 985 /*[clinic input]
952 _codecs.latin_1_encode 986 _codecs.latin_1_encode
953 str: object 987 str: object
954 errors: str(nullable=True) = NULL 988 errors: str(nullable=True) = NULL
955 / 989 /
956 [clinic start generated code]*/ 990 [clinic start generated code]*/
957 991
958 static PyObject * 992 static PyObject *
959 _codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str, const char *erro rs) 993 _codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str,
960 /*[clinic end generated code: output=77df1557422a9c94 input=e2ec958e195e3f30]*/ 994 const char *errors)
995 /*[clinic end generated code: output=ecf00eb8e48c889c input=e2ec958e195e3f30]*/
961 { 996 {
962 PyObject *v; 997 PyObject *v;
963 998
964 str = PyUnicode_FromObject(str); 999 str = PyUnicode_FromObject(str);
965 if (str == NULL || PyUnicode_READY(str) < 0) { 1000 if (str == NULL || PyUnicode_READY(str) < 0) {
966 Py_XDECREF(str); 1001 Py_XDECREF(str);
967 return NULL; 1002 return NULL;
968 } 1003 }
969 v = codec_tuple(_PyUnicode_AsLatin1String(str, errors), 1004 v = codec_tuple(_PyUnicode_AsLatin1String(str, errors),
970 PyUnicode_GET_LENGTH(str)); 1005 PyUnicode_GET_LENGTH(str));
971 Py_DECREF(str); 1006 Py_DECREF(str);
972 return v; 1007 return v;
973 } 1008 }
974 1009
975 /*[clinic input] 1010 /*[clinic input]
976 _codecs.ascii_encode 1011 _codecs.ascii_encode
977 str: object 1012 str: object
978 errors: str(nullable=True) = NULL 1013 errors: str(nullable=True) = NULL
979 / 1014 /
980 [clinic start generated code]*/ 1015 [clinic start generated code]*/
981 1016
982 static PyObject * 1017 static PyObject *
983 _codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str, const char *errors ) 1018 _codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str,
984 /*[clinic end generated code: output=8dde6ff249762a68 input=536afe3b176f737b]*/ 1019 const char *errors)
1020 /*[clinic end generated code: output=a9d18fc6b6b91cfb input=536afe3b176f737b]*/
985 { 1021 {
986 PyObject *v; 1022 PyObject *v;
987 1023
988 str = PyUnicode_FromObject(str); 1024 str = PyUnicode_FromObject(str);
989 if (str == NULL || PyUnicode_READY(str) < 0) { 1025 if (str == NULL || PyUnicode_READY(str) < 0) {
990 Py_XDECREF(str); 1026 Py_XDECREF(str);
991 return NULL; 1027 return NULL;
992 } 1028 }
993 v = codec_tuple(_PyUnicode_AsASCIIString(str, errors), 1029 v = codec_tuple(_PyUnicode_AsASCIIString(str, errors),
994 PyUnicode_GET_LENGTH(str)); 1030 PyUnicode_GET_LENGTH(str));
995 Py_DECREF(str); 1031 Py_DECREF(str);
996 return v; 1032 return v;
997 } 1033 }
998 1034
999 /*[clinic input] 1035 /*[clinic input]
1000 _codecs.charmap_encode 1036 _codecs.charmap_encode
1001 str: object 1037 str: object
1002 errors: str(nullable=True) = NULL 1038 errors: str(nullable=True) = NULL
1003 mapping: object = NULL 1039 mapping: object = NULL
1004 / 1040 /
1005 [clinic start generated code]*/ 1041 [clinic start generated code]*/
1006 1042
1007 static PyObject * 1043 static PyObject *
1008 _codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str, const char *erro rs, PyObject *mapping) 1044 _codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str,
1009 /*[clinic end generated code: output=5df643ee90dda64b input=6cfea1a4be31cde1]*/ 1045 const char *errors, PyObject *mapping)
1046 /*[clinic end generated code: output=14ca42b83853c643 input=6cfea1a4be31cde1]*/
1010 { 1047 {
1011 PyObject *v; 1048 PyObject *v;
1012 1049
1013 if (mapping == Py_None) 1050 if (mapping == Py_None)
1014 mapping = NULL; 1051 mapping = NULL;
1015 1052
1016 str = PyUnicode_FromObject(str); 1053 str = PyUnicode_FromObject(str);
1017 if (str == NULL || PyUnicode_READY(str) < 0) { 1054 if (str == NULL || PyUnicode_READY(str) < 0) {
1018 Py_XDECREF(str); 1055 Py_XDECREF(str);
1019 return NULL; 1056 return NULL;
(...skipping 20 matching lines...) Expand all
1040 #ifdef HAVE_MBCS 1077 #ifdef HAVE_MBCS
1041 1078
1042 /*[clinic input] 1079 /*[clinic input]
1043 _codecs.mbcs_encode 1080 _codecs.mbcs_encode
1044 str: object 1081 str: object
1045 errors: str(nullable=True) = NULL 1082 errors: str(nullable=True) = NULL
1046 / 1083 /
1047 [clinic start generated code]*/ 1084 [clinic start generated code]*/
1048 1085
1049 static PyObject * 1086 static PyObject *
1050 _codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) 1087 _codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str,
1051 /*[clinic end generated code: output=1abdbfcca74446cd input=30a1cf44d9315ec9]*/ 1088 const char *errors)
1089 /*[clinic end generated code: output=d1a013bc68798bd7 input=30a1cf44d9315ec9]*/
1052 { 1090 {
1053 PyObject *v; 1091 PyObject *v;
1054 1092
1055 str = PyUnicode_FromObject(str); 1093 str = PyUnicode_FromObject(str);
1056 if (str == NULL || PyUnicode_READY(str) < 0) { 1094 if (str == NULL || PyUnicode_READY(str) < 0) {
1057 Py_XDECREF(str); 1095 Py_XDECREF(str);
1058 return NULL; 1096 return NULL;
1059 } 1097 }
1060 v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), 1098 v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors),
1061 PyUnicode_GET_LENGTH(str)); 1099 PyUnicode_GET_LENGTH(str));
1062 Py_DECREF(str); 1100 Py_DECREF(str);
1063 return v; 1101 return v;
1064 } 1102 }
1065 1103
1066 /*[clinic input] 1104 /*[clinic input]
1067 _codecs.code_page_encode 1105 _codecs.code_page_encode
1068 code_page: int 1106 code_page: int
1069 str: object 1107 str: object
1070 errors: str(nullable=True) = NULL 1108 errors: str(nullable=True) = NULL
1071 / 1109 /
1072 [clinic start generated code]*/ 1110 [clinic start generated code]*/
1073 1111
1074 static PyObject * 1112 static PyObject *
1075 _codecs_code_page_encode_impl(PyModuleDef *module, int code_page, PyObject *str, const char *errors) 1113 _codecs_code_page_encode_impl(PyModuleDef *module, int code_page,
1076 /*[clinic end generated code: output=dda783c0f0d377cf input=b0c72790c2e2ce28]*/ 1114 PyObject *str, const char *errors)
1115 /*[clinic end generated code: output=3b406618dbfbce25 input=b0c72790c2e2ce28]*/
1077 { 1116 {
1078 PyObject *v; 1117 PyObject *v;
1079 1118
1080 str = PyUnicode_FromObject(str); 1119 str = PyUnicode_FromObject(str);
1081 if (str == NULL || PyUnicode_READY(str) < 0) { 1120 if (str == NULL || PyUnicode_READY(str) < 0) {
1082 Py_XDECREF(str); 1121 Py_XDECREF(str);
1083 return NULL; 1122 return NULL;
1084 } 1123 }
1085 v = codec_tuple(PyUnicode_EncodeCodePage(code_page, 1124 v = codec_tuple(PyUnicode_EncodeCodePage(code_page,
1086 str, 1125 str,
(...skipping 14 matching lines...) Expand all
1101 / 1140 /
1102 1141
1103 Register the specified error handler under the name errors. 1142 Register the specified error handler under the name errors.
1104 1143
1105 handler must be a callable object, that will be called with an exception 1144 handler must be a callable object, that will be called with an exception
1106 instance containing information about the location of the encoding/decoding 1145 instance containing information about the location of the encoding/decoding
1107 error and must return a (replacement, new position) tuple. 1146 error and must return a (replacement, new position) tuple.
1108 [clinic start generated code]*/ 1147 [clinic start generated code]*/
1109 1148
1110 static PyObject * 1149 static PyObject *
1111 _codecs_register_error_impl(PyModuleDef *module, const char *errors, PyObject *h andler) 1150 _codecs_register_error_impl(PyModuleDef *module, const char *errors,
1112 /*[clinic end generated code: output=ed559ea4a806f2ad input=5e6709203c2e33fe]*/ 1151 PyObject *handler)
1152 /*[clinic end generated code: output=be00d3b1849ce68a input=5e6709203c2e33fe]*/
1113 { 1153 {
1114 if (PyCodec_RegisterError(errors, handler)) 1154 if (PyCodec_RegisterError(errors, handler))
1115 return NULL; 1155 return NULL;
1116 Py_RETURN_NONE; 1156 Py_RETURN_NONE;
1117 } 1157 }
1118 1158
1119 /*[clinic input] 1159 /*[clinic input]
1120 _codecs.lookup_error 1160 _codecs.lookup_error
1121 name: str 1161 name: str
1122 / 1162 /
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 NULL, 1235 NULL,
1196 NULL, 1236 NULL,
1197 NULL 1237 NULL
1198 }; 1238 };
1199 1239
1200 PyMODINIT_FUNC 1240 PyMODINIT_FUNC
1201 PyInit__codecs(void) 1241 PyInit__codecs(void)
1202 { 1242 {
1203 return PyModule_Create(&codecsmodule); 1243 return PyModule_Create(&codecsmodule);
1204 } 1244 }
LEFTRIGHT

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