~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Modules/_codecsmodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
   The builtin Unicode codecs use the following interface:
16
16
 
17
17
     <encoding>_encode(Unicode_object[,errors='strict']) ->
18
 
        (string object, bytes consumed)
 
18
        (string object, bytes consumed)
19
19
 
20
20
     <encoding>_decode(char_buffer_obj[,errors='strict']) ->
21
21
        (Unicode object, bytes consumed)
95
95
        return NULL;
96
96
 
97
97
    if (encoding == NULL)
98
 
        encoding = PyUnicode_GetDefaultEncoding();
 
98
        encoding = PyUnicode_GetDefaultEncoding();
99
99
 
100
100
    /* Encode via the codec registry */
101
101
    return PyCodec_Encode(v, encoding, errors);
122
122
        return NULL;
123
123
 
124
124
    if (encoding == NULL)
125
 
        encoding = PyUnicode_GetDefaultEncoding();
 
125
        encoding = PyUnicode_GetDefaultEncoding();
126
126
 
127
127
    /* Decode via the codec registry */
128
128
    return PyCodec_Decode(v, encoding, errors);
132
132
 
133
133
static
134
134
PyObject *codec_tuple(PyObject *unicode,
135
 
                      Py_ssize_t len)
 
135
                      Py_ssize_t len)
136
136
{
137
137
    PyObject *v;
138
138
    if (unicode == NULL)
145
145
/* --- String codecs ------------------------------------------------------ */
146
146
static PyObject *
147
147
escape_decode(PyObject *self,
148
 
              PyObject *args)
 
148
              PyObject *args)
149
149
{
150
150
    const char *errors = NULL;
151
151
    const char *data;
152
152
    Py_ssize_t size;
153
153
 
154
154
    if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
155
 
                          &data, &size, &errors))
156
 
        return NULL;
 
155
                          &data, &size, &errors))
 
156
        return NULL;
157
157
    return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL),
158
 
                       size);
 
158
                       size);
159
159
}
160
160
 
161
161
static PyObject *
162
162
escape_encode(PyObject *self,
163
 
              PyObject *args)
 
163
              PyObject *args)
164
164
{
165
 
        static const char *hexdigits = "0123456789abcdef";
166
 
        PyObject *str;
167
 
        Py_ssize_t size;
168
 
        Py_ssize_t newsize;
169
 
        const char *errors = NULL;
170
 
        PyObject *v;
171
 
 
172
 
        if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
173
 
                              &PyBytes_Type, &str, &errors))
174
 
                return NULL;
175
 
 
176
 
        size = PyBytes_GET_SIZE(str);
177
 
        newsize = 4*size;
178
 
        if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
179
 
                PyErr_SetString(PyExc_OverflowError,
180
 
                        "string is too large to encode");
181
 
                        return NULL;
182
 
        }
183
 
        v = PyBytes_FromStringAndSize(NULL, newsize);
184
 
 
185
 
        if (v == NULL) {
186
 
                return NULL;
187
 
        }
188
 
        else {
189
 
                register Py_ssize_t i;
190
 
                register char c;
191
 
                register char *p = PyBytes_AS_STRING(v);
192
 
 
193
 
                for (i = 0; i < size; i++) {
194
 
                        /* There's at least enough room for a hex escape */
195
 
                        assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
196
 
                        c = PyBytes_AS_STRING(str)[i];
197
 
                        if (c == '\'' || c == '\\')
198
 
                                *p++ = '\\', *p++ = c;
199
 
                        else if (c == '\t')
200
 
                                *p++ = '\\', *p++ = 't';
201
 
                        else if (c == '\n')
202
 
                                *p++ = '\\', *p++ = 'n';
203
 
                        else if (c == '\r')
204
 
                                *p++ = '\\', *p++ = 'r';
205
 
                        else if (c < ' ' || c >= 0x7f) {
206
 
                                *p++ = '\\';
207
 
                                *p++ = 'x';
208
 
                                *p++ = hexdigits[(c & 0xf0) >> 4];
209
 
                                *p++ = hexdigits[c & 0xf];
210
 
                        }
211
 
                        else
212
 
                                *p++ = c;
213
 
                }
214
 
                *p = '\0';
215
 
                if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
216
 
                        return NULL;
217
 
                }
218
 
        }
219
 
        
220
 
        return codec_tuple(v, PyBytes_Size(v));
 
165
    static const char *hexdigits = "0123456789abcdef";
 
166
    PyObject *str;
 
167
    Py_ssize_t size;
 
168
    Py_ssize_t newsize;
 
169
    const char *errors = NULL;
 
170
    PyObject *v;
 
171
 
 
172
    if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
 
173
                          &PyBytes_Type, &str, &errors))
 
174
        return NULL;
 
175
 
 
176
    size = PyBytes_GET_SIZE(str);
 
177
    newsize = 4*size;
 
178
    if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
 
179
        PyErr_SetString(PyExc_OverflowError,
 
180
            "string is too large to encode");
 
181
            return NULL;
 
182
    }
 
183
    v = PyBytes_FromStringAndSize(NULL, newsize);
 
184
 
 
185
    if (v == NULL) {
 
186
        return NULL;
 
187
    }
 
188
    else {
 
189
        register Py_ssize_t i;
 
190
        register char c;
 
191
        register char *p = PyBytes_AS_STRING(v);
 
192
 
 
193
        for (i = 0; i < size; i++) {
 
194
            /* There's at least enough room for a hex escape */
 
195
            assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
 
196
            c = PyBytes_AS_STRING(str)[i];
 
197
            if (c == '\'' || c == '\\')
 
198
                *p++ = '\\', *p++ = c;
 
199
            else if (c == '\t')
 
200
                *p++ = '\\', *p++ = 't';
 
201
            else if (c == '\n')
 
202
                *p++ = '\\', *p++ = 'n';
 
203
            else if (c == '\r')
 
204
                *p++ = '\\', *p++ = 'r';
 
205
            else if (c < ' ' || c >= 0x7f) {
 
206
                *p++ = '\\';
 
207
                *p++ = 'x';
 
208
                *p++ = hexdigits[(c & 0xf0) >> 4];
 
209
                *p++ = hexdigits[c & 0xf];
 
210
            }
 
211
            else
 
212
                *p++ = c;
 
213
        }
 
214
        *p = '\0';
 
215
        if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
 
216
            return NULL;
 
217
        }
 
218
    }
 
219
 
 
220
    return codec_tuple(v, size);
221
221
}
222
222
 
223
223
/* --- Decoder ------------------------------------------------------------ */
224
224
 
225
225
static PyObject *
226
226
unicode_internal_decode(PyObject *self,
227
 
                        PyObject *args)
 
227
                        PyObject *args)
228
228
{
229
229
    PyObject *obj;
230
230
    const char *errors = NULL;
232
232
    Py_ssize_t size;
233
233
 
234
234
    if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
235
 
                          &obj, &errors))
236
 
        return NULL;
 
235
                          &obj, &errors))
 
236
        return NULL;
237
237
 
238
238
    if (PyUnicode_Check(obj)) {
239
 
        Py_INCREF(obj);
240
 
        return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
 
239
        Py_INCREF(obj);
 
240
        return codec_tuple(obj, PyUnicode_GET_SIZE(obj));
241
241
    }
242
242
    else {
243
 
        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
244
 
            return NULL;
 
243
        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
 
244
            return NULL;
245
245
 
246
 
        return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
247
 
                           size);
 
246
        return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors),
 
247
                           size);
248
248
    }
249
249
}
250
250
 
252
252
utf_7_decode(PyObject *self,
253
253
             PyObject *args)
254
254
{
255
 
        Py_buffer pbuf;
 
255
    Py_buffer pbuf;
256
256
    const char *errors = NULL;
257
257
    int final = 0;
258
258
    Py_ssize_t consumed;
259
259
    PyObject *decoded = NULL;
260
260
 
261
261
    if (!PyArg_ParseTuple(args, "y*|zi:utf_7_decode",
262
 
                          &pbuf, &errors, &final))
263
 
        return NULL;
 
262
                          &pbuf, &errors, &final))
 
263
        return NULL;
264
264
    consumed = pbuf.len;
265
265
 
266
266
    decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
267
 
                                           final ? NULL : &consumed);
268
 
        PyBuffer_Release(&pbuf);
 
267
                                           final ? NULL : &consumed);
 
268
    PyBuffer_Release(&pbuf);
269
269
    if (decoded == NULL)
270
270
        return NULL;
271
271
    return codec_tuple(decoded, consumed);
273
273
 
274
274
static PyObject *
275
275
utf_8_decode(PyObject *self,
276
 
            PyObject *args)
 
276
            PyObject *args)
277
277
{
278
 
        Py_buffer pbuf;
 
278
    Py_buffer pbuf;
279
279
    const char *errors = NULL;
280
280
    int final = 0;
281
281
    Py_ssize_t consumed;
282
282
    PyObject *decoded = NULL;
283
283
 
284
284
    if (!PyArg_ParseTuple(args, "y*|zi:utf_8_decode",
285
 
                          &pbuf, &errors, &final))
286
 
        return NULL;
 
285
                          &pbuf, &errors, &final))
 
286
        return NULL;
287
287
    consumed = pbuf.len;
288
288
 
289
289
    decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
290
 
                                           final ? NULL : &consumed);
291
 
        PyBuffer_Release(&pbuf);
 
290
                                           final ? NULL : &consumed);
 
291
    PyBuffer_Release(&pbuf);
292
292
    if (decoded == NULL)
293
 
        return NULL;
 
293
        return NULL;
294
294
    return codec_tuple(decoded, consumed);
295
295
}
296
296
 
297
297
static PyObject *
298
298
utf_16_decode(PyObject *self,
299
 
            PyObject *args)
 
299
            PyObject *args)
300
300
{
301
 
        Py_buffer pbuf;
 
301
    Py_buffer pbuf;
302
302
    const char *errors = NULL;
303
303
    int byteorder = 0;
304
304
    int final = 0;
306
306
    PyObject *decoded;
307
307
 
308
308
    if (!PyArg_ParseTuple(args, "y*|zi:utf_16_decode",
309
 
                          &pbuf, &errors, &final))
310
 
        return NULL;
 
309
                          &pbuf, &errors, &final))
 
310
        return NULL;
311
311
    consumed = pbuf.len; /* This is overwritten unless final is true. */
312
312
    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
313
 
                                        &byteorder, final ? NULL : &consumed);
314
 
        PyBuffer_Release(&pbuf);
 
313
                                        &byteorder, final ? NULL : &consumed);
 
314
    PyBuffer_Release(&pbuf);
315
315
    if (decoded == NULL)
316
 
        return NULL;
 
316
        return NULL;
317
317
    return codec_tuple(decoded, consumed);
318
318
}
319
319
 
320
320
static PyObject *
321
321
utf_16_le_decode(PyObject *self,
322
 
                 PyObject *args)
 
322
                 PyObject *args)
323
323
{
324
 
        Py_buffer pbuf;
 
324
    Py_buffer pbuf;
325
325
    const char *errors = NULL;
326
326
    int byteorder = -1;
327
327
    int final = 0;
329
329
    PyObject *decoded = NULL;
330
330
 
331
331
    if (!PyArg_ParseTuple(args, "y*|zi:utf_16_le_decode",
332
 
                          &pbuf, &errors, &final))
333
 
        return NULL;
 
332
                          &pbuf, &errors, &final))
 
333
        return NULL;
334
334
 
335
335
    consumed = pbuf.len; /* This is overwritten unless final is true. */
336
336
    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
337
 
        &byteorder, final ? NULL : &consumed);
338
 
        PyBuffer_Release(&pbuf);
 
337
        &byteorder, final ? NULL : &consumed);
 
338
    PyBuffer_Release(&pbuf);
339
339
    if (decoded == NULL)
340
 
        return NULL;
 
340
        return NULL;
341
341
    return codec_tuple(decoded, consumed);
342
342
}
343
343
 
344
344
static PyObject *
345
345
utf_16_be_decode(PyObject *self,
346
 
                 PyObject *args)
 
346
                 PyObject *args)
347
347
{
348
 
        Py_buffer pbuf;
 
348
    Py_buffer pbuf;
349
349
    const char *errors = NULL;
350
350
    int byteorder = 1;
351
351
    int final = 0;
353
353
    PyObject *decoded = NULL;
354
354
 
355
355
    if (!PyArg_ParseTuple(args, "y*|zi:utf_16_be_decode",
356
 
                          &pbuf, &errors, &final))
357
 
        return NULL;
 
356
                          &pbuf, &errors, &final))
 
357
        return NULL;
358
358
 
359
359
    consumed = pbuf.len; /* This is overwritten unless final is true. */
360
360
    decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
361
 
        &byteorder, final ? NULL : &consumed);
362
 
        PyBuffer_Release(&pbuf);
 
361
        &byteorder, final ? NULL : &consumed);
 
362
    PyBuffer_Release(&pbuf);
363
363
    if (decoded == NULL)
364
 
        return NULL;
 
364
        return NULL;
365
365
    return codec_tuple(decoded, consumed);
366
366
}
367
367
 
375
375
 
376
376
static PyObject *
377
377
utf_16_ex_decode(PyObject *self,
378
 
                 PyObject *args)
 
