From feea2f3c44dd653efd106476777add1975fbe3ae Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 26 May 2021 16:32:41 +0530 Subject: [PATCH] fix: Use raw string to avoid invalid escape sequence errors --- .github/helper/roulette.py | 2 +- frappe/utils/__init__.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/helper/roulette.py b/.github/helper/roulette.py index ba775d6794..ea4f07b9f7 100644 --- a/.github/helper/roulette.py +++ b/.github/helper/roulette.py @@ -18,7 +18,7 @@ def is_js(file): return file.endswith("js") def is_docs(file): - regex = re.compile('\.(md|png|jpg|jpeg)$|^.github|LICENSE') + regex = re.compile(r'\.(md|png|jpg|jpeg)$|^.github|LICENSE') return bool(regex.search(file)) diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index e776d9945a..94eed0b2bb 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -117,7 +117,10 @@ def validate_email_address(email_str, throw=False): else: email_id = extract_email_id(e) - match = re.match("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", email_id.lower()) if email_id else None + match = re.match( + r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", + email_id.lower() + ) if email_id else None if not match: _valid = False @@ -287,7 +290,7 @@ def remove_blanks(d): def strip_html_tags(text): """Remove html tags from text""" - return re.sub("\<[^>]*\>", "", text) + return re.sub(r"\<[^>]*\>", "", text) def get_file_timestamp(fn): """ @@ -499,7 +502,7 @@ def is_markdown(text): elif "" in text: return False else: - return not re.search("|", text) + return not re.search(r"|", text) def get_sites(sites_path=None): if not sites_path: @@ -609,7 +612,7 @@ def check_format(email_id): def get_name_from_email_string(email_string, email_id, name): name = email_string.replace(email_id, '') - name = re.sub('[^A-Za-z0-9\u00C0-\u024F\/\_\' ]+', '', name).strip() + name = re.sub(r'[^A-Za-z0-9\u00C0-\u024F\/\_\' ]+', '', name).strip() if not name: name = email_id return name