Merge remote-tracking branch 'origin/develop' into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 5fedbbf, 0ad4456 · Browse files · 2 files·+54 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+54 added−26 removed
- other:+54 added−26 removed
Provenance
- Commit
81897dd- Tree
f38c795- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
5fedbbf- Parent 2
0ad4456
2 files changed+54 added−26 removed
modified:requests/__init__.py+29 added-2 removed
4 unmodified lines5 # / ( (- (/ (/ (- _) / _)6 # /7 8 """9-requests10-~~~~~~~~9+requests HTTP library10+~~~~~~~~~~~~~~~~~~~~~11 12+Requests is an HTTP library, written in Python, for human beings. Basic GET13+usage:14+15+ >>> import requests16+ >>> r = requests.get('http://python.org')17+ >>> r.status_code18+ 20019+ >>> 'Python is a programming language' in r.content20+ True21+22+... or POST:23+24+ >>> payload = dict(key1='value1', key2='value2')25+ >>> r = requests.post("http://httpbin.org/post", data=payload)26+ >>> print r.text27+ {28+ // ...snip... //29+ "form": {30+ "key2": "value2",31+ "key1": "value1"32+ },33+ // ...snip... //34+ }35+36+The other HTTP methods are supported - see `requests.api`. Full documentation37+is at <http://requests.rtfd.org/>.38+39 :copyright: (c) 2012 by Kenneth Reitz.40 :license: ISC, see LICENSE for more details.41 42 """18 unmodified linesmodified:requests/auth.py+25 added-24 removed
31 unmodified lines32 33 log = logging.getLogger(__name__)34 35 CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'36+CONTENT_TYPE_MULTI_PART = 'multipart/form-data'37 38 39 def _basic_auth_str(username, password):40 """Returns a Basic Auth string."""33 unmodified lines74 75 Parameters may be included from the body if the content-type is76 urlencoded, if no content type is set an educated guess is made.77 """78+ # split(";") because Content-Type may be "multipart/form-data; boundary=xxxxx"77- contenttype = r.headers.get('Content-Type', None)79+ contenttype = r.headers.get('Content-Type', '').split(";")[0].lower()80 # extract_params will not give params unless the body is a properly81 # formatted string, a dictionary or a list of 2-tuples.82 decoded_body = extract_params(r.data)83 82- _ct = (contenttype is None)83- _ct = _ct or contenttype.lower() == CONTENT_TYPE_FORM_URLENCODED84-85- if _ct and decoded_body != None:86- # extract_params can only check the present r.data and does not know87- # of r.files, thus an extra check is performed. We know that88- # if files are present the request will not have89- # Content-type: x-www-form-urlencoded. We guess it will have90- # a mimetype of multipart/form-encoded and if this is not the case91- # we assume the correct header will be set later.92- if r.files:93- # Omit body data in the signing and since it will always94- # be empty (cant add paras to body if multipart) and we wish95- # to preserve body.96- r.headers['Content-Type'] = 'multipart/form-encoded'97- r.url, r.headers, _ = self.client.sign(98- unicode(r.full_url), unicode(r.method), None, r.headers)99- else:100- # Normal signing101- r.headers['Content-Type'] = 'application/x-www-form-urlencoded'102- r.url, r.headers, r.data = self.client.sign(103- unicode(r.full_url), unicode(r.method), r.data, r.headers)104-84+ # extract_params can only check the present r.data and does not know85+ # of r.files, thus an extra check is performed. We know that86+ # if files are present the request will not have87+ # Content-type: x-www-form-urlencoded. We guess it will have88+ # a mimetype of multipart/form-data and if this is not the case89+ # we assume the correct header will be set later.90+ _oauth_signed = True91+ if r.files and contenttype == CONTENT_TYPE_MULTI_PART:92+ # Omit body data in the signing and since it will always93+ # be empty (cant add paras to body if multipart) and we wish94+ # to preserve body.95+ r.url, r.headers, _ = self.client.sign(96+ unicode(r.full_url), unicode(r.method), None, r.headers)97+ elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):98+ # Normal signing99+ if not contenttype:100+ r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED101+ r.url, r.headers, r.data = self.client.sign(102+ unicode(r.full_url), unicode(r.method), r.data, r.headers)103+ else:104+ _oauth_signed = False105+ if _oauth_signed:106 # Both flows add params to the URL by using r.full_url,107 # so this prevents adding it again later108 r.params = {}109 273 unmodified lines