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.

180 lines
5.1 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. /* --- Codec Lookup APIs --------------------------------------------------
  66. All APIs return a codec object with incremented refcount and are
  67. based on _PyCodec_Lookup(). The same comments w/r to the encoding
  68. name also apply to these APIs.
  69. */
  70. /* Get an encoder function for the given encoding. */
  71. PyAPI_FUNC(PyObject *) PyCodec_Encoder(
  72. const char *encoding
  73. );
  74. /* Get a decoder function for the given encoding. */
  75. PyAPI_FUNC(PyObject *) PyCodec_Decoder(
  76. const char *encoding
  77. );
  78. /* Get a IncrementalEncoder object for the given encoding. */
  79. PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
  80. const char *encoding,
  81. const char *errors
  82. );
  83. /* Get a IncrementalDecoder object function for the given encoding. */
  84. PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
  85. const char *encoding,
  86. const char *errors
  87. );
  88. /* Get a StreamReader factory function for the given encoding. */
  89. PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
  90. const char *encoding,
  91. PyObject *stream,
  92. const char *errors
  93. );
  94. /* Get a StreamWriter factory function for the given encoding. */
  95. PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
  96. const char *encoding,
  97. PyObject *stream,
  98. const char *errors
  99. );
  100. /* Unicode encoding error handling callback registry API */
  101. /* Register the error handling callback function error under the given
  102. name. This function will be called by the codec when it encounters
  103. unencodable characters/undecodable bytes and doesn't know the
  104. callback name, when name is specified as the error parameter
  105. in the call to the encode/decode function.
  106. Return 0 on success, -1 on error */
  107. PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
  108. /* Lookup the error handling callback function registered under the given
  109. name. As a special case NULL can be passed, in which case
  110. the error handling callback for "strict" will be returned. */
  111. PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
  112. /* raise exc as an exception */
  113. PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
  114. /* ignore the unicode error, skipping the faulty input */
  115. PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
  116. /* replace the unicode encode error with ? or U+FFFD */
  117. PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
  118. /* replace the unicode encode error with XML character references */
  119. PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
  120. /* replace the unicode encode error with backslash escapes (\x, \u and \U) */
  121. PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif /* !Py_CODECREGISTRY_H */