Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/_codecsmodule.c

    r2 r391  
    1616
    1717     <encoding>_encode(Unicode_object[,errors='strict']) ->
    18         (string object, bytes consumed)
     18        (string object, bytes consumed)
    1919
    2020     <encoding>_decode(char_buffer_obj[,errors='strict']) ->
     
    9797#ifdef Py_USING_UNICODE
    9898    if (encoding == NULL)
    99         encoding = PyUnicode_GetDefaultEncoding();
     99        encoding = PyUnicode_GetDefaultEncoding();
    100100#else
    101101    if (encoding == NULL) {
    102         PyErr_SetString(PyExc_ValueError, "no encoding specified");
    103         return NULL;
     102        PyErr_SetString(PyExc_ValueError, "no encoding specified");
     103        return NULL;
    104104    }
    105105#endif
     
    131131#ifdef Py_USING_UNICODE
    132132    if (encoding == NULL)
    133         encoding = PyUnicode_GetDefaultEncoding();
     133        encoding = PyUnicode_GetDefaultEncoding();
    134134#else
    135135    if (encoding == NULL) {
    136         PyErr_SetString(PyExc_ValueError, "no encoding specified");
    137         return NULL;
     136        PyErr_SetString(PyExc_ValueError, "no encoding specified");
     137        return NULL;
    138138    }
    139139#endif
     
    147147static
    148148PyObject *codec_tuple(PyObject *unicode,
    149                       Py_ssize_t len)
     149                      Py_ssize_t len)
    150150{
    151151    PyObject *v;
     
    160160static PyObject *
    161161escape_decode(PyObject *self,
    162               PyObject *args)
     162              PyObject *args)
    163163{
    164164    const char *errors = NULL;
     
    167167
    168168    if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
    169                           &data, &size, &errors))
    170         return NULL;
     169                          &data, &size, &errors))
     170        return NULL;
    171171    return codec_tuple(PyString_DecodeEscape(data, size, errors, 0, NULL),
    172                        size);
     172                       size);
    173173}
    174174
    175175static PyObject *
    176176escape_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);
    200201}
    201202
     
    205206static PyObject *
    206207unicode_internal_decode(PyObject *self,
    207                         PyObject *args)
     208                        PyObject *args)
    208209{
    209210    PyObject *obj;
     
    213214
    214215    if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
    215                           &obj, &errors))
    216         return NULL;
     216                          &obj, &errors))
     217        return NULL;
    217218
    218219    if (PyUnicode_Check(obj)) {
    219         Py_INCREF(obj);
    220         return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
     220        Py_INCREF(obj);
     221        return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
    221222    }
    222223    else {
    223         if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
    224             return NULL;
    225 
    226         return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
    227                            size);
     224        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
     225            return NULL;
     226
     227        return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
     228                           size);
    228229    }
    229230}
     
    233234             PyObject *args)
    234235{
    235         Py_buffer pbuf;
     236    Py_buffer pbuf;
    236237    const char *errors = NULL;
    237238    int final = 0;
     
    240241
    241242    if (!PyArg_ParseTuple(args, "s*|zi:utf_7_decode",
    242                           &pbuf, &errors, &final))
    243         return NULL;
     243                          &pbuf, &errors, &final))
     244        return NULL;
    244245    consumed = pbuf.len;
    245246
    246247    decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
    247                                            final ? NULL : &consumed);
    248         PyBuffer_Release(&pbuf);
     248                                           final ? NULL : &consumed);
     249    PyBuffer_Release(&pbuf);
    249250    if (decoded == NULL)
    250251        return NULL;
     
    254255static PyObject *
    255256utf_8_decode(PyObject *self,
    256             PyObject *args)
    257 {
    258         Py_buffer pbuf;
     257            PyObject *args)
     258{
     259    Py_buffer pbuf;
    259260    const char *errors = NULL;
    260261    int final = 0;
     
    263264
    264265    if (!PyArg_ParseTuple(args, "s*|zi:utf_8_decode",
    265                           &pbuf, &errors, &final))
    266         return NULL;
     266                          &pbuf, &errors, &final))
     267        return NULL;
    267268    consumed = pbuf.len;
    268269
    269270    decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
    270                                            final ? NULL : &consumed);
    271         PyBuffer_Release(&pbuf);
     271                                           final ? NULL : &consumed);
     272    PyBuffer_Release(&pbuf);
    272273    if (decoded == NULL)
    273         return NULL;
     274        return NULL;
    274275    return codec_tuple(decoded, consumed);
    275276}
     
    277278static PyObject *
    278279utf_16_decode(PyObject *self,
    279             PyObject *args)
    280 {
    281         Py_buffer pbuf;
     280            PyObject *args)
     281{
     282    Py_buffer pbuf;
    282283    const char *errors = NULL;
    283284    int byteorder = 0;
     
    287288
    288289    if (!PyArg_ParseTuple(args, "s*|zi:utf_16_decode",
    289                           &pbuf, &errors, &final))
    290         return NULL;
     290                          &pbuf, &errors, &final))
     291        return NULL;
    291292    consumed = pbuf.len; /* This is overwritten unless final is true. */
    292293    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
    293                                         &byteorder, final ? NULL : &consumed);
    294         PyBuffer_Release(&pbuf);
     294                                        &byteorder, final ? NULL : &consumed);
     295    PyBuffer_Release(&pbuf);
    295296    if (decoded == NULL)
    296         return NULL;
     297        return NULL;
    297298    return codec_tuple(decoded, consumed);
    298299}
     
    300301static PyObject *
    301302utf_16_le_decode(PyObject *self,
    302                 PyObject *args)
    303 {
    304         Py_buffer pbuf;
     303                PyObject *args)
     304{
     305    Py_buffer pbuf;
    305306    const char *errors = NULL;
    306307    int byteorder = -1;
     
    310311
    311312    if (!PyArg_ParseTuple(args, "s*|zi:utf_16_le_decode",
    312                           &pbuf, &errors, &final))
    313         return NULL;
     313                          &pbuf, &errors, &final))
     314        return NULL;
    314315
    315316    consumed = pbuf.len; /* This is overwritten unless final is true. */
    316317    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
    317         &byteorder, final ? NULL : &consumed);
    318         PyBuffer_Release(&pbuf);
     318        &byteorder, final ? NULL : &consumed);
     319    PyBuffer_Release(&pbuf);
    319320    if (decoded == NULL)
    320         return NULL;
     321        return NULL;
    321322    return codec_tuple(decoded, consumed);
    322323}
     
    324325static PyObject *
    325326utf_16_be_decode(PyObject *self,
    326                 PyObject *args)
    327 {
    328         Py_buffer pbuf;
     327                PyObject *args)
     328{
     329    Py_buffer pbuf;
    329330    const char *errors = NULL;
    330331    int byteorder = 1;
     
    334335
    335336    if (!PyArg_ParseTuple(args, "s*|zi:utf_16_be_decode",
    336                           &pbuf, &errors, &final))
    337         return NULL;
     337                          &pbuf, &errors, &final))
     338        return NULL;
    338339
    339340    consumed = pbuf.len; /* This is overwritten unless final is true. */
    340341    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
    341         &byteorder, final ? NULL : &consumed);
    342         PyBuffer_Release(&pbuf);
     342        &byteorder, final ? NULL : &consumed);
     343    PyBuffer_Release(&pbuf);
    343344    if (decoded == NULL)
    344         return NULL;
     345        return NULL;
    345346    return codec_tuple(decoded, consumed);
    346347}
     
    356357static PyObject *
    357358utf_16_ex_decode(PyObject *self,
    358                 PyObject *args)
    359 {
    360         Py_buffer pbuf;
     359                PyObject *args)
     360{
     361    Py_buffer pbuf;
    361362    const char *errors = NULL;
    362363    int byteorder = 0;
     
    366367
    367368    if (!PyArg_ParseTuple(args, "s*|zii:utf_16_ex_decode",
    368                           &pbuf, &errors, &byteorder, &final))
    369         return NULL;
     369                          &pbuf, &errors, &byteorder, &final))
     370        return NULL;
    370371    consumed = pbuf.len; /* This is overwritten unless final is true. */
    371372    unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
    372                                         &byteorder, final ? NULL : &consumed);
    373         PyBuffer_Release(&pbuf);
     373                                        &byteorder, final ? NULL : &consumed);
     374    PyBuffer_Release(&pbuf);
    374375    if (unicode == NULL)
    375         return NULL;
     376        return NULL;
    376377    tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
    377378    Py_DECREF(unicode);
     
    381382static PyObject *
    382383utf_32_decode(PyObject *self,
    383             PyObject *args)
    384 {
    385         Py_buffer pbuf;
     384            PyObject *args)
     385{
     386    Py_buffer pbuf;
    386387    const char *errors = NULL;
    387388    int byteorder = 0;
     
    391392
    392393    if (!PyArg_ParseTuple(args, "s*|zi:utf_32_decode",
    393                           &pbuf, &errors, &final))
    394         return NULL;
     394                          &pbuf, &errors, &final))
     395        return NULL;
    395396    consumed = pbuf.len; /* This is overwritten unless final is true. */
    396397    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
    397                                         &byteorder, final ? NULL : &consumed);
    398         PyBuffer_Release(&pbuf);
     398                                        &byteorder, final ? NULL : &consumed);
     399    PyBuffer_Release(&pbuf);
    399400    if (decoded == NULL)
    400         return NULL;
     401        return NULL;
    401402    return codec_tuple(decoded, consumed);
    402403}
     
    404405static PyObject *
    405406utf_32_le_decode(PyObject *self,
    406                 PyObject *args)
    407 {
    408         Py_buffer pbuf;
     407                PyObject *args)
     408{
     409    Py_buffer pbuf;
    409410    const char *errors = NULL;
    410411    int byteorder = -1;
     
    414415
    415416    if (!PyArg_ParseTuple(args, "s*|zi:utf_32_le_decode",
    416                           &pbuf, &errors, &final))
    417         return NULL;
     417                          &pbuf, &errors, &final))
     418        return NULL;
    418419    consumed = pbuf.len; /* This is overwritten unless final is true. */
    419420    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
    420                                         &byteorder, final ? NULL : &consumed);
    421         PyBuffer_Release(&pbuf);
     421                                        &byteorder, final ? NULL : &consumed);
     422    PyBuffer_Release(&pbuf);
    422423    if (decoded == NULL)
    423         return NULL;
     424        return NULL;
    424425    return codec_tuple(decoded, consumed);
    425426}
     
    427428static PyObject *
    428429utf_32_be_decode(PyObject *self,
    429                 PyObject *args)
    430 {
    431         Py_buffer pbuf;
     430                PyObject *args)
     431{
     432    Py_buffer pbuf;
    432433    const char *errors = NULL;
    433434    int byteorder = 1;
     
    437438
    438439    if (!PyArg_ParseTuple(args, "s*|zi:utf_32_be_decode",
    439                           &pbuf, &errors, &final))
    440         return NULL;
     440                          &pbuf, &errors, &final))
     441        return NULL;
    441442    consumed = pbuf.len; /* This is overwritten unless final is true. */
    442443    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
    443                                         &byteorder, final ? NULL : &consumed);
    444         PyBuffer_Release(&pbuf);
     444                                        &byteorder, final ? NULL : &consumed);
     445    PyBuffer_Release(&pbuf);
    445446    if (decoded == NULL)
    446         return NULL;
     447        return NULL;
    447448    return codec_tuple(decoded, consumed);
    448449}
     
    458459static PyObject *
    459460utf_32_ex_decode(PyObject *self,
    460                 PyObject *args)
    461 {
    462         Py_buffer pbuf;
     461                PyObject *args)
     462{
     463    Py_buffer pbuf;
    463464    const char *errors = NULL;
    464465    int byteorder = 0;
     
    468469
    469470    if (!PyArg_ParseTuple(args, "s*|zii:utf_32_ex_decode",
    470                           &pbuf, &errors, &byteorder, &final))
    471         return NULL;
     471                          &pbuf, &errors, &byteorder, &final))
     472        return NULL;
    472473    consumed = pbuf.len; /* This is overwritten unless final is true. */
    473474    unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
    474                                         &byteorder, final ? NULL : &consumed);
    475         PyBuffer_Release(&pbuf);
     475                                        &byteorder, final ? NULL : &consumed);
     476    PyBuffer_Release(&pbuf);
    476477    if (unicode == NULL)
    477         return NULL;
     478        return NULL;
    478479    tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
    479480    Py_DECREF(unicode);
     
    483484static PyObject *
    484485unicode_escape_decode(PyObject *self,
    485                      PyObject *args)
    486 {
    487         Py_buffer pbuf;
    488     const char *errors = NULL;
    489         PyObject *unicode;
     486                     PyObject *args)
     487{
     488    Py_buffer pbuf;
     489    const char *errors = NULL;
     490        PyObject *unicode;
    490491
    491492    if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
    492                           &pbuf, &errors))
    493         return NULL;
    494 
    495         unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
    496         PyBuffer_Release(&pbuf);
    497         return codec_tuple(unicode, pbuf.len);
     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);
    498499}
    499500
    500501static PyObject *
    501502raw_unicode_escape_decode(PyObject *self,
    502                         PyObject *args)
    503 {
    504         Py_buffer pbuf;
    505     const char *errors = NULL;
    506         PyObject *unicode;
     503                        PyObject *args)
     504{
     505    Py_buffer pbuf;
     506    const char *errors = NULL;
     507    PyObject *unicode;
    507508
    508509    if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
    509                           &pbuf, &errors))
    510         return NULL;
    511 
    512         unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
    513         PyBuffer_Release(&pbuf);
    514         return codec_tuple(unicode, pbuf.len);
     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);
    515516}
    516517
    517518static PyObject *
    518519latin_1_decode(PyObject *self,
    519                PyObject *args)
    520 {
    521         Py_buffer pbuf;
    522         PyObject *unicode;
     520               PyObject *args)
     521{
     522    Py_buffer pbuf;
     523    PyObject *unicode;
    523524    const char *errors = NULL;
    524525
    525526    if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
    526                           &pbuf, &errors))
    527         return NULL;
    528 
    529         unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
    530         PyBuffer_Release(&pbuf);
    531         return codec_tuple(unicode, pbuf.len);
     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);
    532533}
    533534
    534535static PyObject *
    535536ascii_decode(PyObject *self,
    536              PyObject *args)
    537 {
    538         Py_buffer pbuf;
    539         PyObject *unicode;
     537             PyObject *args)
     538{
     539    Py_buffer pbuf;
     540    PyObject *unicode;
    540541    const char *errors = NULL;
    541542
    542543    if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
    543                           &pbuf, &errors))
    544         return NULL;
    545 
    546         unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
    547         PyBuffer_Release(&pbuf);
    548         return codec_tuple(unicode, pbuf.len);
     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);
    549550}
    550551
    551552static PyObject *
    552553charmap_decode(PyObject *self,
    553                PyObject *args)
    554 {
    555         Py_buffer pbuf;
    556         PyObject *unicode;
     554               PyObject *args)
     555{
     556    Py_buffer pbuf;
     557    PyObject *unicode;
    557558    const char *errors = NULL;
    558559    PyObject *mapping = NULL;
    559560
    560561    if (!PyArg_ParseTuple(args, "s*|zO:charmap_decode",
    561                           &pbuf, &errors, &mapping))
    562         return NULL;
     562                          &pbuf, &errors, &mapping))
     563        return NULL;
    563564    if (mapping == Py_None)
    564         mapping = NULL;
    565 
    566         unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
    567         PyBuffer_Release(&pbuf);
    568         return codec_tuple(unicode, pbuf.len);
     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);
    569570}
    570571
     
    573574static PyObject *
    574575mbcs_decode(PyObject *self,
    575             PyObject *args)
    576 {
    577         Py_buffer pbuf;
     576            PyObject *args)
     577{
     578    Py_buffer pbuf;
    578579    const char *errors = NULL;
    579580    int final = 0;
     
    582583
    583584    if (!PyArg_ParseTuple(args, "s*|zi:mbcs_decode",
    584                           &pbuf, &errors, &final))
    585         return NULL;
     585                          &pbuf, &errors, &final))
     586        return NULL;
    586587    consumed = pbuf.len;
    587588
    588589    decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
    589                                            final ? NULL : &consumed);
    590         PyBuffer_Release(&pbuf);
     590                                           final ? NULL : &consumed);
     591    PyBuffer_Release(&pbuf);
    591592    if (decoded == NULL)
    592         return NULL;
     593        return NULL;
    593594    return codec_tuple(decoded, consumed);
    594595}
     
    600601static PyObject *
    601602readbuffer_encode(PyObject *self,
    602                   PyObject *args)
     603                  PyObject *args)
    603604{
    604605    const char *data;
     
    607608
    608609    if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
    609                           &data, &size, &errors))
    610         return NULL;
     610                          &data, &size, &errors))
     611        return NULL;
    611612
    612613    return codec_tuple(PyString_FromStringAndSize(data, size),
    613                        size);
     614                       size);
    614615}
    615616
    616617static PyObject *
    617618charbuffer_encode(PyObject *self,
    618                   PyObject *args)
     619                  PyObject *args)
    619620{
    620621    const char *data;
     
    623624
    624625    if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
    625                           &data, &size, &errors))
    626         return NULL;
     626                          &data, &size, &errors))
     627        return NULL;
    627628
    628629    return codec_tuple(PyString_FromStringAndSize(data, size),
    629                        size);
     630                       size);
    630631}
    631632
    632633static PyObject *
    633634unicode_internal_encode(PyObject *self,
    634                         PyObject *args)
     635                        PyObject *args)
    635636{
    636637    PyObject *obj;
     
    640641
    641642    if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
    642                           &obj, &errors))
    643         return NULL;
     643                          &obj, &errors))
     644        return NULL;
    644645
    645646    if (PyUnicode_Check(obj)) {
    646         data = PyUnicode_AS_DATA(obj);
    647         size = PyUnicode_GET_DATA_SIZE(obj);
    648         return codec_tuple(PyString_FromStringAndSize(data, size),
    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));
    650651    }
    651652    else {
    652         if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
    653             return NULL;
    654         return codec_tuple(PyString_FromStringAndSize(data, size),
    655                            size);
     653        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
     654            return NULL;
     655        return codec_tuple(PyString_FromStringAndSize(data, size),
     656                           size);
    656657    }
    657658}
     
    659660static PyObject *
    660661utf_7_encode(PyObject *self,
    661             PyObject *args)
     662            PyObject *args)
    662663{
    663664    PyObject *str, *v;
     
    665666
    666667    if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
    667                           &str, &errors))
    668         return NULL;
    669 
    670     str = PyUnicode_FromObject(str);
    671     if (str == NULL)
    672         return NULL;
     668                          &str, &errors))
     669        return NULL;
     670
     671    str = PyUnicode_FromObject(str);
     672    if (str == NULL)
     673        return NULL;
    673674    v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
    674                                         PyUnicode_GET_SIZE(str),
    675                                         0,
    676                                         0,
    677                                         errors),
    678                     PyUnicode_GET_SIZE(str));
     675                                        PyUnicode_GET_SIZE(str),
     676                                        0,
     677                                        0,
     678                                        errors),
     679                    PyUnicode_GET_SIZE(str));
    679680    Py_DECREF(str);
    680681    return v;
     
    683684static PyObject *
    684685utf_8_encode(PyObject *self,
    685             PyObject *args)
     686            PyObject *args)
    686687{
    687688    PyObject *str, *v;
     
    689690
    690691    if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
    691                           &str, &errors))
    692         return NULL;
    693 
    694     str = PyUnicode_FromObject(str);
    695     if (str == NULL)
    696         return NULL;
     692                          &str, &errors))
     693        return NULL;
     694
     695    str = PyUnicode_FromObject(str);
     696    if (str == NULL)
     697        return NULL;
    697698    v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
    698                                         PyUnicode_GET_SIZE(str),
    699                                         errors),
    700                     PyUnicode_GET_SIZE(str));
     699                                        PyUnicode_GET_SIZE(str),
     700                                        errors),
     701                    PyUnicode_GET_SIZE(str));
    701702    Py_DECREF(str);
    702703    return v;
     
    712713static PyObject *
    713714utf_16_encode(PyObject *self,
    714             PyObject *args)
     715            PyObject *args)
    715716{
    716717    PyObject *str, *v;
     
    719720
    720721    if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
    721                           &str, &errors, &byteorder))
    722         return NULL;
    723 
    724     str = PyUnicode_FromObject(str);
    725     if (str == NULL)
    726         return NULL;
     722                          &str, &errors, &byteorder))
     723        return NULL;
     724
     725    str = PyUnicode_FromObject(str);
     726    if (str == NULL)
     727        return NULL;
    727728    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
    728                                           PyUnicode_GET_SIZE(str),
    729                                           errors,
    730                                           byteorder),
    731                     PyUnicode_GET_SIZE(str));
     729                                          PyUnicode_GET_SIZE(str),
     730                                          errors,
     731                                          byteorder),
     732                    PyUnicode_GET_SIZE(str));
    732733    Py_DECREF(str);
    733734    return v;
     
    736737static PyObject *
    737738utf_16_le_encode(PyObject *self,
    738                 PyObject *args)
     739                PyObject *args)
    739740{
    740741    PyObject *str, *v;
     
    742743
    743744    if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
    744                           &str, &errors))
    745         return NULL;
    746 
    747     str = PyUnicode_FromObject(str);
    748     if (str == NULL)
    749         return NULL;
     745                          &str, &errors))
     746        return NULL;
     747
     748    str = PyUnicode_FromObject(str);
     749    if (str == NULL)
     750        return NULL;
    750751    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
    751                                              PyUnicode_GET_SIZE(str),
    752                                              errors,
    753                                              -1),
    754                        PyUnicode_GET_SIZE(str));
     752                                             PyUnicode_GET_SIZE(str),
     753                                             errors,
     754                                             -1),
     755                       PyUnicode_GET_SIZE(str));
    755756    Py_DECREF(str);
    756757    return v;
     
    759760static PyObject *
    760761utf_16_be_encode(PyObject *self,
    761                 PyObject *args)
     762                PyObject *args)
    762763{
    763764    PyObject *str, *v;
     
    765766
    766767    if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
    767                           &str, &errors))
    768         return NULL;
    769 
    770     str = PyUnicode_FromObject(str);
    771     if (str == NULL)
    772         return NULL;
     768                          &str, &errors))
     769        return NULL;
     770
     771    str = PyUnicode_FromObject(str);
     772    if (str == NULL)
     773        return NULL;
    773774    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
    774                                           PyUnicode_GET_SIZE(str),
    775                                           errors,
    776                                           +1),
    777                     PyUnicode_GET_SIZE(str));
     775                                          PyUnicode_GET_SIZE(str),
     776                                          errors,
     777                                          +1),
     778                    PyUnicode_GET_SIZE(str));
    778779    Py_DECREF(str);
    779780    return v;
     
    789790static PyObject *
    790791utf_32_encode(PyObject *self,
    791             PyObject *args)
     792            PyObject *args)
    792793{
    793794    PyObject *str, *v;
     
    796797
    797798    if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode",
    798                           &str, &errors, &byteorder))
    799         return NULL;
    800 
    801     str = PyUnicode_FromObject(str);
    802     if (str == NULL)
    803         return NULL;
     799                          &str, &errors, &byteorder))
     800        return NULL;
     801
     802    str = PyUnicode_FromObject(str);
     803    if (str == NULL)
     804        return NULL;
    804805    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
    805                                           PyUnicode_GET_SIZE(str),
    806                                           errors,
    807                                           byteorder),
    808                     PyUnicode_GET_SIZE(str));
     806                                          PyUnicode_GET_SIZE(str),
     807                                          errors,
     808                                          byteorder),
     809                    PyUnicode_GET_SIZE(str));
    809810    Py_DECREF(str);
    810811    return v;
     
    813814static PyObject *
    814815utf_32_le_encode(PyObject *self,
    815                 PyObject *args)
     816                PyObject *args)
    816817{
    817818    PyObject *str, *v;
     
    819820
    820821    if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode",
    821                           &str, &errors))
    822         return NULL;
    823 
    824     str = PyUnicode_FromObject(str);
    825     if (str == NULL)
    826         return NULL;
     822                          &str, &errors))
     823        return NULL;
     824
     825    str = PyUnicode_FromObject(str);
     826    if (str == NULL)
     827        return NULL;
    827828    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
    828                                              PyUnicode_GET_SIZE(str),
    829                                              errors,
    830                                              -1),
    831                        PyUnicode_GET_SIZE(str));
     829                                             PyUnicode_GET_SIZE(str),
     830                                             errors,
     831                                             -1),
     832                       PyUnicode_GET_SIZE(str));
    832833    Py_DECREF(str);
    833834    return v;
     
    836837static PyObject *
    837838utf_32_be_encode(PyObject *self,
    838                 PyObject *args)
     839                PyObject *args)
    839840{
    840841    PyObject *str, *v;
     
    842843
    843844    if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode",
    844                           &str, &errors))
    845         return NULL;
    846 
    847     str = PyUnicode_FromObject(str);
    848     if (str == NULL)
    849         return NULL;
     845                          &str, &errors))
     846        return NULL;
     847
     848    str = PyUnicode_FromObject(str);
     849    if (str == NULL)
     850        return NULL;
    850851    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
    851                                           PyUnicode_GET_SIZE(str),
    852                                           errors,
    853                                           +1),
    854                     PyUnicode_GET_SIZE(str));
     852                                          PyUnicode_GET_SIZE(str),
     853                                          errors,
     854                                          +1),
     855                    PyUnicode_GET_SIZE(str));
    855856    Py_DECREF(str);
    856857    return v;
     
    859860static PyObject *
    860861unicode_escape_encode(PyObject *self,
    861                      PyObject *args)
     862                     PyObject *args)
    862863{
    863864    PyObject *str, *v;
     
    865866
    866867    if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
    867                           &str, &errors))
    868         return NULL;
    869 
    870     str = PyUnicode_FromObject(str);
    871     if (str == NULL)
    872         return NULL;
     868                          &str, &errors))
     869        return NULL;
     870
     871    str = PyUnicode_FromObject(str);
     872    if (str == NULL)
     873        return NULL;
    873874    v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
    874                                                   PyUnicode_GET_SIZE(str)),
    875                     PyUnicode_GET_SIZE(str));
     875                                                  PyUnicode_GET_SIZE(str)),
     876                    PyUnicode_GET_SIZE(str));
    876877    Py_DECREF(str);
    877878    return v;
     
    880881static PyObject *
    881882raw_unicode_escape_encode(PyObject *self,
    882                         PyObject *args)
     883                        PyObject *args)
    883884{
    884885    PyObject *str, *v;
     
    886887
    887888    if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
    888                           &str, &errors))
    889         return NULL;
    890 
    891     str = PyUnicode_FromObject(str);
    892     if (str == NULL)
    893         return NULL;
     889                          &str, &errors))
     890        return NULL;
     891
     892    str = PyUnicode_FromObject(str);
     893    if (str == NULL)
     894        return NULL;
    894895    v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
    895                                PyUnicode_AS_UNICODE(str),
    896                                PyUnicode_GET_SIZE(str)),
    897                     PyUnicode_GET_SIZE(str));
     896                               PyUnicode_AS_UNICODE(str),
     897                               PyUnicode_GET_SIZE(str)),
     898                    PyUnicode_GET_SIZE(str));
    898899    Py_DECREF(str);
    899900    return v;
     
    902903static PyObject *
    903904latin_1_encode(PyObject *self,
    904                PyObject *args)
     905               PyObject *args)
    905906{
    906907    PyObject *str, *v;
     
    908909
    909910    if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
    910                           &str, &errors))
    911         return NULL;
    912 
    913     str = PyUnicode_FromObject(str);
    914     if (str == NULL)
    915         return NULL;
     911                          &str, &errors))
     912        return NULL;
     913
     914    str = PyUnicode_FromObject(str);
     915    if (str == NULL)
     916        return NULL;
    916917    v = codec_tuple(PyUnicode_EncodeLatin1(
    917                                PyUnicode_AS_UNICODE(str),
    918                                PyUnicode_GET_SIZE(str),
    919                                errors),
    920                     PyUnicode_GET_SIZE(str));
     918                               PyUnicode_AS_UNICODE(str),
     919                               PyUnicode_GET_SIZE(str),
     920                               errors),
     921                    PyUnicode_GET_SIZE(str));
    921922    Py_DECREF(str);
    922923    return v;
     
    925926static PyObject *
    926927ascii_encode(PyObject *self,
    927              PyObject *args)
     928             PyObject *args)
    928929{
    929930    PyObject *str, *v;
     
    931932
    932933    if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
    933                           &str, &errors))
    934         return NULL;
    935 
    936     str = PyUnicode_FromObject(str);
    937     if (str == NULL)
    938         return NULL;
     934                          &str, &errors))
     935        return NULL;
     936
     937    str = PyUnicode_FromObject(str);
     938    if (str == NULL)
     939        return NULL;
    939940    v = codec_tuple(PyUnicode_EncodeASCII(
    940                                PyUnicode_AS_UNICODE(str),
    941                                PyUnicode_GET_SIZE(str),
    942                                errors),
    943                     PyUnicode_GET_SIZE(str));
     941                               PyUnicode_AS_UNICODE(str),
     942                               PyUnicode_GET_SIZE(str),
     943                               errors),
     944                    PyUnicode_GET_SIZE(str));
    944945    Py_DECREF(str);
    945946    return v;
     
    948949static PyObject *
    949950charmap_encode(PyObject *self,
    950              PyObject *args)
     951             PyObject *args)
    951952{
    952953    PyObject *str, *v;
     
    955956
    956957    if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
    957                           &str, &errors, &mapping))
    958         return NULL;
     958                          &str, &errors, &mapping))
     959        return NULL;
    959960    if (mapping == Py_None)
    960         mapping = NULL;
    961 
    962     str = PyUnicode_FromObject(str);
    963     if (str == NULL)
    964         return NULL;
     961        mapping = NULL;
     962
     963    str = PyUnicode_FromObject(str);
     964    if (str == NULL)
     965        return NULL;
    965966    v = codec_tuple(PyUnicode_EncodeCharmap(
    966                                PyUnicode_AS_UNICODE(str),
    967                                PyUnicode_GET_SIZE(str),
    968                                mapping,
    969                                errors),
    970                     PyUnicode_GET_SIZE(str));
     967                               PyUnicode_AS_UNICODE(str),
     968                               PyUnicode_GET_SIZE(str),
     969                               mapping,
     970                               errors),
     971                    PyUnicode_GET_SIZE(str));
    971972    Py_DECREF(str);
    972973    return v;
     
    986987static PyObject *
    987988mbcs_encode(PyObject *self,
    988             PyObject *args)
     989            PyObject *args)
    989990{
    990991    PyObject *str, *v;
     
    992993
    993994    if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
    994                           &str, &errors))
    995         return NULL;
    996 
    997     str = PyUnicode_FromObject(str);
    998     if (str == NULL)
    999         return NULL;
     995                          &str, &errors))
     996        return NULL;
     997
     998    str = PyUnicode_FromObject(str);
     999    if (str == NULL)
     1000        return NULL;
    10001001    v = codec_tuple(PyUnicode_EncodeMBCS(
    1001                                PyUnicode_AS_UNICODE(str),
    1002                                PyUnicode_GET_SIZE(str),
    1003                                errors),
    1004                     PyUnicode_GET_SIZE(str));
     1002                               PyUnicode_AS_UNICODE(str),
     1003                               PyUnicode_GET_SIZE(str),
     1004                               errors),
     1005                    PyUnicode_GET_SIZE(str));
    10051006    Py_DECREF(str);
    10061007    return v;
     
    10271028
    10281029    if (!PyArg_ParseTuple(args, "sO:register_error",
    1029                           &name, &handler))
    1030         return NULL;
     1030                          &name, &handler))
     1031        return NULL;
    10311032    if (PyCodec_RegisterError(name, handler))
    10321033        return NULL;
     
    10451046
    10461047    if (!PyArg_ParseTuple(args, "s:lookup_error",
    1047                           &name))
    1048         return NULL;
     1048                          &name))
     1049        return NULL;
    10491050    return PyCodec_LookupError(name);
    10501051}
     
    10531054
    10541055static PyMethodDef _codecs_functions[] = {
    1055     {"register",                codec_register,                 METH_O,
     1056    {"register",                codec_register,                 METH_O,
    10561057        register__doc__},
    1057     {"lookup",                  codec_lookup,                   METH_VARARGS,
     1058    {"lookup",                  codec_lookup,                   METH_VARARGS,
    10581059        lookup__doc__},
    1059     {"encode",                  codec_encode,                   METH_VARARGS,
    1060         encode__doc__},
    1061     {"decode",                  codec_decode,                   METH_VARARGS,
    1062         decode__doc__},
    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},
    10651066#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,    METH_VARARGS},
    1089     {"raw_unicode_escape_decode", raw_unicode_escape_decode,    METH_VARARGS},
    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},
    10991100#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},
    11021103#endif
    11031104#endif /* Py_USING_UNICODE */
    1104     {"register_error",          register_error,                 METH_VARARGS,
     1105    {"register_error",          register_error,                 METH_VARARGS,
    11051106        register_error__doc__},
    1106     {"lookup_error",            lookup_error,                   METH_VARARGS,
     1107    {"lookup_error",            lookup_error,                   METH_VARARGS,
    11071108        lookup_error__doc__},
    1108     {NULL, NULL}                /* sentinel */
     1109    {NULL, NULL}                /* sentinel */
    11091110};
    11101111
Note: See TracChangeset for help on using the changeset viewer.