-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathppp_utils.py
More file actions
56 lines (42 loc) · 1.24 KB
/
ppp_utils.py
File metadata and controls
56 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def deep_freeze(obj):
"""
Deep freeze an object.
Args:
obj (object): The object to freeze.
Returns:
object: The frozen object.
"""
if isinstance(obj, dict):
return tuple((k, deep_freeze(v)) for k, v in sorted(obj.items()))
if isinstance(obj, list):
return tuple(deep_freeze(i) for i in obj)
if isinstance(obj, set):
return tuple(deep_freeze(i) for i in sorted(obj))
return obj
def escape_single_quotes(s: str):
"""
Escape single quotes in a string.
Args:
s (str): The string to escape.
Returns:
str: The escaped string.
"""
return s.replace("'", "\\'")
def escape_double_quotes(s: str):
"""
Escape double quotes in a string.
Args:
s (str): The string to escape.
Returns:
str: The escaped string.
"""
return s.replace('"', '\\"')
def format_output(text: str) -> str:
"""
Formats the output text by encoding it using unicode_escape and decoding it using utf-8.
Args:
text (str): The input text to be formatted.
Returns:
str: The formatted output text.
"""
return text.encode("unicode_escape").decode("utf-8")