From e7d33407aeb153ae713fe7b7932749e9814f3787 Mon Sep 17 00:00:00 2001 From: Peter Grayson Date: Wed, 30 Aug 2017 22:06:26 -0400 Subject: [PATCH] Use raw strings for regexps with unescaped \'s Signed-off-by: Peter Grayson --- stgit/commands/common.py | 14 +++++++------- stgit/commands/imprt.py | 6 +++--- stgit/commands/mail.py | 2 +- stgit/stack.py | 4 ++-- stgit/utils.py | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 13931c0..1a17f2e 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -339,7 +339,7 @@ def post_rebase(crt_series, applied, nopush, merged): # Patch description/e-mail/diff parsing # def __end_descr(line): - return re.match('---\s*$', line) or re.match('diff -', line) or \ + return re.match(r'---\s*$', line) or re.match('diff -', line) or \ re.match('Index: ', line) or re.match('--- \w', line) def __split_descr_diff(string): @@ -379,21 +379,21 @@ def __parse_description(descr): if not descr_lines[pos]: continue # check for a "From|Author:" line - if re.match('\s*(?:from|author):\s+', descr_lines[pos], re.I): - auth = re.findall('^.*?:\s+(.*)$', descr_lines[pos])[0] + if re.match(r'\s*(?:from|author):\s+', descr_lines[pos], re.I): + auth = re.findall(r'^.*?:\s+(.*)$', descr_lines[pos])[0] authname, authemail = name_email(auth) lasthdr = pos + 1 continue # check for a "Date:" line - if re.match('\s*date:\s+', descr_lines[pos], re.I): - authdate = re.findall('^.*?:\s+(.*)$', descr_lines[pos])[0] + if re.match(r'\s*date:\s+', descr_lines[pos], re.I): + authdate = re.findall(r'^.*?:\s+(.*)$', descr_lines[pos])[0] lasthdr = pos + 1 continue if subject: break # get the subject subject = descr_lines[pos][descr_strip:] - if re.match('commit [\da-f]{40}$', subject): + if re.match(r'commit [\da-f]{40}$', subject): # 'git show' output, look for the real subject subject = '' descr_strip = 4 @@ -433,7 +433,7 @@ def parse_mail(msg): # remove the '[*PATCH*]' expression in the subject if descr: - descr = re.findall('^(\[.*?[Pp][Aa][Tt][Cc][Hh].*?\])?\s*(.*)$', + descr = re.findall(r'^(\[.*?[Pp][Aa][Tt][Cc][Hh].*?\])?\s*(.*)$', descr)[0][1] else: raise CmdException('Subject: line not found') diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py index 15cbeb5..a6b01ba 100644 --- a/stgit/commands/imprt.py +++ b/stgit/commands/imprt.py @@ -104,8 +104,8 @@ options = [ directory = DirectoryHasRepository(log = True) def __strip_patch_name(name): - stripped = re.sub('^[0-9]+-(.*)$', '\g<1>', name) - stripped = re.sub('^(.*)\.(diff|patch)$', '\g<1>', stripped) + stripped = re.sub('^[0-9]+-(.*)$', r'\g<1>', name) + stripped = re.sub(r'^(.*)\.(diff|patch)$', r'\g<1>', stripped) return stripped @@ -135,7 +135,7 @@ def __create_patch(filename, message, author_name, author_email, patch = make_patch_name(message, unacceptable_name) else: # fix possible invalid characters in the patch name - patch = re.sub('[^\w.]+', '-', patch).strip('-') + patch = re.sub(r'[^\w.]+', '-', patch).strip('-') if options.ignore and patch in crt_series.get_applied(): out.info('Ignoring already applied patch "%s"' % patch) diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 2bbbc50..c9b67f5 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -395,7 +395,7 @@ def __get_signers_list(msg): 'tested-by', 'suggested-by', 'reported-and-tested-by') - regex = '^(%s):\s+(.+)$' % tags + regex = r'^(%s):\s+(.+)$' % tags r = re.compile(regex, re.I) for line in msg.split('\n'): diff --git a/stgit/stack.py b/stgit/stack.py index e1619d0..e55787f 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -259,7 +259,7 @@ class Patch(StgitObject): if not date: return date - if re.match('[0-9]+\s+[+-][0-9]+', date): + if re.match(r'[0-9]+\s+[+-][0-9]+', date): # Unix time (seconds) + time zone secs_tz = date.split() date = formatdate(int(secs_tz[0]))[:-5] + secs_tz[1] @@ -393,7 +393,7 @@ class Series(PatchSet): def __patch_name_valid(self, name): """Raise an exception if the patch name is not valid. """ - if not name or re.search('[^\w.-]', name): + if not name or re.search(r'[^\w.-]', name): raise StackException('Invalid patch name: "%s"' % name) def get_patch(self, name): diff --git a/stgit/utils.py b/stgit/utils.py index 609d7cb..ff78ea8 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -271,7 +271,7 @@ def patch_name_from_msg(msg): name_len = 30 subject_line = msg.split('\n', 1)[0].lstrip().lower() - words = re.sub('[\W]+', ' ', subject_line).split() + words = re.sub(r'[\W]+', ' ', subject_line).split() # use loop to avoid truncating the last name name = words and words[0] or 'unknown' @@ -322,7 +322,7 @@ def parse_name_email_date(address): """Return a tuple consisting of the name, email and date parsed from a 'name date' string.""" address = re.sub(r'[\\"]', r'\\\g<0>', address) - str_list = re.findall('^(.*)\s*<(.*)>\s*(.*)\s*$', address) + str_list = re.findall(r'^(.*)\s*<(.*)>\s*(.*)\s*$', address) if not str_list: return None return str_list[0] -- 2.11.4.GIT