15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)from cpython.ref cimport PyObject 25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)cdef extern from "Python.h": 45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ctypedef struct va_list 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ############################################################################ 75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # 7.3.1 String Objects 85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ############################################################################ 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # These functions raise TypeError when expecting a string 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # parameter and are called with a non-string parameter. 125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # PyStringObject 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # This subtype of PyObject represents a Python bytes object. 145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # PyTypeObject PyBytes_Type 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # This instance of PyTypeObject represents the Python bytes type; 165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # it is the same object as bytes and types.BytesType in the Python 175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # layer. 185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bint PyBytes_Check(object o) 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return true if the object o is a string object or an instance of 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # a subtype of the string type. 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bint PyBytes_CheckExact(object o) 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return true if the object o is a string object, but not an instance of a subtype of the string type. 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_FromString(char *v) 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return a new string object with the value v on success, and NULL 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # on failure. The parameter v must not be NULL; it will not be 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # checked. 315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_FromStringAndSize(char *v, Py_ssize_t len) 335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return a new string object with the value v and length len on 355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # success, and NULL on failure. If v is NULL, the contents of the 365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # string are uninitialized. 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_FromFormat(char *format, ...) 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Take a C printf()-style format string and a variable number of 415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # arguments, calculate the size of the resulting Python string and 425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # return a string with the values formatted into it. The variable 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # arguments must be C types and must correspond exactly to the 445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # format characters in the format string. The following format 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # characters are allowed: 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Format Characters Type Comment 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %% n/a The literal % character. 485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %c int A single character, represented as an C int. 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %d int Exactly equivalent to printf("%d"). 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %u unsigned int Exactly equivalent to printf("%u"). 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %ld long Exactly equivalent to printf("%ld"). 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %lu unsigned long Exactly equivalent to printf("%lu"). 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %zd Py_ssize_t Exactly equivalent to printf("%zd"). 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %zu size_t Exactly equivalent to printf("%zu"). 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %i int Exactly equivalent to printf("%i"). 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %x int Exactly equivalent to printf("%x"). 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %s char* A null-terminated C character array. 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # %p void* The hex representation of a C pointer. 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Mostly equivalent to printf("%p") except that it is guaranteed to 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # start with the literal 0x regardless of what the platform's printf 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # yields. 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # An unrecognized format character causes all the rest of the 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # format string to be copied as-is to the result string, and any 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # extra arguments discarded. 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_FromFormatV(char *format, va_list vargs) 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Identical to PyBytes_FromFormat() except that it takes exactly two arguments. 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Py_ssize_t PyBytes_Size(object string) except -1 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return the length of the string in string object string. 735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Py_ssize_t PyBytes_GET_SIZE(object string) 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Macro form of PyBytes_Size() but without error checking. 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) char* PyBytes_AsString(object string) except NULL 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return a NUL-terminated representation of the contents of 795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # string. The pointer refers to the internal buffer of string, not 805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # a copy. The data must not be modified in any way, unless the 815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # string was just created using PyBytes_FromStringAndSize(NULL, 825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # size). It must not be deallocated. If string is a Unicode 835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object, this function computes the default encoding of string 845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # and operates on that. If string is not a string object at all, 855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # PyBytes_AsString() returns NULL and raises TypeError. 865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) char* PyBytes_AS_STRING(object string) 885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Macro form of PyBytes_AsString() but without error 895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # checking. Only string objects are supported; no Unicode objects 905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # should be passed. 915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int PyBytes_AsStringAndSize(object obj, char **buffer, Py_ssize_t *length) except -1 935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return a NULL-terminated representation of the contents of the 945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object obj through the output variables buffer and length. 955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # 965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # The function accepts both string and Unicode objects as 975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # input. For Unicode objects it returns the default encoded 985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # version of the object. If length is NULL, the resulting buffer 995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # may not contain NUL characters; if it does, the function returns 1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # -1 and a TypeError is raised. 1015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # The buffer refers to an internal string buffer of obj, not a 1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # copy. The data must not be modified in any way, unless the 1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # string was just created using PyBytes_FromStringAndSize(NULL, 1055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # size). It must not be deallocated. If string is a Unicode 1065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object, this function computes the default encoding of string 1075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # and operates on that. If string is not a string object at all, 1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # PyBytes_AsStringAndSize() returns -1 and raises TypeError. 1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PyBytes_Concat(PyObject **string, object newpart) 1115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Create a new string object in *string containing the contents of 1125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # newpart appended to string; the caller will own the new 1135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # reference. The reference to the old value of string will be 1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # stolen. If the new string cannot be created, the old reference 1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # to string will still be discarded and the value of *string will 1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # be set to NULL; the appropriate exception will be set. 1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PyBytes_ConcatAndDel(PyObject **string, object newpart) 1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Create a new string object in *string containing the contents of 1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # newpart appended to string. This version decrements the 1215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # reference count of newpart. 1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int _PyBytes_Resize(PyObject **string, Py_ssize_t newsize) except -1 1245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # A way to resize a string object even though it is 1255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # ``immutable''. Only use this to build up a brand new string 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object; don't use this if the string may already be known in 1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # other parts of the code. It is an error to call this function if 1285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # the refcount on the input string object is not one. Pass the 1295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # address of an existing string object as an lvalue (it may be 1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # written into), and the new size desired. On success, *string 1315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # holds the resized string object and 0 is returned; the address 1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # in *string may differ from its input value. If the reallocation 1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # fails, the original string object at *string is deallocated, 1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # *string is set to NULL, a memory exception is set, and -1 is 1355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # returned. 1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_Format(object format, object args) 1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. Return a new string object from 1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # format and args. Analogous to format % args. The args argument 1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # must be a tuple. 1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void PyBytes_InternInPlace(PyObject **string) 1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Intern the argument *string in place. The argument must be the 1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # address of a pointer variable pointing to a Python string 1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object. If there is an existing interned string that is the same 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # as *string, it sets *string to it (decrementing the reference 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # count of the old string object and incrementing the reference 1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # count of the interned string object), otherwise it leaves 1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # *string alone and interns it (incrementing its reference 1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # count). (Clarification: even though there is a lot of talk about 1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # reference counts, think of this function as 1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # reference-count-neutral; you own the object after the call if 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # and only if you owned it before the call.) 1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bytes PyBytes_InternFromString(char *v) 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # A combination of PyBytes_FromString() and 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # PyBytes_InternInPlace(), returning either a new string object 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # that has been interned, or a new (``owned'') reference to an 1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # earlier interned string object with the same value. 1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) object PyBytes_Decode(char *s, Py_ssize_t size, char *encoding, char *errors) 1635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Create an object by decoding size bytes of the encoded buffer s 1655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # using the codec registered for encoding. encoding and errors 1665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # have the same meaning as the parameters of the same name in the 1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # unicode() built-in function. The codec to be used is looked up 1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # using the Python codec registry. Return NULL if an exception was 1695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # raised by the codec. 1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) object PyBytes_AsDecodedObject(object str, char *encoding, char *errors) 1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Decode a string object by passing it to the codec registered for 1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # encoding and return the result as Python object. encoding and 1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # errors have the same meaning as the parameters of the same name 1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # in the string encode() method. The codec to be used is looked up 1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # using the Python codec registry. Return NULL if an exception was 1785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # raised by the codec. 1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) object PyBytes_Encode(char *s, Py_ssize_t size, char *encoding, char *errors) 1815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Encode the char buffer of the given size by passing it to the 1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # codec registered for encoding and return a Python 1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # object. encoding and errors have the same meaning as the 1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # parameters of the same name in the string encode() method. The 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # codec to be used is looked up using the Python codec 1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # registry. Return NULL if an exception was raised by the codec. 1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) object PyBytes_AsEncodedObject(object str, char *encoding, char *errors) 1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Return value: New reference. 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # Encode a string object using the codec registered for encoding 1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # and return the result as Python object. encoding and errors have 1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # the same meaning as the parameters of the same name in the 1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # string encode() method. The codec to be used is looked up using 1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # the Python codec registry. Return NULL if an exception was 1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) # raised by the codec. 1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 199