homepage

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 xuanji
Recipients catlee, davide.rizzo, eric.araujo, georg.brandl, jhylton, orsenthil, pitrou, rcoyner, rhettinger, xuanji
Date 2010年12月01日.15:49:51
SpamBayes Score 8.804815e-09
Marked as misclassified No
Message-id <1291218593.66.0.217611113.issue3243@psf.upfronthosting.co.za>
In-reply-to
Content
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...
History
Date User Action Args
2010年12月01日 15:49:53xuanjisetrecipients: + xuanji, jhylton, georg.brandl, rhettinger, orsenthil, pitrou, catlee, eric.araujo, rcoyner, davide.rizzo
2010年12月01日 15:49:53xuanjisetmessageid: <1291218593.66.0.217611113.issue3243@psf.upfronthosting.co.za>
2010年12月01日 15:49:51xuanjilinkissue3243 messages
2010年12月01日 15:49:51xuanjicreate

AltStyle によって変換されたページ (->オリジナル) /