diff options
| author | Marc Abramowitz <marc@marc-abramowitz.com> | 2014-06-16 06:33:41 -0700 |
|---|---|---|
| committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2014-06-16 07:01:01 -0700 |
| commit | 52fba74d78d3fcce53fb89c7b2c20b24197296a8 (patch) | |
| tree | 461b44231cef3a7947e67b74e435c6e5ec33dc26 | |
| parent | f523a1191176312d0339b828274b67c6e34a1390 (diff) | |
| download | smmap-52fba74d78d3fcce53fb89c7b2c20b24197296a8.tar.gz | |
Deal with lack of `buffer` in py3
| -rw-r--r-- | smmap/mman.py | 1 | ||||
| -rw-r--r-- | smmap/test/test_tutorial.py | 1 | ||||
| -rw-r--r-- | smmap/util.py | 11 |
3 files changed, 12 insertions, 1 deletions
diff --git a/smmap/mman.py b/smmap/mman.py index 637a284..ff32bbb 100644 --- a/smmap/mman.py +++ b/smmap/mman.py @@ -6,6 +6,7 @@ from .util import ( is_64_bit, align_to_mmap, string_types, + buffer, ) from weakref import ref diff --git a/smmap/test/test_tutorial.py b/smmap/test/test_tutorial.py index ad1a9c0..ccc113b 100644 --- a/smmap/test/test_tutorial.py +++ b/smmap/test/test_tutorial.py @@ -44,6 +44,7 @@ class TestTutorial(TestBase): # its recommended not to create big slices when feeding the buffer # into consumers (e.g. struct or zlib). # Instead, either give the buffer directly, or use pythons buffer command. + from smmap.util import buffer buffer(c.buffer(), 1, 9) # first 9 bytes without copying them # you can query absolute offsets, and check whether an offset is included diff --git a/smmap/util.py b/smmap/util.py index 0d8385d..54c6c45 100644 --- a/smmap/util.py +++ b/smmap/util.py @@ -12,11 +12,20 @@ except ImportError: from mmap import PAGESIZE as ALLOCATIONGRANULARITY #END handle pythons missing quality assurance -__all__ = [ "align_to_mmap", "is_64_bit", +__all__ = [ "align_to_mmap", "is_64_bit", "buffer", "MapWindow", "MapRegion", "MapRegionList", "ALLOCATIONGRANULARITY"] #{ Utilities +try: + # Python 2 + buffer = buffer +except NameError: + # Python 3 has no `buffer`; only `memoryview` + def buffer(obj, offset, size): + return memoryview(obj[offset:offset+size]) + + def string_types(): if sys.version_info[0] >= 3: return str |
