MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / decode_params

Function decode_params

tools/python-3.11.9-amd64/Lib/email/utils.py:260–306  ·  view source on GitHub ↗

Decode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value).

(params)

Source from the content-addressed store, hash-verified

258 re.ASCII)
259
260def decode_params(params):
261 """Decode parameters list according to RFC 2231.
262
263 params is a sequence of 2-tuples containing (param name, string value).
264 """
265 new_params = [params[0]]
266 # Map parameter's name to a list of continuations. The values are a
267 # 3-tuple of the continuation number, the string value, and a flag
268 # specifying whether a particular segment is %-encoded.
269 rfc2231_params = {}
270 for name, value in params[1:]:
271 encoded = name.endswith('*')
272 value = unquote(value)
273 mo = rfc2231_continuation.match(name)
274 if mo:
275 name, num = mo.group('name', 'num')
276 if num is not None:
277 num = int(num)
278 rfc2231_params.setdefault(name, []).append((num, value, encoded))
279 else:
280 new_params.append((name, '"%s"' % quote(value)))
281 if rfc2231_params:
282 for name, continuations in rfc2231_params.items():
283 value = []
284 extended = False
285 # Sort by number
286 continuations.sort()
287 # And now append all values in numerical order, converting
288 # %-encodings for the encoded segments. If any of the
289 # continuation names ends in a *, then the entire string, after
290 # decoding segments and concatenating, must have the charset and
291 # language specifiers at the beginning of the string.
292 for num, s, encoded in continuations:
293 if encoded:
294 # Decode as "latin-1", so the characters in s directly
295 # represent the percent-encoded octet values.
296 # collapse_rfc2231_value treats this as an octet sequence.
297 s = urllib.parse.unquote(s, encoding="latin-1")
298 extended = True
299 value.append(s)
300 value = quote(EMPTYSTRING.join(value))
301 if extended:
302 charset, language, value = decode_rfc2231(value)
303 new_params.append((name, (charset, language, '"%s"' % value)))
304 else:
305 new_params.append((name, '"%s"' % value))
306 return new_params
307
308def collapse_rfc2231_value(value, errors='replace',
309 fallback_charset='us-ascii'):

Callers

nothing calls this directly

Calls 11

quoteFunction · 0.90
decode_rfc2231Function · 0.85
endswithMethod · 0.80
unquoteFunction · 0.70
matchMethod · 0.45
groupMethod · 0.45
appendMethod · 0.45
setdefaultMethod · 0.45
itemsMethod · 0.45
sortMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected