MCPcopy Index your code
hub / github.com/python/cpython / get_section

Function get_section

Lib/email/_header_value_parser.py:2435–2462  ·  view source on GitHub ↗

'*' 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)

Source from the content-addressed store, hash-verified

2433 return attribute, value
2434
2435def get_section(value):
2436 """ '*' digits
2437
2438 The formal BNF is more complicated because leading 0s are not allowed. We
2439 check for that and add a defect. We also assume no CFWS is allowed between
2440 the '*' and the digits, though the RFC is not crystal clear on that.
2441 The caller should already have dealt with leading CFWS.
2442
2443 """
2444 section = Section()
2445 if not value or value[0] != '*':
2446 raise errors.HeaderParseError("Expected section but found {}".format(
2447 value))
2448 section.append(ValueTerminal('*', 'section-marker'))
2449 value = value[1:]
2450 if not value or not value[0].isdigit():
2451 raise errors.HeaderParseError("Expected section number but "
2452 "found {}".format(value))
2453 digits = ''
2454 while value and value[0].isdigit():
2455 digits += value[0]
2456 value = value[1:]
2457 if digits[0] == '0' and digits != '0':
2458 section.defects.append(errors.InvalidHeaderDefect(
2459 "section number has an invalid leading 0"))
2460 section.number = int(digits)
2461 section.append(ValueTerminal(digits, 'digits'))
2462 return section, value
2463
2464
2465def get_value(value):

Callers 1

get_parameterFunction · 0.85

Calls 5

ValueTerminalClass · 0.85
isdigitMethod · 0.80
SectionClass · 0.70
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…