Skip to content
Myr

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

2 files+54 added−26 removed

modified:requests/__init__.py+29 added-2 removed
4 unmodified lines
5# / ( (- (/ (/ (- _) / _)6# /78"""9requests10~~~~~~~~9requests HTTP library10~~~~~~~~~~~~~~~~~~~~~1112Requests is an HTTP library, written in Python, for human beings. Basic GET13usage:1415 >>> import requests16 >>> r = requests.get('http://python.org')17 >>> r.status_code18 20019 >>> 'Python is a programming language' in r.content20 True2122... or POST:2324 >>> 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 }3536The other HTTP methods are supported - see `requests.api`. Full documentation37is at <http://requests.rtfd.org/>.3839:copyright: (c) 2012 by Kenneth Reitz.40:license: ISC, see LICENSE for more details.4142"""
18 unmodified lines
modified:requests/auth.py+25 added-24 removed
31 unmodified lines
3233log = logging.getLogger(__name__)3435CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'36CONTENT_TYPE_MULTI_PART = 'multipart/form-data'373839def _basic_auth_str(username, password):40 """Returns a Basic Auth string."""
33 unmodified lines
7475 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)8382 _ct = (contenttype is None)83 _ct = _ct or contenttype.lower() == CONTENT_TYPE_FORM_URLENCODED8485 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)10484 # 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