MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_parameter

Function get_parameter

Lib/email/_header_value_parser.py:2444–2583  ·  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

2442 return v, value
2443
2444def get_parameter(value):
2445 """ attribute [section] ["*"] [CFWS] "=" value
2446
2447 The CFWS is implied by the RFC but not made explicit in the BNF. This
2448 simplified form of the BNF from the RFC is made to conform with the RFC BNF
2449 through some extra checks. We do it this way because it makes both error
2450 recovery and working with the resulting parse tree easier.
2451 """
2452 # It is possible CFWS would also be implicitly allowed between the section
2453 # and the 'extended-attribute' marker (the '*') , but we've never seen that
2454 # in the wild and we will therefore ignore the possibility.
2455 param = Parameter()
2456 token, value = get_attribute(value)
2457 param.append(token)
2458 if not value or value[0] == ';':
2459 param.defects.append(errors.InvalidHeaderDefect("Parameter contains "
2460 "name ({}) but no value".format(token)))
2461 return param, value
2462 if value[0] == '*':
2463 try:
2464 token, value = get_section(value)
2465 param.sectioned = True
2466 param.append(token)
2467 except errors.HeaderParseError:
2468 pass
2469 if not value:
2470 raise errors.HeaderParseError("Incomplete parameter")
2471 if value[0] == '*':
2472 param.append(ValueTerminal('*', 'extended-parameter-marker'))
2473 value = value[1:]
2474 param.extended = True
2475 if value[0] != '=':
2476 raise errors.HeaderParseError("Parameter not followed by '='")
2477 param.append(ValueTerminal('=', 'parameter-separator'))
2478 value = value[1:]
2479 if value and value[0] in CFWS_LEADER:
2480 token, value = get_cfws(value)
2481 param.append(token)
2482 remainder = None
2483 appendto = param
2484 if param.extended and value and value[0] == '"':
2485 # Now for some serious hackery to handle the common invalid case of
2486 # double quotes around an extended value. We also accept (with defect)
2487 # a value marked as encoded that isn't really.
2488 qstring, remainder = get_quoted_string(value)
2489 inner_value = qstring.stripped_value
2490 semi_valid = False
2491 if param.section_number == 0:
2492 if inner_value and inner_value[0] == "'":
2493 semi_valid = True
2494 else:
2495 token, rest = get_attrtext(inner_value)
2496 if rest and rest[0] == "'":
2497 semi_valid = True
2498 else:
2499 try:
2500 token, rest = get_extended_attrtext(inner_value)
2501 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