From: Ben Darnell Date: Mon, 23 Dec 2013 22:08:01 +0000 (-0500) Subject: Remove new HTTPRequest.if_modified_since property. X-Git-Tag: v3.2.0b1~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34796817d9514a10fedeb73ca95a8989117252c7;p=thirdparty%2Ftornado.git Remove new HTTPRequest.if_modified_since property. This property was unusual in that its getter returned a value its setter would not accept, and was redundant with direct access to the headers. Use the property setters in the constructor instead of duplicating logic. --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index ca0305fd3..9b42d401a 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -335,10 +335,11 @@ class HTTPRequest(object): .. versionadded:: 3.1 The ``auth_mode`` argument. """ - if headers is None: - headers = httputil.HTTPHeaders() + # Note that some of these attributes go through property setters + # defined below. + self.headers = headers if if_modified_since: - headers["If-Modified-Since"] = httputil.format_timestamp( + self.headers["If-Modified-Since"] = httputil.format_timestamp( if_modified_since) self.proxy_host = proxy_host self.proxy_port = proxy_port @@ -346,8 +347,7 @@ class HTTPRequest(object): self.proxy_password = proxy_password self.url = url self.method = method - self._headers = headers - self._body = utf8(body) + self.body = body self.auth_username = auth_username self.auth_password = auth_password self.auth_mode = auth_mode @@ -358,9 +358,9 @@ class HTTPRequest(object): self.user_agent = user_agent self.use_gzip = use_gzip self.network_interface = network_interface - self._streaming_callback = stack_context.wrap(streaming_callback) - self._header_callback = stack_context.wrap(header_callback) - self._prepare_curl_callback = stack_context.wrap(prepare_curl_callback) + self.streaming_callback = streaming_callback + self.header_callback = header_callback + self.prepare_curl_callback = prepare_curl_callback self.allow_nonstandard_methods = allow_nonstandard_methods self.validate_cert = validate_cert self.ca_certs = ca_certs @@ -380,14 +380,6 @@ class HTTPRequest(object): else: self._headers = value - @property - def if_modified_since(self): - return self.headers.get("If-Modified-Since") - - @if_modified_since.setter - def if_modified_since(self, value): - self.headers["If-Modified-Since"] = httputil.format_timestamp(value) - @property def body(self): return self._body diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 12a2981fe..0ebdd8ddc 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -508,22 +508,6 @@ class HTTPRequestTestCase(unittest.TestCase): request.headers = None self.assertEqual(request.headers, {}) - def test_if_modified_since(self): - request = HTTPRequest( - 'http://example.com', - if_modified_since=time.strptime("01 Jan 10", "%d %b %y") - ) - self.assertEqual(request.if_modified_since, - 'Fri, 01 Jan 2010 00:00:00 GMT') - - def test_if_modified_since_setter(self): - request = HTTPRequest('http://example.com') - request.if_modified_since = time.strptime("02 Jan 10", "%d %b %y") - self.assertEqual( - request._headers, - {'If-Modified-Since': 'Sat, 02 Jan 2010 00:00:00 GMT'} - ) - def test_body(self): request = HTTPRequest('http://example.com', body='foo') self.assertEqual(request.body, utf8('foo'))