How to convert arbitrary objects directly to base64 without initial string conversion?

Stefan Behnel stefan.behnel-n05pAM at web.de
Thu Jul 13 13:11:11 EDT 2006


Russell Warren wrote:
> How can you tell what objects support the buffer interface?  Is
> anything visible at the python level, or do you need to dig into the C
> source?

At the C level, there is a function for testing:

int PyObject_CheckReadBuffer(PyObject* o)

http://docs.python.org/dev/api/abstract-buffer.html

According to

http://docs.python.org/dev/lib/non-essential-built-in-funcs.html

a Python call to buffer(obj) will either return a buffer object or (tested)
raise a TypeError:

   >>> buffer("123")
   <read-only buffer for 0x2b597d52b9c0, size -1, offset 0 at 0x2b597d52e340>
   >>> buffer(1)
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   TypeError: buffer object expected

Stefan



More information about the Python-list mailing list