python: add __str__() for Region

- Provide a nicer string for debugging purposes.
- improve comments about the purpose of __repr__() and __str__()

Signed-off-by: Axel Heider <axelheider@gmx.de>
This commit is contained in:
Axel Heider
2021-09-12 00:16:05 +02:00
committed by Kent McLeod
parent fcb46e119d
commit 77fb21aa90

View File

@@ -24,8 +24,17 @@ class Region:
return ret
def __repr__(self):
''' Returns a string representation that is a valid Python expression
that eval() can parse. '''
return 'Region(base=0x{:x},size=0x{:x})'.format(self.base, self.size)
def __str__(self):
''' Returns a string representation. '''
return 'Region [0x{:x}..0x{:x}] ({:d} bytes)'.format(
self.base,
self.base + self.size - (1 if self.size > 0 else 0),
self.size)
def __eq__(self, other):
return self.base == other.base and self.size == other.size