Commit 838521ee authored by Jason R. Coombs's avatar Jason R. Coombs

Close #18978: Merge changes.

parents f94a16b4 ea9e0974
...@@ -1466,16 +1466,25 @@ class MiscTests(unittest.TestCase): ...@@ -1466,16 +1466,25 @@ class MiscTests(unittest.TestCase):
self.assertEqual(str(err), expected_errmsg) self.assertEqual(str(err), expected_errmsg)
class RequestTests(unittest.TestCase): class RequestTests(unittest.TestCase):
class PutRequest(Request):
method='PUT'
def setUp(self): def setUp(self):
self.get = Request("http://www.python.org/~jeremy/") self.get = Request("http://www.python.org/~jeremy/")
self.post = Request("http://www.python.org/~jeremy/", self.post = Request("http://www.python.org/~jeremy/",
"data", "data",
headers={"X-Test": "test"}) headers={"X-Test": "test"})
self.head = Request("http://www.python.org/~jeremy/", method='HEAD')
self.put = self.PutRequest("http://www.python.org/~jeremy/")
self.force_post = self.PutRequest("http://www.python.org/~jeremy/",
method="POST")
def test_method(self): def test_method(self):
self.assertEqual("POST", self.post.get_method()) self.assertEqual("POST", self.post.get_method())
self.assertEqual("GET", self.get.get_method()) self.assertEqual("GET", self.get.get_method())
self.assertEqual("HEAD", self.head.get_method())
self.assertEqual("PUT", self.put.get_method())
self.assertEqual("POST", self.force_post.get_method())
def test_data(self): def test_data(self):
self.assertFalse(self.get.data) self.assertFalse(self.get.data)
......
...@@ -271,7 +271,8 @@ class Request: ...@@ -271,7 +271,8 @@ class Request:
origin_req_host = request_host(self) origin_req_host = request_host(self)
self.origin_req_host = origin_req_host self.origin_req_host = origin_req_host
self.unverifiable = unverifiable self.unverifiable = unverifiable
self.method = method if method:
self.method = method
@property @property
def full_url(self): def full_url(self):
...@@ -320,12 +321,8 @@ class Request: ...@@ -320,12 +321,8 @@ class Request:
def get_method(self): def get_method(self):
"""Return a string indicating the HTTP request method.""" """Return a string indicating the HTTP request method."""
if self.method is not None: default_method = "POST" if self.data is not None else "GET"
return self.method return getattr(self, 'method', default_method)
elif self.data is not None:
return "POST"
else:
return "GET"
def get_full_url(self): def get_full_url(self):
return self.full_url return self.full_url
......
...@@ -12,6 +12,9 @@ Core and Builtins ...@@ -12,6 +12,9 @@ Core and Builtins
Library Library
------- -------
- Issue #18978: ``urllib.request.Request`` now allows the method to be
indicated on the class and no longer sets it to None in ``__init__``.
- Issue #18626: the inspect module now offers a basic command line - Issue #18626: the inspect module now offers a basic command line
introspection interface (Initial patch by Claudiu Popa) introspection interface (Initial patch by Claudiu Popa)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment