Decode a field value respecting optional per-field encoding overrides. - If *field_encodings* is provided and *key* is in it, the corresponding encoding is used (``None`` means keep raw bytes). - Otherwise falls back to :func:`str_if_bytes`.
(value, key=None, field_encodings=None)
| 79 | |
| 80 | |
| 81 | def decode_field_value(value, key=None, field_encodings=None): |
| 82 | """Decode a field value respecting optional per-field encoding overrides. |
| 83 | |
| 84 | - If *field_encodings* is provided and *key* is in it, the corresponding |
| 85 | encoding is used (``None`` means keep raw bytes). |
| 86 | - Otherwise falls back to :func:`str_if_bytes`. |
| 87 | """ |
| 88 | if not isinstance(value, bytes): |
| 89 | return value |
| 90 | if field_encodings and key is not None and key in field_encodings: |
| 91 | encoding = field_encodings[key] |
| 92 | if encoding is None: |
| 93 | return value |
| 94 | return value.decode(encoding, "replace") |
| 95 | return str_if_bytes(value) |
| 96 | |
| 97 | |
| 98 | def dict_merge(*dicts: Mapping[str, Any]) -> Dict[str, Any]: |
no test coverage detected