Skip to content

Commit

Permalink
Simplify PreparedRequest.prepare API
Browse files Browse the repository at this point in the history
Do not require that hooks be passed as an empty list to
PreparedRequest.prepare. In the event hooks is None in prepare or
prepare_hooks, use an empty list as a default.

Related to psf#2552
  • Loading branch information
sigmavirus24 committed Apr 21, 2015
1 parent a0632d8 commit 35045e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ def prepare_cookies(self, cookies):

def prepare_hooks(self, hooks):
"""Prepares the given hooks."""
# hooks can be passed as None to the prepare method and to this
# method. To prevent iterating over None, simply use an empty list
# if hooks is False-y
hooks = hooks or []
for event in hooks:
self.register_hook(event, hooks[event])

Expand Down
1 change: 0 additions & 1 deletion test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ def test_prepare_unicode_url():
p.prepare(
method='GET',
url=u('http://www.example.com/üniçø∂é'),
hooks=[]
)
assert_copy(p, p.copy())

Expand Down

0 comments on commit 35045e8

Please sign in to comment.