Changeset 391 for python/trunk/Modules/_codecsmodule.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/_codecsmodule.c
r2 r391 16 16 17 17 <encoding>_encode(Unicode_object[,errors='strict']) -> 18 18 (string object, bytes consumed) 19 19 20 20 <encoding>_decode(char_buffer_obj[,errors='strict']) -> … … 97 97 #ifdef Py_USING_UNICODE 98 98 if (encoding == NULL) 99 99 encoding = PyUnicode_GetDefaultEncoding(); 100 100 #else 101 101 if (encoding == NULL) { 102 103 102 PyErr_SetString(PyExc_ValueError, "no encoding specified"); 103 return NULL; 104 104 } 105 105 #endif … … 131 131 #ifdef Py_USING_UNICODE 132 132 if (encoding == NULL) 133 133 encoding = PyUnicode_GetDefaultEncoding(); 134 134 #else 135 135 if (encoding == NULL) { 136 137 136 PyErr_SetString(PyExc_ValueError, "no encoding specified"); 137 return NULL; 138 138 } 139 139 #endif … … 147 147 static 148 148 PyObject *codec_tuple(PyObject *unicode, 149 149 Py_ssize_t len) 150 150 { 151 151 PyObject *v; … … 160 160 static PyObject * 161 161 escape_decode(PyObject *self, 162 162 PyObject *args) 163 163 { 164 164 const char *errors = NULL; … … 167 167 168 168 if (!PyArg_ParseTuple(args, "s#|z:escape_decode", 169 170 169 &data, &size, &errors)) 170 return NULL; 171 171 return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL), 172 172 size); 173 173 } 174 174 175 175 static PyObject * 176 176 escape_encode(PyObject *self, 177 PyObject *args) 178 { 179 PyObject *str; 180 const char *errors = NULL; 181 char *buf; 182 Py_ssize_t len; 183 184 if (!PyArg_ParseTuple(args, "O!|z:escape_encode", 185 &PyString_Type, &str, &errors)) 186 return NULL; 187 188 str = PyString_Repr(str, 0); 189 if (!str) 190 return NULL; 191 192 /* The string will be quoted. Unquote, similar to unicode-escape. */ 193 buf = PyString_AS_STRING (str); 194 len = PyString_GET_SIZE (str); 195 memmove(buf, buf+1, len-2); 196 if (_PyString_Resize(&str, len-2) < 0) 197 return NULL; 198 199 return codec_tuple(str, PyString_Size(str)); 177 PyObject *args) 178 { 179 PyObject *str; 180 const char *errors = NULL; 181 char *buf; 182 Py_ssize_t consumed, len; 183 184 if (!PyArg_ParseTuple(args, "S|z:escape_encode", 185 &str, &errors)) 186 return NULL; 187 188 consumed = PyString_GET_SIZE(str); 189 str = PyString_Repr(str, 0); 190 if (!str) 191 return NULL; 192 193 /* The string will be quoted. Unquote, similar to unicode-escape. */ 194 buf = PyString_AS_STRING (str); 195 len = PyString_GET_SIZE (str); 196 memmove(buf, buf+1, len-2); 197 if (_PyString_Resize(&str, len-2) < 0) 198 return NULL; 199 200 return codec_tuple(str, consumed); 200 201 } 201 202 … … 205 206 static PyObject * 206 207 unicode_internal_decode(PyObject *self, 207 208 PyObject *args) 208 209 { 209 210 PyObject *obj; … … 213 214 214 215 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", 215 216 216 &obj, &errors)) 217 return NULL; 217 218 218 219 if (PyUnicode_Check(obj)) { 219 220 220 Py_INCREF(obj); 221 return codec_tuple(obj, PyUnicode_GET_SIZE(obj)); 221 222 } 222 223 else { 223 224 225 226 227 224 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) 225 return NULL; 226 227 return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors), 228 size); 228 229 } 229 230 } … … 233 234 PyObject *args) 234 235 { 235 236 Py_buffer pbuf; 236 237 const char *errors = NULL; 237 238 int final = 0; … … 240 241 241 242 if (!PyArg_ParseTuple(args, "s*|zi:utf_7_decode", 242 243 243 &pbuf, &errors, &final)) 244 return NULL; 244 245 consumed = pbuf.len; 245 246 246 247 decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors, 247 248 248 final ? NULL : &consumed); 249 PyBuffer_Release(&pbuf); 249 250 if (decoded == NULL) 250 251 return NULL; … … 254 255 static PyObject * 255 256 utf_8_decode(PyObject *self, 256 257 { 258 257 PyObject *args) 258 { 259 Py_buffer pbuf; 259 260 const char *errors = NULL; 260 261 int final = 0; … … 263 264 264 265 if (!PyArg_ParseTuple(args, "s*|zi:utf_8_decode", 265 266 266 &pbuf, &errors, &final)) 267 return NULL; 267 268 consumed = pbuf.len; 268 269 269 270 decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors, 270 271 271 final ? NULL : &consumed); 272 PyBuffer_Release(&pbuf); 272 273 if (decoded == NULL) 273 274 return NULL; 274 275 return codec_tuple(decoded, consumed); 275 276 } … … 277 278 static PyObject * 278 279 utf_16_decode(PyObject *self, 279 280 { 281 280 PyObject *args) 281 { 282 Py_buffer pbuf; 282 283 const char *errors = NULL; 283 284 int byteorder = 0; … … 287 288 288 289 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_decode", 289 290 290 &pbuf, &errors, &final)) 291 return NULL; 291 292 consumed = pbuf.len; /* This is overwritten unless final is true. */ 292 293 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, 293 294 294 &byteorder, final ? NULL : &consumed); 295 PyBuffer_Release(&pbuf); 295 296 if (decoded == NULL) 296 297 return NULL; 297 298 return codec_tuple(decoded, consumed); 298 299 } … … 300 301 static PyObject * 301 302 utf_16_le_decode(PyObject *self, 302 303 { 304 303 PyObject *args) 304 { 305 Py_buffer pbuf; 305 306 const char *errors = NULL; 306 307 int byteorder = -1; … … 310 311 311 312 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_le_decode", 312 313 313 &pbuf, &errors, &final)) 314 return NULL; 314 315 315 316 consumed = pbuf.len; /* This is overwritten unless final is true. */ 316 317 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, 317 318 318 &byteorder, final ? NULL : &consumed); 319 PyBuffer_Release(&pbuf); 319 320 if (decoded == NULL) 320 321 return NULL; 321 322 return codec_tuple(decoded, consumed); 322 323 } … … 324 325 static PyObject * 325 326 utf_16_be_decode(PyObject *self, 326 327 { 328 327 PyObject *args) 328 { 329 Py_buffer pbuf; 329 330 const char *errors = NULL; 330 331 int byteorder = 1; … … 334 335 335 336 if (!PyArg_ParseTuple(args, "s*|zi:utf_16_be_decode", 336 337 337 &pbuf, &errors, &final)) 338 return NULL; 338 339 339 340 consumed = pbuf.len; /* This is overwritten unless final is true. */ 340 341 decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, 341 342 342 &byteorder, final ? NULL : &consumed); 343 PyBuffer_Release(&pbuf); 343 344 if (decoded == NULL) 344 345 return NULL; 345 346 return codec_tuple(decoded, consumed); 346 347 } … … 356 357 static PyObject * 357 358 utf_16_ex_decode(PyObject *self, 358 359 { 360 359 PyObject *args) 360 { 361 Py_buffer pbuf; 361 362 const char *errors = NULL; 362 363 int byteorder = 0; … … 366 367 367 368 if (!PyArg_ParseTuple(args, "s*|zii:utf_16_ex_decode", 368 369 369 &pbuf, &errors, &byteorder, &final)) 370 return NULL; 370 371 consumed = pbuf.len; /* This is overwritten unless final is true. */ 371 372 unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, 372 373 373 &byteorder, final ? NULL : &consumed); 374 PyBuffer_Release(&pbuf); 374 375 if (unicode == NULL) 375 376 return NULL; 376 377 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); 377 378 Py_DECREF(unicode); … … 381 382 static PyObject * 382 383 utf_32_decode(PyObject *self, 383 384 { 385 384 PyObject *args) 385 { 386 Py_buffer pbuf; 386 387 const char *errors = NULL; 387 388 int byteorder = 0; … … 391 392 392 393 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_decode", 393 394 394 &pbuf, &errors, &final)) 395 return NULL; 395 396 consumed = pbuf.len; /* This is overwritten unless final is true. */ 396 397 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, 397 398 398 &byteorder, final ? NULL : &consumed); 399 PyBuffer_Release(&pbuf); 399 400 if (decoded == NULL) 400 401 return NULL; 401 402 return codec_tuple(decoded, consumed); 402 403 } … … 404 405 static PyObject * 405 406 utf_32_le_decode(PyObject *self, 406 407 { 408 407 PyObject *args) 408 { 409 Py_buffer pbuf; 409 410 const char *errors = NULL; 410 411 int byteorder = -1; … … 414 415 415 416 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_le_decode", 416 417 417 &pbuf, &errors, &final)) 418 return NULL; 418 419 consumed = pbuf.len; /* This is overwritten unless final is true. */ 419 420 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, 420 421 421 &byteorder, final ? NULL : &consumed); 422 PyBuffer_Release(&pbuf); 422 423 if (decoded == NULL) 423 424 return NULL; 424 425 return codec_tuple(decoded, consumed); 425 426 } … … 427 428 static PyObject * 428 429 utf_32_be_decode(PyObject *self, 429 430 { 431 430 PyObject *args) 431 { 432 Py_buffer pbuf; 432 433 const char *errors = NULL; 433 434 int byteorder = 1; … … 437 438 438 439 if (!PyArg_ParseTuple(args, "s*|zi:utf_32_be_decode", 439 440 440 &pbuf, &errors, &final)) 441 return NULL; 441 442 consumed = pbuf.len; /* This is overwritten unless final is true. */ 442 443 decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, 443 444 444 &byteorder, final ? NULL : &consumed); 445 PyBuffer_Release(&pbuf); 445 446 if (decoded == NULL) 446 447 return NULL; 447 448 return codec_tuple(decoded, consumed); 448 449 } … … 458 459 static PyObject * 459 460 utf_32_ex_decode(PyObject *self, 460 461 { 462 461 PyObject *args) 462 { 463 Py_buffer pbuf; 463 464 const char *errors = NULL; 464 465 int byteorder = 0; … … 468 469 469 470 if (!PyArg_ParseTuple(args, "s*|zii:utf_32_ex_decode", 470 471 471 &pbuf, &errors, &byteorder, &final)) 472 return NULL; 472 473 consumed = pbuf.len; /* This is overwritten unless final is true. */ 473 474 unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, 474 475 475 &byteorder, final ? NULL : &consumed); 476 PyBuffer_Release(&pbuf); 476 477 if (unicode == NULL) 477 478 return NULL; 478 479 tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); 479 480 Py_DECREF(unicode); … … 483 484 static PyObject * 484 485 unicode_escape_decode(PyObject *self, 485 486 { 487 488 const char *errors = NULL; 489 486 PyObject *args) 487 { 488 Py_buffer pbuf; 489 const char *errors = NULL; 490 PyObject *unicode; 490 491 491 492 if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode", 492 493 494 495 496 497 493 &pbuf, &errors)) 494 return NULL; 495 496 unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors); 497 PyBuffer_Release(&pbuf); 498 return codec_tuple(unicode, pbuf.len); 498 499 } 499 500 500 501 static PyObject * 501 502 raw_unicode_escape_decode(PyObject *self, 502 503 { 504 505 const char *errors = NULL; 506 503 PyObject *args) 504 { 505 Py_buffer pbuf; 506 const char *errors = NULL; 507 PyObject *unicode; 507 508 508 509 if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode", 509 510 511 512 513 514 510 &pbuf, &errors)) 511 return NULL; 512 513 unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors); 514 PyBuffer_Release(&pbuf); 515 return codec_tuple(unicode, pbuf.len); 515 516 } 516 517 517 518 static PyObject * 518 519 latin_1_decode(PyObject *self, 519 520 { 521 522 520 PyObject *args) 521 { 522 Py_buffer pbuf; 523 PyObject *unicode; 523 524 const char *errors = NULL; 524 525 525 526 if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode", 526 527 528 529 530 531 527 &pbuf, &errors)) 528 return NULL; 529 530 unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors); 531 PyBuffer_Release(&pbuf); 532 return codec_tuple(unicode, pbuf.len); 532 533 } 533 534 534 535 static PyObject * 535 536 ascii_decode(PyObject *self, 536 537 { 538 539 537 PyObject *args) 538 { 539 Py_buffer pbuf; 540 PyObject *unicode; 540 541 const char *errors = NULL; 541 542 542 543 if (!PyArg_ParseTuple(args, "s*|z:ascii_decode", 543 544 545 546 547 548 544 &pbuf, &errors)) 545 return NULL; 546 547 unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors); 548 PyBuffer_Release(&pbuf); 549 return codec_tuple(unicode, pbuf.len); 549 550 } 550 551 551 552 static PyObject * 552 553 charmap_decode(PyObject *self, 553 554 { 555 556 554 PyObject *args) 555 { 556 Py_buffer pbuf; 557 PyObject *unicode; 557 558 const char *errors = NULL; 558 559 PyObject *mapping = NULL; 559 560 560 561 if (!PyArg_ParseTuple(args, "s*|zO:charmap_decode", 561 562 562 &pbuf, &errors, &mapping)) 563 return NULL; 563 564 if (mapping == Py_None) 564 565 566 567 568 565 mapping = NULL; 566 567 unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors); 568 PyBuffer_Release(&pbuf); 569 return codec_tuple(unicode, pbuf.len); 569 570 } 570 571 … … 573 574 static PyObject * 574 575 mbcs_decode(PyObject *self, 575 576 { 577 576 PyObject *args) 577 { 578 Py_buffer pbuf; 578 579 const char *errors = NULL; 579 580 int final = 0; … … 582 583 583 584 if (!PyArg_ParseTuple(args, "s*|zi:mbcs_decode", 584 585 585 &pbuf, &errors, &final)) 586 return NULL; 586 587 consumed = pbuf.len; 587 588 588 589 decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors, 589 590 590 final ? NULL : &consumed); 591 PyBuffer_Release(&pbuf); 591 592 if (decoded == NULL) 592 593 return NULL; 593 594 return codec_tuple(decoded, consumed); 594 595 } … … 600 601 static PyObject * 601 602 readbuffer_encode(PyObject *self, 602 603 PyObject *args) 603 604 { 604 605 const char *data; … … 607 608 608 609 if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode", 609 610 610 &data, &size, &errors)) 611 return NULL; 611 612 612 613 return codec_tuple(PyString_FromStringAndSize(data, size), 613 614 size); 614 615 } 615 616 616 617 static PyObject * 617 618 charbuffer_encode(PyObject *self, 618 619 PyObject *args) 619 620 { 620 621 const char *data; … … 623 624 624 625 if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode", 625 626 626 &data, &size, &errors)) 627 return NULL; 627 628 628 629 return codec_tuple(PyString_FromStringAndSize(data, size), 629 630 size); 630 631 } 631 632 632 633 static PyObject * 633 634 unicode_internal_encode(PyObject *self, 634 635 PyObject *args) 635 636 { 636 637 PyObject *obj; … … 640 641 641 642 if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode", 642 643 643 &obj, &errors)) 644 return NULL; 644 645 645 646 if (PyUnicode_Check(obj)) { 646 647 648 649 size);647 data = PyUnicode_AS_DATA(obj); 648 size = PyUnicode_GET_DATA_SIZE(obj); 649 return codec_tuple(PyString_FromStringAndSize(data, size), 650 PyUnicode_GET_SIZE(obj)); 650 651 } 651 652 else { 652 653 654 655 653 if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) 654 return NULL; 655 return codec_tuple(PyString_FromStringAndSize(data, size), 656 size); 656 657 } 657 658 } … … 659 660 static PyObject * 660 661 utf_7_encode(PyObject *self, 661 662 PyObject *args) 662 663 { 663 664 PyObject *str, *v; … … 665 666 666 667 if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", 667 668 669 670 str = PyUnicode_FromObject(str); 671 if (str == NULL) 672 668 &str, &errors)) 669 return NULL; 670 671 str = PyUnicode_FromObject(str); 672 if (str == NULL) 673 return NULL; 673 674 v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str), 674 675 676 677 678 675 PyUnicode_GET_SIZE(str), 676 0, 677 0, 678 errors), 679 PyUnicode_GET_SIZE(str)); 679 680 Py_DECREF(str); 680 681 return v; … … 683 684 static PyObject * 684 685 utf_8_encode(PyObject *self, 685 686 PyObject *args) 686 687 { 687 688 PyObject *str, *v; … … 689 690 690 691 if (!PyArg_ParseTuple(args, "O|z:utf_8_encode", 691 692 693 694 str = PyUnicode_FromObject(str); 695 if (str == NULL) 696 692 &str, &errors)) 693 return NULL; 694 695 str = PyUnicode_FromObject(str); 696 if (str == NULL) 697 return NULL; 697 698 v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str), 698 699 700 699 PyUnicode_GET_SIZE(str), 700 errors), 701 PyUnicode_GET_SIZE(str)); 701 702 Py_DECREF(str); 702 703 return v; … … 712 713 static PyObject * 713 714 utf_16_encode(PyObject *self, 714 715 PyObject *args) 715 716 { 716 717 PyObject *str, *v; … … 719 720 720 721 if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", 721 722 723 724 str = PyUnicode_FromObject(str); 725 if (str == NULL) 726 722 &str, &errors, &byteorder)) 723 return NULL; 724 725 str = PyUnicode_FromObject(str); 726 if (str == NULL) 727 return NULL; 727 728 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), 728 729 730 731 729 PyUnicode_GET_SIZE(str), 730 errors, 731 byteorder), 732 PyUnicode_GET_SIZE(str)); 732 733 Py_DECREF(str); 733 734 return v; … … 736 737 static PyObject * 737 738 utf_16_le_encode(PyObject *self, 738 739 PyObject *args) 739 740 { 740 741 PyObject *str, *v; … … 742 743 743 744 if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", 744 745 746 747 str = PyUnicode_FromObject(str); 748 if (str == NULL) 749 745 &str, &errors)) 746 return NULL; 747 748 str = PyUnicode_FromObject(str); 749 if (str == NULL) 750 return NULL; 750 751 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), 751 752 753 754 752 PyUnicode_GET_SIZE(str), 753 errors, 754 -1), 755 PyUnicode_GET_SIZE(str)); 755 756 Py_DECREF(str); 756 757 return v; … … 759 760 static PyObject * 760 761 utf_16_be_encode(PyObject *self, 761 762 PyObject *args) 762 763 { 763 764 PyObject *str, *v; … … 765 766 766 767 if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", 767 768 769 770 str = PyUnicode_FromObject(str); 771 if (str == NULL) 772 768 &str, &errors)) 769 return NULL; 770 771 str = PyUnicode_FromObject(str); 772 if (str == NULL) 773 return NULL; 773 774 v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str), 774 775 776 777 775 PyUnicode_GET_SIZE(str), 776 errors, 777 +1), 778 PyUnicode_GET_SIZE(str)); 778 779 Py_DECREF(str); 779 780 return v; … … 789 790 static PyObject * 790 791 utf_32_encode(PyObject *self, 791 792 PyObject *args) 792 793 { 793 794 PyObject *str, *v; … … 796 797 797 798 if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", 798 799 800 801 str = PyUnicode_FromObject(str); 802 if (str == NULL) 803 799 &str, &errors, &byteorder)) 800 return NULL; 801 802 str = PyUnicode_FromObject(str); 803 if (str == NULL) 804 return NULL; 804 805 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), 805 806 807 808 806 PyUnicode_GET_SIZE(str), 807 errors, 808 byteorder), 809 PyUnicode_GET_SIZE(str)); 809 810 Py_DECREF(str); 810 811 return v; … … 813 814 static PyObject * 814 815 utf_32_le_encode(PyObject *self, 815 816 PyObject *args) 816 817 { 817 818 PyObject *str, *v; … … 819 820 820 821 if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", 821 822 823 824 str = PyUnicode_FromObject(str); 825 if (str == NULL) 826 822 &str, &errors)) 823 return NULL; 824 825 str = PyUnicode_FromObject(str); 826 if (str == NULL) 827 return NULL; 827 828 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), 828 829 830 831 829 PyUnicode_GET_SIZE(str), 830 errors, 831 -1), 832 PyUnicode_GET_SIZE(str)); 832 833 Py_DECREF(str); 833 834 return v; … … 836 837 static PyObject * 837 838 utf_32_be_encode(PyObject *self, 838 839 PyObject *args) 839 840 { 840 841 PyObject *str, *v; … … 842 843 843 844 if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", 844 845 846 847 str = PyUnicode_FromObject(str); 848 if (str == NULL) 849 845 &str, &errors)) 846 return NULL; 847 848 str = PyUnicode_FromObject(str); 849 if (str == NULL) 850 return NULL; 850 851 v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str), 851 852 853 854 852 PyUnicode_GET_SIZE(str), 853 errors, 854 +1), 855 PyUnicode_GET_SIZE(str)); 855 856 Py_DECREF(str); 856 857 return v; … … 859 860 static PyObject * 860 861 unicode_escape_encode(PyObject *self, 861 862 PyObject *args) 862 863 { 863 864 PyObject *str, *v; … … 865 866 866 867 if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", 867 868 869 870 str = PyUnicode_FromObject(str); 871 if (str == NULL) 872 868 &str, &errors)) 869 return NULL; 870 871 str = PyUnicode_FromObject(str); 872 if (str == NULL) 873 return NULL; 873 874 v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str), 874 875 875 PyUnicode_GET_SIZE(str)), 876 PyUnicode_GET_SIZE(str)); 876 877 Py_DECREF(str); 877 878 return v; … … 880 881 static PyObject * 881 882 raw_unicode_escape_encode(PyObject *self, 882 883 PyObject *args) 883 884 { 884 885 PyObject *str, *v; … … 886 887 887 888 if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", 888 889 890 891 str = PyUnicode_FromObject(str); 892 if (str == NULL) 893 889 &str, &errors)) 890 return NULL; 891 892 str = PyUnicode_FromObject(str); 893 if (str == NULL) 894 return NULL; 894 895 v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape( 895 896 897 896 PyUnicode_AS_UNICODE(str), 897 PyUnicode_GET_SIZE(str)), 898 PyUnicode_GET_SIZE(str)); 898 899 Py_DECREF(str); 899 900 return v; … … 902 903 static PyObject * 903 904 latin_1_encode(PyObject *self, 904 905 PyObject *args) 905 906 { 906 907 PyObject *str, *v; … … 908 909 909 910 if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", 910 911 912 913 str = PyUnicode_FromObject(str); 914 if (str == NULL) 915 911 &str, &errors)) 912 return NULL; 913 914 str = PyUnicode_FromObject(str); 915 if (str == NULL) 916 return NULL; 916 917 v = codec_tuple(PyUnicode_EncodeLatin1( 917 918 919 920 918 PyUnicode_AS_UNICODE(str), 919 PyUnicode_GET_SIZE(str), 920 errors), 921 PyUnicode_GET_SIZE(str)); 921 922 Py_DECREF(str); 922 923 return v; … … 925 926 static PyObject * 926 927 ascii_encode(PyObject *self, 927 928 PyObject *args) 928 929 { 929 930 PyObject *str, *v; … … 931 932 932 933 if (!PyArg_ParseTuple(args, "O|z:ascii_encode", 933 934 935 936 str = PyUnicode_FromObject(str); 937 if (str == NULL) 938 934 &str, &errors)) 935 return NULL; 936 937 str = PyUnicode_FromObject(str); 938 if (str == NULL) 939 return NULL; 939 940 v = codec_tuple(PyUnicode_EncodeASCII( 940 941 942 943 941 PyUnicode_AS_UNICODE(str), 942 PyUnicode_GET_SIZE(str), 943 errors), 944 PyUnicode_GET_SIZE(str)); 944 945 Py_DECREF(str); 945 946 return v; … … 948 949 static PyObject * 949 950 charmap_encode(PyObject *self, 950 951 PyObject *args) 951 952 { 952 953 PyObject *str, *v; … … 955 956 956 957 if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", 957 958 958 &str, &errors, &mapping)) 959 return NULL; 959 960 if (mapping == Py_None) 960 961 962 str = PyUnicode_FromObject(str); 963 if (str == NULL) 964 961 mapping = NULL; 962 963 str = PyUnicode_FromObject(str); 964 if (str == NULL) 965 return NULL; 965 966 v = codec_tuple(PyUnicode_EncodeCharmap( 966 967 968 969 970 967 PyUnicode_AS_UNICODE(str), 968 PyUnicode_GET_SIZE(str), 969 mapping, 970 errors), 971 PyUnicode_GET_SIZE(str)); 971 972 Py_DECREF(str); 972 973 return v; … … 986 987 static PyObject * 987 988 mbcs_encode(PyObject *self, 988 989 PyObject *args) 989 990 { 990 991 PyObject *str, *v; … … 992 993 993 994 if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", 994 995 996 997 str = PyUnicode_FromObject(str); 998 if (str == NULL) 999 995 &str, &errors)) 996 return NULL; 997 998 str = PyUnicode_FromObject(str); 999 if (str == NULL) 1000 return NULL; 1000 1001 v = codec_tuple(PyUnicode_EncodeMBCS( 1001 1002 1003 1004 1002 PyUnicode_AS_UNICODE(str), 1003 PyUnicode_GET_SIZE(str), 1004 errors), 1005 PyUnicode_GET_SIZE(str)); 1005 1006 Py_DECREF(str); 1006 1007 return v; … … 1027 1028 1028 1029 if (!PyArg_ParseTuple(args, "sO:register_error", 1029 1030 1030 &name, &handler)) 1031 return NULL; 1031 1032 if (PyCodec_RegisterError(name, handler)) 1032 1033 return NULL; … … 1045 1046 1046 1047 if (!PyArg_ParseTuple(args, "s:lookup_error", 1047 1048 1048 &name)) 1049 return NULL; 1049 1050 return PyCodec_LookupError(name); 1050 1051 } … … 1053 1054 1054 1055 static PyMethodDef _codecs_functions[] = { 1055 {"register", codec_register,METH_O,1056 {"register", codec_register, METH_O, 1056 1057 register__doc__}, 1057 {"lookup", codec_lookup,METH_VARARGS,1058 {"lookup", codec_lookup, METH_VARARGS, 1058 1059 lookup__doc__}, 1059 {"encode", codec_encode,METH_VARARGS,1060 1061 {"decode", codec_decode,METH_VARARGS,1062 1063 {"escape_encode", escape_encode,METH_VARARGS},1064 {"escape_decode", escape_decode,METH_VARARGS},1060 {"encode", codec_encode, METH_VARARGS, 1061 encode__doc__}, 1062 {"decode", codec_decode, METH_VARARGS, 1063 decode__doc__}, 1064 {"escape_encode", escape_encode, METH_VARARGS}, 1065 {"escape_decode", escape_decode, METH_VARARGS}, 1065 1066 #ifdef Py_USING_UNICODE 1066 {"utf_8_encode", utf_8_encode,METH_VARARGS},1067 {"utf_8_decode", utf_8_decode,METH_VARARGS},1068 {"utf_7_encode", utf_7_encode,METH_VARARGS},1069 {"utf_7_decode", utf_7_decode,METH_VARARGS},1070 {"utf_16_encode", utf_16_encode,METH_VARARGS},1071 {"utf_16_le_encode", utf_16_le_encode,METH_VARARGS},1072 {"utf_16_be_encode", utf_16_be_encode,METH_VARARGS},1073 {"utf_16_decode", utf_16_decode,METH_VARARGS},1074 {"utf_16_le_decode", utf_16_le_decode,METH_VARARGS},1075 {"utf_16_be_decode", utf_16_be_decode,METH_VARARGS},1076 {"utf_16_ex_decode", utf_16_ex_decode,METH_VARARGS},1077 {"utf_32_encode", utf_32_encode,METH_VARARGS},1078 {"utf_32_le_encode", utf_32_le_encode,METH_VARARGS},1079 {"utf_32_be_encode", utf_32_be_encode,METH_VARARGS},1080 {"utf_32_decode", utf_32_decode,METH_VARARGS},1081 {"utf_32_le_decode", utf_32_le_decode,METH_VARARGS},1082 {"utf_32_be_decode", utf_32_be_decode,METH_VARARGS},1083 {"utf_32_ex_decode", utf_32_ex_decode,METH_VARARGS},1084 {"unicode_escape_encode", unicode_escape_encode,METH_VARARGS},1085 {"unicode_escape_decode", unicode_escape_decode,METH_VARARGS},1086 {"unicode_internal_encode", unicode_internal_encode,METH_VARARGS},1087 {"unicode_internal_decode", unicode_internal_decode,METH_VARARGS},1088 {"raw_unicode_escape_encode", raw_unicode_escape_encode, 1089 {"raw_unicode_escape_decode", raw_unicode_escape_decode, 1090 {"latin_1_encode", latin_1_encode,METH_VARARGS},1091 {"latin_1_decode", latin_1_decode,METH_VARARGS},1092 {"ascii_encode", ascii_encode,METH_VARARGS},1093 {"ascii_decode", ascii_decode,METH_VARARGS},1094 {"charmap_encode", charmap_encode,METH_VARARGS},1095 {"charmap_decode", charmap_decode,METH_VARARGS},1096 {"charmap_build", charmap_build,METH_VARARGS},1097 {"readbuffer_encode", readbuffer_encode,METH_VARARGS},1098 {"charbuffer_encode", charbuffer_encode,METH_VARARGS},1067 {"utf_8_encode", utf_8_encode, METH_VARARGS}, 1068 {"utf_8_decode", utf_8_decode, METH_VARARGS}, 1069 {"utf_7_encode", utf_7_encode, METH_VARARGS}, 1070 {"utf_7_decode", utf_7_decode, METH_VARARGS}, 1071 {"utf_16_encode", utf_16_encode, METH_VARARGS}, 1072 {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS}, 1073 {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS}, 1074 {"utf_16_decode", utf_16_decode, METH_VARARGS}, 1075 {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS}, 1076 {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS}, 1077 {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS}, 1078 {"utf_32_encode", utf_32_encode, METH_VARARGS}, 1079 {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS}, 1080 {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS}, 1081 {"utf_32_decode", utf_32_decode, METH_VARARGS}, 1082 {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS}, 1083 {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS}, 1084 {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS}, 1085 {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS}, 1086 {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS}, 1087 {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS}, 1088 {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS}, 1089 {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS}, 1090 {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS}, 1091 {"latin_1_encode", latin_1_encode, METH_VARARGS}, 1092 {"latin_1_decode", latin_1_decode, METH_VARARGS}, 1093 {"ascii_encode", ascii_encode, METH_VARARGS}, 1094 {"ascii_decode", ascii_decode, METH_VARARGS}, 1095 {"charmap_encode", charmap_encode, METH_VARARGS}, 1096 {"charmap_decode", charmap_decode, METH_VARARGS}, 1097 {"charmap_build", charmap_build, METH_VARARGS}, 1098 {"readbuffer_encode", readbuffer_encode, METH_VARARGS}, 1099 {"charbuffer_encode", charbuffer_encode, METH_VARARGS}, 1099 1100 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) 1100 {"mbcs_encode", mbcs_encode,METH_VARARGS},1101 {"mbcs_decode", mbcs_decode,METH_VARARGS},1101 {"mbcs_encode", mbcs_encode, METH_VARARGS}, 1102 {"mbcs_decode", mbcs_decode, METH_VARARGS}, 1102 1103 #endif 1103 1104 #endif /* Py_USING_UNICODE */ 1104 {"register_error", register_error,METH_VARARGS,1105 {"register_error", register_error, METH_VARARGS, 1105 1106 register_error__doc__}, 1106 {"lookup_error", lookup_error,METH_VARARGS,1107 {"lookup_error", lookup_error, METH_VARARGS, 1107 1108 lookup_error__doc__}, 1108 {NULL, NULL} 1109 {NULL, NULL} /* sentinel */ 1109 1110 }; 1110 1111
Note:
See TracChangeset
for help on using the changeset viewer.