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

Function parse_mime_parameters

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

2626 return param, value
2627
2628def parse_mime_parameters(value):
2629 """ parameter *( ";" parameter )
2630
2631 That BNF is meant to indicate this routine should only be called after
2632 finding and handling the leading ';'. There is no corresponding rule in
2633 the formal RFC grammar, but it is more convenient for us for the set of
2634 parameters to be treated as its own TokenList.
2635
2636 This is 'parse' routine because it consumes the remaining value, but it
2637 would never be called to parse a full header. Instead it is called to
2638 parse everything after the non-parameter value of a specific MIME header.
2639
2640 """
2641 mime_parameters = MimeParameters()
2642 while value:
2643 try:
2644 token, value = get_parameter(value)
2645 mime_parameters.append(token)
2646 except errors.HeaderParseError:
2647 leader = None
2648 if value[0] in CFWS_LEADER:
2649 leader, value = get_cfws(value)
2650 if not value:
2651 mime_parameters.append(leader)
2652 return mime_parameters
2653 if value[0] == ';':
2654 if leader is not None:
2655 mime_parameters.append(leader)
2656 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2657 "parameter entry with no content"))
2658 else:
2659 token, value = get_invalid_parameter(value)
2660 if leader:
2661 token[:0] = [leader]
2662 mime_parameters.append(token)
2663 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2664 "invalid parameter {!r}".format(token)))
2665 if value and value[0] != ';':
2666 # Junk after the otherwise valid parameter. Mark it as
2667 # invalid, but it will have a value.
2668 param = mime_parameters[-1]
2669 param.token_type = 'invalid-parameter'
2670 token, value = get_invalid_parameter(value)
2671 param.extend(token)
2672 mime_parameters.defects.append(errors.InvalidHeaderDefect(
2673 "parameter with invalid trailing text {!r}".format(token)))
2674 if value:
2675 # Must be a ';' at this point.
2676 mime_parameters.append(ValueTerminal(';', 'parameter-separator'))
2677 value = value[1:]
2678 return mime_parameters
2679
2680def _find_mime_parameters(tokenlist, value):
2681 """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

Used in the wild real call sites across dependent graphs

searching dependent graphs…