2 from __future__ import absolute_import, print_function
6 from bup.compat import pending_raise
10 def byte_stream(file):
14 """Return a string representation of a path."""
15 # FIXME: configurability (might git-config quotePath be involved?)
16 return x.decode(errors='backslashreplace')
18 def byte_stream(file):
22 """Return a string representation of a path."""
23 # FIXME: configurability (might git-config quotePath be involved?)
27 assert not hasattr(py_mmap.mmap, '__del__')
28 if hasattr(py_mmap.mmap, '__enter__'):
29 assert hasattr(py_mmap.mmap, '__exit__')
31 class mmap(py_mmap.mmap):
32 '''mmap.mmap wrapper that detects and complains about any instances
33 that aren't explicitly closed.
37 def __init__(self, *args, **kwargs):
38 self._bup_closed = True
39 # Silence deprecation warnings. mmap's current parent is
40 # object, which accepts no params and as of at least 2.7
42 if py_mmap.mmap.__init__ is not object.__init__:
43 super(mmap, self).__init__(self, *args, **kwargs)
44 self._bup_closed = False
47 self._bup_closed = True
48 super(mmap, self).close()
50 if hasattr(py_mmap.mmap, '__enter__'):
52 super(mmap, self).__enter__()
54 def __exit__(self, type, value, traceback):
55 # Don't call self.close() when the parent has its own __exit__;
57 self._bup_closed = True
58 result = super(mmap, self).__exit__(type, value, traceback)
63 def __exit__(self, type, value, traceback):
64 with pending_raise(value, rethrow=False):
68 assert self._bup_closed