1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

use raw strings for regular expressions

This commit is contained in:
Kelly Brazil
2020-02-28 08:50:35 -08:00
parent c02b6b5d82
commit a18bf03079
2 changed files with 7 additions and 7 deletions

View File

@ -159,7 +159,7 @@ def parse(data, raw=False, quiet=False):
entry = entry.replace(' still logged in', '- still_logged_in') entry = entry.replace(' still logged in', '- still_logged_in')
linedata = entry.split() 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, '-') linedata.insert(2, '-')
output_line['user'] = linedata[0] output_line['user'] = linedata[0]

View File

@ -227,11 +227,11 @@ def parse(data, raw=False, quiet=False):
# Delete first line if it starts with 'total 1234' # Delete first line if it starts with 'total 1234'
if linedata: if linedata:
if re.match('^total [0-9]+', linedata[0]): if re.match(r'total [0-9]+', linedata[0]):
linedata.pop(0) linedata.pop(0)
# Look for parent line if glob or -R is used # 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(':'): and linedata[0].endswith(':'):
parent = linedata.pop(0)[:-1] parent = linedata.pop(0)[:-1]
# Pop following total line # Pop following total line
@ -239,13 +239,13 @@ def parse(data, raw=False, quiet=False):
if linedata: if linedata:
# Check if -l was used to parse extra data # 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: for entry in linedata:
output_line = {} output_line = {}
parsed_line = entry.split(maxsplit=8) 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(':'): and entry.endswith(':'):
parent = entry[:-1] parent = entry[:-1]
new_section = True new_section = True
@ -254,13 +254,13 @@ def parse(data, raw=False, quiet=False):
raw_output[-1]['filename'] = raw_output[-1]['filename'][:-1] raw_output[-1]['filename'] = raw_output[-1]['filename'][:-1]
continue continue
if re.match('^total [0-9]+', entry): if re.match(r'total [0-9]+', entry):
new_section = False new_section = False
continue continue
# fixup for filenames with newlines # fixup for filenames with newlines
if not new_section \ 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 raw_output[-1]['filename'] = raw_output[-1]['filename'] + '\n' + entry
continue continue