summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorScott Lagler <laglerscott@gmail.com>2024-10-06 13:39:18 -0400
committerGlenn Smith <glenn@vector35.com>2024-10-22 15:31:29 -0400
commit0422763449035778245530022986590375546973 (patch)
tree41461d29d68f722b878ee4d921c375b9d20cdcaa /python
parent7421118805997155191953874367677542369042 (diff)
fix: implement slicing on TypedDataAccessor for ArrayTypes
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 6adb8b1e..60cc4f28 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -10425,7 +10425,7 @@ class TypedDataAccessor:
for i in range(_type.count):
yield self[i]
- def __getitem__(self, key: Union[str, int]) -> 'TypedDataAccessor':
+ def __getitem__(self, key: Union[str, int, slice]) -> Union['TypedDataAccessor', List['TypedDataAccessor']]:
_type = self.type
if isinstance(_type, _types.NamedTypeReferenceType):
_type = _type.target(self.view)
@@ -10433,6 +10433,8 @@ class TypedDataAccessor:
if key >= _type.count:
raise ValueError(f"Index {key} out of bounds array has {_type.count} elements")
return TypedDataAccessor(_type.element_type, self.address + key * len(_type.element_type), self.view, self.endian)
+ if isinstance(_type, _types.ArrayType) and isinstance(key, slice):
+ return [self[i] for i in range(*key.indices(len(self.value)))]
if not isinstance(_type, _types.StructureType):
raise ValueError("Can't get member of non-structure")
if not isinstance(key, str):