Skip to content

Commit f9391a1

Browse files
committed
improved docstrings, removed extra calls.
1 parent b123f4d commit f9391a1

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

intelhex/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,22 +338,17 @@ def tobinarray(self, start=None, end=None, pad=_DEPRECATED, size=None):
338338
return self._tobinarray_really(start, end, pad, size)
339339

340340
def _tobinarray_really(self, start, end, pad, size):
341+
"""Return binary array."""
341342
if pad is None:
342343
pad = self.padding
343-
344344
bin = array('B')
345-
346345
if self._buf == {} and None in (start, end):
347346
return bin
348-
349347
if size is not None and size <= 0:
350348
raise ValueError("tobinarray: wrong value for size")
351-
352349
start, end = self._get_start_end(start, end, size)
353-
354350
for i in range_g(start, end+1):
355351
bin.append(self._buf.get(i, pad))
356-
357352
return bin
358353

359354
def tobinstr(self, start=None, end=None, pad=_DEPRECATED, size=None):
@@ -364,7 +359,7 @@ def tobinstr(self, start=None, end=None, pad=_DEPRECATED, size=None):
364359
fill empty spaces with this value
365360
(if pad is None then this method uses self.padding).
366361
@param size size of the block, used with start or end parameter.
367-
@return string of binary data.
362+
@return bytes string of binary data.
368363
'''
369364
if not isinstance(pad, _DeprecatedParam):
370365
print ("IntelHex.tobinstr: 'pad' parameter is deprecated.")
@@ -711,7 +706,8 @@ def tofile(self, fobj, format):
711706
def gets(self, addr, length):
712707
"""Get string of bytes from given address. If any entries are blank
713708
from addr through addr+length, a NotEnoughDataError exception will
714-
be raised. Padding is not used."""
709+
be raised. Padding is not used.
710+
"""
715711
a = array('B', asbytes('\0'*length))
716712
try:
717713
for i in range_g(length):
@@ -729,7 +725,7 @@ def puts(self, addr, s):
729725
self._buf[addr+i] = a[i]
730726

731727
def getsz(self, addr):
732-
"""Get zero-terminated string from given address. Will raise
728+
"""Get zero-terminated bytes string from given address. Will raise
733729
NotEnoughDataError exception if a hole is encountered before a 0.
734730
"""
735731
i = 0
@@ -744,7 +740,7 @@ def getsz(self, addr):
744740
return self.gets(addr, i)
745741

746742
def putsz(self, addr, s):
747-
"""Put string in object at addr and append terminating zero at end."""
743+
"""Put bytes string in object at addr and append terminating zero at end."""
748744
self.puts(addr, s)
749745
self._buf[addr+len(s)] = 0
750746

intelhex/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_tobinarray_with_size(self):
494494
def test_tobinstr(self):
495495
ih = IntelHex(self.f)
496496
s1 = ih.tobinstr()
497-
s2 = asbytes(array_tobytes(bin8))
497+
s2 = array_tobytes(bin8)
498498
self.assertEqual(s2, s1, "data not equal\n%s\n\n%s" % (s1, s2))
499499

500500
def test_tobinfile(self):
@@ -503,14 +503,14 @@ def test_tobinfile(self):
503503
ih.tobinfile(sio)
504504
s1 = sio.getvalue()
505505
sio.close()
506-
s2 = asbytes(array_tobytes(bin8))
506+
s2 = array_tobytes(bin8)
507507
self.assertEqual(s2, s1, "data not equal\n%s\n\n%s" % (s1, s2))
508508
# new API: .tofile universal method
509509
sio = BytesIO()
510510
ih.tofile(sio, format='bin')
511511
s1 = sio.getvalue()
512512
sio.close()
513-
s2 = asbytes(array_tobytes(bin8))
513+
s2 = array_tobytes(bin8)
514514
self.assertEqual(s2, s1, "data not equal\n%s\n\n%s" % (s1, s2))
515515

516516
def test_tobinfile_realfile(self):

0 commit comments

Comments
 (0)