You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.8 KiB

  1. #ifndef Py_CODECREGISTRY_H
  2. #define Py_CODECREGISTRY_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* ------------------------------------------------------------------------
  7. Python Codec Registry and support functions
  8. Written by Marc-Andre Lemburg (mal@lemburg.com).
  9. Copyright (c) Corporation for National Research Initiatives.
  10. ------------------------------------------------------------------------ */
  11. /* Register a new codec search function.
  12. As side effect, this tries to load the encodings package, if not
  13. yet done, to make sure that it is always first in the list of
  14. search functions.
  15. The search_function's refcount is incremented by this function. */
  16. PyAPI_FUNC(int) PyCodec_Register(
  17. PyObject *search_function
  18. );
  19. /* Codec registry lookup API.
  20. Looks up the given encoding and returns a CodecInfo object with
  21. function attributes which implement the different aspects of
  22. processing the encoding.
  23. The encoding string is looked up converted to all lower-case
  24. characters. This makes encodings looked up through this mechanism
  25. effectively case-insensitive.
  26. If no codec is found, a KeyError is set and NULL returned.
  27. As side effect, this tries to load the encodings package, if not
  28. yet done. This is part of the lazy load strategy for the encodings
  29. package.
  30. */
  31. #ifndef Py_LIMITED_API
  32. PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
  33. const char *encoding
  34. );
  35. #endif
  36. /* Codec registry encoding check API.
  37. Returns 1/0 depending on whether there is a registered codec for
  38. the given encoding.
  39. */
  40. PyAPI_FUNC(int) PyCodec_KnownEncoding(
  41. const char *encoding
  42. );
  43. /* Generic codec based encoding API.
  44. object is passed through the encoder function found for the given
  45. encoding using the error handling method defined by errors. errors
  46. may be NULL to use the default method defined for the codec.
  47. Raises a LookupError in case no encoder can be found.
  48. */
  49. PyAPI_FUNC(PyObject *) PyCodec_Encode(
  50. PyObject *object,
  51. const char *encoding,
  52. const char *errors
  53. );
  54. /* Generic codec based decoding API.
  55. object is passed through the decoder function found for the given
  56. encoding using the error handling method defined by errors. errors
  57. may be NULL to use the default method defined for the codec.
  58. Raises a LookupError in case no encoder can be found.
  59. */
  60. PyAPI_FUNC(PyObject *) PyCodec_Decode(
  61. PyObject *object,
  62. const char *encoding,
  63. const char *errors
  64. );
  65. #ifndef PY_LIMITED_API
  66. /* Text codec specific encoding and decoding API.
  67. Checks the encoding against a list of codecs which do not
  68. implement a str<->bytes encoding before attempting the
  69. operation.
  70. Please note that these APIs are internal and should not
  71. be used in Python C extensions.
  72. */
  73. PyAPI_FUNC(PyObject *) _PyCodec_EncodeText(
  74. PyObject *object,
  75. const char *encoding,
  76. const char *errors
  77. );
  78. PyAPI_FUNC(PyObject *) _PyCodec_DecodeText(
  79. PyObject *object,
  80. const char *encoding,
  81. const char *errors
  82. );
  83. #endif
  84. /* --- Codec Lookup APIs --------------------------------------------------
  85. All APIs return a codec object with incremented refcount and are
  86. based on _PyCodec_Lookup(). The same comments w/r to the encoding
  87. name also apply to these APIs.
  88. */
  89. /* Get an encoder function for the given encoding. */
  90. PyAPI_FUNC(PyObject *) PyCodec_Encoder(
  91. const char *encoding
  92. );
  93. /* Get a decoder function for the given encoding. */
  94. PyAPI_FUNC(PyObject *) PyCodec_Decoder(
  95. const char *encoding
  96. );
  97. /* Get a IncrementalEncoder object for the given encoding. */
  98. PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
  99. const char *encoding,
  100. const char *errors
  101. );
  102. /* Get a IncrementalDecoder object function for the given encoding. */
  103. PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
  104. const char *encoding,
  105. const char *errors
  106. );
  107. /* Get a StreamReader factory function for the given encoding. */
  108. PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
  109. const char *encoding,
  110. PyObject *stream,
  111. const char *errors
  112. );
  113. /* Get a StreamWriter factory function for the given encoding. */
  114. PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
  115. const char *encoding,
  116. PyObject *stream,
  117. const char *errors
  118. );
  119. /* Unicode encoding error handling callback registry API */
  120. /* Register the error handling callback function error under the given
  121. name. This function will be called by the codec when it encounters
  122. unencodable characters/undecodable bytes and doesn't know the
  123. callback name, when name is specified as the error parameter
  124. in the call to the encode/decode function.
  125. Return 0 on success, -1 on error */
  126. PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
  127. /* Lookup the error handling callback function registered under the given
  128. name. As a special case NULL can be passed, in which case
  129. the error handling callback for "strict" will be returned. */
  130. PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
  131. /* raise exc as an exception */
  132. PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
  133. /* ignore the unicode error, skipping the faulty input */
  134. PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
  135. /* replace the unicode encode error with ? or U+FFFD */
  136. PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
  137. /* replace the unicode encode error with XML character references */
  138. PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
  139. /* replace the unicode encode error with backslash escapes (\x, \u and \U) */
  140. PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
  141. PyAPI_DATA(const char *) Py_hexdigits;
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* !Py_CODECREGISTRY_H */