Lint: W605 invalid escape sequence '<char>'

The previous attempt to correct these with character classes failed.
Instead, use the proper `r'blah'` regex formatting.
This commit is contained in:
Joshua Boniface 2020-11-07 17:41:09 -05:00
parent 3ed97d209f
commit 0bf130077c
6 changed files with 33 additions and 33 deletions

View File

@ -70,11 +70,11 @@ def list_ova(limit, is_fuzzy=True):
if limit: if limit:
if is_fuzzy: if is_fuzzy:
# Handle fuzzy vs. non-fuzzy limits # Handle fuzzy vs. non-fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '%' + limit limit = '%' + limit
else: else:
limit = limit[1:] limit = limit[1:]
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '%' limit = limit + '%'
else: else:
limit = limit[:-1] limit = limit[:-1]
@ -252,7 +252,7 @@ def upload_ova(pool, name, ova_size):
return output, retcode return output, retcode
# Parse through the members list and extract the OVF file # Parse through the members list and extract the OVF file
for element in set(x for x in members if re.match('.*\.ovf$', x.name)): for element in set(x for x in members if re.match(r'.*\.ovf$', x.name)):
ovf_file = ova_archive.extractfile(element) ovf_file = ova_archive.extractfile(element)
# Parse the OVF file to get our VM details # Parse the OVF file to get our VM details

View File

@ -106,11 +106,11 @@ def list_template(limit, table, is_fuzzy=True):
if limit: if limit:
if is_fuzzy: if is_fuzzy:
# Handle fuzzy vs. non-fuzzy limits # Handle fuzzy vs. non-fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '%' + limit limit = '%' + limit
else: else:
limit = limit[1:] limit = limit[1:]
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '%' limit = limit + '%'
else: else:
limit = limit[:-1] limit = limit[:-1]
@ -606,11 +606,11 @@ def list_userdata(limit, is_fuzzy=True):
if limit: if limit:
if is_fuzzy: if is_fuzzy:
# Handle fuzzy vs. non-fuzzy limits # Handle fuzzy vs. non-fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '%' + limit limit = '%' + limit
else: else:
limit = limit[1:] limit = limit[1:]
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '%' limit = limit + '%'
else: else:
limit = limit[:-1] limit = limit[:-1]
@ -701,11 +701,11 @@ def list_script(limit, is_fuzzy=True):
if limit: if limit:
if is_fuzzy: if is_fuzzy:
# Handle fuzzy vs. non-fuzzy limits # Handle fuzzy vs. non-fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '%' + limit limit = '%' + limit
else: else:
limit = limit[1:] limit = limit[1:]
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '%' limit = limit + '%'
else: else:
limit = limit[:-1] limit = limit[:-1]
@ -796,11 +796,11 @@ def list_profile(limit, is_fuzzy=True):
if limit: if limit:
if is_fuzzy: if is_fuzzy:
# Handle fuzzy vs. non-fuzzy limits # Handle fuzzy vs. non-fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '%' + limit limit = '%' + limit
else: else:
limit = limit[1:] limit = limit[1:]
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '%' limit = limit + '%'
else: else:
limit = limit[:-1] limit = limit[:-1]

View File

@ -733,11 +733,11 @@ def vm_modify(domain, cfgfile, editor, restart):
click.echo('') click.echo('')
diff = list(difflib.unified_diff(current_vm_cfgfile.split('\n'), new_vm_cfgfile.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm='')) diff = list(difflib.unified_diff(current_vm_cfgfile.split('\n'), new_vm_cfgfile.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm=''))
for line in diff: for line in diff:
if re.match('^\+', line) is not None: if re.match(r'^\+', line) is not None:
click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET) click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET)
elif re.match('^\-', line) is not None: elif re.match(r'^\-', line) is not None:
click.echo(colorama.Fore.RED + line + colorama.Fore.RESET) click.echo(colorama.Fore.RED + line + colorama.Fore.RESET)
elif re.match('^\^', line) is not None: elif re.match(r'^\^', line) is not None:
click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET) click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET)
else: else:
click.echo(line) click.echo(line)
@ -3039,11 +3039,11 @@ def provisioner_userdata_modify(name, filename, editor):
click.echo('') click.echo('')
diff = list(difflib.unified_diff(current_userdata.split('\n'), new_userdata.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm='')) diff = list(difflib.unified_diff(current_userdata.split('\n'), new_userdata.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm=''))
for line in diff: for line in diff:
if re.match('^\+', line) is not None: if re.match(r'^\+', line) is not None:
click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET) click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET)
elif re.match('^\-', line) is not None: elif re.match(r'^\-', line) is not None:
click.echo(colorama.Fore.RED + line + colorama.Fore.RESET) click.echo(colorama.Fore.RED + line + colorama.Fore.RESET)
elif re.match('^\^', line) is not None: elif re.match(r'^\^', line) is not None:
click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET) click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET)
else: else:
click.echo(line) click.echo(line)
@ -3224,11 +3224,11 @@ def provisioner_script_modify(name, filename, editor):
click.echo('') click.echo('')
diff = list(difflib.unified_diff(current_script.split('\n'), new_script.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm='')) diff = list(difflib.unified_diff(current_script.split('\n'), new_script.split('\n'), fromfile='current', tofile='modified', fromfiledate='', tofiledate='', n=3, lineterm=''))
for line in diff: for line in diff:
if re.match('^\+', line) is not None: if re.match(r'^\+', line) is not None:
click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET) click.echo(colorama.Fore.GREEN + line + colorama.Fore.RESET)
elif re.match('^\-', line) is not None: elif re.match(r'^\-', line) is not None:
click.echo(colorama.Fore.RED + line + colorama.Fore.RESET) click.echo(colorama.Fore.RED + line + colorama.Fore.RESET)
elif re.match('^\^', line) is not None: elif re.match(r'^\^', line) is not None:
click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET) click.echo(colorama.Fore.BLUE + line + colorama.Fore.RESET)
else: else:
click.echo(line) click.echo(line)

View File

@ -118,7 +118,7 @@ def format_bytes_fromhuman(datahuman):
# Trim off human-readable character # Trim off human-readable character
dataunit = str(datahuman)[-1] dataunit = str(datahuman)[-1]
datasize = int(str(datahuman)[:-1]) datasize = int(str(datahuman)[:-1])
if not re.match('[A-Z]', dataunit): if not re.match(r'[A-Z]', dataunit):
dataunit = 'B' dataunit = 'B'
datasize = int(datahuman) datasize = int(datahuman)
databytes = datasize * byte_unit_matrix[dataunit] databytes = datasize * byte_unit_matrix[dataunit]
@ -322,9 +322,9 @@ def get_list_osd(zk_conn, limit, is_fuzzy=True):
if is_fuzzy and limit: if is_fuzzy and limit:
# Implicitly assume fuzzy limits # Implicitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
for osd in full_osd_list: for osd in full_osd_list:
@ -658,9 +658,9 @@ def get_list_volume(zk_conn, pool, limit, is_fuzzy=True):
limit = '^' + limit + '$' limit = '^' + limit + '$'
else: else:
# Implicitly assume fuzzy limits # Implicitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
for volume in full_volume_list: for volume in full_volume_list:
@ -764,9 +764,9 @@ def get_list_snapshot(zk_conn, pool, volume, limit, is_fuzzy=True):
if is_fuzzy and limit: if is_fuzzy and limit:
# Implicitly assume fuzzy limits # Implicitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
for snapshot in full_snapshot_list: for snapshot in full_snapshot_list:

View File

@ -574,9 +574,9 @@ def get_list_dhcp(zk_conn, network, limit, only_static=False, is_fuzzy=True):
limit = '^' + limit + '$' limit = '^' + limit + '$'
# Implcitly assume fuzzy limits # Implcitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
except Exception as e: except Exception as e:
return False, 'Regex Error: {}'.format(e) return False, 'Regex Error: {}'.format(e)
@ -620,9 +620,9 @@ def get_list_acl(zk_conn, network, limit, direction, is_fuzzy=True):
limit = '^' + limit + '$' limit = '^' + limit + '$'
# Implcitly assume fuzzy limits # Implcitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
except Exception as e: except Exception as e:
return False, 'Regex Error: {}'.format(e) return False, 'Regex Error: {}'.format(e)

View File

@ -689,9 +689,9 @@ def get_list(zk_conn, node, state, limit, is_fuzzy=True):
if limit and is_fuzzy: if limit and is_fuzzy:
try: try:
# Implcitly assume fuzzy limits # Implcitly assume fuzzy limits
if not re.match('\^.*', limit): if not re.match(r'\^.*', limit):
limit = '.*' + limit limit = '.*' + limit
if not re.match('.*\$', limit): if not re.match(r'.*\$', limit):
limit = limit + '.*' limit = limit + '.*'
except Exception as e: except Exception as e:
return False, 'Regex Error: {}'.format(e) return False, 'Regex Error: {}'.format(e)