[issue3243] Support iterable bodies in httplib
Xuanji Li
report at bugs.python.org
Wed Dec 1 16:50:30 CET 2010
Xuanji Li <xuanji at gmail.com> added the comment:
attaching new patch. this implements the memoryview solution suggested by pitrou. but it does contain this thing:
if not request.has_header('Content-length'):
if (not hasattr(data, '__read__') and
isinstance(data, collections.Iterable)):
print(data,"is an iterable")
try:
m = memoryview(data)
print(m.itemsize * len(m))
request.add_unredirected_header(
'Content-length', '%d' % (len(m) * m.itemsize))
except TypeError:
try:
request.add_unredirected_header(
'Content-length', '%d' % len(data))
except TypeError:
raise ValueError(
"No Content-Length specified for iterable body")
why is it so nested? because data can support 3 different interfaces:
1) Buffer interface, in that case use memoryview to count bytes
2) Can call len but not buffer: assume len == #bytes
3) Iterable but cannot call len or memoryview: raise ValueError
I hope there is a simpler way...
----------
Added file: http://bugs.python.org/file19892/issue_3243_py3k_5.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3243>
_______________________________________
More information about the Python-bugs-list
mailing list