From: Ben Darnell Date: Fri, 18 Jul 2014 03:26:12 +0000 (-0400) Subject: Add a default value to a getaddr() call in HTTPServerRequest. X-Git-Tag: v4.1.0b1~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13c02a3629a72e8503251fc36930ba1b8300829b;p=thirdparty%2Ftornado.git Add a default value to a getaddr() call in HTTPServerRequest. Closes #1118. --- diff --git a/tornado/httputil.py b/tornado/httputil.py index a67489725..1c5753822 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -335,7 +335,7 @@ class HTTPServerRequest(object): # set remote IP and protocol context = getattr(connection, 'context', None) - self.remote_ip = getattr(context, 'remote_ip') + self.remote_ip = getattr(context, 'remote_ip', None) self.protocol = getattr(context, 'protocol', "http") self.host = host or self.headers.get("Host") or "127.0.0.1" diff --git a/tornado/test/httputil_test.py b/tornado/test/httputil_test.py index 1e84da76f..8e0bf9824 100644 --- a/tornado/test/httputil_test.py +++ b/tornado/test/httputil_test.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function, with_statement -from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp +from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp, HTTPServerRequest from tornado.escape import utf8 from tornado.log import gen_log from tornado.testing import ExpectLog @@ -253,3 +253,13 @@ class FormatTimestampTest(unittest.TestCase): def test_datetime(self): self.check(datetime.datetime.utcfromtimestamp(self.TIMESTAMP)) + + +# HTTPServerRequest is mainly tested incidentally to the server itself, +# but this tests the parts of the class that can be tested in isolation. +class HTTPServerRequestTest(unittest.TestCase): + def test_default_constructor(self): + # All parameters are formally optional, but uri is required + # (and has been for some time). This test ensures that no + # more required parameters slip in. + HTTPServerRequest(uri='/')