(value, errors='replace',
fallback_charset='us-ascii')
| 447 | return new_params |
| 448 | |
| 449 | def 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 | # |
nothing calls this directly
no test coverage detected