]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Fixed ObjIterator for python3, fixed output of _color and added missing parameter...
authorTeto <mattator@gmail.com>
Wed, 2 Oct 2013 20:18:31 +0000 (22:18 +0200)
committerThomas Graf <tgraf@suug.ch>
Mon, 7 Oct 2013 07:52:08 +0000 (09:52 +0200)
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>
python/netlink/core.py
python/netlink/util.py

index ee40b0de3cc6939ca8119dfb7bf07d1c63ebd97a..fbd1c9e6ac53b7943a388b18bd2fd40f3a1eade0 100644 (file)
@@ -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')
index 23940336fde80bad1ddc41c9e9e17b68a71e88ed..22ed5cfc0e72844fb9c0aa57673a02e61ccaaa63 100644 (file)
@@ -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)