summaryrefslogtreecommitdiff
path: root/waitress
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2018-09-05 23:33:23 -0600
committerBert JW Regeer <bertjw@regeer.org>2018-09-05 23:33:23 -0600
commit0cf4c61d315b0d3429c4daedc157df7fcf64307f (patch)
tree4fe0233045a75a17c67d19e72d350e8eb8b2a85d /waitress
parent761c30122dc78a8dc13a2e5a1f160416609a45be (diff)
downloadwaitress-0cf4c61d315b0d3429c4daedc157df7fcf64307f.tar.gz
get_server_name requires an IP, passing empty is invalid
Diffstat (limited to 'waitress')
-rw-r--r--waitress/server.py14
-rw-r--r--waitress/tests/test_server.py3
2 files changed, 6 insertions, 11 deletions
diff --git a/waitress/server.py b/waitress/server.py
index 7175c64..22bcae7 100644
--- a/waitress/server.py
+++ b/waitress/server.py
@@ -193,15 +193,11 @@ class BaseWSGIServer(wasyncore.dispatcher, object):
def get_server_name(self, ip):
"""Given an IP or hostname, try to determine the server name."""
- if ip:
- server_name = str(ip)
- else:
- server_name = str(self.socketmod.gethostname())
-
- # Convert to a host name if necessary.
- for c in server_name:
- if c != '.' and not c.isdigit():
- return server_name
+
+ if not ip:
+ raise ValueError('Requires an IP to get the server name')
+
+ server_name = str(ip)
try:
if server_name == '0.0.0.0' or server_name == '::':
return 'localhost'
diff --git a/waitress/tests/test_server.py b/waitress/tests/test_server.py
index 76eade5..27285fe 100644
--- a/waitress/tests/test_server.py
+++ b/waitress/tests/test_server.py
@@ -74,8 +74,7 @@ class TestWSGIServer(unittest.TestCase):
def test_get_server_name_empty(self):
inst = self._makeOneWithMap(_start=False)
- result = inst.get_server_name('')
- self.assertTrue(result)
+ self.assertRaises(ValueError, inst.get_server_name, '')
def test_get_server_name_with_ip(self):
inst = self._makeOneWithMap(_start=False)