Pārlūkot izejas kodu

Merge pull request #4151 from ThomasWaldmann/flake8-1.1

Flake8 fixes (backport to 1.1-maint)
TW 6 gadi atpakaļ
vecāks
revīzija
fd1fe93c9a

+ 1 - 1
scripts/glibc_check.py

@@ -41,7 +41,7 @@ def main():
             overall_versions.add(requires_glibc)
             overall_versions.add(requires_glibc)
             if verbose:
             if verbose:
                 print("%s %s" % (filename, format_version(requires_glibc)))
                 print("%s %s" % (filename, format_version(requires_glibc)))
-        except subprocess.CalledProcessError as e:
+        except subprocess.CalledProcessError:
             if verbose:
             if verbose:
                 print("%s errored." % filename)
                 print("%s errored." % filename)
 
 

+ 3 - 1
setup.cfg

@@ -5,7 +5,9 @@ python_files = testsuite/*.py
 # please note that the values are adjusted so that they do not cause failures
 # please note that the values are adjusted so that they do not cause failures
 # with existing code. if you want to change them, you should first fix all
 # with existing code. if you want to change them, you should first fix all
 # flake8 failures that appear with your change.
 # flake8 failures that appear with your change.
-ignore = E122,E123,E125,E126,E127,E128,E226,E402,E722,E731,E741,F401,F405,F811
+ignore = E122,E123,E125,E126,E127,E128,E226,E402,E722,E731,E741,
+         F401,F405,F811,
+         W504
 # line length long term target: 120
 # line length long term target: 120
 max-line-length = 255
 max-line-length = 255
 exclude = build,dist,.git,.idea,.cache,.tox,docs/conf.py
 exclude = build,dist,.git,.idea,.cache,.tox,docs/conf.py

+ 2 - 2
src/borg/archive.py

@@ -773,7 +773,7 @@ Utilization of max. archive size: {csize_max:.0%}
         def fetch_async_response(wait=True):
         def fetch_async_response(wait=True):
             try:
             try:
                 return self.repository.async_response(wait=wait)
                 return self.repository.async_response(wait=wait)
-            except Repository.ObjectNotFound as e:
+            except Repository.ObjectNotFound:
                 nonlocal error
                 nonlocal error
                 # object not in repo - strange, but we wanted to delete it anyway.
                 # object not in repo - strange, but we wanted to delete it anyway.
                 if forced == 0:
                 if forced == 0:
@@ -1523,7 +1523,7 @@ class ArchiveChecker:
                                 yield Item(internal_dict=item)
                                 yield Item(internal_dict=item)
                             else:
                             else:
                                 report('Did not get expected metadata dict when unpacking item metadata (%s)' % reason, chunk_id, i)
                                 report('Did not get expected metadata dict when unpacking item metadata (%s)' % reason, chunk_id, i)
-                    except RobustUnpacker.UnpackerCrashed as err:
+                    except RobustUnpacker.UnpackerCrashed:
                         report('Unpacker crashed while unpacking item metadata, trying to resync...', chunk_id, i)
                         report('Unpacker crashed while unpacking item metadata, trying to resync...', chunk_id, i)
                         unpacker.resync()
                         unpacker.resync()
                     except Exception:
                     except Exception:

+ 6 - 6
src/borg/archiver.py

@@ -2166,7 +2166,7 @@ class Archiver:
 
 
         `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
         `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
             This is the default style for ``--exclude`` and ``--exclude-from``.
             This is the default style for ``--exclude`` and ``--exclude-from``.
-            These patterns use a variant of shell pattern syntax, with '\*' matching
+            These patterns use a variant of shell pattern syntax, with '\\*' matching
             any number of characters, '?' matching any single character, '[...]'
             any number of characters, '?' matching any single character, '[...]'
             matching any single character specified, including ranges, and '[!...]'
             matching any single character specified, including ranges, and '[!...]'
             matching any character not specified. For the purpose of these patterns,
             matching any character not specified. For the purpose of these patterns,
@@ -2177,7 +2177,7 @@ class Archiver:
             from the start of the full path to just before a path separator. Except
             from the start of the full path to just before a path separator. Except
             for the root path, paths will never end in the path separator when
             for the root path, paths will never end in the path separator when
             matching is attempted.  Thus, if a given pattern ends in a path
             matching is attempted.  Thus, if a given pattern ends in a path
-            separator, a '\*' is appended before matching is attempted.
+            separator, a '\\*' is appended before matching is attempted.
 
 
         Shell-style patterns, selector `sh:`
         Shell-style patterns, selector `sh:`
             This is the default style for ``--pattern`` and ``--patterns-from``.
             This is the default style for ``--pattern`` and ``--patterns-from``.
@@ -2252,7 +2252,7 @@ class Archiver:
 
 
             # The contents of directories in '/home' are not backed up when their name
             # The contents of directories in '/home' are not backed up when their name
             # ends in '.tmp'
             # ends in '.tmp'
-            $ borg create --exclude 're:^/home/[^/]+\.tmp/' backup /
+            $ borg create --exclude 're:^/home/[^/]+\\.tmp/' backup /
 
 
             # Load exclusions from file
             # Load exclusions from file
             $ cat >exclude.txt <<EOF
             $ cat >exclude.txt <<EOF
@@ -2260,7 +2260,7 @@ class Archiver:
             /home/*/junk
             /home/*/junk
             *.tmp
             *.tmp
             fm:aa:something/*
             fm:aa:something/*
-            re:^/home/[^/]\.tmp/
+            re:^/home/[^/]\\.tmp/
             sh:/home/*/.thumbnails
             sh:/home/*/.thumbnails
             EOF
             EOF
             $ borg create --exclude-from exclude.txt backup /
             $ borg create --exclude-from exclude.txt backup /
@@ -3218,7 +3218,7 @@ class Archiver:
 
 
         The ``--exclude`` patterns are not like tar. In tar ``--exclude`` .bundler/gems will
         The ``--exclude`` patterns are not like tar. In tar ``--exclude`` .bundler/gems will
         exclude foo/.bundler/gems. In borg it will not, you need to use ``--exclude``
         exclude foo/.bundler/gems. In borg it will not, you need to use ``--exclude``
-        '\*/.bundler/gems' to get the same effect. See ``borg help patterns`` for
+        '\\*/.bundler/gems' to get the same effect. See ``borg help patterns`` for
         more information.
         more information.
 
 
         In addition to using ``--exclude`` patterns, it is possible to use
         In addition to using ``--exclude`` patterns, it is possible to use
@@ -4210,7 +4210,7 @@ class Archiver:
 
 
         It creates input data below the given PATH and backups this data into the given REPO.
         It creates input data below the given PATH and backups this data into the given REPO.
         The REPO must already exist (it could be a fresh empty repo or an existing repo, the
         The REPO must already exist (it could be a fresh empty repo or an existing repo, the
-        command will create / read / update / delete some archives named borg-test-data\* there.
+        command will create / read / update / delete some archives named borg-test-data\\* there.
 
 
         Make sure you have free space there, you'll need about 1GB each (+ overhead).
         Make sure you have free space there, you'll need about 1GB each (+ overhead).
 
 

+ 1 - 1
src/borg/crypto/nonces.py

@@ -37,7 +37,7 @@ class NonceManager:
     def get_repo_free_nonce(self):
     def get_repo_free_nonce(self):
         try:
         try:
             return self.repository.get_free_nonce()
             return self.repository.get_free_nonce()
-        except InvalidRPCMethod as error:
+        except InvalidRPCMethod:
             # old server version, suppress further calls
             # old server version, suppress further calls
             sys.stderr.write("Please upgrade to borg version 1.1+ on the server for safer AES-CTR nonce handling.\n")
             sys.stderr.write("Please upgrade to borg version 1.1+ on the server for safer AES-CTR nonce handling.\n")
             self.get_repo_free_nonce = lambda: None
             self.get_repo_free_nonce = lambda: None

+ 2 - 2
src/borg/helpers.py

@@ -1110,9 +1110,9 @@ class Location:
         return ', '.join(items)
         return ', '.join(items)
 
 
     def to_key_filename(self):
     def to_key_filename(self):
-        name = re.sub('[^\w]', '_', self.path).strip('_')
+        name = re.sub(r'[^\w]', '_', self.path).strip('_')
         if self.proto != 'file':
         if self.proto != 'file':
-            name = re.sub('[^\w]', '_', self.host) + '__' + name
+            name = re.sub(r'[^\w]', '_', self.host) + '__' + name
         if len(name) > 100:
         if len(name) > 100:
             # Limit file names to some reasonable length. Most file systems
             # Limit file names to some reasonable length. Most file systems
             # limit them to 255 [unit of choice]; due to variations in unicode
             # limit them to 255 [unit of choice]; due to variations in unicode

+ 2 - 2
src/borg/testsuite/__init__.py

@@ -111,7 +111,7 @@ def is_utime_fully_supported():
             new_stats = os.stat(filepath, follow_symlinks=False)
             new_stats = os.stat(filepath, follow_symlinks=False)
             if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000:
             if new_stats.st_atime == 1000 and new_stats.st_mtime == 2000:
                 return True
                 return True
-        except OSError as err:
+        except OSError:
             pass
             pass
         return False
         return False
 
 
@@ -133,7 +133,7 @@ def is_birthtime_fully_supported():
             new_stats = os.stat(filepath, follow_symlinks=False)
             new_stats = os.stat(filepath, follow_symlinks=False)
             if new_stats.st_birthtime == birthtime and new_stats.st_mtime == mtime and new_stats.st_atime == atime:
             if new_stats.st_birthtime == birthtime and new_stats.st_mtime == mtime and new_stats.st_atime == atime:
                 return True
                 return True
-        except OSError as err:
+        except OSError:
             pass
             pass
         return False
         return False
 
 

+ 1 - 1
src/borg/testsuite/key.py

@@ -34,7 +34,7 @@ class TestKey:
         /cXJq7jrqmrJ1phd6dg4SHAM/i+hubadZoS6m25OQzYAW09wZD/phG8OVa698Z5ed3HTaT
         /cXJq7jrqmrJ1phd6dg4SHAM/i+hubadZoS6m25OQzYAW09wZD/phG8OVa698Z5ed3HTaT
         SmrtgJL3EoOKgUI9d6BLE4dJdBqntifo""".strip()
         SmrtgJL3EoOKgUI9d6BLE4dJdBqntifo""".strip()
 
 
-    keyfile2_cdata = unhexlify(re.sub('\W', '', """
+    keyfile2_cdata = unhexlify(re.sub(r'\W', '', """
         0055f161493fcfc16276e8c31493c4641e1eb19a79d0326fad0291e5a9c98e5933
         0055f161493fcfc16276e8c31493c4641e1eb19a79d0326fad0291e5a9c98e5933
         00000000000003e8d21eaf9b86c297a8cd56432e1915bb
         00000000000003e8d21eaf9b86c297a8cd56432e1915bb
         """))
         """))

+ 3 - 3
src/borg/testsuite/patterns.py

@@ -229,13 +229,13 @@ def test_invalid_unicode_pattern(pattern):
       "",
       "",
       "# EOF"],
       "# EOF"],
      ["/more/data", "/home", " #/wsfoobar"]),
      ["/more/data", "/home", " #/wsfoobar"]),
-    (["re:.*"], []),
-    (["re:\s"], ["/data/something00.txt", "/more/data", "/home"]),
+    ([r"re:.*"], []),
+    ([r"re:\s"], ["/data/something00.txt", "/more/data", "/home"]),
     ([r"re:(.)(\1)"], ["/more/data", "/home", "\tstart/whitespace", "/whitespace/end\t"]),
     ([r"re:(.)(\1)"], ["/more/data", "/home", "\tstart/whitespace", "/whitespace/end\t"]),
     (["", "", "",
     (["", "", "",
       "# This is a test with mixed pattern styles",
       "# This is a test with mixed pattern styles",
       # Case-insensitive pattern
       # Case-insensitive pattern
-      "re:(?i)BAR|ME$",
+      r"re:(?i)BAR|ME$",
       "",
       "",
       "*whitespace*",
       "*whitespace*",
       "fm:*/something00*"],
       "fm:*/something00*"],