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

Function collapse_rfc2231_value

Lib/email/utils.py:449–466  ·  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 return str(rawbytes, charset, errors)
464 except LookupError:
465 # charset is not a known codec.
466 return unquote(text)
467
468
469#

Callers

nothing calls this directly

Calls 4

isinstanceFunction · 0.85
lenFunction · 0.85
strFunction · 0.85
unquoteFunction · 0.70

Tested by

no test coverage detected