Skip to content

Commit 25e5035

Browse files
committed
Added rather trivial implementation for the region list, including test
1 parent 0bf7387 commit 25e5035

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

smmap/mman.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,37 @@ def ofs_end(self):
158158
#END handle compat layer
159159

160160

161+
class MappedRegionList(list):
162+
"""List of MappedRegion instances associating a path with a list of regions."""
163+
__slots__ = (
164+
'_path', # path which is mapped by all our regions
165+
'_file_size' # total size of the file we map
166+
)
167+
168+
def __new__(cls, path):
169+
return super(MappedRegionList, cls).__new__(cls)
170+
171+
def __init__(self, path):
172+
self._path = path
173+
self._file_size = None
174+
175+
def path(self):
176+
""":return: path to file whose regions we manage"""
177+
return self._path
178+
179+
def file_size(self):
180+
""":return: size of file we manager"""
181+
if self._file_size is None:
182+
self._file_size = os.stat(self._path).st_size
183+
#END update file size
184+
return self._file_size
185+
186+
161187
class Cursor(object):
162188
"""Pointer into the mapped region of the memory manager, keeping the current window
163189
alive until it is destroyed"""
164190

165-
166-
class MappedRegionList(list):
167-
"""List of MappedRegion instances with specific functionality"""
168191

169-
170192
class MappedMemoryManager(object):
171193
"""Maintains a list of ranges of mapped memory regions in one or more files and allows to easily
172194
obtain additional regions assuring there is no overlap.

smmap/test/test_mman.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ def test_region(self):
8888
assert w.ofs == rfull.ofs_begin() and w.ofs_end() == rfull.ofs_end()
8989

9090
def test_region_list(self):
91-
pass
91+
fc = FileCreator(100, "sample_file")
92+
ml = MappedRegionList(fc.path)
93+
94+
assert len(ml) == 0
95+
assert ml.path() == fc.path
96+
assert ml.file_size() == fc.size
9297

9398
def test_cursor(self):
9499
pass

0 commit comments

Comments
 (0)