Skip to content

Commit 01dac15

Browse files
committed
pep8 linting
E201 whitespace after '(' E203 whitespace before ',' E221 multiple spaces before operator E225 missing whitespace around operator E227 missing whitespace around bitwise or shift operator E231 missing whitespace after ',' E251 unexpected spaces around keyword / parameter equals W291 trailing whitespace W293 blank line contains whitespace E302 expected 2 blank lines, found 1 E303 too many blank lines (3) W391 blank line at end of file
1 parent f4b6b25 commit 01dac15

File tree

9 files changed

+258
-260
lines changed

9 files changed

+258
-260
lines changed

smmap/buf.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@
1010

1111

1212
class SlidingWindowMapBuffer(object):
13-
"""A buffer like object which allows direct byte-wise object and slicing into
13+
"""A buffer like object which allows direct byte-wise object and slicing into
1414
memory of a mapped file. The mapping is controlled by the provided cursor.
15-
16-
The buffer is relative, that is if you map an offset, index 0 will map to the
15+
16+
The buffer is relative, that is if you map an offset, index 0 will map to the
1717
first byte at the offset you used during initialization or begin_access
18-
18+
1919
**Note:** Although this type effectively hides the fact that there are mapped windows
2020
underneath, it can unfortunately not be used in any non-pure python method which
2121
needs a buffer or string"""
2222
__slots__ = (
2323
'_c', # our cursor
2424
'_size', # our supposed size
2525
)
26-
27-
28-
def __init__(self, cursor = None, offset = 0, size = sys.maxsize, flags = 0):
26+
27+
def __init__(self, cursor=None, offset=0, size=sys.maxsize, flags=0):
2928
"""Initalize the instance to operate on the given cursor.
3029
:param cursor: if not None, the associated cursor to the file you want to access
31-
If None, you have call begin_access before using the buffer and provide a cursor
30+
If None, you have call begin_access before using the buffer and provide a cursor
3231
:param offset: absolute offset in bytes
3332
:param size: the total size of the mapping. Defaults to the maximum possible size
3433
From that point on, the __len__ of the buffer will be the given size or the file size.
@@ -44,10 +43,10 @@ def __init__(self, cursor = None, offset = 0, size = sys.maxsize, flags = 0):
4443

4544
def __del__(self):
4645
self.end_access()
47-
46+
4847
def __len__(self):
4948
return self._size
50-
49+
5150
def __getitem__(self, i):
5251
if isinstance(i, slice):
5352
return self.__getslice__(i.start or 0, i.stop or self._size)
@@ -59,10 +58,10 @@ def __getitem__(self, i):
5958
c.use_region(i, 1)
6059
# END handle region usage
6160
return c.buffer()[i-c.ofs_begin()]
62-
61+
6362
def __getslice__(self, i, j):
6463
c = self._c
65-
# fast path, slice fully included - safes a concatenate operation and
64+
# fast path, slice fully included - safes a concatenate operation and
6665
# should be the default
6766
assert c.is_valid()
6867
if i < 0:
@@ -91,18 +90,18 @@ def __getslice__(self, i, j):
9190
return bytes().join(md)
9291
# END fast or slow path
9392
#{ Interface
94-
95-
def begin_access(self, cursor = None, offset = 0, size = sys.maxsize, flags = 0):
93+
94+
def begin_access(self, cursor=None, offset=0, size=sys.maxsize, flags=0):
9695
"""Call this before the first use of this instance. The method was already
9796
called by the constructor in case sufficient information was provided.
98-
97+
9998
For more information no the parameters, see the __init__ method
100-
:param path: if cursor is None the existing one will be used.
99+
:param path: if cursor is None the existing one will be used.
101100
:return: True if the buffer can be used"""
102101
if cursor:
103102
self._c = cursor
104103
#END update our cursor
105-
104+
106105
# reuse existing cursors if possible
107106
if self._c is not None and self._c.is_associated():
108107
res = self._c.use_region(offset, size, flags).is_valid()
@@ -114,27 +113,25 @@ def begin_access(self, cursor = None, offset = 0, size = sys.maxsize, flags = 0)
114113
if size > self._c.file_size():
115114
size = self._c.file_size() - offset
116115
#END handle size
117-
self._size = size
116+
self._size = size
118117
#END set size
119118
return res
120119
# END use our cursor
121120
return False
122-
121+
123122
def end_access(self):
124-
"""Call this method once you are done using the instance. It is automatically
123+
"""Call this method once you are done using the instance. It is automatically
125124
called on destruction, and should be called just in time to allow system
126125
resources to be freed.
127-
126+
128127
Once you called end_access, you must call begin access before reusing this instance!"""
129128
self._size = 0
130129
if self._c is not None:
131130
self._c.unuse_region()
132131
#END unuse region
133-
132+
134133
def cursor(self):
135134
""":return: the currently set cursor which provides access to the data"""
136135
return self._c
137-
138-
#}END interface
139-
140136

137+
#}END interface

smmap/exc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Module with system exceptions"""
22

3+
34
class MemoryManagerError(Exception):
45
"""Base class for all exceptions thrown by the memory manager"""
5-
6+
7+
68
class RegionCollectionError(MemoryManagerError):
7-
"""Thrown if a memory region could not be collected, or if no region for collection was found"""
9+
"""Thrown if a memory region could not be collected, or if no region for collection was found"""

0 commit comments

Comments
 (0)