MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / escape

Method escape

pymysql/connections.py:535–553  ·  view source on GitHub ↗

Escape whatever value is passed. Non-standard, for internal use; do not use this in your applications.

(self, obj, mapping=None)

Source from the content-addressed store, hash-verified

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().

Callers 9

_send_autocommit_modeMethod · 0.95
literalMethod · 0.95
callprocMethod · 0.80
test_escape_stringMethod · 0.80
test_escape_list_itemMethod · 0.80

Calls 1

_escape_stringMethod · 0.95