fixup! euci: add default values to get methods

parent 781ab46f
Pipeline #48281 failed with stages
in 22 seconds
......@@ -47,6 +47,10 @@ class EUci(Uci):
super(EUci, self).__init__(*args, **kwargs)
def get(self, *args, default=None):
"""Override UCI get method with additional check for missing keys.
Raises UciExceptionNotFound if key cannot be found and default value is unset.
Returns default value if key cannot be found and default value is set.
"""
try:
return super().get(*args)
except UciExceptionNotFound:
......@@ -59,6 +63,8 @@ class EUci(Uci):
Value '0', 'no', 'off', 'false' or 'disabled' is returned as False.
Value '1' , 'yes', 'on', 'true' or 'enabled' is returned as True.
ValueError is raised on any other value.
Raises UciExceptionNotFound if key cannot be found and default value is unset.
Returns default value if key cannot be found and default value is set.
"""
try:
value = self.get(*args)
......@@ -80,6 +86,8 @@ class EUci(Uci):
def get_integer(self, *args, default=None):
"""Returns given UCI config as an integer.
Raises ValueError if config value can't be converted to int.
Raises UciExceptionNotFound if key cannot be found and default value is unset.
Returns default value if key cannot be found and default value is set.
"""
try:
return int(self.get(*args))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment