diff options
author | Bert JW Regeer <bertjw@regeer.org> | 2016-10-14 14:48:16 -0600 |
---|---|---|
committer | Bert JW Regeer <bertjw@regeer.org> | 2016-10-14 14:48:16 -0600 |
commit | fda05ee9ec48a970031b325c21a618beaec9a8c7 (patch) | |
tree | 8bccf41ac1c1f002af3b317cb369683edae6e49f | |
parent | 7e807c9ecefb2388d1e696c3253085d674ac4590 (diff) | |
download | waitress-fda05ee9ec48a970031b325c21a618beaec9a8c7.tar.gz |
On Windows, turn port into an integer
We can't use service names instead of port numbers on Windows, so
attempt to turn the port into an integer. If unable to do so, raise an
error.
-rw-r--r-- | waitress/adjustments.py | 14 | ||||
-rw-r--r-- | waitress/compat.py | 4 |
2 files changed, 17 insertions, 1 deletions
diff --git a/waitress/adjustments.py b/waitress/adjustments.py index 97c47e4..047ef6e 100644 --- a/waitress/adjustments.py +++ b/waitress/adjustments.py @@ -16,7 +16,10 @@ import getopt import socket -from waitress.compat import string_types +from waitress.compat import ( + string_types, + WIN, + ) truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1')) @@ -242,6 +245,15 @@ class Adjustments(object): else: (host, port) = (i, str(self.port)) + if WIN: # pragma: no cover + try: + # Try turning the port into an integer + port = int(port) + except: + raise ValueError( + 'Windows does not support service names instead of port numbers' + ) + try: if '[' in host and ']' in host: # pragma: nocover host = host.strip('[').rstrip(']') diff --git a/waitress/compat.py b/waitress/compat.py index 9e06cde..2ffcf42 100644 --- a/waitress/compat.py +++ b/waitress/compat.py @@ -1,5 +1,6 @@ import sys import types +import platform try: import urlparse @@ -9,6 +10,9 @@ except ImportError: # pragma: no cover # True if we are running on Python 3. PY3 = sys.version_info[0] == 3 +# True if we are running on Windows +WIN = platform.system() == 'Windows' + if PY3: # pragma: no cover string_types = str, integer_types = int, |