summaryrefslogtreecommitdiffstats
path: root/Lib/urllib
diff options
context:
space:
mode:
authorMatt Eaton <agnosticdev@gmail.com>2018-03-20 06:41:37 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2018-03-20 06:41:37 (GMT)
commit2cb4661707818cfd92556e7fdf9068a993577002 (patch)
tree0c3f6933e3e5117b5289845d998da35da46f8d72 /Lib/urllib
parent7389fd935c95b4b6f094312294e703ee0de18719 (diff)
downloadcpython-2cb4661707818cfd92556e7fdf9068a993577002.zip
cpython-2cb4661707818cfd92556e7fdf9068a993577002.tar.gz
cpython-2cb4661707818cfd92556e7fdf9068a993577002.tar.bz2
bpo-33034: Improve exception message when cast fails for {Parse,Split}Result.port (GH-6078)
Diffstat (limited to 'Lib/urllib')
-rw-r--r--Lib/urllib/parse.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index 58460f9..3f8cfe5 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -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