'*' digits The formal BNF is more complicated because leading 0s are not allowed. We check for that and add a defect. We also assume no CFWS is allowed between the '*' and the digits, though the RFC is not crystal clear on that. The caller should already have dealt with leading C
(value)
| 2390 | return attribute, value |
| 2391 | |
| 2392 | def get_section(value): |
| 2393 | """ '*' digits |
| 2394 | |
| 2395 | The formal BNF is more complicated because leading 0s are not allowed. We |
| 2396 | check for that and add a defect. We also assume no CFWS is allowed between |
| 2397 | the '*' and the digits, though the RFC is not crystal clear on that. |
| 2398 | The caller should already have dealt with leading CFWS. |
| 2399 | |
| 2400 | """ |
| 2401 | section = Section() |
| 2402 | if not value or value[0] != '*': |
| 2403 | raise errors.HeaderParseError("Expected section but found {}".format( |
| 2404 | value)) |
| 2405 | section.append(ValueTerminal('*', 'section-marker')) |
| 2406 | value = value[1:] |
| 2407 | if not value or not value[0].isdigit(): |
| 2408 | raise errors.HeaderParseError("Expected section number but " |
| 2409 | "found {}".format(value)) |
| 2410 | digits = '' |
| 2411 | while value and value[0].isdigit(): |
| 2412 | digits += value[0] |
| 2413 | value = value[1:] |
| 2414 | if digits[0] == '0' and digits != '0': |
| 2415 | section.defects.append(errors.InvalidHeaderDefect( |
| 2416 | "section number has an invalid leading 0")) |
| 2417 | section.number = int(digits) |
| 2418 | section.append(ValueTerminal(digits, 'digits')) |
| 2419 | return section, value |
| 2420 | |
| 2421 | |
| 2422 | def get_value(value): |
no test coverage detected