[issue3243] Support iterable bodies in httplib
Antoine Pitrou
report at bugs.python.org
Tue Nov 30 17:37:47 CET 2010
Antoine Pitrou <pitrou at free.fr> added the comment:
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)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3243>
_______________________________________
More information about the Python-bugs-list
mailing list