Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:45

0001 #ifndef Py_INTERNAL_CODECS_H
0002 #define Py_INTERNAL_CODECS_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 #include "pycore_lock.h"          // PyMutex
0012 
0013 /* Initialize codecs-related state for the given interpreter, including
0014    registering the first codec search function. Must be called before any other
0015    PyCodec-related functions, and while only one thread is active. */
0016 extern PyStatus _PyCodec_InitRegistry(PyInterpreterState *interp);
0017 
0018 /* Finalize codecs-related state for the given interpreter. No PyCodec-related
0019    functions other than PyCodec_Unregister() may be called after this. */
0020 extern void _PyCodec_Fini(PyInterpreterState *interp);
0021 
0022 extern PyObject* _PyCodec_Lookup(const char *encoding);
0023 
0024 /* Text codec specific encoding and decoding API.
0025 
0026    Checks the encoding against a list of codecs which do not
0027    implement a str<->bytes encoding before attempting the
0028    operation.
0029 
0030    Please note that these APIs are internal and should not
0031    be used in Python C extensions.
0032 
0033    XXX (ncoghlan): should we make these, or something like them, public
0034    in Python 3.5+?
0035 
0036  */
0037 extern PyObject* _PyCodec_LookupTextEncoding(
0038    const char *encoding,
0039    const char *alternate_command);
0040 
0041 extern PyObject* _PyCodec_EncodeText(
0042    PyObject *object,
0043    const char *encoding,
0044    const char *errors);
0045 
0046 extern PyObject* _PyCodec_DecodeText(
0047    PyObject *object,
0048    const char *encoding,
0049    const char *errors);
0050 
0051 /* These two aren't actually text encoding specific, but _io.TextIOWrapper
0052  * is the only current API consumer.
0053  */
0054 extern PyObject* _PyCodecInfo_GetIncrementalDecoder(
0055    PyObject *codec_info,
0056    const char *errors);
0057 
0058 extern PyObject* _PyCodecInfo_GetIncrementalEncoder(
0059    PyObject *codec_info,
0060    const char *errors);
0061 
0062 // Per-interpreter state used by codecs.c.
0063 struct codecs_state {
0064     // A list of callable objects used to search for codecs.
0065     PyObject *search_path;
0066 
0067     // A dict mapping codec names to codecs returned from a callable in
0068     // search_path.
0069     PyObject *search_cache;
0070 
0071     // A dict mapping error handling strategies to functions to implement them.
0072     PyObject *error_registry;
0073 
0074 #ifdef Py_GIL_DISABLED
0075     // Used to safely delete a specific item from search_path.
0076     PyMutex search_path_mutex;
0077 #endif
0078 
0079     // Whether or not the rest of the state is initialized.
0080     int initialized;
0081 };
0082 
0083 #ifdef __cplusplus
0084 }
0085 #endif
0086 #endif /* !Py_INTERNAL_CODECS_H */