Commit 40b118d3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Introduce better item getter helper in

And also use it for simple network fields. Currently the Python
library returns jsnull, which is formatted as 'None' by the Python
client, which (IMHO) is not nice, since these fields are strings (some
of them) or "other". An undeclared gateway is easier to diagnose when
properly reported by the server as missing, rather than "existing but
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarHelga Velroyen <>
parent 60a67263
......@@ -977,6 +977,23 @@ def _GetItemAttr(attr):
return lambda _, item: getter(item)
def _GetItemMaybeAttr(attr):
"""Returns a field function to return a not-None attribute of the item.
If the value is None, then C{_FS_UNAVAIL} will be returned instead.
@param attr: Attribute name
def _helper(_, obj):
val = getattr(obj, attr)
if val is None:
return _FS_UNAVAIL
return val
return _helper
def _GetNDParam(name):
"""Return a field function to return an ND parameter out of the context.
......@@ -2614,7 +2631,7 @@ def _BuildNetworkFields():
# Add simple fields
(_MakeField(name, title, kind, doc),
NETQ_CONFIG, 0, _GetItemAttr(name))
NETQ_CONFIG, 0, _GetItemMaybeAttr(name))
for (name, (title, kind, _, doc)) in _NETWORK_SIMPLE_FIELDS.items()])
def _GetLength(getter):
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