Move handling of method to PreparedRequest

This commit is contained in:
Ian Cordasco
2015-06-02 14:02:46 -05:00
parent 4aa4f82b37
commit 8c4d4f1af3
2 changed files with 14 additions and 3 deletions
+4 -3
View File
@@ -230,7 +230,7 @@ class Request(RequestHooksMixin):
for (k, v) in list(hooks.items()):
self.register_hook(event=k, hook=v)
self.method = to_native_string(method)
self.method = method
self.url = url
self.headers = headers
self.files = files
@@ -328,8 +328,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
def prepare_method(self, method):
"""Prepares the given HTTP method."""
self.method = method
if self.method is not None:
self.method = self.method.upper()
if self.method is None:
raise ValueError('Request method cannot be "None"')
self.method = to_native_string(self.method).upper()
def prepare_url(self, url, params):
"""Prepares the given HTTP URL."""
+10
View File
@@ -1617,6 +1617,16 @@ def test_prepare_unicode_url():
assert_copy(p, p.copy())
def test_prepare_requires_a_request_method():
req = Request()
with pytest.raises(ValueError):
req.prepare()
prepped = PreparedRequest()
with pytest.raises(ValueError):
prepped.prepare()
def test_urllib3_retries():
from requests.packages.urllib3.util import Retry
s = requests.Session()