Escape whatever value is passed. Non-standard, for internal use; do not use this in your applications.
(self, obj, mapping=None)
| 533 | self._read_ok_packet() |
| 534 | |
| 535 | def escape(self, obj, mapping=None) -> str: |
| 536 | """Escape whatever value is passed. |
| 537 | |
| 538 | Non-standard, for internal use; do not use this in your applications. |
| 539 | """ |
| 540 | if isinstance(obj, str): |
| 541 | return f"'{self._escape_string(obj)}'" |
| 542 | |
| 543 | if isinstance(obj, (bytes, bytearray)): |
| 544 | return f"X'{obj.hex()}'" |
| 545 | |
| 546 | # don't use isinstance here. it breaks subclasses like time.struct_time. |
| 547 | if type(obj) in (tuple, list, set, frozenset): |
| 548 | escape = self.escape |
| 549 | return "(" + ",".join([escape(item, mapping) for item in obj]) + ")" |
| 550 | |
| 551 | if mapping is None: |
| 552 | mapping = self.encoders |
| 553 | return converters.escape_item(obj, self.encoding, mapping=mapping) |
| 554 | |
| 555 | def literal(self, obj) -> str: |
| 556 | """Alias for escape(). |