(val, charset=None, mapping=None)
| 13 | |
| 14 | |
| 15 | def escape_item(val, charset=None, mapping=None): |
| 16 | if mapping is None: |
| 17 | mapping = encoders |
| 18 | encoder = mapping.get(type(val)) |
| 19 | |
| 20 | # Fallback to default when no encoder found |
| 21 | if not encoder: |
| 22 | try: |
| 23 | encoder = mapping[str] |
| 24 | except KeyError: |
| 25 | raise TypeError("no default type converter defined") |
| 26 | |
| 27 | if encoder == escape_sequence: |
| 28 | val = encoder(val, charset, mapping) |
| 29 | else: |
| 30 | val = encoder(val, mapping) |
| 31 | return val |
| 32 | |
| 33 | |
| 34 | def escape_not_supported(val, charset=None, mapping=None): |
no test coverage detected