• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_INTERNAL_CODECS_H
2 #define Py_INTERNAL_CODECS_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #ifndef Py_BUILD_CORE
8 #  error "this header requires Py_BUILD_CORE define"
9 #endif
10 
11 #include "pycore_lock.h"          // PyMutex
12 
13 /* Initialize codecs-related state for the given interpreter, including
14    registering the first codec search function. Must be called before any other
15    PyCodec-related functions, and while only one thread is active. */
16 extern PyStatus _PyCodec_InitRegistry(PyInterpreterState *interp);
17 
18 /* Finalize codecs-related state for the given interpreter. No PyCodec-related
19    functions other than PyCodec_Unregister() may be called after this. */
20 extern void _PyCodec_Fini(PyInterpreterState *interp);
21 
22 extern PyObject* _PyCodec_Lookup(const char *encoding);
23 
24 /* Text codec specific encoding and decoding API.
25 
26    Checks the encoding against a list of codecs which do not
27    implement a str<->bytes encoding before attempting the
28    operation.
29 
30    Please note that these APIs are internal and should not
31    be used in Python C extensions.
32 
33    XXX (ncoghlan): should we make these, or something like them, public
34    in Python 3.5+?
35 
36  */
37 extern PyObject* _PyCodec_LookupTextEncoding(
38    const char *encoding,
39    const char *alternate_command);
40 
41 extern PyObject* _PyCodec_EncodeText(
42    PyObject *object,
43    const char *encoding,
44    const char *errors);
45 
46 extern PyObject* _PyCodec_DecodeText(
47    PyObject *object,
48    const char *encoding,
49    const char *errors);
50 
51 /* These two aren't actually text encoding specific, but _io.TextIOWrapper
52  * is the only current API consumer.
53  */
54 extern PyObject* _PyCodecInfo_GetIncrementalDecoder(
55    PyObject *codec_info,
56    const char *errors);
57 
58 extern PyObject* _PyCodecInfo_GetIncrementalEncoder(
59    PyObject *codec_info,
60    const char *errors);
61 
62 // Per-interpreter state used by codecs.c.
63 struct codecs_state {
64     // A list of callable objects used to search for codecs.
65     PyObject *search_path;
66 
67     // A dict mapping codec names to codecs returned from a callable in
68     // search_path.
69     PyObject *search_cache;
70 
71     // A dict mapping error handling strategies to functions to implement them.
72     PyObject *error_registry;
73 
74 #ifdef Py_GIL_DISABLED
75     // Used to safely delete a specific item from search_path.
76     PyMutex search_path_mutex;
77 #endif
78 
79     // Whether or not the rest of the state is initialized.
80     int initialized;
81 };
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 #endif /* !Py_INTERNAL_CODECS_H */
87