232
232
utf_7_decode(PyObject *self,
237
236
const char *errors = NULL;
239
238
Py_ssize_t consumed;
240
239
PyObject *decoded = NULL;
242
if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode",
243
&data, &size, &errors, &final))
241
if (!PyArg_ParseTuple(args, "s*|zi:utf_7_decode",
242
&pbuf, &errors, &final))
247
decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors,
248
final ? NULL : &consumed);
246
decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
247
final ? NULL : &consumed);
248
PyBuffer_Release(&pbuf);
249
249
if (decoded == NULL)
251
251
return codec_tuple(decoded, consumed);
255
255
utf_8_decode(PyObject *self,
260
259
const char *errors = NULL;
262
261
Py_ssize_t consumed;
263
262
PyObject *decoded = NULL;
265
if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
266
&data, &size, &errors, &final))
264
if (!PyArg_ParseTuple(args, "s*|zi:utf_8_decode",
265
&pbuf, &errors, &final))
269
PyErr_SetString(PyExc_ValueError, "negative argument");
274
decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
269
decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
275
270
final ? NULL : &consumed);
271
PyBuffer_Release(&pbuf);
276
272
if (decoded == NULL)
278
274
return codec_tuple(decoded, consumed);
282
278
utf_16_decode(PyObject *self,
287
282
const char *errors = NULL;
288
283
int byteorder = 0;
290
285
Py_ssize_t consumed;
291
286
PyObject *decoded;
293
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
294
&data, &size, &errors, &final))
288
if (!PyArg_ParseTuple(args, "s*|zi:utf_16_decode",
289
&pbuf, &errors, &final))
297
PyErr_SetString(PyExc_ValueError, "negative argument");
300
consumed = size; /* This is overwritten unless final is true. */
301
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
302
final ? NULL : &consumed);
291
consumed = pbuf.len; /* This is overwritten unless final is true. */
292
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
293
&byteorder, final ? NULL : &consumed);
294
PyBuffer_Release(&pbuf);
303
295
if (decoded == NULL)
305
297
return codec_tuple(decoded, consumed);
309
301
utf_16_le_decode(PyObject *self,
314
305
const char *errors = NULL;
315
306
int byteorder = -1;
317
308
Py_ssize_t consumed;
318
309
PyObject *decoded = NULL;
320
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
321
&data, &size, &errors, &final))
311
if (!PyArg_ParseTuple(args, "s*|zi:utf_16_le_decode",
312
&pbuf, &errors, &final))
325
PyErr_SetString(PyExc_ValueError, "negative argument");
328
consumed = size; /* This is overwritten unless final is true. */
329
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
315
consumed = pbuf.len; /* This is overwritten unless final is true. */
316
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
330
317
&byteorder, final ? NULL : &consumed);
318
PyBuffer_Release(&pbuf);
331
319
if (decoded == NULL)
333
321
return codec_tuple(decoded, consumed);
337
324
static PyObject *
338
325
utf_16_be_decode(PyObject *self,
343
329
const char *errors = NULL;
344
330
int byteorder = 1;
346
332
Py_ssize_t consumed;
347
333
PyObject *decoded = NULL;
349
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
350
&data, &size, &errors, &final))
335
if (!PyArg_ParseTuple(args, "s*|zi:utf_16_be_decode",
336
&pbuf, &errors, &final))
353
PyErr_SetString(PyExc_ValueError, "negative argument");
356
consumed = size; /* This is overwritten unless final is true. */
357
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
339
consumed = pbuf.len; /* This is overwritten unless final is true. */
340
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
358
341
&byteorder, final ? NULL : &consumed);
342
PyBuffer_Release(&pbuf);
359
343
if (decoded == NULL)
361
345
return codec_tuple(decoded, consumed);
373
357
utf_16_ex_decode(PyObject *self,
378
361
const char *errors = NULL;
379
362
int byteorder = 0;
380
363
PyObject *unicode, *tuple;
382
365
Py_ssize_t consumed;
384
if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
385
&data, &size, &errors, &byteorder, &final))
367
if (!PyArg_ParseTuple(args, "s*|zii:utf_16_ex_decode",
368
&pbuf, &errors, &byteorder, &final))
388
PyErr_SetString(PyExc_ValueError, "negative argument");
391
consumed = size; /* This is overwritten unless final is true. */
392
unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
393
final ? NULL : &consumed);
370
consumed = pbuf.len; /* This is overwritten unless final is true. */
371
unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
372
&byteorder, final ? NULL : &consumed);
373
PyBuffer_Release(&pbuf);
394
374
if (unicode == NULL)
396
376
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
402
382
utf_32_decode(PyObject *self,
407
386
const char *errors = NULL;
408
387
int byteorder = 0;
410
389
Py_ssize_t consumed;
411
390
PyObject *decoded;
413
if (!PyArg_ParseTuple(args, "t#|zi:utf_32_decode",
414
&data, &size, &errors, &final))
392
if (!PyArg_ParseTuple(args, "s*|zi:utf_32_decode",
393
&pbuf, &errors, &final))
417
PyErr_SetString(PyExc_ValueError, "negative argument");
420
consumed = size; /* This is overwritten unless final is true. */
421
decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder,
422
final ? NULL : &consumed);
395
consumed = pbuf.len; /* This is overwritten unless final is true. */
396
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
397
&byteorder, final ? NULL : &consumed);
398
PyBuffer_Release(&pbuf);
423
399
if (decoded == NULL)
425
401
return codec_tuple(decoded, consumed);
429
405
utf_32_le_decode(PyObject *self,
434
409
const char *errors = NULL;
435
410
int byteorder = -1;
437
412
Py_ssize_t consumed;
438
PyObject *decoded = NULL;
440
if (!PyArg_ParseTuple(args, "t#|zi:utf_32_le_decode",
441
&data, &size, &errors, &final))
415
if (!PyArg_ParseTuple(args, "s*|zi:utf_32_le_decode",
416
&pbuf, &errors, &final))
445
PyErr_SetString(PyExc_ValueError, "negative argument");
448
consumed = size; /* This is overwritten unless final is true. */
449
decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors,
450
&byteorder, final ? NULL : &consumed);
418
consumed = pbuf.len; /* This is overwritten unless final is true. */
419
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
420
&byteorder, final ? NULL : &consumed);
421
PyBuffer_Release(&pbuf);
451
422
if (decoded == NULL)
453
424
return codec_tuple(decoded, consumed);
457
427
static PyObject *
458
428
utf_32_be_decode(PyObject *self,
463
432
const char *errors = NULL;
464
433
int byteorder = 1;
466
435
Py_ssize_t consumed;
467
PyObject *decoded = NULL;
469
if (!PyArg_ParseTuple(args, "t#|zi:utf_32_be_decode",
470
&data, &size, &errors, &final))
438
if (!PyArg_ParseTuple(args, "s*|zi:utf_32_be_decode",
439
&pbuf, &errors, &final))
473
PyErr_SetString(PyExc_ValueError, "negative argument");
476
consumed = size; /* This is overwritten unless final is true. */
477
decoded = PyUnicode_DecodeUTF32Stateful(data, size, errors,
478
&byteorder, final ? NULL : &consumed);
441
consumed = pbuf.len; /* This is overwritten unless final is true. */
442
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
443
&byteorder, final ? NULL : &consumed);
444
PyBuffer_Release(&pbuf);
479
445
if (decoded == NULL)
481
447
return codec_tuple(decoded, consumed);
493
459
utf_32_ex_decode(PyObject *self,
498
463
const char *errors = NULL;
499
464
int byteorder = 0;
500
465
PyObject *unicode, *tuple;
502
467
Py_ssize_t consumed;
504
if (!PyArg_ParseTuple(args, "t#|zii:utf_32_ex_decode",
505
&data, &size, &errors, &byteorder, &final))
469
if (!PyArg_ParseTuple(args, "s*|zii:utf_32_ex_decode",
470
&pbuf, &errors, &byteorder, &final))
508
PyErr_SetString(PyExc_ValueError, "negative argument");
511
consumed = size; /* This is overwritten unless final is true. */
512
unicode = PyUnicode_DecodeUTF32Stateful(data, size, errors, &byteorder,
513
final ? NULL : &consumed);
472
consumed = pbuf.len; /* This is overwritten unless final is true. */
473
unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
474
&byteorder, final ? NULL : &consumed);
475
PyBuffer_Release(&pbuf);
514
476
if (unicode == NULL)
516
478
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
522
484
unicode_escape_decode(PyObject *self,
527
488
const char *errors = NULL;
529
if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
530
&data, &size, &errors))
491
if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
533
return codec_tuple(PyUnicode_DecodeUnicodeEscape(data, size, errors),
495
unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
496
PyBuffer_Release(&pbuf);
497
return codec_tuple(unicode, pbuf.len);
537
500
static PyObject *
538
501
raw_unicode_escape_decode(PyObject *self,
543
505
const char *errors = NULL;
545
if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
546
&data, &size, &errors))
508
if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
549
return codec_tuple(PyUnicode_DecodeRawUnicodeEscape(data, size, errors),
512
unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
513
PyBuffer_Release(&pbuf);
514
return codec_tuple(unicode, pbuf.len);
553
517
static PyObject *
554
518
latin_1_decode(PyObject *self,
559
523
const char *errors = NULL;
561
if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
562
&data, &size, &errors))
525
if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
565
return codec_tuple(PyUnicode_DecodeLatin1(data, size, errors),
529
unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
530
PyBuffer_Release(&pbuf);
531
return codec_tuple(unicode, pbuf.len);
569
534
static PyObject *
570
535
ascii_decode(PyObject *self,
575
540
const char *errors = NULL;
577
if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
578
&data, &size, &errors))
542
if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
581
return codec_tuple(PyUnicode_DecodeASCII(data, size, errors),
546
unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
547
PyBuffer_Release(&pbuf);
548
return codec_tuple(unicode, pbuf.len);
585
551
static PyObject *
586
552
charmap_decode(PyObject *self,
591
557
const char *errors = NULL;
592
558
PyObject *mapping = NULL;
594
if (!PyArg_ParseTuple(args, "t#|zO:charmap_decode",
595
&data, &size, &errors, &mapping))
560
if (!PyArg_ParseTuple(args, "s*|zO:charmap_decode",
561
&pbuf, &errors, &mapping))
597
563
if (mapping == Py_None)
600
return codec_tuple(PyUnicode_DecodeCharmap(data, size, mapping, errors),
566
unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
567
PyBuffer_Release(&pbuf);
568
return codec_tuple(unicode, pbuf.len);
604
571
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
607
574
mbcs_decode(PyObject *self,
611
Py_ssize_t size, consumed;
612
578
const char *errors = NULL;
616
if (!PyArg_ParseTuple(args, "t#|zi:mbcs_decode",
617
&data, &size, &errors, &final))
620
decoded = PyUnicode_DecodeMBCSStateful(
621
data, size, errors, final ? NULL : &consumed);
624
return codec_tuple(decoded, final ? size : consumed);
581
PyObject *decoded = NULL;
583
if (!PyArg_ParseTuple(args, "s*|zi:mbcs_decode",
584
&pbuf, &errors, &final))
588
decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
589
final ? NULL : &consumed);
590
PyBuffer_Release(&pbuf);
593
return codec_tuple(decoded, consumed);
627
596
#endif /* MS_WINDOWS */