@@ -116,16 +116,13 @@ class MapRegion(object):
116
116
'_size' , # cached size of our memory map
117
117
'__weakref__'
118
118
]
119
- _need_compat_layer = sys .version_info [0 ] < 3 and sys . version_info [ 1 ] < 6
119
+ _need_compat_layer = sys .version_info [: 2 ] < ( 2 , 6 )
120
120
121
121
if _need_compat_layer :
122
122
__slots__ .append ('_mfb' ) # mapped memory buffer to provide offset
123
123
# END handle additional slot
124
124
125
125
#{ Configuration
126
- # Used for testing only. If True, all data will be loaded into memory at once.
127
- # This makes sure no file handles will remain open.
128
- _test_read_into_memory = False
129
126
#} END configuration
130
127
131
128
def __init__ (self , path_or_fd , ofs , size , flags = 0 ):
@@ -160,10 +157,7 @@ def __init__(self, path_or_fd, ofs, size, flags=0):
160
157
# bark that the size is too large ... many extra file accesses because
161
158
# if this ... argh !
162
159
actual_size = min (os .fstat (fd ).st_size - sizeofs , corrected_size )
163
- if self ._test_read_into_memory :
164
- self ._mf = self ._read_into_memory (fd , ofs , actual_size )
165
- else :
166
- self ._mf = mmap (fd , actual_size , ** kwargs )
160
+ self ._mf = mmap (fd , actual_size , ** kwargs )
167
161
# END handle memory mode
168
162
169
163
self ._size = len (self ._mf )
@@ -179,19 +173,6 @@ def __init__(self, path_or_fd, ofs, size, flags=0):
179
173
# We assume the first one to use us keeps us around
180
174
self .increment_client_count ()
181
175
182
- def _read_into_memory (self , fd , offset , size ):
183
- """:return: string data as read from the given file descriptor, offset and size """
184
- os .lseek (fd , offset , os .SEEK_SET )
185
- mf = ''
186
- bytes_todo = size
187
- while bytes_todo :
188
- chunk = 1024 * 1024
189
- d = os .read (fd , chunk )
190
- bytes_todo -= len (d )
191
- mf += d
192
- # END loop copy items
193
- return mf
194
-
195
176
def __repr__ (self ):
196
177
return "MapRegion<%i, %i>" % (self ._b , self .size ())
197
178
@@ -267,7 +248,7 @@ class MapRegionList(list):
267
248
"""List of MapRegion instances associating a path with a list of regions."""
268
249
__slots__ = (
269
250
'_path_or_fd' , # path or file descriptor which is mapped by all our regions
270
- '_file_size' # total size of the file we map
251
+ '_file_size' # total size of the file we map
271
252
)
272
253
273
254
def __new__ (cls , path ):
0 commit comments