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

Function parse_mime_parameters

Lib/email/_header_value_parser.py:2585–2635  ·  view source on GitHub ↗

parameter *( ";" parameter ) That BNF is meant to indicate this routine should only be called after finding and handling the leading ';'. There is no corresponding rule in the formal RFC grammar, but it is more convenient for us for the set of parameters to be treated as its own T

(value)

Source from the content-addressed store, hash-verified

2583 return param, value
2584
2585def parse_mime_parameters(value):
2586 """ parameter *( ";" parameter )
2587
2588 That BNF is meant to indicate this routine should only be called after
2589 finding and handling the leading ';'. There is no corresponding rule in
2590 the formal RFC grammar, but it is more convenient for us for the set of
2591 parameters to be treated as its own TokenList.
2592
2593 This is 'parse' routine because it consumes the remaining value, but it
2594 would never be called to parse a full header. Instead it is called to
2595 parse everything after the non-parameter value of a specific MIME header.
2596
2597 """
2598 mime_parameters = MimeParameters()
2599 while value:
2600 try:
2601 token, value = get_parameter(value)
2602 mime_parameters.append(token)
2603 except errors.HeaderParseError:
2604 leader = None
2605 if value[0] in CFWS_LEADER:
2606 leader, value = get_cfws(value)
2607 if not value:
2608 mime_parameters.append(leader)
2609 return mime_parameters
2610 if value[0] == ';':
2611 if leader is not None:
2612 mime_parameters.append(leader)
2613 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2614 "parameter entry with no content"))
2615 else:
2616 token, value = get_invalid_parameter(value)
2617 if leader:
2618 token[:0] = [leader]
2619 mime_parameters.append(token)
2620 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2621 "invalid parameter {!r}".format(token)))
2622 if value and value[0] != ';':
2623 # Junk after the otherwise valid parameter. Mark it as
2624 # invalid, but it will have a value.
2625 param = mime_parameters[-1]
2626 param.token_type = 'invalid-parameter'
2627 token, value = get_invalid_parameter(value)
2628 param.extend(token)
2629 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2630 "parameter with invalid trailing text {!r}".format(token)))
2631 if value:
2632 # Must be a ';' at this point.
2633 mime_parameters.append(ValueTerminal(';', 'parameter-separator'))
2634 value = value[1:]
2635 return mime_parameters
2636
2637def _find_mime_parameters(tokenlist, value):
2638 """Do our best to find the parameters in an invalid MIME header

Callers 3

_find_mime_parametersFunction · 0.85

Calls 8

MimeParametersClass · 0.85
get_parameterFunction · 0.85
get_cfwsFunction · 0.85
get_invalid_parameterFunction · 0.85
ValueTerminalClass · 0.85
appendMethod · 0.45
formatMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected