This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients catlee, davide.rizzo, eric.araujo, georg.brandl, jhylton, orsenthil, pitrou, rcoyner, rhettinger, xuanji
Date 2010-11-30.16:37:46
SpamBayes Score 2.792325e-06
Marked as misclassified No
Message-id <1291135067.89.0.39569474795.issue3243@psf.upfronthosting.co.za>
In-reply-to
Content
Answering to myself, sorry. memoryview() does return the right answer of whether the object supports the buffer interface, *however* it doesn't mean the len() will be right. For example, take an array.array of ints:

>>> memoryview(array.array("I", [1,2,3]))
<memory at 0x1cf5720>
>>> len(array.array("I", [1,2,3]))
3
>>> len(memoryview(array.array("I", [1,2,3])))
3
>>> len(bytes(array.array("I", [1,2,3])))
12

len() returns 3 but the number of bytes written out by sendall() will really be 12...

*However*, the right len can be calculated using the memoryview:

>>> m = memoryview(array.array("I", [1,2,3]))
>>> len(m) * m.itemsize
12

(without actually converting to a bytes object, so all this is cheap even for very large buffers)
History
Date User Action Args
2010-11-30 16:37:48pitrousetrecipients: + pitrou, jhylton, georg.brandl, rhettinger, orsenthil, catlee, eric.araujo, rcoyner, xuanji, davide.rizzo
2010-11-30 16:37:47pitrousetmessageid: <1291135067.89.0.39569474795.issue3243@psf.upfronthosting.co.za>
2010-11-30 16:37:46pitroulinkissue3243 messages
2010-11-30 16:37:46pitroucreate