mirror of
https://github.com/RYGhub/royalnet.git
synced 2025-03-31 04:10:31 +00:00
13 lines
408 B
Python
13 lines
408 B
Python
class SafeDict(dict):
|
|
def __missing__(self, key):
|
|
return "{" + key + "}"
|
|
|
|
|
|
def safeformat(string: str, ignore_escaping: bool = False, **words: str) -> str:
|
|
if ignore_escaping:
|
|
escaped = words
|
|
else:
|
|
escaped = {}
|
|
for key in words:
|
|
escaped[key] = str(words[key]).replace("<", "<").replace(">", ">")
|
|
return string.format_map(SafeDict(**escaped))
|