From e693748e57f2af7413ec119d7474921a09d66803 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 2 Sep 2022 19:34:11 +0300 Subject: [PATCH] power_fields: allow slicing fields --- src/openpower/decoder/power_fields.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/openpower/decoder/power_fields.py b/src/openpower/decoder/power_fields.py index 4b7d0365..e7660d83 100644 --- a/src/openpower/decoder/power_fields.py +++ b/src/openpower/decoder/power_fields.py @@ -127,6 +127,19 @@ class FieldMeta(type): def __len__(cls): return len(cls.__members__) + def __getitem__(cls, selector): + if isinstance(selector, int): + selector = (selector,) + + items = [] + for idx in selector: + if not isinstance(idx, int): + raise ValueError(selector) + item = cls.__members__[idx] + items.append(item) + + return cls.__class__(cls.__name__, (Field,), {}, items=items) + def remap(cls, scheme): if isinstance(scheme, type) and issubclass(scheme, Mapping): scheme = range(len(scheme)) -- 2.30.2