From 01e40b5e02e90ccac06e3b0ec0adf1f8f4e48ebd Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 13 Jul 2014 17:29:58 -0400 Subject: Use memoryview instead of buffer This uses memoryview by default, which is supported in Python 3 and Python 2.7, but not Python 2.6, and falls back to the old `buffer` type in Python 2.6 and when the memoryview does not support the type, such as when mmap instaces are passed in. --- gitdb/stream.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gitdb') diff --git a/gitdb/stream.py b/gitdb/stream.py index 52b54af..a099eeb 100644 --- a/gitdb/stream.py +++ b/gitdb/stream.py @@ -270,7 +270,10 @@ class DecompressMemMapReader(LazyMixin): # END adjust winsize # takes a slice, but doesn't copy the data, it says ... - indata = buffer(self._m, self._cws, self._cwe - self._cws) + try: + indata = memoryview(self._m)[self._cws:self._cwe].tobytes() + except (NameError, TypeError): + indata = buffer(self._m, self._cws, self._cwe - self._cws) # get the actual window end to be sure we don't use it for computations self._cwe = self._cws + len(indata) -- cgit v1.2.1