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