summaryrefslogtreecommitdiffstats
path: root/python/netlink/util.py
diff options
context:
space:
mode:
authorКоренберг Марк <mark@ideco.ru>2012-06-07 07:48:06 (GMT)
committerКоренберг Марк (ноутбук дома) <socketpair@gmail.com>2012-06-08 16:26:35 (GMT)
commit87d370912ca8fe4aa68e8fd61cfee201d959ee1b (patch)
treefe1804952ec76bdbdcb97f2965e8104341961c5f /python/netlink/util.py
parent139e3d3203955723606ba395c726a343d3c343ed (diff)
downloadlibnl-87d370912ca8fe4aa68e8fd61cfee201d959ee1b.zip
libnl-87d370912ca8fe4aa68e8fd61cfee201d959ee1b.tar.gz
libnl-87d370912ca8fe4aa68e8fd61cfee201d959ee1b.tar.bz2
netlink.nlattr re-implemented in more pythonic way
Diffstat (limited to 'python/netlink/util.py')
-rw-r--r--python/netlink/util.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/python/netlink/util.py b/python/netlink/util.py
index 0f2e547..2394033 100644
--- a/python/netlink/util.py
+++ b/python/netlink/util.py
@@ -80,24 +80,19 @@ class MyFormatter(Formatter):
self._indent = indent
def _nlattr(self, key):
- value = getattr(self._obj, key)
- title_ = None
+ value = getattr(self._obj.__class__, key)
+ if not isinstance(value, property):
+ raise ValueError('Invalid formatting string {0}'.format(key))
- if isinstance(value, types.MethodType):
- value = value()
+ d = getattr(value.fget, 'formatinfo', dict())
- try:
- d = netlink.attrs[self._obj._name + '.' + key]
+ # value = value.fget() is exactly the same
+ value = getattr(self._obj, key)
- if 'fmt' in d:
- value = d['fmt'](value)
+ if 'fmt' in d:
+ value = d['fmt'](value)
- if 'title' in d:
- title_ = d['title']
- except KeyError:
- pass
- except AttributeError:
- pass
+ title_ = d.get('title', None)
return title_, str(value)