MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _anonymous_label

Class _anonymous_label

lib/sqlalchemy/sql/elements.py:5968–6036  ·  view source on GitHub ↗

A unicode subclass used to identify anonymously generated names.

Source from the content-addressed store, hash-verified

5966
5967
5968class _anonymous_label(_truncated_label):
5969 """A unicode subclass used to identify anonymously
5970 generated names."""
5971
5972 __slots__ = ()
5973
5974 @classmethod
5975 def safe_construct_with_key(
5976 cls, seed: int | str, body: str, sanitize_key: bool = False
5977 ) -> typing_Tuple[_anonymous_label, str]:
5978 # need to escape chars that interfere with format
5979 # strings in any case, issue #8724
5980 body = _anonymous_label_escape.sub("_", body)
5981
5982 if sanitize_key:
5983 # sanitize_key is then an extra step used by BindParameter
5984 body = body.strip("_")
5985
5986 key = f"{seed} {body.replace('%', '%%')}"
5987 label = _anonymous_label(f"%({key})s")
5988 return label, key
5989
5990 @classmethod
5991 def safe_construct(
5992 cls, seed: int | str, body: str, sanitize_key: bool = False
5993 ) -> _anonymous_label:
5994 # need to escape chars that interfere with format
5995 # strings in any case, issue #8724
5996 body = _anonymous_label_escape.sub("_", body)
5997
5998 if sanitize_key:
5999 # sanitize_key is then an extra step used by BindParameter
6000 body = body.strip("_")
6001
6002 return _anonymous_label(f"%({seed} {body.replace('%', '%%')})s")
6003
6004 def __add__(self, other: str) -> _anonymous_label:
6005 if "%" in other and not isinstance(other, _anonymous_label):
6006 other = str(other).replace("%", "%%")
6007 else:
6008 other = str(other)
6009
6010 return _anonymous_label(
6011 quoted_name(
6012 str.__add__(self, other),
6013 self.quote,
6014 )
6015 )
6016
6017 def __radd__(self, other: str) -> _anonymous_label:
6018 if "%" in other and not isinstance(other, _anonymous_label):
6019 other = str(other).replace("%", "%%")
6020 else:
6021 other = str(other)
6022
6023 return _anonymous_label(
6024 quoted_name(
6025 str.__add__(other, self),

Callers 10

test_concat_anonMethod · 0.90
test_rconcat_anonMethod · 0.90
test_apply_map_quotedMethod · 0.90
test_apply_map_plainMethod · 0.90
_anon_labelMethod · 0.85
safe_constructMethod · 0.85
__add__Method · 0.85
__radd__Method · 0.85

Calls

no outgoing calls

Tested by 5

test_concat_anonMethod · 0.72
test_rconcat_anonMethod · 0.72
test_apply_map_quotedMethod · 0.72
test_apply_map_plainMethod · 0.72