Skip to content

Commit def1dfe

Browse files
artemrysArtem Rys
authored andcommitted
fix: remove json related functions
Removes escape_json_control_chars and unescape_json_control_chars as they are not used across add-ons and should not be a part of solnlib.
1 parent 1be2f2c commit def1dfe

File tree

2 files changed

+0
-47
lines changed

2 files changed

+0
-47
lines changed

solnlib/utils.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"datetime_to_seconds",
3232
"is_true",
3333
"is_false",
34-
"escape_json_control_chars",
3534
"retry",
3635
"extract_http_scheme_host_port",
3736
]
@@ -101,38 +100,6 @@ def is_false(val: Union[str, int]) -> bool:
101100
return False
102101

103102

104-
def escape_json_control_chars(json_str: str) -> str:
105-
"""Escape json control chars in `json_str`.
106-
107-
Arguments:
108-
json_str: Json string to escape.
109-
110-
Returns:
111-
Escaped string.
112-
"""
113-
114-
control_chars = ((r"\n", "\\\\n"), (r"\r", "\\\\r"), (r"\r\n", "\\\\r\\\\n"))
115-
for ch, replace in control_chars:
116-
json_str = json_str.replace(ch, replace)
117-
return json_str
118-
119-
120-
def unescape_json_control_chars(json_str: str) -> str:
121-
"""Unescape json control chars in `json_str`.
122-
123-
Arguments:
124-
json_str: Json string to unescape.
125-
126-
Returns:
127-
Unescaped string.
128-
"""
129-
130-
control_chars = (("\\\\n", r"\n"), ("\\\\r", r"\r"), ("\\\\r\\\\n", r"\r\n"))
131-
for ch, replace in control_chars:
132-
json_str = json_str.replace(ch, replace)
133-
return json_str
134-
135-
136103
def retry(
137104
retries: int = 3,
138105
reraise: bool = True,

tests/unit/test_utils.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@ def test_is_true(monkeypatch):
6464
assert not utils.is_true(val)
6565

6666

67-
def test_escape_json_control_chars(monkeypatch):
68-
str1 = r"hello\nworld"
69-
escaped_str1 = r"hello\\nworld"
70-
assert escaped_str1 == utils.escape_json_control_chars(str1)
71-
72-
str1 = r"hello\rworld"
73-
escaped_str1 = r"hello\\rworld"
74-
assert escaped_str1 == utils.escape_json_control_chars(str1)
75-
76-
str1 = r"hello\r\nworld"
77-
escaped_str1 = r"hello\\r\\nworld"
78-
assert escaped_str1 == utils.escape_json_control_chars(str1)
79-
80-
8167
def test_retry(monkeypatch):
8268
def _old_func():
8369
raise ValueError("Exception for test.")

0 commit comments

Comments
 (0)