Parses strings in the following format, enforces number of segments: /flow-filter/status
(option: str)
| 15 | |
| 16 | |
| 17 | def parse_spec(option: str) -> BlockSpec: |
| 18 | """ |
| 19 | Parses strings in the following format, enforces number of segments: |
| 20 | |
| 21 | /flow-filter/status |
| 22 | |
| 23 | """ |
| 24 | sep, rem = option[0], option[1:] |
| 25 | |
| 26 | parts = rem.split(sep, 2) |
| 27 | if len(parts) != 2: |
| 28 | raise ValueError("Invalid number of parameters (2 are expected)") |
| 29 | flow_patt, status = parts |
| 30 | try: |
| 31 | status_code = int(status) |
| 32 | except ValueError: |
| 33 | raise ValueError(f"Invalid HTTP status code: {status}") |
| 34 | flow_filter = flowfilter.parse(flow_patt) |
| 35 | |
| 36 | return BlockSpec(matches=flow_filter, status_code=status_code) |
| 37 | |
| 38 | |
| 39 | class BlockList: |