Objects: Add a convenience function for validating enum values

This commit is contained in:
Mike Auty
2020-07-29 20:25:34 +01:00
committed by ikelos
parent bbaf4f22d6
commit 180eee569f
+5
View File
@@ -466,6 +466,11 @@ class Enumeration(interfaces.objects.ObjectInterface, int):
def choices(self) -> Dict[str, int]:
return self._vol['choices']
@property
def legal(self) -> bool:
"""Returns whether the value for the object is a valid choice"""
return self in self.choices.values()
def __getattr__(self, attr: str) -> str:
"""Returns the value for a specific name."""
if attr in self._vol['choices']: