Skip to content

Commit

Permalink
fix: remove json related functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
artemrys authored and Artem Rys committed Nov 18, 2021
1 parent 1be2f2c commit def1dfe
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
33 changes: 0 additions & 33 deletions solnlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"datetime_to_seconds",
"is_true",
"is_false",
"escape_json_control_chars",
"retry",
"extract_http_scheme_host_port",
]
Expand Down Expand Up @@ -101,38 +100,6 @@ def is_false(val: Union[str, int]) -> bool:
return False


def escape_json_control_chars(json_str: str) -> str:
"""Escape json control chars in `json_str`.
Arguments:
json_str: Json string to escape.
Returns:
Escaped string.
"""

control_chars = ((r"\n", "\\\\n"), (r"\r", "\\\\r"), (r"\r\n", "\\\\r\\\\n"))
for ch, replace in control_chars:
json_str = json_str.replace(ch, replace)
return json_str


def unescape_json_control_chars(json_str: str) -> str:
"""Unescape json control chars in `json_str`.
Arguments:
json_str: Json string to unescape.
Returns:
Unescaped string.
"""

control_chars = (("\\\\n", r"\n"), ("\\\\r", r"\r"), ("\\\\r\\\\n", r"\r\n"))
for ch, replace in control_chars:
json_str = json_str.replace(ch, replace)
return json_str


def retry(
retries: int = 3,
reraise: bool = True,
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ def test_is_true(monkeypatch):
assert not utils.is_true(val)


def test_escape_json_control_chars(monkeypatch):
str1 = r"hello\nworld"
escaped_str1 = r"hello\\nworld"
assert escaped_str1 == utils.escape_json_control_chars(str1)

str1 = r"hello\rworld"
escaped_str1 = r"hello\\rworld"
assert escaped_str1 == utils.escape_json_control_chars(str1)

str1 = r"hello\r\nworld"
escaped_str1 = r"hello\\r\\nworld"
assert escaped_str1 == utils.escape_json_control_chars(str1)


def test_retry(monkeypatch):
def _old_func():
raise ValueError("Exception for test.")
Expand Down

0 comments on commit def1dfe

Please sign in to comment.