diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-12-19 10:49:52 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-12-19 10:49:52 (GMT) |
commit | 7bc0d872ddb023333acc05b7d038cdb74cfc047b (patch) | |
tree | 6225e5ecb0546a7826743510555c604751b238c7 /Lib/urllib/request.py | |
parent | 8a60e94802b04a838607b4aebba6fc8b70f7b87c (diff) | |
download | cpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.zip cpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.tar.gz cpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.tar.bz2 |
Issue3243 - Support iterable bodies in httplib. Patch contributions by Xuanji Li and Chris AtLee.
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r-- | Lib/urllib/request.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index fe66a67..732c112 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -94,6 +94,7 @@ import re import socket import sys import time +import collections from urllib.error import URLError, HTTPError, ContentTooShortError from urllib.parse import ( @@ -1053,8 +1054,17 @@ class AbstractHTTPHandler(BaseHandler): 'Content-type', 'application/x-www-form-urlencoded') if not request.has_header('Content-length'): - request.add_unredirected_header( - 'Content-length', '%d' % len(data)) + try: + mv = memoryview(data) + except TypeError: + print(data) + if isinstance(data, collections.Iterable): + raise ValueError("Content-Length should be specified \ + for iterable data of type %r %r" % (type(data), + data)) + else: + request.add_unredirected_header( + 'Content-length', '%d' % len(mv) * mv.itemsize) sel_host = host if request.has_proxy(): |