From f6b215938a9758f7c1e54ddc19161280a37dbe68 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 26 May 2021 19:30:08 +0530 Subject: [PATCH] fix: Use raw string to avoid invalid sequence errors Escaped when proven easier --- frappe/translate.py | 2 +- frappe/utils/__init__.py | 2 +- frappe/utils/data.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frappe/translate.py b/frappe/translate.py index f95fdad015..b7b780e594 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -589,7 +589,7 @@ def is_translatable(m): def add_line_number(messages, code): ret = [] messages = sorted(messages, key=lambda x: x[0]) - newlines = [m.start() for m in re.compile('\\n').finditer(code)] + newlines = [m.start() for m in re.compile(r'\n').finditer(code)] line = 1 newline_i = 0 for pos, message, context in messages: diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index 9985d2dcf3..2d3637d527 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -151,7 +151,7 @@ def split_emails(txt): # emails can be separated by comma or newline s = re.sub(r'[\t\n\r]', ' ', cstr(txt)) - for email in re.split('''[,\\n](?=(?:[^"]|"[^"]*")*$)''', s): + for email in re.split(r'[,\n](?=(?:[^"]|"[^"]*")*$)', s): email = strip(cstr(email)) if email: email_list.append(email) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 09b02a918a..df36524c16 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -454,7 +454,7 @@ def duration_to_seconds(duration): def validate_duration_format(duration): import re - is_valid_duration = re.match("^(?:(\d+d)?((^|\s)\d+h)?((^|\s)\d+m)?((^|\s)\d+s)?)$", duration) + is_valid_duration = re.match(r"^(?:(\d+d)?((^|\s)\d+h)?((^|\s)\d+m)?((^|\s)\d+s)?)$", duration) if not is_valid_duration: frappe.throw(frappe._("Value {0} must be in the valid duration format: d h m s").format(frappe.bold(duration))) @@ -1341,10 +1341,10 @@ def expand_relative_urls(html): return "".join(to_expand) - html = re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html) + html = re.sub(r'(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html) # background-image: url('/assets/...') - html = re.sub('(:[\s]?url)(\([\'"]?)((?!http)[^\'" >]+)([\'"]?\))', _expand_relative_urls, html) + html = re.sub(r'(:[\s]?url)(\([\'"]?)((?!http)[^\'" >]+)([\'"]?\))', _expand_relative_urls, html) return html def quoted(url): @@ -1355,7 +1355,7 @@ def quote_urls(html): groups = list(match.groups()) groups[2] = quoted(groups[2]) return "".join(groups) - return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)', + return re.sub(r'(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)', _quote_url, html) def unique(seq):