bpo-33034: Improve exception message when cast fails for {Parse,Split}Result.port (GH-6078)

This commit is contained in:
Matt Eaton 2018-03-20 01:41:37 -05:00 committed by Berker Peksag
parent 7389fd935c
commit 2cb4661707
3 changed files with 18 additions and 1 deletions

View file

@ -166,7 +166,11 @@ class _NetlocResultMixinBase(object):
def port(self):
port = self._hostinfo[1]
if port is not None:
port = int(port, 10)
try:
port = int(port, 10)
except ValueError:
message = f'Port could not be cast to integer value as {port!r}'
raise ValueError(message) from None
if not ( 0 <= port <= 65535):
raise ValueError("Port out of range 0-65535")
return port