Skip to content

Commit

Permalink
Use raw strings for regexes; fixes SyntaxWarning: invalid escape sequ…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
dlitz authored and keirf committed Sep 13, 2024
1 parent 623bd0f commit f139f46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions scripts/misc/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def print_usage():
download = False
url = sys.argv[1]

url = re.sub('github.com', 'nightly.link', url)
url = re.sub('suites/\d+', 'actions', url)
url = re.sub(r'github.com', 'nightly.link', url)
url = re.sub(r'suites/\d+', 'actions', url)
url += '.zip'
print(url)

if download:
res = requests.get(url)
content_disposition = res.headers['Content-Disposition']
zipname = re.search('filename=([^ ]+.zip);', content_disposition).group(1)
zipname = re.search(r'filename=([^ ]+.zip);', content_disposition).group(1)
print('Downloading to: ' + zipname)
with open(zipname, 'wb') as f:
f.write(res.content)
8 changes: 4 additions & 4 deletions src/greaseweazle/codec/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_diskdef(
active = False
continue
tracks_match = re.match(r'tracks\s+([0-9,.*-]+)'
'\s+([\w,.-]+)', t)
r'\s+([\w,.-]+)', t)
if tracks_match:
parse_mode = ParseMode.Track
if not active:
Expand All @@ -233,7 +233,7 @@ def get_diskdef(
disk.track_map[c,hd] = track
else:
t_match = re.match(r'(\d+)(?:-(\d+))?'
'(?:\.([01]))?', x)
r'(?:\.([01]))?', x)
error.check(t_match is not None,
'bad track specifier')
assert t_match is not None # mypy
Expand Down Expand Up @@ -261,7 +261,7 @@ def get_diskdef(
assert disk is not None # mypy

keyval_match = re.match(r'([a-zA-Z0-9:,._-]+)\s*='
'\s*([a-zA-Z0-9:,._-]+)', t)
r'\s*([a-zA-Z0-9:,._-]+)', t)
error.check(keyval_match is not None, 'syntax error')
assert keyval_match is not None # mypy
disk.add_param(keyval_match.group(1),
Expand All @@ -280,7 +280,7 @@ def get_diskdef(
assert track is not None # mypy

keyval_match = re.match(r'([a-zA-Z0-9:,._-]+)\s*='
'\s*([a-zA-Z0-9:,._*-]+)', t)
r'\s*([a-zA-Z0-9:,._*-]+)', t)
error.check(keyval_match is not None, 'syntax error')
assert keyval_match is not None # mypy
track.add_param(keyval_match.group(1),
Expand Down
22 changes: 11 additions & 11 deletions src/greaseweazle/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ def level(letter):
# Returns time period in seconds (float)
# Accepts rpm, ms, us, ns, scp. Naked value is assumed rpm.
def period(arg):
m = re.match('(\d*\.\d+|\d+)rpm', arg)
m = re.match(r'(\d*\.\d+|\d+)rpm', arg)
if m is not None:
return 60 / float(m.group(1))
m = re.match('(\d*\.\d+|\d+)ms', arg)
m = re.match(r'(\d*\.\d+|\d+)ms', arg)
if m is not None:
return float(m.group(1)) / 1e3
m = re.match('(\d*\.\d+|\d+)us', arg)
m = re.match(r'(\d*\.\d+|\d+)us', arg)
if m is not None:
return float(m.group(1)) / 1e6
m = re.match('(\d*\.\d+|\d+)ns', arg)
m = re.match(r'(\d*\.\d+|\d+)ns', arg)
if m is not None:
return float(m.group(1)) / 1e9
m = re.match('(\d*\.\d+|\d+)scp', arg)
m = re.match(r'(\d*\.\d+|\d+)scp', arg)
if m is not None:
return float(m.group(1)) / 40e6 # SCP @ 40MHz
return 60 / float(arg)
Expand Down Expand Up @@ -190,7 +190,7 @@ def update_from_trackspec(self, trackspec):
if k == 'c':
cyls = set()
for crange in v.split(','):
m = re.match('(\d+)(-(\d+)(/(\d+))?)?$', crange)
m = re.match(r'(\d+)(-(\d+)(/(\d+))?)?$', crange)
if m is None: raise ValueError()
if m.group(3) is None:
s,e,step = int(m.group(1)), int(m.group(1)), 1
Expand All @@ -204,7 +204,7 @@ def update_from_trackspec(self, trackspec):
elif k == 'h':
heads = [False]*2
for hrange in v.split(','):
m = re.match('([01])(-([01]))?$', hrange)
m = re.match(r'([01])(-([01]))?$', hrange)
if m is None: raise ValueError()
if m.group(3) is None:
s,e = int(m.group(1)), int(m.group(1))
Expand All @@ -215,13 +215,13 @@ def update_from_trackspec(self, trackspec):
self.heads = []
for h in range(len(heads)):
if heads[h]: self.heads.append(h)
elif re.match('h[01].off$', k):
h = int(re.match('h([01]).off$', k).group(1))
m = re.match('([+-]\d+)$', v)
elif re.match(r'h[01].off$', k):
h = int(re.match(r'h([01]).off$', k).group(1))
m = re.match(r'([+-]\d+)$', v)
if m is None: raise ValueError()
self.h_off[h] = int(m.group(1))
elif k == 'step':
m = re.match('1/(\d+)$', v)
m = re.match(r'1/(\d+)$', v)
self.step = -int(m.group(1)) if m is not None else int(v)
else:
raise ValueError()
Expand Down

0 comments on commit f139f46

Please sign in to comment.