Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kasa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@
try:
from rich import print as _do_echo
except ImportError:
# Remove 7-bit C1 ANSI sequences
# https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")

Check warning

Code scanning / CodeQL

Overly permissive regular expression range

Suspicious character range that is equivalent to \[@A-Z\].

Check warning

Code scanning / CodeQL

Overly permissive regular expression range

Suspicious character range that is equivalent to \[0-9:;<=>?\].

def _strip_rich_formatting(echo_func):
"""Strip rich formatting from messages."""

@wraps(echo_func)
def wrapper(message=None, *args, **kwargs):
if message is not None:
message = re.sub(r"\[/?.+?]", "", message)
message = ansi_escape.sub("", message)
echo_func(message, *args, **kwargs)

return wrapper
Expand Down