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

Function collapse_rfc2231_value

Lib/email/utils.py:449–470  ·  view source on GitHub ↗
(value, errors='replace',
                           fallback_charset='us-ascii')

Source from the content-addressed store, hash-verified

447 return new_params
448
449def collapse_rfc2231_value(value, errors='replace',
450 fallback_charset='us-ascii'):
451 if not isinstance(value, tuple) or len(value) != 3:
452 return unquote(value)
453 # While value comes to us as a unicode string, we need it to be a bytes
454 # object. We do not want bytes() normal utf-8 decoder, we want a straight
455 # interpretation of the string as character bytes.
456 charset, language, text = value
457 if charset is None:
458 # Issue 17369: if charset/lang is None, decode_rfc2231 couldn't parse
459 # the value, so use the fallback_charset.
460 charset = fallback_charset
461 rawbytes = bytes(text, 'raw-unicode-escape')
462 try:
463 # Explicitly look up the codec for warning generation, see gh-140030
464 # Can be removed in 3.17
465 import codecs
466 codecs.lookup(charset)
467 return str(rawbytes, charset, errors)
468 except LookupError:
469 # charset is not a known codec.
470 return unquote(text)
471
472
473#

Callers

nothing calls this directly

Calls 3

strFunction · 0.85
unquoteFunction · 0.70
lookupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…