Skip to content

Commit

Permalink
Specify chunks padding size in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Oct 8, 2023
1 parent 9331d55 commit 4ce0924
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def chunks(self, size=32, alignment=1, padding=b''):
Each chunk is itself a Segment.
`size` and `alignment` are in words. `size` must be a multiple of
`alignment`.
`alignment`. If set, `padding` must be a word value.
If `padding` is set, the first and final chunks are padded so that:
1. The first chunk is aligned even if the segment itself is not.
Expand All @@ -379,7 +379,8 @@ def chunks(self, size=32, alignment=1, padding=b''):
raise Error(f'size {size} is not a multiple of alignment {alignment}')

if padding and len(padding) != self.word_size_bytes:
raise Error(f'padding must be same length as word ({self.word_size_bytes})')
raise Error(f'padding must be a word value (size {self.word_size_bytes}),'
f' got {padding}')

size *= self.word_size_bytes
alignment *= self.word_size_bytes
Expand Down Expand Up @@ -656,7 +657,7 @@ def chunks(self, size=32, alignment=1, padding=b''):
Each chunk is itself a Segment.
`size` and `alignment` are in words. `size` must be a multiple of
`alignment`.
`alignment`. If set, `padding` must be a word value.
If `padding` is set, the first and final chunks of each segment are
padded so that:
Expand All @@ -669,7 +670,8 @@ def chunks(self, size=32, alignment=1, padding=b''):
raise Error(f'size {size} is not a multiple of alignment {alignment}')

if padding and len(padding) != self.word_size_bytes:
raise Error(f'padding must be same length as word ({self.word_size_bytes})')
raise Error(f'padding must be a word value (size {self.word_size_bytes}),'
f' got {padding}')

for segment in self:
for chunk in segment.chunks(size, alignment, padding):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def test_chunks_bad_arguments(self):
list(binfile.segments.chunks(padding=b'\xff\xff'))

self.assertEqual(str(cm.exception),
'padding must be same length as word (1)')
r"padding must be a word value (size 1), got b'\xff\xff'")

def test_segment(self):
binfile = bincopy.BinFile()
Expand Down

0 comments on commit 4ce0924

Please sign in to comment.