codecs.pxd 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. cdef extern from "Python.h":
  2. ###########################################################################
  3. # Codec registry and support functions
  4. ###########################################################################
  5. int PyCodec_Register(object search_function)
  6. # Register a new codec search function.
  7. # As side effect, this tries to load the encodings package, if not yet
  8. # done, to make sure that it is always first in the list of search
  9. # functions.
  10. int PyCodec_KnownEncoding(const char *encoding)
  11. # Return 1 or 0 depending on whether there is a registered codec for the
  12. # given encoding. This function always succeeds.
  13. object PyCodec_Encode(object o, const char *encoding, const char *errors)
  14. # Return value: New reference.
  15. # Generic codec based encoding API.
  16. # o is passed through the encoder function found for the given encoding
  17. # using the error handling method defined by errors. errors may be NULL
  18. # to use the default method defined for the codec. Raises a LookupError
  19. # if no encoder can be found.
  20. object PyCodec_Decode(object o, const char *encoding, const char *errors)
  21. # Return value: New reference.
  22. # Generic codec based decoding API.
  23. # o is passed through the decoder function found for the given encoding
  24. # using the error handling method defined by errors. errors may be NULL
  25. # to use the default method defined for the codec. Raises a LookupError
  26. # if no encoder can be found.
  27. # Codec lookup API
  28. # In the following functions, the encoding string is looked up converted
  29. # to all lower-case characters, which makes encodings looked up through
  30. # this mechanism effectively case-insensitive. If no codec is found, a
  31. # KeyError is set and NULL returned.
  32. object PyCodec_Encoder(const char *encoding)
  33. # Return value: New reference.
  34. # Get an encoder function for the given encoding.
  35. object PyCodec_Decoder(const char *encoding)
  36. # Return value: New reference.
  37. # Get a decoder function for the given encoding.
  38. object PyCodec_IncrementalEncoder(const char *encoding, const char *errors)
  39. # Return value: New reference.
  40. # Get an IncrementalEncoder object for the given encoding.
  41. object PyCodec_IncrementalDecoder(const char *encoding, const char *errors)
  42. # Return value: New reference.
  43. # Get an IncrementalDecoder object for the given encoding.
  44. object PyCodec_StreamReader(const char *encoding, object stream, const char *errors)
  45. # Return value: New reference.
  46. # Get a StreamReader factory function for the given encoding.
  47. object PyCodec_StreamWriter(const char *encoding, object stream, const char *errors)
  48. # Return value: New reference.
  49. # Get a StreamWriter factory function for the given encoding.
  50. # Registry API for Unicode encoding error handlers
  51. int PyCodec_RegisterError(const char *name, object error) except? -1
  52. # Register the error handling callback function error under the given
  53. # name. This callback function will be called by a codec when it
  54. # encounters unencodable characters/undecodable bytes and name is
  55. # specified as the error parameter in the call to the encode/decode
  56. # function.
  57. # The callback gets a single argument, an instance of
  58. # UnicodeEncodeError, UnicodeDecodeError or UnicodeTranslateError that
  59. # holds information about the problematic sequence of characters or bytes
  60. # and their offset in the original string (see Unicode Exception Objects
  61. # for functions to extract this information). The callback must either
  62. # raise the given exception, or return a two-item tuple containing the
  63. # replacement for the problematic sequence, and an integer giving the
  64. # offset in the original string at which encoding/decoding should be
  65. # resumed.
  66. # Return 0 on success, -1 on error.
  67. object PyCodec_LookupError(const char *name)
  68. # Return value: New reference.
  69. # Lookup the error handling callback function registered under name. As a
  70. # special case NULL can be passed, in which case the error handling
  71. # callback for "strict" will be returned.
  72. object PyCodec_StrictErrors(object exc)
  73. # Return value: Always NULL.
  74. # Raise exc as an exception.
  75. object PyCodec_IgnoreErrors(object exc)
  76. # Return value: New reference.
  77. # Ignore the unicode error, skipping the faulty input.
  78. object PyCodec_ReplaceErrors(object exc)
  79. # Return value: New reference.
  80. # Replace the unicode encode error with "?" or "U+FFFD".
  81. object PyCodec_XMLCharRefReplaceErrors(object exc)
  82. # Return value: New reference.
  83. # Replace the unicode encode error with XML character references.
  84. object PyCodec_BackslashReplaceErrors(object exc)
  85. # Return value: New reference.
  86. # Replace the unicode encode error with backslash escapes ("\x", "\u"
  87. # and "\U").
  88. object PyCodec_NameReplaceErrors(object exc)
  89. # Return value: New reference.
  90. # Replace the unicode encode error with "\N{...}" escapes.
  91. # New in version 3.5.