From 64f7eecf581032d0ff0f0bc2abeb99893bbc871d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 14 Jun 2017 04:04:10 +0200 Subject: [PATCH] features: implement get() method --- qubesadmin/features.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qubesadmin/features.py b/qubesadmin/features.py index 54d6437..cd33d59 100644 --- a/qubesadmin/features.py +++ b/qubesadmin/features.py @@ -67,6 +67,15 @@ class Features(object): _NO_DEFAULT = object() + def get(self, item, default=_NO_DEFAULT): + '''Get a feature, return default value if missing.''' + try: + return self[item] + except KeyError: + if default is self._NO_DEFAULT: + raise + return default + def check_with_template(self, feature, default=_NO_DEFAULT): ''' Check if the vm's template has the specified feature. ''' try: