Commit 6b134225 authored by Guido Günther's avatar Guido Günther

Fix flake8's W605 (invalid escape sequence)

See also

    https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
parent 497addcb
......@@ -29,19 +29,19 @@ class DscFile(object):
compressions = r"(%s)" % '|'.join(DebianUpstreamSource.known_compressions())
pkg_re = re.compile(r'Source:\s+(?P<pkg>.+)\s*')
version_re = re.compile(r'Version:\s((?P<epoch>\d+)\:)?'
'(?P<version>[%s]+)\s*$'
r'(?P<version>[%s]+)\s*$'
% DebianPkgPolicy.debianversion_chars)
tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+'
'(\.orig)?\.tar\.%s)$' % compressions)
r'(\.orig)?\.tar\.%s)$' % compressions)
add_tar_re = re.compile(r'^\s\w+\s\d+\s+(?P<tar>[^_]+_[^_]+'
'\.orig-(?P<dir>[a-zA-Z0-9-]+)\.tar\.%s)$' % compressions)
r'\.orig-(?P<dir>[a-zA-Z0-9-]+)\.tar\.%s)$' % compressions)
diff_re = re.compile(r'^\s\w+\s\d+\s+(?P<diff>[^_]+_[^_]+'
'\.diff.(gz|bz2))$')
r'\.diff.(gz|bz2))$')
deb_tgz_re = re.compile(r'^\s\w+\s\d+\s+(?P<deb_tgz>[^_]+_[^_]+'
'\.debian.tar.%s)$' % compressions)
r'\.debian.tar.%s)$' % compressions)
format_re = re.compile(r'Format:\s+(?P<format>[0-9.]+)\s*')
sig_re = re.compile(r'^\s\w+\s\d+\s+(?P<sig>[^_]+_[^_]+'
'\.orig(-[a-z0-9-]+)?\.tar\.%s.asc)$' % compressions)
r'\.orig(-[a-z0-9-]+)?\.tar\.%s.asc)$' % compressions)
def __init__(self, dscfile):
self.pkg = ""
......
......@@ -33,9 +33,9 @@ class DebianGitRepository(PkgGitRepository):
"""A git repository that holds the source of a Debian package"""
version_mangle_re = (r'%\(version'
'%(?P<M>[^%])'
'%(?P<R>([^%]|\\%))+'
'\)s')
r'%(?P<M>[^%])'
r'%(?P<R>([^%]|\\%))+'
r'\)s')
def __init__(self, *args, **kwargs):
super(DebianGitRepository, self).__init__(*args, **kwargs)
......@@ -166,7 +166,7 @@ class DebianGitRepository(PkgGitRepository):
'libfoo-1-8-1'
>>> DebianGitRepository.version_to_tag("v%(version%.%_)s", "1.2.3")
'v1_2_3'
>>> DebianGitRepository.version_to_tag("%(version%-%\%)s", "0-1.2.3")
>>> DebianGitRepository.version_to_tag(r'%(version%-%\\%)s', "0-1.2.3")
'0%1.2.3'
"""
f, v = cls._mangle_version(format, version)
......@@ -178,13 +178,13 @@ class DebianGitRepository(PkgGitRepository):
"""
Basic version mangling to replce single characters
>>> DebianGitRepository._mangle_version("%(version%-%\%)s", "0-1.2.3")
>>> DebianGitRepository._mangle_version(r'%(version%-%\\%)s', "0-1.2.3")
('%(version)s', '0%1.2.3')
"""
r = re.search(cls.version_mangle_re, format)
if r:
f = re.sub(cls.version_mangle_re, "%(version)s", format)
v = version.replace(r.group('M'), r.group('R').replace('\%', '%'))
v = version.replace(r.group('M'), r.group('R').replace(r'\%', '%'))
return f, v
else:
return format, version
......@@ -207,7 +207,7 @@ class DebianGitRepository(PkgGitRepository):
"""
r = re.search(cls.version_mangle_re, format)
if r:
v = tag.replace(r.group('R').replace('\%', '%'), r.group('M'))
v = tag.replace(r.group('R').replace(r'\%', '%'), r.group('M'))
return v
else:
return tag
......@@ -231,7 +231,7 @@ class DebianGitRepository(PkgGitRepository):
>>> DebianGitRepository._sanitize_version("0.lock")
'0.#lock'
"""
v = re.sub('\.(?=\.|$|lock$)', '.#', version)
v = re.sub(r'\.(?=\.|$|lock$)', '.#', version)
return v.replace('~', '_').replace(':', '%')
@staticmethod
......@@ -262,7 +262,7 @@ class DebianGitRepository(PkgGitRepository):
>>> DebianGitRepository.tag_to_version("foo/2.3.4", "upstream/%(version)s")
"""
f = cls._unmangle_format(format)
version_re = f.replace('%(version)s', '(?P<version>[\w_%+-.#]+)')
version_re = f.replace('%(version)s', r'(?P<version>[\w_%+-.#]+)')
r = re.match(version_re, tag)
if r:
v = cls._unsanitize_version(r.group('version'))
......
......@@ -43,7 +43,7 @@ class DebianPkgPolicy(PkgPolicy):
# must consist only of lower case letters (a-z), digits (0-9), plus (+)
# and minus (-) signs, and periods (.). They must be at least two
# characters long and must start with an alphanumeric character."
packagename_re = re.compile("^[a-zA-Z0-9][a-zA-Z0-9\.\+\-~]+$")
packagename_re = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9\.\+\-~]+$')
packagename_msg = """Package names must be at least two characters long, start with an
alphanumeric and can only containg letters (a-z,A-Z), digits
(0-9), plus signs (+), minus signs (-), periods (.) and hyphens (~)"""
......@@ -55,7 +55,7 @@ class DebianPkgPolicy(PkgPolicy):
# are not allowed; if there is no epoch then colons are not allowed."
# Since we don't know about any epochs and debian revisions yet, the
# last two conditions are not checked.
upstreamversion_re = re.compile("^[0-9][a-zA-Z0-9\.\+\-\:\~]*$")
upstreamversion_re = re.compile(r'^[0-9][a-zA-Z0-9\.\+\-\:\~]*$')
upstreamversion_msg = """Upstream version numbers must start with a digit and can only containg lower case
letters (a-z), digits (0-9), full stops (.), plus signs (+), minus signs
(-), colons (:) and tildes (~)"""
......
......@@ -36,11 +36,11 @@ class DebianPristineTar(PristineTar):
@type comp_type: C{str}
"""
if not comp_type:
ext = '\w\+'
ext = r'\w\+'
else:
ext = Compressor.Exts[comp_type]
name_regexp = '%s_%s\.orig\.tar\.%s' % (package, version, ext)
name_regexp = r'%s_%s\.orig\.tar\.%s' % (package, version, ext)
return super(DebianPristineTar, self).has_commit(name_regexp)
......
......@@ -1186,10 +1186,10 @@ class GitRepository(object):
fetch_url = None
push_urls = []
for line in out.decode().splitlines():
match = re.match('\s*Fetch\s+URL:\s*(\S.*)', line)
match = re.match(r'\s*Fetch\s+URL:\s*(\S.*)', line)
if match:
fetch_url = match.group(1)
match = re.match('\s*Push\s+URL:\s*(\S.*)', line)
match = re.match(r'\s*Push\s+URL:\s*(\S.*)', line)
if match:
push_urls.append(match.group(1))
remotes[remote] = GitRemote(remote, fetch_url, push_urls)
......
......@@ -272,8 +272,8 @@ class PatchSeries(list):
"""
A series of L{Patch}es as read from a quilt series file).
"""
comment_re = re.compile('\s+#.*$')
level_re = re.compile('-p(?P<level>[0-9]+)')
comment_re = re.compile(r'\s+#.*$')
level_re = re.compile(r'-p(?P<level>[0-9]+)')
@classmethod
def read_series_file(cls, seriesfile):
......
......@@ -115,11 +115,11 @@ class SrcRpmFile(object):
class SpecFile(object):
"""Class for parsing/modifying spec files"""
tag_re = re.compile(r'^(?P<name>[a-z]+)(?P<num>[0-9]+)?\s*:\s*'
'(?P<value>\S(.*\S)?)\s*$', flags=re.I)
r'(?P<value>\S(.*\S)?)\s*$', flags=re.I)
directive_re = re.compile(r'^%(?P<name>[a-z]+)(?P<num>[0-9]+)?'
'(\s+(?P<args>.*))?$', flags=re.I)
r'(\s+(?P<args>.*))?$', flags=re.I)
gbptag_re = re.compile(r'^\s*#\s*gbp-(?P<name>[a-z-]+)'
'(\s*:\s*(?P<args>\S.*))?$', flags=re.I)
r'(\s*:\s*(?P<args>\S.*))?$', flags=re.I)
# Here "sections" stand for all scripts, scriptlets and other directives,
# but not macros
section_identifiers = ('package', 'description', 'prep', 'build', 'install',
......@@ -626,7 +626,7 @@ class SpecFile(object):
if not tag['num'] in ignored:
tag_prev = self._delete_tag('patch', tag['num'])
# Remove a preceding comment if it seems to originate from GBP
if re.match("^\s*#.*patch.*auto-generated",
if re.match(r'^\s*#.*patch.*auto-generated',
str(tag_prev), flags=re.I):
tag_prev = self._content.delete(tag_prev)
......@@ -643,7 +643,7 @@ class SpecFile(object):
# Remove a preceding comment line if it ends with '.patch' or
# '.diff' plus an optional compression suffix
if re.match("^\s*#.+(patch|diff)(\.(gz|bz2|xz|lzma))?\s*$",
if re.match(r'^\s*#.+(patch|diff)(\.(gz|bz2|xz|lzma))?\s*$',
str(macro_prev), flags=re.I):
macro_prev = self._content.delete(macro_prev)
......
......@@ -30,9 +30,9 @@ class RpmPkgPolicy(PkgPolicy):
alnum = 'a-zA-Z0-9'
# Valid characters for RPM pkg name
name_whitelist_chars = '._+%{}\-'
name_whitelist_chars = r'._+%{}\-'
# Valid characters for RPM pkg version
version_whitelist_chars = '._+%{}~'
version_whitelist_chars = r'._+%{}~'
# Regexp for checking the validity of package name
packagename_re = re.compile("^[%s][%s%s]+$" %
......
......@@ -152,7 +152,7 @@ def write_patch_file(filename, commit_info, diff):
name = commit_info['author']['name']
email = commit_info['author']['email']
# Git compat: put name in quotes if special characters found
if re.search("[,.@()\[\]\\\:;]", name):
if re.search(r'[,.@()\[\]\\\:;]', name):
name = '"%s"' % name
from_header = Header(header_name='from')
try:
......@@ -216,7 +216,7 @@ def format_patch(outdir, repo, commit_info, series, abbrev, numbered=True,
if renumber:
# Remove any existing numeric prefix if the patch
# should be renumbered
name = re.sub('^\d+[-_]*', '', name)
name = re.sub(r'^\d+[-_]*', '', name)
else:
# Otherwise, clear proposed prefix
num_prefix = ''
......
......@@ -34,7 +34,7 @@ from gbp.scripts.common import ExitCodes, maybe_debug_raise
from gbp.scripts.common.hook import Hook
user_customizations = {}
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
snapshot_re = re.compile(r'\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*')
def guess_version_from_upstream(repo, upstream_tag_format, upstream_branch, cp=None):
......
......@@ -235,7 +235,7 @@ def guess_comp_type(comp_type, source, repo, tarball_dir):
if comp_type == 'auto':
if repo and repo.has_pristine_tar_branch():
regex = 'pristine-tar .* %s_%s\.orig.tar\.' % (source.name, source.upstream_version)
regex = r'pristine-tar .* %s_%s\.orig.tar\.' % (source.name, source.upstream_version)
commits = repo.grep_log(regex, repo.pristine_tar_branch, merges=False)
if commits:
commit = commits[-1]
......
......@@ -48,7 +48,7 @@ def parse_old_style_topic(commit_info):
"""Parse 'gbp-pq-topic:' line(s) from commit info"""
commit = commit_info['id']
topic_regex = 'gbp-pq-topic:\s*(?P<topic>\S.*)'
topic_regex = r'gbp-pq-topic:\s*(?P<topic>\S.*)'
mangled_body = ''
topic = ''
# Parse and filter commit message body
......
......@@ -48,7 +48,7 @@ class TestDep3Patch(unittest.TestCase):
patchfile = os.path.join(self.data_dir, "dep3-iso8859-1.patch")
self.assertTrue(os.path.exists(patchfile))
p = Dep3Patch(patchfile)
self.assertEqual('Replace all -- in man page by \-\- to make lintian happy.', p.subject)
self.assertEqual(r'Replace all -- in man page by \-\- to make lintian happy.', p.subject)
self.assertEqual("Roland Rosenfeld", p.author)
self.assertEqual("roland@debian.org", p.email)
self.assertEqual("", p.long_desc)
......
......@@ -371,7 +371,7 @@ class TestScriptDch(DebianGitTestRepo):
msg="""test non-debian closes 1\n\nCloses: EX-123""")
self.add_file("closes1", "test file",
msg="""test non-debian closes 2\n\nCloses: EX-5678""")
options = ["--meta", '--meta-closes-bugnum=ex-\d+']
options = ["--meta", r'--meta-closes-bugnum=ex-\d+']
lines = self.run_dch(options)
self.assertIn(""" * test non-debian closes 1 (Closes: EX-123)\n""",
lines)
......@@ -383,7 +383,7 @@ class TestScriptDch(DebianGitTestRepo):
msg="""test non-debian closes 1\n\nExample: EX-123""")
self.add_file("closes1", "test file",
msg="""test non-debian closes 2\n\nExample: EX-5678""")
options = ["--meta", '--meta-closes-bugnum=ex-\d+',
options = ["--meta", r'--meta-closes-bugnum=ex-\d+',
'--meta-closes=Example']
lines = self.run_dch(options)
self.assertIn(""" * test non-debian closes 1 (Example: EX-123)\n""",
......
......@@ -50,7 +50,7 @@ class TestConfigParser(unittest.TestCase, GbpLogTester):
parser = GbpOptionParser('%scmd2' % prefix)
self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1')
for line in range(0, 2):
self._check_log(line, ".*Old style config section \[git-cmd2\] found please rename to \[cmd2\]")
self._check_log(line, r'.*Old style config section \[git-cmd2\] found please rename to \[cmd2\]')
def test_single_gbp_override(self):
"""
......@@ -60,7 +60,7 @@ class TestConfigParser(unittest.TestCase, GbpLogTester):
parser = GbpOptionParser('%scmd3' % prefix)
self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1')
for line in range(0, 2):
self._check_log(line, ".*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]")
self._check_log(line, r'.*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]')
def test_single_git_override_disabled_deprecations(self):
"""
......
......@@ -41,7 +41,7 @@ Closes: 456
"""Test non-default BTS commands. We use the example given in the
documentation manpages."""
options = OptionsStub()
options.meta_closes_bugnum = "(?:bug)?\s*ex-\d+"
options.meta_closes_bugnum = r'(?:bug)?\s*ex-\d+'
lines = """This is a test commit
some more lines...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment