Skip to content
Myr

Facilitate for multiple hooks

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

authored by Johannes Gorset · committed by Johannes Gorset · parent 5bff8e3 · Browse files · 2 files+68 added−4 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+68 added−4 removed

  • other:+68 added−4 removed

2 files+68 added−4 removed

modified:requests/hooks.py+9 added-4 removed
29 unmodified lines
3031 hooks = hooks or dict()3233 if key in hooks:34 try:35 return hooks.get(key).__call__(hook_data) or hook_data34 hooks = hooks.get(key)3537 except Exception:38 traceback.print_exc()36 if hasattr(hooks, '__call__'):37 hooks = [hooks]3839 for hook in hooks:40 try:41 hook_data = hook(hook_data) or hook_data42 except Exception:43 traceback.print_exc()4445 return hook_data
modified:test_requests.py+59 added
514 unmodified lines
515 assert new_heads['User-agent'] in r3.content516517 self.assertEqual(r2.status_code, 200)518519 def test_single_hook(self):520521 def add_foo_header(args):522 if not args.get('headers'):523 args['headers'] = {}524525 args['headers'].update({526 'X-Foo': 'foo'527 })528529 return args530531 for service in SERVICES:532 url = service('headers')533534 response = requests.get(535 url = url,536 hooks = {537 'args': add_foo_header538 }539 )540541 assert 'foo' in response.content542543 def test_multiple_hooks(self):544545 def add_foo_header(args):546 if not args.get('headers'):547 args['headers'] = {}548549 args['headers'].update({550 'X-Foo': 'foo'551 })552553 return args554555 def add_bar_header(args):556 if not args.get('headers'):557 args['headers'] = {}558559 args['headers'].update({560 'X-Bar': 'bar'561 })562563 return args564565 for service in SERVICES:566 url = service('headers')567568 response = requests.get(569 url = url,570 hooks = {571 'args': [add_foo_header, add_bar_header]572 }573 )574575 assert 'foo' in response.content576 assert 'bar' in response.content577578 def test_session_persistent_cookies(self):579580 s = requests.session()581
146 unmodified lines