From b2ebf2570a11db9eb8b951e1fd5ae088cfedd80f Mon Sep 17 00:00:00 2001
From: Karsten Hopp <karsten@redhat.com>
Date: Oct 25 2018 12:19:25 +0000
Subject: [PATCH 1/4] fix regular expression strings


tests/test_style.py fails now with lots of 'invalid escape sequence' errors.
Use raw strings to fix this.

Signed-off-by: Karsten Hopp <karsten@redhat.com>

---

diff --git a/pagure/utils.py b/pagure/utils.py
index a833429..21a474c 100644
--- a/pagure/utils.py
+++ b/pagure/utils.py
@@ -298,8 +298,8 @@ def __get_file_in_tree(repo_obj, tree, filepath, bail_on_tree=False):
                 )
 
 
-ip_middle_octet = "(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
-ip_last_octet = "(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
+ip_middle_octet = r"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
+ip_last_octet = r"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
 
 """
 regex based on https://github.com/kvesteri/validators/blob/
@@ -332,7 +332,7 @@ IN THE SOFTWARE.
 urlregex = re.compile(
     "^"
     # protocol identifier
-    "(?:(?:https?|ftp|git)://)"
+    r"(?:(?:https?|ftp|git)://)"
     # user:pass authentication
     "(?:[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:]+"
     "(?::[-a-z0-9._~%!$&'()*+,;=:]*)?@)?"
@@ -341,8 +341,8 @@ urlregex = re.compile(
     # IP address exclusion
     # private & local networks
     "(?:(?:10|127)" + ip_middle_octet + "{2}" + ip_last_octet + ")|"
-    "(?:(?:169\.254|192\.168)" + ip_middle_octet + ip_last_octet + ")|"
-    "(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + "))"
+    r"(?:(?:169\.254|192\.168)" + ip_middle_octet + ip_last_octet + ")|"
+    r"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + "))"
     "|"
     # private & local hosts
     "(?P<private_host>" "(?:localhost))" "|"
@@ -352,12 +352,12 @@ urlregex = re.compile(
     # excludes network & broadcast addresses
     # (first & last IP address of each class)
     "(?P<public_ip>"
-    "(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
+    r"(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
     "" + ip_middle_octet + "{2}"
     "" + ip_last_octet + ")"
     "|"
     # IPv6 RegEx from https://stackoverflow.com/a/17871737
-    "\[("
+    r"\[("
     # 1:2:3:4:5:6:7:8
     "([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|"
     # 1::                              1:2:3:4:5:6:7::
@@ -380,29 +380,29 @@ urlregex = re.compile(
     # (link-local IPv6 addresses with zone index)
     "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|"
     "::(ffff(:0{1,4}){0,1}:){0,1}"
-    "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
+    r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
     # ::255.255.255.255   ::ffff:255.255.255.255  ::ffff:0:255.255.255.255
     # (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
     "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|"
     "([0-9a-fA-F]{1,4}:){1,4}:"
-    "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
+    r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
     # 2001:db8:3:4::192.0.2.33  64:ff9b::192.0.2.33
     # (IPv4-Embedded IPv6 Address)
-    "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" ")\]|"
+    "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" r")\]|"
     # host name
     "(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)"
     # domain name
-    "(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
+    r"(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
     # TLD identifier
-    "(?:\.(?:[a-z\u00a1-\uffff]{2,}))" ")"
+    r"(?:\.(?:[a-z\u00a1-\uffff]{2,}))" ")"
     # port number
-    "(?::\d{2,5})?"
+    r"(?::\d{2,5})?"
     # resource path
-    "(?:/[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
+    r"(?:/[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
     # query string
-    "(?:\?\S*)?"
+    r"(?:\?\S*)?"
     # fragment
-    "(?:#\S*)?" "$",
+    r"(?:#\S*)?" "$",
     re.UNICODE | re.IGNORECASE,
 )
 urlpattern = re.compile(urlregex)
@@ -411,7 +411,7 @@ urlpattern = re.compile(urlregex)
 ssh_urlregex = re.compile(
     "^"
     # protocol identifier
-    "(?:(?:ssh|git\+ssh)://)?"
+    r"(?:(?:ssh|git\+ssh)://)?"
     # user@ authentication
     "[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:]+@"
     # Opening section about host
@@ -420,8 +420,8 @@ ssh_urlregex = re.compile(
     "(?P<private_ip>"
     # private & local networks
     "(?:(?:10|127)" + ip_middle_octet + "{2}" + ip_last_octet + ")|"
-    "(?:(?:169\.254|192\.168)" + ip_middle_octet + ip_last_octet + ")|"
-    "(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + "))"
+    r"(?:(?:169\.254|192\.168)" + ip_middle_octet + ip_last_octet + ")|"
+    r"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + "))"
     "|"
     # private & local hosts
     "(?P<private_host>" "(?:localhost))" "|"
@@ -431,12 +431,12 @@ ssh_urlregex = re.compile(
     # excludes network & broadcast addresses
     # (first & last IP address of each class)
     "(?P<public_ip>"
-    "(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
+    r"(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
     "" + ip_middle_octet + "{2}"
     "" + ip_last_octet + ")"
     "|"
     # IPv6 RegEx from https://stackoverflow.com/a/17871737
-    "\[("
+    r"\[("
     # 1:2:3:4:5:6:7:8
     "([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|"
     # 1::                              1:2:3:4:5:6:7::
@@ -459,31 +459,31 @@ ssh_urlregex = re.compile(
     # (link-local IPv6 addresses with zone index)
     "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|"
     "::(ffff(:0{1,4}){0,1}:){0,1}"
-    "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
+    r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
     # ::255.255.255.255   ::ffff:255.255.255.255  ::ffff:0:255.255.255.255
     # (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
     "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|"
     "([0-9a-fA-F]{1,4}:){1,4}:"
-    "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
+    r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}"
     # 2001:db8:3:4::192.0.2.33  64:ff9b::192.0.2.33
     # (IPv4-Embedded IPv6 Address)
-    "(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" ")\]|"
+    r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" r")\]|"
     # host name
-    "(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)"
+    r"(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)"
     # domain name
-    "(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
+    r"(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*"
     # TLD identifier
-    "(?:\.(?:[a-z\u00a1-\uffff]{2,}))"
+    r"(?:\.(?:[a-z\u00a1-\uffff]{2,}))"
     # Closing the entire section about host
     ")"
     # port number
-    "(?::\d{2,5})?"
+    r"(?::\d{2,5})?"
     # resource path
-    "(?:[:/][-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
+    r"(?:[:/][-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
     # query string
-    "(?:\?\S*)?"
+    r"(?:\?\S*)?"
     # fragment
-    "(?:#\S*)?" "$",
+    r"(?:#\S*)?" "$",
     re.UNICODE | re.IGNORECASE,
 )
 ssh_urlpattern = re.compile(ssh_urlregex)

From b310aff1911de8c262ddda107b6d725aa22cb1b1 Mon Sep 17 00:00:00 2001
From: Karsten Hopp <karsten@redhat.com>
Date: Oct 26 2018 09:49:14 +0000
Subject: [PATCH 2/4] convert more strings to 'raw strings' to fix errors reported by flake8-9


Signed-off-by: Karsten Hopp <karsten@redhat.com>

---

diff --git a/dev/run-tests-docker.py b/dev/run-tests-docker.py
index 4cff364..525a8f9 100755
--- a/dev/run-tests-docker.py
+++ b/dev/run-tests-docker.py
@@ -6,15 +6,15 @@ from string import Template
 
 TEMPLATE = 'dev/docker/test_env_template'
 
-PKG_LIST = 'python-alembic python-arrow python-binaryornot \ \n'\
-           'python-bleach python-blinker python-chardet python-cryptography \ \n'\
-           'python-docutils python-enum34 python-flask python2-fedora-flask \ \n'\
-           'python-flask-wtf python2-bcrypt python-jinja2 \ \n'\
-           'python-markdown python-munch python-openid-cla python-openid-teams \ \n'\
-           'python-psutil python-pygit2 python2-pillow \ \n'\
-           'python-sqlalchemy python-straight-plugin python-wtforms python-nose \ \n'\
-           'python3-coverage python-mock python-mock python-eventlet python2-flask-oidc \ \n'\
-           'python-flake8 python-celery python-redis python-trololio python-beautifulsoup4 redis vim git'
+PKG_LIST = r'python-alembic python-arrow python-binaryornot \ \n'\
+           r'python-bleach python-blinker python-chardet python-cryptography \ \n'\
+           r'python-docutils python-enum34 python-flask python2-fedora-flask \ \n'\
+           r'python-flask-wtf python2-bcrypt python-jinja2 \ \n'\
+           r'python-markdown python-munch python-openid-cla python-openid-teams \ \n'\
+           r'python-psutil python-pygit2 python2-pillow \ \n'\
+           r'python-sqlalchemy python-straight-plugin python-wtforms python-nose \ \n'\
+           r'python3-coverage python-mock python-mock python-eventlet python2-flask-oidc \ \n'\
+           r'python-flake8 python-celery python-redis python-trololio python-beautifulsoup4 redis vim git'
 
 
 def setup_parser():
diff --git a/pagure/lib/link.py b/pagure/lib/link.py
index 2d50bfb..3d78390 100644
--- a/pagure/lib/link.py
+++ b/pagure/lib/link.py
@@ -21,19 +21,19 @@ FIXES = [
     re.compile(r"(?:.*\s+)?fixe?[sd]?:?\s*?#(\d+)", re.I),
     re.compile(
         r"(?:.*\s+)?fixe?[sd]?:?\s*?https?://.*/([a-zA-z0-9_][a-zA-Z0-9-_]*)"
-        "/(?:issue|pull-request)/(\d+)",
+        r"/(?:issue|pull-request)/(\d+)",
         re.I,
     ),
     re.compile(r"(?:.*\s+)?merge?[sd]?:?\s*?#(\d+)", re.I),
     re.compile(
         r"(?:.*\s+)?merge?[sd]?:?\s*?https?://.*/([a-zA-z0-9_][a-zA-Z0-9-_]*)"
-        "/(?:issue|pull-request)/(\d+)",
+        r"/(?:issue|pull-request)/(\d+)",
         re.I,
     ),
     re.compile(r"(?:.*\s+)?close?[sd]?:?\s*?#(\d+)", re.I),
     re.compile(
         r"(?:.*\s+)?close?[sd]?:?\s*?https?://.*/([a-zA-z0-9_][a-zA-Z0-9-_]*)"
-        "/(?:issue|pull-request)/(\d+)",
+        r"/(?:issue|pull-request)/(\d+)",
         re.I,
     ),
 ]
@@ -43,7 +43,7 @@ RELATES = [
     re.compile(r"(?:.*\s+)?relate[sd]?:?\s?#(\d+)", re.I),
     re.compile(
         r"(?:.*\s+)?relate[sd]?:?\s*?(?:to)?\s*?"
-        "https?://.*/([a-zA-z0-9_][a-zA-Z0-9-_]*)/issue/(\d+)",
+        r"https?://.*/([a-zA-z0-9_][a-zA-Z0-9-_]*)/issue/(\d+)",
         re.I,
     ),
 ]
diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 2725665..b2ea0a3 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -1295,9 +1295,9 @@ class Issue(BASE):
         def extract_info(text):
             """ Return a tuple containing the link, file name, and the
             "display" file name from the markdown attachment link """
-            pattern_md = re.compile("^\[\!(.*)\]")
-            pattern_link = re.compile("\(([^)]+)\)")
-            pattern_file = re.compile("\[([^]]+)\]")
+            pattern_md = re.compile(r"^\[\!(.*)\]")
+            pattern_link = re.compile(r"\(([^)]+)\)")
+            pattern_file = re.compile(r"\[([^]]+)\]")
 
             try:
                 md_link = pattern_md.search(text).group(1)
diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py
index b84d5d4..086cda3 100644
--- a/pagure/ui/repo.py
+++ b/pagure/ui/repo.py
@@ -3164,7 +3164,7 @@ def update_tags(repo, username=None, namespace=None):
                 )
                 error = True
 
-        color_pattern = re.compile("^#\w{3,6}$")
+        color_pattern = re.compile(r"^#\w{3,6}$")
         for color in colors:
             if not color_pattern.match(color):
                 flask.flash(
diff --git a/tests/__init__.py b/tests/__init__.py
index b8022e3..beb52e5 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -125,7 +125,7 @@ REPOSPANNER_REGIONS = {
 LOG.info('BUILD_ID: %s', os.environ.get('BUILD_ID'))
 
 
-WAIT_REGEX = re.compile("""var _url = '(\/wait\/[a-z0-9-]+\??.*)'""")
+WAIT_REGEX = re.compile(r"""var _url = '(\/wait\/[a-z0-9-]+\??.*)'""")
 def get_wait_target(html):
     """ This parses the window.location out of the HTML for the wait page. """
     found = WAIT_REGEX.findall(html)
diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py
index d1a4194..e7a9a28 100644
--- a/tests/test_pagure_flask_ui_fork.py
+++ b/tests/test_pagure_flask_ui_fork.py
@@ -1183,7 +1183,7 @@ class PagureFlaskForktests(tests.Modeltests):
                 row = row.split(' ', 2)[2]
             npatch.append(row)
 
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: A commit on branch feature
 
@@ -1249,7 +1249,7 @@ index 9f44358..2a552bb 100644
         output = self.app.get('/test/pull-request/1.diff')
         self.assertEqual(output.status_code, 200)
 
-        exp = """diff --git a/.gitignore b/.gitignore
+        exp = r"""diff --git a/.gitignore b/.gitignore
 new file mode 100644
 index 0000000..e4e5f6c
 --- /dev/null
@@ -1302,7 +1302,7 @@ index 9f44358..2a552bb 100644
                 row = row.split(' ', 2)[2]
             npatch.append(row)
 
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: A commit on branch feature
 
@@ -1419,7 +1419,7 @@ index 9f44358..2a552bb 100644
                 row = row.split(' ', 2)[2]
             npatch.append(row)
 
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: A commit on branch feature
 
diff --git a/tests/test_pagure_flask_ui_quick_reply.py b/tests/test_pagure_flask_ui_quick_reply.py
index 0fc4efd..1563ab5 100644
--- a/tests/test_pagure_flask_ui_quick_reply.py
+++ b/tests/test_pagure_flask_ui_quick_reply.py
@@ -91,7 +91,7 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
 
     def assertQuickReplyLinks(self, output):
         """Assert reply links created by setup_quick_replies are present."""
-        link = 'data-qr="%s">\s*%s\s*</a>'
+        link = r'data-qr="%s">\s*%s\s*</a>'
         six.assertRegex(
             self,
             output.get_data(as_text=True),
diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index e8d957d..43dfa4c 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -2571,7 +2571,7 @@ class PagureFlaskRepotests(tests.Modeltests):
 
         output = self.app.get('/test/blame/foofile')
         self.assertEqual(output.status_code, 404)
-        regex = re.compile('>(\w+)</a></td>\n<td class="cell2">')
+        regex = re.compile(r'>(\w+)</a></td>\n<td class="cell2">')
 
         # View in master branch
         output = self.app.get('/test/blame/sources')
@@ -2704,7 +2704,7 @@ class PagureFlaskRepotests(tests.Modeltests):
     def test_view_blame_file_on_tag(self):
         """ Test the view_blame_file endpoint. """
 
-        regex = re.compile('>(\w+)</a></td>\n<td class="cell2">')
+        regex = re.compile(r'>(\w+)</a></td>\n<td class="cell2">')
         tests.create_projects(self.session)
         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
         # Add some content to the git repo
@@ -2906,7 +2906,7 @@ class PagureFlaskRepotests(tests.Modeltests):
         output = self.app.get('/test/c/%s.patch' % commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
-        self.assertIn('''diff --git a/README.rst b/README.rst
+        self.assertIn(r'''diff --git a/README.rst b/README.rst
 new file mode 100644
 index 0000000..fb7093d
 --- /dev/null
@@ -2945,7 +2945,7 @@ index 0000000..fb7093d
         self.assertIn(
             'Subject: Add some directory and a file for more testing',
             output_text)
-        self.assertIn('''diff --git a/folder1/folder2/file b/folder1/folder2/file
+        self.assertIn(r'''diff --git a/folder1/folder2/file b/folder1/folder2/file
 new file mode 100644
 index 0000000..11980b1
 --- /dev/null
@@ -2986,7 +2986,7 @@ index 0000000..11980b1
             '/fork/pingou/test3/c/%s.patch' % commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
-        self.assertIn('''diff --git a/README.rst b/README.rst
+        self.assertIn(r'''diff --git a/README.rst b/README.rst
 new file mode 100644
 index 0000000..fb7093d
 --- /dev/null
@@ -3037,7 +3037,7 @@ index 0000000..fb7093d
         output = self.app.get('/test/c/%s.diff' % commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
-        self.assertEqual('''diff --git a/README.rst b/README.rst
+        self.assertEqual(r'''diff --git a/README.rst b/README.rst
 new file mode 100644
 index 0000000..fb7093d
 --- /dev/null
diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py
index d9f10b2..69e3576 100644
--- a/tests/test_pagure_lib_git.py
+++ b/tests/test_pagure_lib_git.py
@@ -1426,7 +1426,7 @@ repo requests/forks/pingou/test3
 
         # Use patch to validate the repo
         commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: pagure <pagure>
 Subject: Updated issue <hash>: Test issue
 
@@ -1525,7 +1525,7 @@ index 0000000..60f7480
         repo = pygit2.Repository(self.gitrepo)
         commit = repo.revparse_single('HEAD')
         commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: pagure <pagure>
 Subject: Updated issue <hash>: Test issue
 
@@ -1686,7 +1686,7 @@ index 458821a..77674a8
 
         # Use patch to validate the repo
         patch = pagure.lib.git.commit_to_patch(repo, commit)
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: pagure <pagure>
 Subject: Updated pull-request <hash>: test PR
 
@@ -3088,7 +3088,7 @@ class PagureLibGitCommitToPatchtests(tests.Modeltests):
         repo = pygit2.init_repository(self.gitrepo)
 
         patch = pagure.lib.git.commit_to_patch(repo, self.first_commit)
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: Add sources file for testing
 
@@ -3122,7 +3122,7 @@ index 0000000..9f44358
         repo = pygit2.init_repository(self.gitrepo)
 
         patch = pagure.lib.git.commit_to_patch(repo, self.second_commit)
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: Add baz and boose to the sources
 
@@ -3161,7 +3161,7 @@ index 9f44358..2a552bb 100644
 
         patch = pagure.lib.git.commit_to_patch(
             repo, [self.first_commit, self.second_commit])
-        exp = """Mon Sep 17 00:00:00 2001
+        exp = r"""Mon Sep 17 00:00:00 2001
 From: Alice Author <alice@authors.tld>
 Subject: [PATCH 1/2] Add sources file for testing
 
@@ -3217,7 +3217,7 @@ index 9f44358..2a552bb 100644
 
         patch = pagure.lib.git.commit_to_patch(
             repo, self.first_commit, diff_view=True)
-        exp = """diff --git a/sources b/sources
+        exp = r"""diff --git a/sources b/sources
 new file mode 100644
 index 0000000..9f44358
 --- /dev/null
@@ -3244,7 +3244,7 @@ index 0000000..9f44358
 
         patch = pagure.lib.git.commit_to_patch(
             repo, self.second_commit, diff_view=True)
-        exp = """diff --git a/sources b/sources
+        exp = r"""diff --git a/sources b/sources
 index 9f44358..2a552bb 100644
 --- a/sources
 +++ b/sources
@@ -3274,7 +3274,7 @@ index 9f44358..2a552bb 100644
 
         patch = pagure.lib.git.commit_to_patch(
             repo, [self.first_commit, self.second_commit], diff_view=True)
-        exp = """diff --git a/sources b/sources
+        exp = r"""diff --git a/sources b/sources
 new file mode 100644
 index 0000000..9f44358
 --- /dev/null
@@ -3313,7 +3313,7 @@ index 9f44358..2a552bb 100644
 
         patches = pagure.lib.git.commit_to_patch(
             repo, self.first_commit, diff_view=True, separated=True)
-        exp = """diff --git a/sources b/sources
+        exp = r"""diff --git a/sources b/sources
 new file mode 100644
 index 0000000..9f44358
 --- /dev/null
@@ -3344,7 +3344,7 @@ index 0000000..9f44358
 
         patches = pagure.lib.git.commit_to_patch(
             repo, self.second_commit, diff_view=True, separated=True)
-        exp = """diff --git a/sources b/sources
+        exp = r"""diff --git a/sources b/sources
 index 9f44358..2a552bb 100644
 --- a/sources
 +++ b/sources
@@ -3379,7 +3379,7 @@ index 9f44358..2a552bb 100644
         patches = pagure.lib.git.commit_to_patch(
             repo, [self.first_commit, self.second_commit], diff_view=True,
             separated=True)
-        exp = ["""diff --git a/sources b/sources
+        exp = [r"""diff --git a/sources b/sources
 new file mode 100644
 index 0000000..9f44358
 --- /dev/null
@@ -3389,7 +3389,7 @@ index 0000000..9f44358
 + bar
 \ No newline at end of file
 """,
-"""diff --git a/sources b/sources
+r"""diff --git a/sources b/sources
 index 9f44358..2a552bb 100644
 --- a/sources
 +++ b/sources
diff --git a/tests/test_pagure_lib_gitolite_config.py b/tests/test_pagure_lib_gitolite_config.py
index 56add8d..a4e6315 100644
--- a/tests/test_pagure_lib_gitolite_config.py
+++ b/tests/test_pagure_lib_gitolite_config.py
@@ -101,7 +101,7 @@ class PagureLibGitoliteConfigtests(tests.Modeltests):
         self.postconf = os.path.join(self.path, 'footer_gitolite')
         with open(self.postconf, 'w', encoding="utf-8") as stream:
             stream.write('# end of generated configuration\n')
-            stream.write('# \ó/\n')
+            stream.write(r'# \ó/\n')
             stream.write('# end of footer\n')
 
     def tearDown(self):
@@ -129,7 +129,7 @@ class PagureLibGitoliteConfigtests(tests.Modeltests):
         with open(self.outputconf, 'r') as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -187,7 +187,7 @@ class PagureLibGitoliteConfigtests(tests.Modeltests):
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -227,7 +227,7 @@ class PagureLibGitoliteConfigtests(tests.Modeltests):
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -294,7 +294,7 @@ repo requests/test
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -468,7 +468,7 @@ class PagureLibGitoliteGroupConfigtests(tests.Modeltests):
         self.postconf = os.path.join(self.path, 'footer_gitolite')
         with open(self.postconf, 'w') as stream:
             stream.write('# end of generated configuration\n')
-            stream.write('# \ó/\n')
+            stream.write(r'# \ó/\n')
             stream.write('# end of footer\n')
 
     def tearDown(self):
@@ -502,7 +502,7 @@ class PagureLibGitoliteGroupConfigtests(tests.Modeltests):
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -554,7 +554,7 @@ repo requests/test
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -606,7 +606,7 @@ repo requests/test
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -672,7 +672,7 @@ repo requests/test
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou
@@ -765,7 +765,7 @@ repo requests/test
         with open(self.outputconf) as stream:
             data = stream.read()
 
-        exp = """# this is a header that is manually added
+        exp = r"""# this is a header that is manually added
 
 @group1 = foo bar baz
 @group2 = threebean puiterwijk kevin pingou

From 4bbb2b72355549a44f84863c598e520d1c3eaa8a Mon Sep 17 00:00:00 2001
From: Karsten Hopp <karsten@redhat.com>
Date: Oct 26 2018 10:50:21 +0000
Subject: [PATCH 3/4] fix header comparison


Signed-off-by: Karsten Hopp <karsten@redhat.com>

---

diff --git a/tests/test_pagure_lib_gitolite_config.py b/tests/test_pagure_lib_gitolite_config.py
index a4e6315..3660c75 100644
--- a/tests/test_pagure_lib_gitolite_config.py
+++ b/tests/test_pagure_lib_gitolite_config.py
@@ -101,8 +101,8 @@ class PagureLibGitoliteConfigtests(tests.Modeltests):
         self.postconf = os.path.join(self.path, 'footer_gitolite')
         with open(self.postconf, 'w', encoding="utf-8") as stream:
             stream.write('# end of generated configuration\n')
-            stream.write(r'# \ó/\n')
-            stream.write('# end of footer\n')
+            stream.write(r'# \ó/')
+            stream.write('\n# end of footer\n')
 
     def tearDown(self):
         """ Tearn down the environnment, ran before every tests. """
@@ -468,8 +468,8 @@ class PagureLibGitoliteGroupConfigtests(tests.Modeltests):
         self.postconf = os.path.join(self.path, 'footer_gitolite')
         with open(self.postconf, 'w') as stream:
             stream.write('# end of generated configuration\n')
-            stream.write(r'# \ó/\n')
-            stream.write('# end of footer\n')
+            stream.write(r'# \ó/')
+            stream.write('\n# end of footer\n')
 
     def tearDown(self):
         """ Tearn down the environnment, ran before every tests. """

From 3b333e5ae8e2e810fef055f74f51e3dc2fdd6fae Mon Sep 17 00:00:00 2001
From: Karsten Hopp <karsten@redhat.com>
Date: Oct 26 2018 12:10:11 +0000
Subject: [PATCH 4/4] more fixes for new flake8


Signed-off-by: Karsten Hopp <karsten@redhat.com>

---

diff --git a/pagure/api/issue.py b/pagure/api/issue.py
index f09b2a5..648cbf3 100644
--- a/pagure/api/issue.py
+++ b/pagure/api/issue.py
@@ -871,7 +871,7 @@ def api_change_status_issue(repo, issueid, username=None, namespace=None):
             raise pagure.exceptions.APIError(
                 400, error_code=APIERROR.ENOCODE, error=str(err)
             )
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             raise pagure.exceptions.APIError(400, error_code=APIERROR.EDBERROR)
 
@@ -976,7 +976,7 @@ def api_change_milestone_issue(repo, issueid, username=None, namespace=None):
             raise pagure.exceptions.APIError(
                 400, error_code=APIERROR.ENOCODE, error=str(err)
             )
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             raise pagure.exceptions.APIError(400, error_code=APIERROR.EDBERROR)
 
diff --git a/pagure/api/project.py b/pagure/api/project.py
index 50d9625..c90ad91 100644
--- a/pagure/api/project.py
+++ b/pagure/api/project.py
@@ -1637,7 +1637,7 @@ def api_update_project_watchers(repo, username=None, namespace=None):
 
     try:
         pagure.lib.get_user(flask.g.session, watcher)
-    except pagure.exceptions.PagureException as err:
+    except pagure.exceptions.PagureException:
         _log.debug(
             "api_update_project_watchers: Invalid user watching: %s", watcher
         )
@@ -1859,7 +1859,7 @@ def api_modify_acls(repo, namespace=None, username=None):
                     project.fullname,
                 )
                 try:
-                    msg = pagure.lib.remove_user_of_project(
+                    pagure.lib.remove_user_of_project(
                         flask.g.session,
                         user_obj,
                         project,
diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index 3fa18aa..3d0e108 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -1590,7 +1590,7 @@ def merge_pull_request(session, request, username, domerge=True):
                 pagure.lib.close_pull_request(session, request, username)
                 try:
                     session.commit()
-                except SQLAlchemyError as err:  # pragma: no cover
+                except SQLAlchemyError:  # pragma: no cover
                     session.rollback()
                     _log.exception("  Could not merge the PR in the DB")
                     raise pagure.exceptions.PagureException(
diff --git a/pagure/lib/tasks_services.py b/pagure/lib/tasks_services.py
index 1fed13e..33af2b0 100644
--- a/pagure/lib/tasks_services.py
+++ b/pagure/lib/tasks_services.py
@@ -382,9 +382,9 @@ def load_json_commits_to_db(
                     "Issue import report",
                     user_obj.default_email,
                 )
-        except pagure.exceptions.PagureException as err:
+        except pagure.exceptions.PagureException:
             _log.exception("LOADJSON: Could not find user %s" % agent)
-    except SQLAlchemyError as err:  # pragma: no cover
+    except SQLAlchemyError:  # pragma: no cover
         session.rollback()
     _log.info("LOADJSON: Ready for another")
 
diff --git a/pagure/ui/groups.py b/pagure/ui/groups.py
index 1b27575..e007bbd 100644
--- a/pagure/ui/groups.py
+++ b/pagure/ui/groups.py
@@ -99,7 +99,7 @@ def view_group(group):
             return flask.redirect(
                 flask.url_for("ui_ns.view_group", group=group.group_name)
             )
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             flask.flash(
                 "Could not add user `%s` to group `%s`."
@@ -165,7 +165,7 @@ def edit_group(group):
             return flask.redirect(
                 flask.url_for("ui_ns.view_group", group=group.group_name)
             )
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             flask.flash(
                 "Could not edit group `%s`." % (group.group_name), "error"
@@ -211,7 +211,7 @@ def group_user_delete(user, group):
             return flask.redirect(
                 flask.url_for("ui_ns.view_group", group=group)
             )
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             flask.flash(
                 "Could not remove user `%s` from the group `%s`."
@@ -323,7 +323,7 @@ def add_group():
         except pagure.exceptions.PagureException as err:
             flask.g.session.rollback()
             flask.flash("%s" % err, "error")
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             flask.flash("Could not create group.")
             _log.exception("Could not create group.")
diff --git a/pagure/ui/plugins.py b/pagure/ui/plugins.py
index ab6518c..1c7b2d3 100644
--- a/pagure/ui/plugins.py
+++ b/pagure/ui/plugins.py
@@ -125,7 +125,7 @@ def view_plugin(repo, plugin, username=None, namespace=None, full=True):
             flask.g.session.add(dbobj)
         try:
             flask.g.session.flush()
-        except SQLAlchemyError as err:  # pragma: no cover
+        except SQLAlchemyError:  # pragma: no cover
             flask.g.session.rollback()
             _log.exception("Could not add plugin %s", plugin.name)
             message = Markup(

