diff options
author | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 13:19:41 -0700 |
---|---|---|
committer | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 13:19:41 -0700 |
commit | b6ab7bae87b22c6fae783e8850533219d3bf8a29 (patch) | |
tree | 472a760e2e976ea3e9545e09584392accee9cd6d /urllib3/request.py | |
parent | 54bdd56778a37ea9d56d451d4ae49b99cbbfceaa (diff) | |
download | python-urllib3-b6ab7bae87b22c6fae783e8850533219d3bf8a29.tar python-urllib3-b6ab7bae87b22c6fae783e8850533219d3bf8a29.tar.gz |
Imported Upstream version 1.10
Diffstat (limited to 'urllib3/request.py')
-rw-r--r-- | urllib3/request.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/urllib3/request.py b/urllib3/request.py index 51fe238..b08d6c9 100644 --- a/urllib3/request.py +++ b/urllib3/request.py @@ -118,18 +118,24 @@ class RequestMethods(object): which is used to compose the body of the request. The random boundary string can be explicitly set with the ``multipart_boundary`` parameter. """ - if encode_multipart: - body, content_type = encode_multipart_formdata( - fields or {}, boundary=multipart_boundary) - else: - body, content_type = (urlencode(fields or {}), - 'application/x-www-form-urlencoded') - if headers is None: headers = self.headers - headers_ = {'Content-Type': content_type} - headers_.update(headers) + extra_kw = {'headers': {}} + + if fields: + if 'body' in urlopen_kw: + raise TypeError('request got values for both \'fields\' and \'body\', can only specify one.') + + if encode_multipart: + body, content_type = encode_multipart_formdata(fields, boundary=multipart_boundary) + else: + body, content_type = urlencode(fields), 'application/x-www-form-urlencoded' + + extra_kw['body'] = body + extra_kw['headers'] = {'Content-Type': content_type} + + extra_kw['headers'].update(headers) + extra_kw.update(urlopen_kw) - return self.urlopen(method, url, body=body, headers=headers_, - **urlopen_kw) + return self.urlopen(method, url, **extra_kw) |