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

Function get_parameter

Lib/email/_header_value_parser.py:2487–2626  ·  view source on GitHub ↗

attribute [section] ["*"] [CFWS] "=" value The CFWS is implied by the RFC but not made explicit in the BNF. This simplified form of the BNF from the RFC is made to conform with the RFC BNF through some extra checks. We do it this way because it makes both error recovery and worki

(value)

Source from the content-addressed store, hash-verified

2485 return v, value
2486
2487def get_parameter(value):
2488 """ attribute [section] ["*"] [CFWS] "=" value
2489
2490 The CFWS is implied by the RFC but not made explicit in the BNF. This
2491 simplified form of the BNF from the RFC is made to conform with the RFC BNF
2492 through some extra checks. We do it this way because it makes both error
2493 recovery and working with the resulting parse tree easier.
2494 """
2495 # It is possible CFWS would also be implicitly allowed between the section
2496 # and the 'extended-attribute' marker (the '*') , but we've never seen that
2497 # in the wild and we will therefore ignore the possibility.
2498 param = Parameter()
2499 token, value = get_attribute(value)
2500 param.append(token)
2501 if not value or value[0] == ';':
2502 param.defects.append(errors.InvalidHeaderDefect("Parameter contains "
2503 "name ({}) but no value".format(token)))
2504 return param, value
2505 if value[0] == '*':
2506 try:
2507 token, value = get_section(value)
2508 param.sectioned = True
2509 param.append(token)
2510 except errors.HeaderParseError:
2511 pass
2512 if not value:
2513 raise errors.HeaderParseError("Incomplete parameter")
2514 if value[0] == '*':
2515 param.append(ValueTerminal('*', 'extended-parameter-marker'))
2516 value = value[1:]
2517 param.extended = True
2518 if value[0] != '=':
2519 raise errors.HeaderParseError("Parameter not followed by '='")
2520 param.append(ValueTerminal('=', 'parameter-separator'))
2521 value = value[1:]
2522 if value and value[0] in CFWS_LEADER:
2523 token, value = get_cfws(value)
2524 param.append(token)
2525 remainder = None
2526 appendto = param
2527 if param.extended and value and value[0] == '"':
2528 # Now for some serious hackery to handle the common invalid case of
2529 # double quotes around an extended value. We also accept (with defect)
2530 # a value marked as encoded that isn't really.
2531 qstring, remainder = get_quoted_string(value)
2532 inner_value = qstring.stripped_value
2533 semi_valid = False
2534 if param.section_number == 0:
2535 if inner_value and inner_value[0] == "'":
2536 semi_valid = True
2537 else:
2538 token, rest = get_attrtext(inner_value)
2539 if rest and rest[0] == "'":
2540 semi_valid = True
2541 else:
2542 try:
2543 token, rest = get_extended_attrtext(inner_value)
2544 except:

Callers 1

parse_mime_parametersFunction · 0.85

Calls 14

get_sectionFunction · 0.85
ValueTerminalClass · 0.85
get_cfwsFunction · 0.85
get_quoted_stringFunction · 0.85
get_attrtextFunction · 0.85
get_extended_attrtextFunction · 0.85
get_fwsFunction · 0.85
get_qcontentFunction · 0.85
ParameterClass · 0.70
get_attributeFunction · 0.70
get_valueFunction · 0.70
ValueClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…