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 <tgraf@suug.ch>
This commit is contained in:
parent
f2e6f502eb
commit
a4e588d04a
2 changed files with 9 additions and 3 deletions
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue