|
15 | 15 |
|
16 | 16 | ------------------------------------------------------------------------ */ |
17 | 17 |
|
| 18 | +/* Register a new codec search function. |
| 19 | +
|
| 20 | + As side effect, this tries to load the encodings package, if not |
| 21 | + yet done, to make sure that it is always first in the list of |
| 22 | + search functions. |
| 23 | +
|
| 24 | + The search_function's refcount is incremented by this function. */ |
| 25 | + |
18 | 26 | extern DL_IMPORT(int) PyCodec_Register( |
19 | 27 | PyObject *search_function |
20 | 28 | ); |
21 | 29 |
|
| 30 | +/* Codec register lookup API. |
| 31 | +
|
| 32 | + Looks up the given encoding and returns a tuple (encoder, decoder, |
| 33 | + stream reader, stream writer) of functions which implement the |
| 34 | + different aspects of processing the encoding. |
| 35 | +
|
| 36 | + The encoding string is looked up converted to all lower-case |
| 37 | + characters. This makes encodings looked up through this mechanism |
| 38 | + effectively case-insensitive. |
| 39 | +
|
| 40 | + If no codec is found, a KeyError is set and NULL returned. |
| 41 | +
|
| 42 | + As side effect, this tries to load the encodings package, if not |
| 43 | + yet done. This is part of the lazy load strategy for the encodings |
| 44 | + package. |
| 45 | +
|
| 46 | + */ |
| 47 | + |
22 | 48 | extern DL_IMPORT(PyObject *) _PyCodec_Lookup( |
23 | 49 | const char *encoding |
24 | 50 | ); |
25 | 51 |
|
| 52 | +/* Generic codec based encoding API. |
| 53 | +
|
| 54 | + object is passed through the encoder function found for the given |
| 55 | + encoding using the error handling method defined by errors. errors |
| 56 | + may be NULL to use the default method defined for the codec. |
| 57 | + |
| 58 | + Raises a LookupError in case no encoder can be found. |
| 59 | +
|
| 60 | + */ |
| 61 | + |
| 62 | +extern DL_IMPORT(PyObject *) PyCodec_Encode( |
| 63 | + PyObject *object, |
| 64 | + const char *encoding, |
| 65 | + const char *errors |
| 66 | + ); |
| 67 | + |
| 68 | +/* Generic codec based decoding API. |
| 69 | +
|
| 70 | + object is passed through the decoder function found for the given |
| 71 | + encoding using the error handling method defined by errors. errors |
| 72 | + may be NULL to use the default method defined for the codec. |
| 73 | + |
| 74 | + Raises a LookupError in case no encoder can be found. |
| 75 | +
|
| 76 | + */ |
| 77 | + |
| 78 | +extern DL_IMPORT(PyObject *) PyCodec_Decode( |
| 79 | + PyObject *object, |
| 80 | + const char *encoding, |
| 81 | + const char *errors |
| 82 | + ); |
| 83 | + |
| 84 | +/* --- Codec Lookup APIs -------------------------------------------------- |
| 85 | +
|
| 86 | + All APIs return a codec object with incremented refcount and are |
| 87 | + based on _PyCodec_Lookup(). The same comments w/r to the encoding |
| 88 | + name also apply to these APIs. |
| 89 | +
|
| 90 | +*/ |
| 91 | + |
| 92 | +/* Get an encoder function for the given encoding. */ |
| 93 | + |
26 | 94 | extern DL_IMPORT(PyObject *) PyCodec_Encoder( |
27 | 95 | const char *encoding |
28 | 96 | ); |
29 | 97 |
|
| 98 | +/* Get a decoder function for the given encoding. */ |
| 99 | + |
30 | 100 | extern DL_IMPORT(PyObject *) PyCodec_Decoder( |
31 | 101 | const char *encoding |
32 | 102 | ); |
33 | 103 |
|
| 104 | +/* Get a StreamReader factory function for the given encoding. */ |
| 105 | + |
34 | 106 | extern DL_IMPORT(PyObject *) PyCodec_StreamReader( |
35 | 107 | const char *encoding, |
36 | 108 | PyObject *stream, |
37 | 109 | const char *errors |
38 | 110 | ); |
39 | 111 |
|
40 | | -extern DL_IMPORT(PyObject *) PyCodec_Encode( |
41 | | - PyObject *object, |
42 | | - const char *encoding, |
43 | | - const char *errors |
44 | | - ); |
| 112 | +/* Get a StreamWriter factory function for the given encoding. */ |
45 | 113 |
|
46 | | -extern DL_IMPORT(PyObject *) PyCodec_Decode( |
47 | | - PyObject *object, |
| 114 | +extern DL_IMPORT(PyObject *) PyCodec_StreamWriter( |
48 | 115 | const char *encoding, |
| 116 | + PyObject *stream, |
49 | 117 | const char *errors |
50 | 118 | ); |
51 | 119 |
|
|
0 commit comments