From 6b1342253eecd83e514400fccc531205450b13d3 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 14 Oct 2018 11:17:43 +0200 Subject: Fix flake8's W605 (invalid escape sequence) See also https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior --- gbp/deb/dscfile.py | 12 ++++++------ gbp/deb/git.py | 18 +++++++++--------- gbp/deb/policy.py | 4 ++-- gbp/deb/pristinetar.py | 4 ++-- gbp/git/repository.py | 4 ++-- gbp/patch_series.py | 4 ++-- gbp/rpm/__init__.py | 10 +++++----- gbp/rpm/policy.py | 4 ++-- gbp/scripts/common/pq.py | 4 ++-- gbp/scripts/dch.py | 2 +- gbp/scripts/export_orig.py | 2 +- gbp/scripts/pq.py | 2 +- tests/08_test_patch.py | 2 +- tests/11_test_dch_main.py | 4 ++-- tests/18_test_Config.py | 4 ++-- tests/23_test_dch_extract_bts_cmds.py | 2 +- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/gbp/deb/dscfile.py b/gbp/deb/dscfile.py index 76676fc6..41ab869e 100644 --- a/gbp/deb/dscfile.py +++ b/gbp/deb/dscfile.py @@ -29,19 +29,19 @@ class DscFile(object): compressions = r"(%s)" % '|'.join(DebianUpstreamSource.known_compressions()) pkg_re = re.compile(r'Source:\s+(?P.+)\s*') version_re = re.compile(r'Version:\s((?P\d+)\:)?' - '(?P[%s]+)\s*$' + r'(?P[%s]+)\s*$' % DebianPkgPolicy.debianversion_chars) tar_re = re.compile(r'^\s\w+\s\d+\s+(?P[^_]+_[^_]+' - '(\.orig)?\.tar\.%s)$' % compressions) + r'(\.orig)?\.tar\.%s)$' % compressions) add_tar_re = re.compile(r'^\s\w+\s\d+\s+(?P[^_]+_[^_]+' - '\.orig-(?P[a-zA-Z0-9-]+)\.tar\.%s)$' % compressions) + r'\.orig-(?P[a-zA-Z0-9-]+)\.tar\.%s)$' % compressions) diff_re = re.compile(r'^\s\w+\s\d+\s+(?P[^_]+_[^_]+' - '\.diff.(gz|bz2))$') + r'\.diff.(gz|bz2))$') deb_tgz_re = re.compile(r'^\s\w+\s\d+\s+(?P[^_]+_[^_]+' - '\.debian.tar.%s)$' % compressions) + r'\.debian.tar.%s)$' % compressions) format_re = re.compile(r'Format:\s+(?P[0-9.]+)\s*') sig_re = re.compile(r'^\s\w+\s\d+\s+(?P[^_]+_[^_]+' - '\.orig(-[a-z0-9-]+)?\.tar\.%s.asc)$' % compressions) + r'\.orig(-[a-z0-9-]+)?\.tar\.%s.asc)$' % compressions) def __init__(self, dscfile): self.pkg = "" diff --git a/gbp/deb/git.py b/gbp/deb/git.py index 7e87eda0..fa865ee2 100644 --- a/gbp/deb/git.py +++ b/gbp/deb/git.py @@ -33,9 +33,9 @@ class DebianGitRepository(PkgGitRepository): """A git repository that holds the source of a Debian package""" version_mangle_re = (r'%\(version' - '%(?P[^%])' - '%(?P([^%]|\\%))+' - '\)s') + r'%(?P[^%])' + r'%(?P([^%]|\\%))+' + 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[\w_%+-.#]+)') + version_re = f.replace('%(version)s', r'(?P[\w_%+-.#]+)') r = re.match(version_re, tag) if r: v = cls._unsanitize_version(r.group('version')) diff --git a/gbp/deb/policy.py b/gbp/deb/policy.py index d9b27ac0..6664f4ff 100644 --- a/gbp/deb/policy.py +++ b/gbp/deb/policy.py @@ -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 (~)""" diff --git a/gbp/deb/pristinetar.py b/gbp/deb/pristinetar.py index 2f52f3ac..843e52e9 100644 --- a/gbp/deb/pristinetar.py +++ b/gbp/deb/pristinetar.py @@ -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) diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 2ff127d2..617c172f 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -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) diff --git a/gbp/patch_series.py b/gbp/patch_series.py index 3d272fd9..c74a414a 100644 --- a/gbp/patch_series.py +++ b/gbp/patch_series.py @@ -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[0-9]+)') + comment_re = re.compile(r'\s+#.*$') + level_re = re.compile(r'-p(?P[0-9]+)') @classmethod def read_series_file(cls, seriesfile): diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index b37dfdab..61d9d35e 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -115,11 +115,11 @@ class SrcRpmFile(object): class SpecFile(object): """Class for parsing/modifying spec files""" tag_re = re.compile(r'^(?P[a-z]+)(?P[0-9]+)?\s*:\s*' - '(?P\S(.*\S)?)\s*$', flags=re.I) + r'(?P\S(.*\S)?)\s*$', flags=re.I) directive_re = re.compile(r'^%(?P[a-z]+)(?P[0-9]+)?' - '(\s+(?P.*))?$', flags=re.I) + r'(\s+(?P.*))?$', flags=re.I) gbptag_re = re.compile(r'^\s*#\s*gbp-(?P[a-z-]+)' - '(\s*:\s*(?P\S.*))?$', flags=re.I) + r'(\s*:\s*(?P\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) diff --git a/gbp/rpm/policy.py b/gbp/rpm/policy.py index a027ed99..a667bb7d 100644 --- a/gbp/rpm/policy.py +++ b/gbp/rpm/policy.py @@ -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]+$" % diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index b6033a28..552602e2 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -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 = '' diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 6297d2d7..b1c8aa82 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -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[a-z0-9]+)\s+\*\*") +snapshot_re = re.compile(r'\s*\*\* SNAPSHOT build @(?P[a-z0-9]+)\s+\*\*') def guess_version_from_upstream(repo, upstream_tag_format, upstream_branch, cp=None): diff --git a/gbp/scripts/export_orig.py b/gbp/scripts/export_orig.py index ea6c8870..1afbe6db 100755 --- a/gbp/scripts/export_orig.py +++ b/gbp/scripts/export_orig.py @@ -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] diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 7bf7736f..babff1c5 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -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\S.*)' + topic_regex = r'gbp-pq-topic:\s*(?P\S.*)' mangled_body = '' topic = '' # Parse and filter commit message body diff --git a/tests/08_test_patch.py b/tests/08_test_patch.py index b4ba2b8f..c0f3e5ce 100644 --- a/tests/08_test_patch.py +++ b/tests/08_test_patch.py @@ -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) diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py index 7fc82600..14cf5939 100644 --- a/tests/11_test_dch_main.py +++ b/tests/11_test_dch_main.py @@ -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""", diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py index 60cd9cff..43513c2b 100644 --- a/tests/18_test_Config.py +++ b/tests/18_test_Config.py @@ -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): """ diff --git a/tests/23_test_dch_extract_bts_cmds.py b/tests/23_test_dch_extract_bts_cmds.py index e1fb7e0a..bc4b5ce0 100644 --- a/tests/23_test_dch_extract_bts_cmds.py +++ b/tests/23_test_dch_extract_bts_cmds.py @@ -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... -- cgit v1.2.3