瀏覽代碼

suppress unneeded exception context (PEP 409)

Thomas Waldmann 9 年之前
父節點
當前提交
fc52101d46
共有 9 個文件被更改,包括 12 次插入12 次删除
  1. 2 2
      borg/archive.py
  2. 1 1
      borg/cache.py
  3. 1 1
      borg/fuse.py
  4. 1 1
      borg/helpers.py
  5. 1 1
      borg/key.py
  6. 1 1
      borg/locking.py
  7. 1 1
      borg/remote.py
  8. 3 3
      borg/repository.py
  9. 1 1
      borg/testsuite/__init__.py

+ 2 - 2
borg/archive.py

@@ -292,7 +292,7 @@ Number of files: {0.stats.nfiles}'''.format(self)
             else:
                 os.unlink(path)
         except UnicodeEncodeError:
-            raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding())
+            raise self.IncompatibleFilesystemEncodingError(path, sys.getfilesystemencoding()) from None
         except OSError:
             pass
         mode = item[b'mode']
@@ -332,7 +332,7 @@ Number of files: {0.stats.nfiles}'''.format(self)
             try:
                 os.symlink(source, path)
             except UnicodeEncodeError:
-                raise self.IncompatibleFilesystemEncodingError(source, sys.getfilesystemencoding())
+                raise self.IncompatibleFilesystemEncodingError(source, sys.getfilesystemencoding()) from None
             self.restore_attrs(path, item, symlink=True)
         elif stat.S_ISFIFO(mode):
             if not os.path.exists(os.path.dirname(path)):

+ 1 - 1
borg/cache.py

@@ -136,7 +136,7 @@ Chunk index:    {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
                 raise Exception('%s has unexpected cache version %d (wanted: %d).' % (
                     config_path, cache_version, wanted_version))
         except configparser.NoSectionError as e:
-            raise Exception('%s does not look like a Borg cache.' % config_path)
+            raise Exception('%s does not look like a Borg cache.' % config_path) from None
         self.id = self.config.get('cache', 'repository')
         self.manifest_id = unhexlify(self.config.get('cache', 'manifest'))
         self.timestamp = self.config.get('cache', 'timestamp', fallback=None)

+ 1 - 1
borg/fuse.py

@@ -173,7 +173,7 @@ class FuseOperations(llfuse.Operations):
         try:
             return item.get(b'xattrs', {})[name]
         except KeyError:
-            raise llfuse.FUSEError(errno.ENODATA)
+            raise llfuse.FUSEError(errno.ENODATA) from None
 
     def _load_pending_archive(self, inode):
         # Check if this is an archive we need to load

+ 1 - 1
borg/helpers.py

@@ -777,7 +777,7 @@ def location_validator(archive=None):
         try:
             loc = Location(text)
         except ValueError:
-            raise argparse.ArgumentTypeError('Invalid location format: "%s"' % text)
+            raise argparse.ArgumentTypeError('Invalid location format: "%s"' % text) from None
         if archive is True and not loc.archive:
             raise argparse.ArgumentTypeError('"%s": No archive specified' % text)
         elif archive is False and loc.archive:

+ 1 - 1
borg/key.py

@@ -390,7 +390,7 @@ class RepoKey(KeyfileKeyBase):
             self.repository.load_key()
             return loc
         except configparser.NoOptionError:
-            raise RepoKeyNotFoundError(loc)
+            raise RepoKeyNotFoundError(loc) from None
 
     def get_new_target(self, args):
         return self.repository

+ 1 - 1
borg/locking.py

@@ -138,7 +138,7 @@ class ExclusiveLock:
                 if timer.timed_out_or_sleep():
                     raise LockTimeout(self.path)
             except OSError as err:
-                raise LockFailed(self.path, str(err))
+                raise LockFailed(self.path, str(err)) from None
             else:
                 with open(self.unique_name, "wb"):
                     pass

+ 1 - 1
borg/remote.py

@@ -159,7 +159,7 @@ class RemoteRepository:
         try:
             version = self.call('negotiate', RPC_PROTOCOL_VERSION)
         except ConnectionClosed:
-            raise ConnectionClosedWithHint('Is borg working on the server?')
+            raise ConnectionClosedWithHint('Is borg working on the server?') from None
         if version != RPC_PROTOCOL_VERSION:
             raise Exception('Server insisted on using unsupported protocol version %d' % version)
         self.id = self.call('open', location.path, create, lock_wait, lock)

+ 3 - 3
borg/repository.py

@@ -417,7 +417,7 @@ class Repository:
             segment, offset = self.index[id_]
             return self.io.read(segment, offset, id_)
         except KeyError:
-            raise self.ObjectNotFound(id_, self.path)
+            raise self.ObjectNotFound(id_, self.path) from None
 
     def get_many(self, ids, is_preloaded=False):
         for id_ in ids:
@@ -446,7 +446,7 @@ class Repository:
         try:
             segment, offset = self.index.pop(id)
         except KeyError:
-            raise self.ObjectNotFound(id, self.path)
+            raise self.ObjectNotFound(id, self.path) from None
         self.segments[segment] -= 1
         self.compact.add(segment)
         segment = self.io.write_delete(id)
@@ -628,7 +628,7 @@ class LoggedIO:
             hdr_tuple = fmt.unpack(header)
         except struct.error as err:
             raise IntegrityError('Invalid segment entry header [segment {}, offset {}]: {}'.format(
-                segment, offset, err))
+                segment, offset, err)) from None
         if fmt is self.put_header_fmt:
             crc, size, tag, key = hdr_tuple
         elif fmt is self.header_fmt:

+ 1 - 1
borg/testsuite/__init__.py

@@ -144,4 +144,4 @@ class FakeInputs:
         try:
             return self.inputs.pop(0)
         except IndexError:
-            raise EOFError
+            raise EOFError from None