378
                 PyObject *args)
379
379
{
380
 
        Py_buffer pbuf;
 
380
    Py_buffer pbuf;
381
381
    const char *errors = NULL;
382
382
    int byteorder = 0;
383
383
    PyObject *unicode, *tuple;
385
385
    Py_ssize_t consumed;
386
386
 
387
387
    if (!PyArg_ParseTuple(args, "y*|zii:utf_16_ex_decode",
388
 
                          &pbuf, &errors, &byteorder, &final))
389
 
        return NULL;
 
388
                          &pbuf, &errors, &byteorder, &final))
 
389
        return NULL;
390
390
    consumed = pbuf.len; /* This is overwritten unless final is true. */
391
391
    unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
392
 
                                        &byteorder, final ? NULL : &consumed);
393
 
        PyBuffer_Release(&pbuf);
 
392
                                        &byteorder, final ? NULL : &consumed);
 
393
    PyBuffer_Release(&pbuf);
394
394
    if (unicode == NULL)
395
 
        return NULL;
 
395
        return NULL;
396
396
    tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
397
397
    Py_DECREF(unicode);
398
398
    return tuple;
400
400
 
401
401
static PyObject *
402
402
utf_32_decode(PyObject *self,
403
 
            PyObject *args)
 
403
            PyObject *args)
404
404
{
405
 
        Py_buffer pbuf;
 
405
    Py_buffer pbuf;
406
406
    const char *errors = NULL;
407
407
    int byteorder = 0;
408
408
    int final = 0;
410
410
    PyObject *decoded;
411
411
 
412
412
    if (!PyArg_ParseTuple(args, "y*|zi:utf_32_decode",
413
 
                          &pbuf, &errors, &final))
414
 
        return NULL;
 
413
                          &pbuf, &errors, &final))
 
414
        return NULL;
415
415
    consumed = pbuf.len; /* This is overwritten unless final is true. */
416
416
    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
417
 
                                        &byteorder, final ? NULL : &consumed);
418
 
        PyBuffer_Release(&pbuf);
 
417
                                        &byteorder, final ? NULL : &consumed);
 
418
    PyBuffer_Release(&pbuf);
419
419
    if (decoded == NULL)
420
 
        return NULL;
 
420
        return NULL;
421
421
    return codec_tuple(decoded, consumed);
422
422
}
423
423
 
424
424
static PyObject *
425
425
utf_32_le_decode(PyObject *self,
426
 
                 PyObject *args)
 
426
                 PyObject *args)
427
427
{
428
 
        Py_buffer pbuf;
 
428
    Py_buffer pbuf;
429
429
    const char *errors = NULL;
430
430
    int byteorder = -1;
431
431
    int final = 0;
433
433
    PyObject *decoded;
434
434
 
435
435
    if (!PyArg_ParseTuple(args, "y*|zi:utf_32_le_decode",
436
 
                          &pbuf, &errors, &final))
437
 
        return NULL;
 
436
                          &pbuf, &errors, &final))
 
437
        return NULL;
438
438
    consumed = pbuf.len; /* This is overwritten unless final is true. */
439
439
    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
440
 
                                        &byteorder, final ? NULL : &consumed);
441
 
        PyBuffer_Release(&pbuf);
 
440
                                        &byteorder, final ? NULL : &consumed);
 
441
    PyBuffer_Release(&pbuf);
442
442
    if (decoded == NULL)
443
 
        return NULL;
 
443
        return NULL;
444
444
    return codec_tuple(decoded, consumed);
445
445
}
446
446
 
447
447
static PyObject *
448
448
utf_32_be_decode(PyObject *self,
449
 
                 PyObject *args)
 
449
                 PyObject *args)
450
450
{
451
 
        Py_buffer pbuf;
 
451
    Py_buffer pbuf;
452
452
    const char *errors = NULL;
453
453
    int byteorder = 1;
454
454
    int final = 0;
456
456
    PyObject *decoded;
457
457
 
458
458
    if (!PyArg_ParseTuple(args, "y*|zi:utf_32_be_decode",
459
 
                          &pbuf, &errors, &final))
460
 
        return NULL;
 
459
                          &pbuf, &errors, &final))
 
460
        return NULL;
461
461
    consumed = pbuf.len; /* This is overwritten unless final is true. */
462
462
    decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
463
 
                                        &byteorder, final ? NULL : &consumed);
464
 
        PyBuffer_Release(&pbuf);
 
463
                                        &byteorder, final ? NULL : &consumed);
 
464
    PyBuffer_Release(&pbuf);
465
465
    if (decoded == NULL)
466
 
        return NULL;
 
466
        return NULL;
467
467
    return codec_tuple(decoded, consumed);
468
468
}
469
469
 
477
477
 
478
478
static PyObject *
479
479
utf_32_ex_decode(PyObject *self,
480
 
                 PyObject *args)
 
480
                 PyObject *args)
481
481
{
482
 
        Py_buffer pbuf;
 
482
    Py_buffer pbuf;
483
483
    const char *errors = NULL;
484
484
    int byteorder = 0;
485
485
    PyObject *unicode, *tuple;
487
487
    Py_ssize_t consumed;
488
488
 
489
489
    if (!PyArg_ParseTuple(args, "y*|zii:utf_32_ex_decode",
490
 
                          &pbuf, &errors, &byteorder, &final))
491
 
        return NULL;
 
490
                          &pbuf, &errors, &byteorder, &final))
 
491
        return NULL;
492
492
    consumed = pbuf.len; /* This is overwritten unless final is true. */
493
493
    unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
494
 
                                        &byteorder, final ? NULL : &consumed);
495
 
        PyBuffer_Release(&pbuf);
 
494
                                        &byteorder, final ? NULL : &consumed);
 
495
    PyBuffer_Release(&pbuf);
496
496
    if (unicode == NULL)
497
 
        return NULL;
 
497
        return NULL;
498
498
    tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
499
499
    Py_DECREF(unicode);
500
500
    return tuple;
502
502
 
503
503
static PyObject *
504
504
unicode_escape_decode(PyObject *self,
505
 
                     PyObject *args)
 
505
                     PyObject *args)
506
506
{
507
 
        Py_buffer pbuf;
 
507
    Py_buffer pbuf;
508
508
    const char *errors = NULL;
509
 
        PyObject *unicode;
 
509
        PyObject *unicode;
510
510
 
511
511
    if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode",
512
 
                          &pbuf, &errors))
513
 
        return NULL;
 
512
                          &pbuf, &errors))
 
513
        return NULL;
514
514
 
515
 
        unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
516
 
        PyBuffer_Release(&pbuf);
517
 
        return codec_tuple(unicode, pbuf.len);
 
515
    unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
 
516
    PyBuffer_Release(&pbuf);
 
517
    return codec_tuple(unicode, pbuf.len);
518
518
}
519
519
 
520
520
static PyObject *
521
521
raw_unicode_escape_decode(PyObject *self,
522
 
                        PyObject *args)
 
522
                        PyObject *args)
523
523
{
524
 
        Py_buffer pbuf;
 
524
    Py_buffer pbuf;
525
525
    const char *errors = NULL;
526
 
        PyObject *unicode;
 
526
    PyObject *unicode;
527
527
 
528
528
    if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
529
 
                          &pbuf, &errors))
530
 
        return NULL;
 
529
                          &pbuf, &errors))
 
530
        return NULL;
531
531
 
532
 
        unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
533
 
        PyBuffer_Release(&pbuf);
534
 
        return codec_tuple(unicode, pbuf.len);
 
532
    unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
 
533
    PyBuffer_Release(&pbuf);
 
534
    return codec_tuple(unicode, pbuf.len);
535
535
}
536
536
 
537
537
static PyObject *
538
538
latin_1_decode(PyObject *self,
539
 
               PyObject *args)
 
539
               PyObject *args)
540
540
{
541
 
        Py_buffer pbuf;
542
 
        PyObject *unicode;
 
541
    Py_buffer pbuf;
 
542
    PyObject *unicode;
543
543
    const char *errors = NULL;
544
544
 
545
545
    if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode",
546
 
                          &pbuf, &errors))
547
 
        return NULL;
 
546
                          &pbuf, &errors))
 
547
        return NULL;
548
548
 
549
 
        unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
550
 
        PyBuffer_Release(&pbuf);
551
 
        return codec_tuple(unicode, pbuf.len);
 
549
    unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
 
550
    PyBuffer_Release(&pbuf);
 
551
    return codec_tuple(unicode, pbuf.len);
552
552
}
553
553
 
554
554
static PyObject *
555
555
ascii_decode(PyObject *self,
556
 
             PyObject *args)
 
556
             PyObject *args)
557
557
{
558
 
        Py_buffer pbuf;
559
 
        PyObject *unicode;
 
558
    Py_buffer pbuf;
 
559
    PyObject *unicode;
560
560
    const char *errors = NULL;
561
561
 
562
562
    if (!PyArg_ParseTuple(args, "y*|z:ascii_decode",
563
 
                          &pbuf, &errors))
564
 
        return NULL;
 
563
                          &pbuf, &errors))
 
564
        return NULL;
565
565
 
566
 
        unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
567
 
        PyBuffer_Release(&pbuf);
568
 
        return codec_tuple(unicode, pbuf.len);
 
566
    unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
 
567
    PyBuffer_Release(&pbuf);
 
568
    return codec_tuple(unicode, pbuf.len);
569
569
}
570
570
 
571
571
static PyObject *
572
572
charmap_decode(PyObject *self,
573
 
               PyObject *args)
 
573
               PyObject *args)
574
574
{
575
 
        Py_buffer pbuf;
576
 
        PyObject *unicode;
 
575
    Py_buffer pbuf;
 
576
    PyObject *unicode;
577
577
    const char *errors = NULL;
578
578
    PyObject *mapping = NULL;
579
579
 
580
580
    if (!PyArg_ParseTuple(args, "y*|zO:charmap_decode",
581
 
                          &pbuf, &errors, &mapping))
582
 
        return NULL;
 
581
                          &pbuf, &errors, &mapping))
 
582
        return NULL;
583
583
    if (mapping == Py_None)
584
 
        mapping = NULL;
 
584
        mapping = NULL;
585
585
 
586
 
        unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
587
 
        PyBuffer_Release(&pbuf);
588
 
        return codec_tuple(unicode, pbuf.len);
 
586
    unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
 
587
    PyBuffer_Release(&pbuf);
 
588
    return codec_tuple(unicode, pbuf.len);
589
589
}
590
590
 
591
591
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
592
592
 
593
593
static PyObject *
594
594
mbcs_decode(PyObject *self,
595
 
            PyObject *args)
 
595
            PyObject *args)
596
596
{
597
 
        Py_buffer pbuf;
 
597
    Py_buffer pbuf;
598
598
    const char *errors = NULL;
599
599
    int final = 0;
600
600
    Py_ssize_t consumed;
601
601
    PyObject *decoded = NULL;
602
602
 
603
603
    if (!PyArg_ParseTuple(args, "y*|zi:mbcs_decode",
604
 
                          &pbuf, &errors, &final))
605
 
        return NULL;
 
604
                          &pbuf, &errors, &final))
 
605
        return NULL;
606
606
    consumed = pbuf.len;
607
607
 
608
608
    decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
609
 
                                           final ? NULL : &consumed);
610
 
        PyBuffer_Release(&pbuf);
 
609
                                           final ? NULL : &consumed);
 
610
    PyBuffer_Release(&pbuf);
611
611
    if (decoded == NULL)
612
 
        return NULL;
 
612
        return NULL;
613
613
    return codec_tuple(decoded, consumed);
614
614
}
615
615
 
619
619
 
620
620
static PyObject *
621
621
readbuffer_encode(PyObject *self,
622
 
                  PyObject *args)
 
622
                  PyObject *args)
623
623
{
624
624
    Py_buffer pdata;
625
625
    const char *data;
628
628
    PyObject *result;
629
629
 
630
630
    if (!PyArg_ParseTuple(args, "s*|z:readbuffer_encode",
631
 
                          &pdata, &errors))
632
 
        return NULL;
 
631
                          &pdata, &errors))
 
632
        return NULL;
633
633
    data = pdata.buf;
634
634
    size = pdata.len;
635
635
 
640
640
 
641
641
static PyObject *
642
642
charbuffer_encode(PyObject *self,
643
 
                  PyObject *args)
 
643
                  PyObject *args)
644
644
{
645
645
    const char *data;
646
646
    Py_ssize_t size;
647
647
    const char *errors = NULL;
648
648
 
649
649
    if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
650
 
                          &data, &size, &errors))
651
 
        return NULL;
 
650
                          &data, &size, &errors))
 
651
        return NULL;
652
652
 
653
653
    return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
654
654
}
655
655
 
656
656
static PyObject *
657
657
unicode_internal_encode(PyObject *self,
658
 
                        PyObject *args)
 
658
                        PyObject *args)
659
659
{
660
660
    PyObject *obj;
661
661
    const char *errors = NULL;
663
663
    Py_ssize_t size;
664
664
 
665
665
    if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
666
 
                          &obj, &errors))
667
 
        return NULL;
 
666
                          &obj, &errors))
 
667
        return NULL;
668
668
 
669
669
    if (PyUnicode_Check(obj)) {
670
 
        data = PyUnicode_AS_DATA(obj);
671
 
        size = PyUnicode_GET_DATA_SIZE(obj);
672
 
        return codec_tuple(PyBytes_FromStringAndSize(data, size),
673
 
                           PyUnicode_GET_SIZE(obj));
 
670
        data = PyUnicode_AS_DATA(obj);
 
671
        size = PyUnicode_GET_DATA_SIZE(obj);
 
672
        return codec_tuple(PyBytes_FromStringAndSize(data, size),
 
673
                           PyUnicode_GET_SIZE(obj));
674
674
    }
675
675
    else {
676
 
        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
677
 
            return NULL;
678
 
        return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
 
676
        if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
 
677
            return NULL;
 
678
        return codec_tuple(PyBytes_FromStringAndSize(data, size), size);
679
679
    }
680
680
}
681
681
 
682
682
static PyObject *
683
683
utf_7_encode(PyObject *self,
684
 
            PyObject *args)
 
684
            PyObject *args)
685
685
{
686
686
    PyObject *str, *v;
687
687
    const char *errors = NULL;
688
688
 
689
689
    if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
690
 
                          &str, &errors))
691
 
        return NULL;
 
690
                          &str, &errors))
 
691
        return NULL;
692
692
 
693
693
    str = PyUnicode_FromObject(str);
694
694
    if (str == NULL)
695
 
        return NULL;
 
695
        return NULL;
696
696
    v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
697
 
                                         PyUnicode_GET_SIZE(str),
698
 
                                         0,
699
 
                                         0,
700
 
                                         errors),
701
 
                    PyUnicode_GET_SIZE(str));
 
697
                                         PyUnicode_GET_SIZE(str),
 
698
                                         0,
 
699
                                         0,
 
700
                                         errors),
 
701
                    PyUnicode_GET_SIZE(str));
702
702
    Py_DECREF(str);
703
703
    return v;
704
704
}
705
705
 
706
706
static PyObject *
707
707
utf_8_encode(PyObject *self,
708
 
            PyObject *args)
 
708
            PyObject *args)
709
709
{
710
710
    PyObject *str, *v;
711
711
    const char *errors = NULL;
712
712
 
713
713
    if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
714
 
                          &str, &errors))
715
 
        return NULL;
 
714
                          &str, &errors))
 
715
        return NULL;
716
716
 
717
717
    str = PyUnicode_FromObject(str);
718
718
    if (str == NULL)
719
 
        return NULL;
 
719
        return NULL;
720
720
    v = codec_tuple(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(str),
721
 
                                         PyUnicode_GET_SIZE(str),
722
 
                                         errors),
723
 
                    PyUnicode_GET_SIZE(str));
 
721
                                         PyUnicode_GET_SIZE(str),
 
722
                                         errors),
 
723
                    PyUnicode_GET_SIZE(str));
724
724
    Py_DECREF(str);
725
725
    return v;
726
726
}
734
734
 
735
735
static PyObject *
736
736
utf_16_encode(PyObject *self,
737
 
            PyObject *args)
 
737
            PyObject *args)
738
738
{
739
739
    PyObject *str, *v;
740
740
    const char *errors = NULL;
741
741
    int byteorder = 0;
742
742
 
743
743
    if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
744
 
                          &str, &errors, &byteorder))
745
 
        return NULL;
 
744
                          &str, &errors, &byteorder))
 
745
        return NULL;
746
746
 
747
747
    str = PyUnicode_FromObject(str);
748
748
    if (str == NULL)
749
 
        return NULL;
 
749
        return NULL;
750
750
    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
751
 
                                          PyUnicode_GET_SIZE(str),
752
 
                                          errors,
753
 
                                          byteorder),
754
 
                    PyUnicode_GET_SIZE(str));
 
751
                                          PyUnicode_GET_SIZE(str),
 
752
                                          errors,
 
753
                                          byteorder),
 
754
                    PyUnicode_GET_SIZE(str));
755
755
    Py_DECREF(str);
756
756
    return v;
757
757
}
758
758
 
759
759
static PyObject *
760
760
utf_16_le_encode(PyObject *self,
761
 
                 PyObject *args)
 
761
                 PyObject *args)
762
762
{
763
763
    PyObject *str, *v;
764
764
    const char *errors = NULL;
765
765
 
766
766
    if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
767
 
                          &str, &errors))
768
 
        return NULL;
 
767
                          &str, &errors))
 
768
        return NULL;
769
769
 
770
770
    str = PyUnicode_FromObject(str);
771
771
    if (str == NULL)
772
 
        return NULL;
 
772
        return NULL;
773
773
    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
774
 
                                             PyUnicode_GET_SIZE(str),
775
 
                                             errors,
776
 
                                             -1),
777
 
                       PyUnicode_GET_SIZE(str));
 
774
                                             PyUnicode_GET_SIZE(str),
 
775
                                             errors,
 
776
                                             -1),
 
777
                       PyUnicode_GET_SIZE(str));
778
778
    Py_DECREF(str);
779
779
    return v;
780
780
}
781
781
 
782
782
static PyObject *
783
783
utf_16_be_encode(PyObject *self,
784
 
                 PyObject *args)
 
784
                 PyObject *args)
785
785
{
786
786
    PyObject *str, *v;
787
787
    const char *errors = NULL;
788
788
 
789
789
    if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
790
 
                          &str, &errors))
791
 
        return NULL;
 
790
                          &str, &errors))
 
791
        return NULL;
792
792
 
793
793
    str = PyUnicode_FromObject(str);
794
794
    if (str == NULL)
795
 
        return NULL;
 
795
        return NULL;
796
796
    v = codec_tuple(PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(str),
797
 
                                          PyUnicode_GET_SIZE(str),
798
 
                                          errors,
799
 
                                          +1),
800
 
                    PyUnicode_GET_SIZE(str));
 
797
                                          PyUnicode_GET_SIZE(str),
 
798
                                          errors,
 
799
                                          +1),
 
800
                    PyUnicode_GET_SIZE(str));
801
801
    Py_DECREF(str);
802
802
    return v;
803
803
}
811
811
 
812
812
static PyObject *
813
813
utf_32_encode(PyObject *self,
814
 
            PyObject *args)
 
814
            PyObject *args)
815
815
{
816
816
    PyObject *str, *v;
817
817
    const char *errors = NULL;
818
818
    int byteorder = 0;
819
819
 
820
820
    if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode",
821
 
                          &str, &errors, &byteorder))
822
 
        return NULL;
 
821
                          &str, &errors, &byteorder))
 
822
        return NULL;
823
823
 
824
824
    str = PyUnicode_FromObject(str);
825
825
    if (str == NULL)
826
 
        return NULL;
 
826
        return NULL;
827
827
    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
828
 
                                          PyUnicode_GET_SIZE(str),
829
 
                                          errors,
830
 
                                          byteorder),
831
 
                    PyUnicode_GET_SIZE(str));
 
828
                                          PyUnicode_GET_SIZE(str),
 
829
                                          errors,
 
830
                                          byteorder),
 
831
                    PyUnicode_GET_SIZE(str));
832
832
    Py_DECREF(str);
833
833
    return v;
834
834
}
835
835
 
836
836
static PyObject *
837
837
utf_32_le_encode(PyObject *self,
838
 
                 PyObject *args)
 
838
                 PyObject *args)
839
839
{
840
840
    PyObject *str, *v;
841
841
    const char *errors = NULL;
842
842
 
843
843
    if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode",
844
 
                          &str, &errors))
845
 
        return NULL;
 
844
                          &str, &errors))
 
845
        return NULL;
846
846
 
847
847
    str = PyUnicode_FromObject(str);
848
848
    if (str == NULL)
849
 
        return NULL;
 
849
        return NULL;
850
850
    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
851
 
                                             PyUnicode_GET_SIZE(str),
852
 
                                             errors,
853
 
                                             -1),
854
 
                       PyUnicode_GET_SIZE(str));
 
851
                                             PyUnicode_GET_SIZE(str),
 
852
                                             errors,
 
853
                                             -1),
 
854
                       PyUnicode_GET_SIZE(str));
855
855
    Py_DECREF(str);
856
856
    return v;
857
857
}
858
858
 
859
859
static PyObject *
860
860
utf_32_be_encode(PyObject *self,
861
 
                 PyObject *args)
 
861
                 PyObject *args)
862
862
{
863
863
    PyObject *str, *v;
864
864
    const char *errors = NULL;
865
865
 
866
866
    if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode",
867
 
                          &str, &errors))
868
 
        return NULL;
 
867
                          &str, &errors))
 
868
        return NULL;
869
869
 
870
870
    str = PyUnicode_FromObject(str);
871
871
    if (str == NULL)
872
 
        return NULL;
 
872
        return NULL;
873
873
    v = codec_tuple(PyUnicode_EncodeUTF32(PyUnicode_AS_UNICODE(str),
874
 
                                          PyUnicode_GET_SIZE(str),
875
 
                                          errors,
876
 
                                          +1),
877
 
                    PyUnicode_GET_SIZE(str));
 
874
                                          PyUnicode_GET_SIZE(str),
 
875
                                          errors,
 
876
                                          +1),
 
877
                    PyUnicode_GET_SIZE(str));
878
878
    Py_DECREF(str);
879
879
    return v;
880
880
}
881
881
 
882
882
static PyObject *
883
883
unicode_escape_encode(PyObject *self,
884
 
                     PyObject *args)
 
884
                     PyObject *args)
885
885
{
886
886
    PyObject *str, *v;
887
887
    const char *errors = NULL;
888
888
 
889
889
    if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
890
 
                          &str, &errors))
891
 
        return NULL;
 
890
                          &str, &errors))
 
891
        return NULL;
892
892
 
893
893
    str = PyUnicode_FromObject(str);
894
894
    if (str == NULL)
895
 
        return NULL;
 
895
        return NULL;
896
896
    v = codec_tuple(PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(str),
897
 
                                                  PyUnicode_GET_SIZE(str)),
898
 
                    PyUnicode_GET_SIZE(str));
 
897
                                                  PyUnicode_GET_SIZE(str)),
 
898
                    PyUnicode_GET_SIZE(str));
899
899
    Py_DECREF(str);
900
900
    return v;
901
901
}
902
902
 
903
903
static PyObject *
904
904
raw_unicode_escape_encode(PyObject *self,
905
 
                        PyObject *args)
 
905
                        PyObject *args)
906
906
{
907
907
    PyObject *str, *v;
908
908
    const char *errors = NULL;
909
909
 
910
910
    if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
911
 
                          &str, &errors))
912
 
        return NULL;
 
911
                          &str, &errors))
 
912
        return NULL;
913
913
 
914
914
    str = PyUnicode_FromObject(str);
915
915
    if (str == NULL)
916
 
        return NULL;
 
916
        return NULL;
917
917
    v = codec_tuple(PyUnicode_EncodeRawUnicodeEscape(
918
 
                               PyUnicode_AS_UNICODE(str),
919
 
                               PyUnicode_GET_SIZE(str)),
920
 
                    PyUnicode_GET_SIZE(str));
 
918
                               PyUnicode_AS_UNICODE(str),
 
919
                               PyUnicode_GET_SIZE(str)),
 
920
                    PyUnicode_GET_SIZE(str));
921
921
    Py_DECREF(str);
922
922
    return v;
923
923
}
924
924
 
925
925
static PyObject *
926
926
latin_1_encode(PyObject *self,
927
 
               PyObject *args)
 
927
               PyObject *args)
928
928
{
929
929
    PyObject *str, *v;
930
930
    const char *errors = NULL;
931
931
 
932
932
    if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
933
 
                          &str, &errors))
934
 
        return NULL;
 
933
                          &str, &errors))
 
934
        return NULL;
935
935
 
936
936
    str = PyUnicode_FromObject(str);
937
937
    if (str == NULL)
938
 
        return NULL;
 
938
        return NULL;
939
939
    v = codec_tuple(PyUnicode_EncodeLatin1(
940
 
                               PyUnicode_AS_UNICODE(str),
941
 
                               PyUnicode_GET_SIZE(str),
942
 
                               errors),
943
 
                    PyUnicode_GET_SIZE(str));
 
940
                               PyUnicode_AS_UNICODE(str),
 
941
                               PyUnicode_GET_SIZE(str),
 
942
                               errors),
 
943
                    PyUnicode_GET_SIZE(str));
944
944
    Py_DECREF(str);
945
945
    return v;
946
946
}
947
947
 
948
948
static PyObject *
949
949
ascii_encode(PyObject *self,
950
 
             PyObject *args)
 
950
             PyObject *args)
951
951
{
952
952
    PyObject *str, *v;
953
953
    const char *errors = NULL;
954
954
 
955
955
    if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
956
 
                          &str, &errors))
957
 
        return NULL;
 
956
                          &str, &errors))
 
957
        return NULL;
958
958
 
959
959
    str = PyUnicode_FromObject(str);
960
960
    if (str == NULL)
961
 
        return NULL;
 
961
        return NULL;
962
962
    v = codec_tuple(PyUnicode_EncodeASCII(
963
 
                               PyUnicode_AS_UNICODE(str),
964
 
                               PyUnicode_GET_SIZE(str),
965
 
                               errors),
966
 
                    PyUnicode_GET_SIZE(str));
 
963
                               PyUnicode_AS_UNICODE(str),
 
964
                               PyUnicode_GET_SIZE(str),
 
965
                               errors),
 
966
                    PyUnicode_GET_SIZE(str));
967
967
    Py_DECREF(str);
968
968
    return v;
969
969
}
970
970
 
971
971
static PyObject *
972
972
charmap_encode(PyObject *self,
973
 
             PyObject *args)
 
973
             PyObject *args)
974
974
{
975
975
    PyObject *str, *v;
976
976
    const char *errors = NULL;
977
977
    PyObject *mapping = NULL;
978
978
 
979
979
    if (!PyArg_ParseTuple(args, "O|zO:charmap_encode",
980
 
                          &str, &errors, &mapping))
981
 
        return NULL;
 
980
                          &str, &errors, &mapping))
 
981
        return NULL;
982
982
    if (mapping == Py_None)
983
 
        mapping = NULL;
 
983
        mapping = NULL;
984
984
 
985
985
    str = PyUnicode_FromObject(str);
986
986
    if (str == NULL)
987
 
        return NULL;
 
987
        return NULL;
988
988
    v = codec_tuple(PyUnicode_EncodeCharmap(
989
 
                               PyUnicode_AS_UNICODE(str),
990
 
                               PyUnicode_GET_SIZE(str),
991
 
                               mapping,
992
 
                               errors),
993
 
                    PyUnicode_GET_SIZE(str));
 
989
                               PyUnicode_AS_UNICODE(str),
 
990
                               PyUnicode_GET_SIZE(str),
 
991
                               mapping,
 
992
                               errors),
 
993
                    PyUnicode_GET_SIZE(str));
994
994
    Py_DECREF(str);
995
995
    return v;
996
996
}
1008
1008
 
1009
1009
static PyObject *
1010
1010
mbcs_encode(PyObject *self,
1011
 
            PyObject *args)
 
1011
            PyObject *args)
1012
1012
{
1013
1013
    PyObject *str, *v;
1014
1014
    const char *errors = NULL;
1015
1015
 
1016
1016
    if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
1017
 
                          &str, &errors))
1018
 
        return NULL;
 
1017
                          &str, &errors))
 
1018
        return NULL;
1019
1019
 
1020
1020
    str = PyUnicode_FromObject(str);
1021
1021
    if (str == NULL)
1022
 
        return NULL;
 
1022
        return NULL;
1023
1023
    v = codec_tuple(PyUnicode_EncodeMBCS(
1024
 
                               PyUnicode_AS_UNICODE(str),
1025
 
                               PyUnicode_GET_SIZE(str),
1026
 
                               errors),
1027
 
                    PyUnicode_GET_SIZE(str));
 
1024
                               PyUnicode_AS_UNICODE(str),
 
1025
                               PyUnicode_GET_SIZE(str),
 
1026
                               errors),
 
1027
                    PyUnicode_GET_SIZE(str));
1028
1028
    Py_DECREF(str);
1029
1029
    return v;
1030
1030
}
1048
1048
    PyObject *handler;
1049
1049
 
1050
1050
    if (!PyArg_ParseTuple(args, "sO:register_error",
1051
 
                          &name, &handler))
1052
 
        return NULL;
 
1051
                          &name, &handler))
 
1052
        return NULL;
1053
1053
    if (PyCodec_RegisterError(name, handler))
1054
1054
        return NULL;
1055
1055
    Py_RETURN_NONE;
1066
1066
    const char *name;
1067
1067
 
1068
1068
    if (!PyArg_ParseTuple(args, "s:lookup_error",
1069
 
                          &name))
1070
 
        return NULL;
 
1069
                          &name))
 
1070
        return NULL;
1071
1071
    return PyCodec_LookupError(name);
1072
1072
}
1073
1073
 
1074
1074
/* --- Module API --------------------------------------------------------- */
1075
1075
 
1076
1076
static PyMethodDef _codecs_functions[] = {
1077
 
    {"register",                codec_register,                 METH_O,
 
1077
    {"register",                codec_register,                 METH_O,
1078
1078
        register__doc__},
1079
 
    {"lookup",                  codec_lookup,                   METH_VARARGS,
 
1079
    {"lookup",                  codec_lookup,                   METH_VARARGS,
1080
1080
        lookup__doc__},
1081
 
    {"encode",                  codec_encode,                   METH_VARARGS,
1082
 
        encode__doc__},
1083
 
    {"decode",                  codec_decode,                   METH_VARARGS,
1084
 
        decode__doc__},
1085
 
    {"escape_encode",           escape_encode,                  METH_VARARGS},
1086
 
    {"escape_decode",           escape_decode,                  METH_VARARGS},
1087
 
    {"utf_8_encode",            utf_8_encode,                   METH_VARARGS},
1088
 
    {"utf_8_decode",            utf_8_decode,                   METH_VARARGS},
1089
 
    {"utf_7_encode",            utf_7_encode,                   METH_VARARGS},
1090
 
    {"utf_7_decode",            utf_7_decode,                   METH_VARARGS},
1091
 
    {"utf_16_encode",           utf_16_encode,                  METH_VARARGS},
1092
 
    {"utf_16_le_encode",        utf_16_le_encode,               METH_VARARGS},
1093
 
    {"utf_16_be_encode",        utf_16_be_encode,               METH_VARARGS},
1094
 
    {"utf_16_decode",           utf_16_decode,                  METH_VARARGS},
1095
 
    {"utf_16_le_decode",        utf_16_le_decode,               METH_VARARGS},
1096
 
    {"utf_16_be_decode",        utf_16_be_decode,               METH_VARARGS},
1097
 
    {"utf_16_ex_decode",        utf_16_ex_decode,               METH_VARARGS},
1098
 
    {"utf_32_encode",           utf_32_encode,                  METH_VARARGS},
1099
 
    {"utf_32_le_encode",        utf_32_le_encode,               METH_VARARGS},
1100
 
    {"utf_32_be_encode",        utf_32_be_encode,               METH_VARARGS},
1101
 
    {"utf_32_decode",           utf_32_decode,                  METH_VARARGS},
1102
 
    {"utf_32_le_decode",        utf_32_le_decode,               METH_VARARGS},
1103
 
    {"utf_32_be_decode",        utf_32_be_decode,               METH_VARARGS},
1104
 
    {"utf_32_ex_decode",        utf_32_ex_decode,               METH_VARARGS},
1105
 
    {"unicode_escape_encode",   unicode_escape_encode,          METH_VARARGS},
1106
 
    {"unicode_escape_decode",   unicode_escape_decode,          METH_VARARGS},
1107
 
    {"unicode_internal_encode", unicode_internal_encode,        METH_VARARGS},
1108
 
    {"unicode_internal_decode", unicode_internal_decode,        METH_VARARGS},
1109
 
    {"raw_unicode_escape_encode", raw_unicode_escape_encode,    METH_VARARGS},
1110
 
    {"raw_unicode_escape_decode", raw_unicode_escape_decode,    METH_VARARGS},
1111
 
    {"latin_1_encode",          latin_1_encode,                 METH_VARARGS},
1112
 
    {"latin_1_decode",          latin_1_decode,                 METH_VARARGS},
1113
 
    {"ascii_encode",            ascii_encode,                   METH_VARARGS},
1114
 
    {"ascii_decode",            ascii_decode,                   METH_VARARGS},
1115
 
    {"charmap_encode",          charmap_encode,                 METH_VARARGS},
1116
 
    {"charmap_decode",          charmap_decode,                 METH_VARARGS},
1117
 
    {"charmap_build",           charmap_build,                  METH_VARARGS},
1118
 
    {"readbuffer_encode",       readbuffer_encode,              METH_VARARGS},
1119
 
    {"charbuffer_encode",       charbuffer_encode,              METH_VARARGS},
 
1081
    {"encode",                  codec_encode,                   METH_VARARGS,
 
1082
        encode__doc__},
 
1083
    {"decode",                  codec_decode,                   METH_VARARGS,
 
1084
        decode__doc__},
 
1085
    {"escape_encode",           escape_encode,                  METH_VARARGS},
 
1086
    {"escape_decode",           escape_decode,                  METH_VARARGS},
 
1087
    {"utf_8_encode",            utf_8_encode,                   METH_VARARGS},
 
1088
    {"utf_8_decode",            utf_8_decode,                   METH_VARARGS},
 
1089
    {"utf_7_encode",            utf_7_encode,                   METH_VARARGS},
 
1090
    {"utf_7_decode",            utf_7_decode,                   METH_VARARGS},
 
1091
    {"utf_16_encode",           utf_16_encode,                  METH_VARARGS},
 
1092
    {"utf_16_le_encode",        utf_16_le_encode,               METH_VARARGS},
 
1093
    {"utf_16_be_encode",        utf_16_be_encode,               METH_VARARGS},
 
1094
    {"utf_16_decode",           utf_16_decode,                  METH_VARARGS},
 
1095
    {"utf_16_le_decode",        utf_16_le_decode,               METH_VARARGS},
 
1096
    {"utf_16_be_decode",        utf_16_be_decode,               METH_VARARGS},
 
1097
    {"utf_16_ex_decode",        utf_16_ex_decode,               METH_VARARGS},
 
1098
    {"utf_32_encode",           utf_32_encode,                  METH_VARARGS},
 
1099
    {"utf_32_le_encode",        utf_32_le_encode,               METH_VARARGS},
 
1100
    {"utf_32_be_encode",        utf_32_be_encode,               METH_VARARGS},
 
1101
    {"utf_32_decode",           utf_32_decode,                  METH_VARARGS},
 
1102
    {"utf_32_le_decode",        utf_32_le_decode,               METH_VARARGS},
 
1103
    {"utf_32_be_decode",        utf_32_be_decode,               METH_VARARGS},
 
1104
    {"utf_32_ex_decode",        utf_32_ex_decode,               METH_VARARGS},
 
1105
    {"unicode_escape_encode",   unicode_escape_encode,          METH_VARARGS},
 
1106
    {"unicode_escape_decode",   unicode_escape_decode,          METH_VARARGS},
 
1107
    {"unicode_internal_encode", unicode_internal_encode,        METH_VARARGS},
 
1108
    {"unicode_internal_decode", unicode_internal_decode,        METH_VARARGS},
 
1109
    {"raw_unicode_escape_encode", raw_unicode_escape_encode,    METH_VARARGS},
 
1110
    {"raw_unicode_escape_decode", raw_unicode_escape_decode,    METH_VARARGS},
 
1111
    {"latin_1_encode",          latin_1_encode,                 METH_VARARGS},
 
1112
    {"latin_1_decode",          latin_1_decode,                 METH_VARARGS},
 
1113
    {"ascii_encode",            ascii_encode,                   METH_VARARGS},
 
1114
    {"ascii_decode",            ascii_decode,                   METH_VARARGS},
 
1115
    {"charmap_encode",          charmap_encode,                 METH_VARARGS},
 
1116
    {"charmap_decode",          charmap_decode,                 METH_VARARGS},
 
1117
    {"charmap_build",           charmap_build,                  METH_VARARGS},
 
1118
    {"readbuffer_encode",       readbuffer_encode,              METH_VARARGS},
 
1119
    {"charbuffer_encode",       charbuffer_encode,              METH_VARARGS},
1120
1120
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
1121
 
    {"mbcs_encode",             mbcs_encode,                    METH_VARARGS},
1122
 
    {"mbcs_decode",             mbcs_decode,                    METH_VARARGS},
 
1121
    {"mbcs_encode",             mbcs_encode,                    METH_VARARGS},
 
1122
    {"mbcs_decode",             mbcs_decode,                    METH_VARARGS},
1123
1123
#endif
1124
 
    {"register_error",          register_error,                 METH_VARARGS,
 
1124
    {"register_error",          register_error,                 METH_VARARGS,
1125
1125
        register_error__doc__},
1126
 
    {"lookup_error",            lookup_error,                   METH_VARARGS,
 
1126
    {"lookup_error",            lookup_error,                   METH_VARARGS,
1127
1127
        lookup_error__doc__},
1128
 
    {NULL, NULL}                /* sentinel */
 
1128
    {NULL, NULL}                /* sentinel */
1129
1129
};
1130
1130
 
1131
1131
static struct PyModuleDef codecsmodule = {
1132
 
        PyModuleDef_HEAD_INIT,
1133
 
        "_codecs",
1134
 
        NULL,
1135
 
        -1,
1136
 
        _codecs_functions,
1137
 
        NULL,
1138
 
        NULL,
1139
 
        NULL,
1140
 
        NULL
 
1132
        PyModuleDef_HEAD_INIT,
 
1133
        "_codecs",
 
1134
        NULL,
 
1135
        -1,
 
1136
        _codecs_functions,
 
1137
        NULL,
 
1138
        NULL,
 
1139
        NULL,
 
1140
        NULL
1141
1141
};
1142
1142
 
1143
1143
PyMODINIT_FUNC
1144
1144
PyInit__codecs(void)
1145
1145
{
1146
 
        return PyModule_Create(&codecsmodule);
 
1146
        return PyModule_Create(&codecsmodule);
1147
1147
}