File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -936,6 +936,16 @@ def test_issue14072(self):
936
936
self .assertEqual (p2 .scheme , 'tel' )
937
937
self .assertEqual (p2 .path , '+31641044153' )
938
938
939
+ def test_port_casting_failure_message (self ):
940
+ message = "Port could not be cast to integer value as 'oracle'"
941
+ p1 = urllib .parse .urlparse ('http://Server=sde; Service=sde:oracle' )
942
+ with self .assertRaisesRegex (ValueError , message ):
943
+ p1 .port
944
+
945
+ p2 = urllib .parse .urlsplit ('http://Server=sde; Service=sde:oracle' )
946
+ with self .assertRaisesRegex (ValueError , message ):
947
+ p2 .port
948
+
939
949
def test_telurl_params (self ):
940
950
p1 = urllib .parse .urlparse ('tel:123-4;phone-context=+1-650-516' )
941
951
self .assertEqual (p1 .scheme , 'tel' )
Original file line number Diff line number Diff line change @@ -166,7 +166,11 @@ def hostname(self):
166
166
def port (self ):
167
167
port = self ._hostinfo [1 ]
168
168
if port is not None :
169
- port = int (port , 10 )
169
+ try :
170
+ port = int (port , 10 )
171
+ except ValueError :
172
+ message = f'Port could not be cast to integer value as { port !r} '
173
+ raise ValueError (message ) from None
170
174
if not ( 0 <= port <= 65535 ):
171
175
raise ValueError ("Port out of range 0-65535" )
172
176
return port
Original file line number Diff line number Diff line change
1
+ Providing an explicit error message when casting the port property to anything
2
+ that is not an integer value using ``urlparse() `` and ``urlsplit() ``.
3
+ Patch by Matt Eaton.
You can’t perform that action at this time.
0 commit comments