1
1
2
-
3
2
def add_port_mapping (port_bindings , internal_port , external ):
4
3
if internal_port in port_bindings :
5
4
port_bindings [internal_port ].append (external )
@@ -33,9 +32,8 @@ def to_port_range(port):
33
32
if "/" in port :
34
33
parts = port .split ("/" )
35
34
if len (parts ) != 2 :
36
- raise ValueError ('Invalid port "%s", should be '
37
- '[[remote_ip:]remote_port[-remote_port]:]'
38
- 'port[/protocol]' % port )
35
+ _raise_invalid_port (port )
36
+
39
37
port , protocol = parts
40
38
protocol = "/" + protocol
41
39
@@ -52,11 +50,17 @@ def to_port_range(port):
52
50
'port or startport-endport' % port )
53
51
54
52
53
+ def _raise_invalid_port (port ):
54
+ raise ValueError ('Invalid port "%s", should be '
55
+ '[[remote_ip:]remote_port[-remote_port]:]'
56
+ 'port[/protocol]' % port )
57
+
58
+
55
59
def split_port (port ):
56
60
parts = str (port ).split (':' )
61
+
57
62
if not 1 <= len (parts ) <= 3 :
58
- raise ValueError ('Invalid port "%s", should be '
59
- '[[remote_ip:]remote_port:]port[/protocol]' % port )
63
+ _raise_invalid_port (port )
60
64
61
65
if len (parts ) == 1 :
62
66
internal_port , = parts
@@ -66,6 +70,10 @@ def split_port(port):
66
70
67
71
internal_range = to_port_range (internal_port )
68
72
external_range = to_port_range (external_port )
73
+
74
+ if internal_range is None or external_range is None :
75
+ _raise_invalid_port (port )
76
+
69
77
if len (internal_range ) != len (external_range ):
70
78
raise ValueError ('Port ranges don\' t match in length' )
71
79
0 commit comments