Conditions | 6 |
Total Lines | 23 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 6 |
Changes | 0 |
1 | """ |
||
29 | 1 | def parse_port(value: str) -> Port: |
|
30 | """Extract port number and protocol from string representation.""" |
||
31 | 1 | tokens = value.split('/', maxsplit=1) |
|
32 | 1 | if len(tokens) != 2: |
|
33 | 1 | raise ValueError(f'Invalid port string "{value}"') |
|
34 | |||
35 | 1 | number_str = tokens[0] |
|
36 | 1 | try: |
|
37 | 1 | number = int(number_str) |
|
38 | 1 | except ValueError: |
|
39 | 1 | raise ValueError(f'Invalid port number "{number_str}"') |
|
40 | 1 | if number < 1 or number > 65535: |
|
41 | 1 | raise ValueError(f'Invalid port number "{number_str}"') |
|
42 | |||
43 | 1 | transport_protocol_str = tokens[1] |
|
44 | 1 | try: |
|
45 | 1 | transport_protocol = TransportProtocol[transport_protocol_str.upper()] |
|
46 | 1 | except KeyError: |
|
47 | 1 | raise ValueError( |
|
48 | f'Unknown transport protocol "{transport_protocol_str}"' |
||
49 | ) |
||
50 | |||
51 | return Port(number=number, transport_protocol=transport_protocol) |
||
52 |