From a18bf030794efef125c70a32fe82855e47649b32 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 28 Feb 2020 08:50:35 -0800 Subject: [PATCH] use raw strings for regular expressions --- jc/parsers/last.py | 2 +- jc/parsers/ls.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jc/parsers/last.py b/jc/parsers/last.py index 22ebdfcf..af7bb37f 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -159,7 +159,7 @@ def parse(data, raw=False, quiet=False): entry = entry.replace(' still logged in', '- still_logged_in') linedata = entry.split() - if re.match('[MTWFS][ouerha][nedritnu] [JFMASOND][aepuco][nbrynlgptvc]', ' '.join(linedata[2:4])): + if re.match(r'[MTWFS][ouerha][nedritnu] [JFMASOND][aepuco][nbrynlgptvc]', ' '.join(linedata[2:4])): linedata.insert(2, '-') output_line['user'] = linedata[0] diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index ec0dd6f1..9bcf0914 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -227,11 +227,11 @@ def parse(data, raw=False, quiet=False): # Delete first line if it starts with 'total 1234' if linedata: - if re.match('^total [0-9]+', linedata[0]): + if re.match(r'total [0-9]+', linedata[0]): linedata.pop(0) # Look for parent line if glob or -R is used - if not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \ + if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]) \ and linedata[0].endswith(':'): parent = linedata.pop(0)[:-1] # Pop following total line @@ -239,13 +239,13 @@ def parse(data, raw=False, quiet=False): if linedata: # Check if -l was used to parse extra data - if re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]): + if re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', linedata[0]): for entry in linedata: output_line = {} parsed_line = entry.split(maxsplit=8) - if not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ + if not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry) \ and entry.endswith(':'): parent = entry[:-1] new_section = True @@ -254,13 +254,13 @@ def parse(data, raw=False, quiet=False): raw_output[-1]['filename'] = raw_output[-1]['filename'][:-1] continue - if re.match('^total [0-9]+', entry): + if re.match(r'total [0-9]+', entry): new_section = False continue # fixup for filenames with newlines if not new_section \ - and not re.match('^[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry): + and not re.match(r'[-dclpsbDCMnP?]([-r][-w][-xsS]){2}([-r][-w][-xtT])[+]?', entry): raw_output[-1]['filename'] = raw_output[-1]['filename'] + '\n' + entry continue