Skip to content
Myr

Merge branch 'develop' of https://github.com/catwell/requests 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 d4a77cf, f3ad56f · Browse files · 3 files+55 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+55 added−23 removed

  • tests:+14 added−0 removed
  • other:+41 added−23 removed

3 files+55 added−23 removed

modified:requests/auth.py+2 added
54 unmodified lines
5556 def handle_401(self, r):57 """Takes the given response and tries digest-auth, if needed."""5859 r.request.deregister_hook('response', self.handle_401)6061 s_auth = r.headers.get('www-authenticate', '')6263 if 'digest' in s_auth.lower():64
86 unmodified lines
modified:requests/models.py+39 added-23 removed
78 unmodified lines
79 #: Dictionary of HTTP Headers to attach to the :class:`Request <Request>`.80 self.headers = dict(headers or [])8182 #: Dictionary of files to multipart upload (``{filename: content}``).83 self.files = files83 self.files = None8485 #: HTTP Method to use.86 self.method = method87
25 unmodified lines
113 self.proxies['https'] = os.environ['HTTPS_PROXY']114115 self.data, self._enc_data = self._encode_params(data)116 self.params, self._enc_params = self._encode_params(params)117 self.files, self._enc_files = self._encode_files(files)118119 #: :class:`Response <Response>` instance, containing120 #: content and metadata of HTTP Response, once :attr:`sent <send>`.121 self.response = Response()
207 unmodified lines
329 return result, urlencode(result, doseq=True)330 else:331 return data, data332333 def _encode_files(self,files):334335 if (not files) or isinstance(self.data, str):336 return None, None337338 try:339 fields = self.data.copy()340 except AttributeError:341 fields = dict(self.data)342343 for (k, v) in list(files.items()):344 # support for explicit filename345 if isinstance(v, (tuple, list)):346 fn, fp = v347 else:348 fn = guess_filename(v) or k349 fp = v350 fields.update({k: (fn, fp.read())})351352 (body, content_type) = encode_multipart_formdata(fields)353354 return files, (body, content_type)355356 @property357 def full_url(self):358 """Build the actual URL to use."""359
71 unmodified lines
431432 def register_hook(self, event, hook):433 """Properly register a hook."""434411 return self.hooks[event].append(hook)435 self.hooks[event].append(hook)436437 def deregister_hook(self,event,hook):438 """Deregister a previously registered hook.439 Returns True if the hook existed, False if not.440 """441442 try:443 self.hooks[event].remove(hook)444 return True445 except ValueError:446 return False447448 def send(self, anyway=False, prefetch=False):449 """Sends the request. Returns True of successful, False if not.450 If there was an HTTPError during transmission,451 self.response.status_code will contain the HTTPError code.
18 unmodified lines
470 content_type = None471472 # Multi-part file uploads.473 if self.files:439 if not isinstance(self.data, str):440441 try:442 fields = self.data.copy()443 except AttributeError:444 fields = dict(self.data)445446 for (k, v) in list(self.files.items()):447 # support for explicit filename448 if isinstance(v, (tuple, list)):449 fn, fp = v450 else:451 fn = guess_filename(v) or k452 fp = v453 fields.update({k: (fn, fp.read())})454455 (body, content_type) = encode_multipart_formdata(fields)456 else:457 pass458 # TODO: Conflict?474 (body, content_type) = self._enc_files475 else:476 if self.data:477478 body = self._enc_data
291 unmodified lines
770771 except AttributeError:772 self._content = None773758 self._content_consumed = True 774 self._content_consumed = True775 return self._content776777 def _detected_encoding(self):778 try:
59 unmodified lines
modified:tests/test_requests.py+14 added
270 unmodified lines
271 s = requests.session(auth=auth)272 r = get(url, session=s)273 self.assertEqual(r.status_code, 200)274275 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):276277 for service in SERVICES:278279 auth = HTTPDigestAuth('user', 'wrongpass')280 url = service('digest-auth', 'auth', 'user', 'pass')281282 r = get(url, auth=auth)283 self.assertEqual(r.status_code, 401)284285 s = requests.session(auth=auth)286 r = get(url, session=s)287 self.assertEqual(r.status_code, 401)288289 def test_POSTBIN_GET_POST_FILES(self):290291 for service in SERVICES:292
545 unmodified lines