Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raw strings for regexes; fixes SyntaxWarning: invalid escape sequence #486

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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