From a4e588d04a1aca0d940d8becc8cabe2e54feb6ad Mon Sep 17 00:00:00 2001 From: Teto Date: Wed, 2 Oct 2013 22:18:31 +0200 Subject: [PATCH] Fixed ObjIterator for python3, fixed output of _color and added missing parameter to nl_cache_resync Here are a few things I fixed and that provoked a python error. I canno't answer to this thread but one solution I found while using the python binding is to iterate over all and filter via python http://list-archives.org/2013/09/09/libnl-lists-infradead-org/missing-feature-for-retrieving-cached- address-objects/f/5031600704 Example: cache = nlrta.AddressCache() cache.resync() for i in cache: print ("item", i ) # then you can filter here Signed-off-by: Thomas Graf --- python/netlink/core.py | 9 +++++++-- python/netlink/util.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/netlink/core.py b/python/netlink/core.py index ee40b0d..fbd1c9e 100644 --- a/python/netlink/core.py +++ b/python/netlink/core.py @@ -449,6 +449,9 @@ class ObjIterator(object): return capi.nl_cache_get_next(self._nl_object) def next(self): + return self.__next__(self) + + def __next__(self): if self._end: raise StopIteration() @@ -566,12 +569,12 @@ class Cache(object): capi.nl_cache_refill(socket._sock, self._nl_cache) return self - def resync(self, socket=None, cb=None): + def resync(self, socket=None, cb=None, args=None): """Synchronize cache with content in kernel""" if socket is None: socket = lookup_socket(self._protocol) - capi.nl_cache_resync(socket._sock, self._nl_cache, cb) + capi.nl_cache_resync(socket._sock, self._nl_cache, cb, args) def provide(self): """Provide this cache to others @@ -668,6 +671,8 @@ class AbstractAddress(object): self._nl_addr = None if isinstance(addr, str): + # returns None on success I guess + # TO CORRECT addr = capi.addr_parse(addr, socket.AF_UNSPEC) if addr is None: raise ValueError('Invalid address format') diff --git a/python/netlink/util.py b/python/netlink/util.py index 2394033..22ed5cf 100644 --- a/python/netlink/util.py +++ b/python/netlink/util.py @@ -17,8 +17,9 @@ import types __version__ = '1.0' +#rename into colored_output def _color(t, c): - return b'{esc}[{color}m{text}{esc}[0m'.format(esc=b'\x1b', color=c, text=t) + return '{esc}[{color}m{text}{esc}[0m'.format(esc=b'\x1b'.decode(), color=c, text=t) def black(t): return _color(t, 30) -- 2.40.0