File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
161187class 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-
170192class 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments