4 from bup.compat import pending_raise
11 """Return a string representation of a path."""
12 # FIXME: configurability (might git-config quotePath be involved?)
13 return x.decode(errors='backslashreplace')
16 assert not hasattr(py_mmap.mmap, '__del__')
17 if hasattr(py_mmap.mmap, '__enter__'):
18 assert hasattr(py_mmap.mmap, '__exit__')
20 class mmap(py_mmap.mmap):
21 '''mmap.mmap wrapper that detects and complains about any instances
22 that aren't explicitly closed.
25 def __new__(cls, *args, **kwargs):
26 result = super().__new__(cls, *args, **kwargs)
27 result._bup_closed = True # supports __del__
30 def __init__(self, *args, **kwargs):
31 # Silence deprecation warnings. mmap's current parent is
32 # object, which accepts no params and as of at least 2.7
34 if py_mmap.mmap.__init__ is not object.__init__:
35 super().__init__(self, *args, **kwargs)
36 self._bup_closed = False
39 self._bup_closed = True
40 super(mmap, self).close()
42 if hasattr(py_mmap.mmap, '__enter__'):
44 super(mmap, self).__enter__()
46 def __exit__(self, type, value, traceback):
47 # Don't call self.close() when the parent has its own __exit__;
49 self._bup_closed = True
50 result = super(mmap, self).__exit__(type, value, traceback)
55 def __exit__(self, type, value, traceback):
56 with pending_raise(value, rethrow=False):
60 assert self._bup_closed