From 54a34e8976587762df7b02ef09b0150c065fb9e1 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 7 Sep 2018 22:04:27 +0300 Subject: Drop support for EOL Python --- smmap/buf.py | 43 ++++++++++++++----------------------------- smmap/util.py | 38 +------------------------------------- 2 files changed, 15 insertions(+), 66 deletions(-) (limited to 'smmap') diff --git a/smmap/buf.py b/smmap/buf.py index 438292b..786775a 100644 --- a/smmap/buf.py +++ b/smmap/buf.py @@ -88,35 +88,20 @@ class SlidingWindowMapBuffer(object): # It's fastest to keep tokens and join later, especially in py3, which was 7 times slower # in the previous iteration of this code pyvers = sys.version_info[:2] - if (3, 0) <= pyvers <= (3, 3): - # Memory view cannot be joined below python 3.4 ... - out = bytes() - while l: - c.use_region(ofs, l) - assert c.is_valid() - d = c.buffer()[:l] - ofs += len(d) - l -= len(d) - # This is slower than the join ... but what can we do ... - out += d - del(d) - # END while there are bytes to read - return out - else: - md = list() - while l: - c.use_region(ofs, l) - assert c.is_valid() - d = c.buffer()[:l] - ofs += len(d) - l -= len(d) - # Make sure we don't keep references, as c.use_region() might attempt to free resources, but - # can't unless we use pure bytes - if hasattr(d, 'tobytes'): - d = d.tobytes() - md.append(d) - # END while there are bytes to read - return bytes().join(md) + md = list() + while l: + c.use_region(ofs, l) + assert c.is_valid() + d = c.buffer()[:l] + ofs += len(d) + l -= len(d) + # Make sure we don't keep references, as c.use_region() might attempt to free resources, but + # can't unless we use pure bytes + if hasattr(d, 'tobytes'): + d = d.tobytes() + md.append(d) + # END while there are bytes to read + return bytes().join(md) # END fast or slow path #{ Interface diff --git a/smmap/util.py b/smmap/util.py index 02df41a..defef1f 100644 --- a/smmap/util.py +++ b/smmap/util.py @@ -3,13 +3,7 @@ import os import sys from mmap import mmap, ACCESS_READ -try: - from mmap import ALLOCATIONGRANULARITY -except ImportError: - # in python pre 2.6, the ALLOCATIONGRANULARITY does not exist as it is mainly - # useful for aligning the offset. The offset argument doesn't exist there though - from mmap import PAGESIZE as ALLOCATIONGRANULARITY -# END handle pythons missing quality assurance +from mmap import ALLOCATIONGRANULARITY __all__ = ["align_to_mmap", "is_64_bit", "buffer", "MapWindow", "MapRegion", "MapRegionList", "ALLOCATIONGRANULARITY"] @@ -116,11 +110,6 @@ class MapRegion(object): '_size', # cached size of our memory map '__weakref__' ] - _need_compat_layer = sys.version_info[:2] < (2, 6) - - if _need_compat_layer: - __slots__.append('_mfb') # mapped memory buffer to provide offset - # END handle additional slot #{ Configuration #} END configuration @@ -147,11 +136,6 @@ class MapRegion(object): kwargs = dict(access=ACCESS_READ, offset=ofs) corrected_size = size sizeofs = ofs - if self._need_compat_layer: - del(kwargs['offset']) - corrected_size += ofs - sizeofs = 0 - # END handle python not supporting offset ! Arg # have to correct size, otherwise (instead of the c version) it will # bark that the size is too large ... many extra file accesses because @@ -161,10 +145,6 @@ class MapRegion(object): # END handle memory mode self._size = len(self._mf) - - if self._need_compat_layer: - self._mfb = buffer(self._mf, ofs, self._size) - # END handle buffer wrapping finally: if isinstance(path_or_fd, string_types()): os.close(fd) @@ -224,22 +204,6 @@ class MapRegion(object): """Release all resources this instance might hold. Must only be called if there usage_count() is zero""" self._mf.close() - # re-define all methods which need offset adjustments in compatibility mode - if _need_compat_layer: - def size(self): - return self._size - self._b - - def ofs_end(self): - # always the size - we are as large as it gets - return self._size - - def buffer(self): - return self._mfb - - def includes_ofs(self, ofs): - return self._b <= ofs < self._size - # END handle compat layer - #} END interface -- cgit v1.2.1