X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=lib%2Fbup%2Fcompat.py;h=00575036e27cc46f7fb6b3408e273831526b9daa;hb=4448f184253125e1b8bd0c55d0098a335d15b90b;hp=68006f5178679e1796ecf55a67da8e761043a5d5;hpb=d2fa0418334507cb6ef08c0c9caca8e9bf5ce19d;p=bup.git diff --git a/lib/bup/compat.py b/lib/bup/compat.py index 68006f5..0057503 100644 --- a/lib/bup/compat.py +++ b/lib/bup/compat.py @@ -14,7 +14,6 @@ if py3: # pylint: disable=unused-import from contextlib import ExitStack, nullcontext - from mmap import mmap from os import environb as environ from os import fsdecode, fsencode from shlex import quote @@ -48,13 +47,17 @@ if py3: """ def __init__(self, ex, rethrow=True): + self.closed = False self.ex = ex self.rethrow = rethrow def __enter__(self): return None def __exit__(self, exc_type, exc_value, traceback): + self.closed = True if not exc_type and self.ex and self.rethrow: raise self.ex + def __del__(self): + assert self.closed def items(x): return x.items() @@ -85,7 +88,6 @@ if py3: else: # Python 2 from contextlib import contextmanager - import mmap as py_mmap ModuleNotFoundError = ImportError @@ -146,12 +148,14 @@ else: # Python 2 """ def __init__(self, ex, rethrow=True): + self.closed = False self.ex = ex self.rethrow = rethrow def __enter__(self): if self.ex: add_ex_tb(self.ex) def __exit__(self, exc_type, exc_value, traceback): + self.closed = True if exc_value: if self.ex: add_ex_tb(exc_value) @@ -159,6 +163,8 @@ else: # Python 2 return if self.rethrow and self.ex: raise self.ex + def __del__(self): + assert self.closed def dump_traceback(ex): stack = [ex] @@ -217,16 +223,6 @@ else: # Python 2 buffer = buffer - assert not hasattr(py_mmap.mmap, '__enter__') - assert not hasattr(py_mmap.mmap, '__exit__') - - class mmap(py_mmap.mmap): - def __enter__(self): - return self - def __exit__(self, type, value, traceback): - with pending_raise(value, rethrow=False): - self.close() - try: import bup_main except ModuleNotFoundError: