]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Refine some places
authorКоренберг Марк (ноутбук дома) <socketpair@gmail.com>
Tue, 5 Jun 2012 17:02:10 +0000 (23:02 +0600)
committerКоренберг Марк (ноутбук дома) <socketpair@gmail.com>
Fri, 8 Jun 2012 16:26:35 +0000 (22:26 +0600)
No real logick change

python/netlink/core.py
python/netlink/route/tc.py

index 3aa69c4685a9fab5b6cfe6601bf245d419a1e17c..ecb02c3eaef48b283408836c9ab5886fbce83478 100644 (file)
@@ -463,7 +463,8 @@ class ReverseObjIterator(ObjIterator):
 class Cache(object):
     """Collection of netlink objects"""
     def __init__(self):
-        raise NotImplementedError()
+        if self.__class__ is Cache:
+            raise NotImplementedError()
         self.arg1 = None
         self.arg2 = None
 
index 370058571777337fa1f94e6e574e47d076f72e5e..a79f31ee3bc1810c6fd0cab055a1413aebb4b842 100644 (file)
@@ -610,10 +610,13 @@ def get_qdisc(ifindex, handle=None, parent=None):
     _qdisc_cache.refill()
 
     for qdisc in _qdisc_cache:
-        if qdisc.ifindex == ifindex and \
-           (handle == None or qdisc.handle == handle) and \
-           (parent == None or qdisc.parent == parent):
-            l.append(qdisc)
+        if qdisc.ifindex != ifindex:
+            continue
+        if (handle is not None) and (qdisc.handle != handle):
+            continue
+        if (parent is not None) and (qdisc.parent != parent):
+            continue
+        l.append(qdisc)
 
     return l
 
@@ -631,32 +634,29 @@ def get_class(ifindex, parent, handle=None):
     cache.refill()
 
     for cl in cache:
-        if (parent == None or cl.parent == parent) and \
-           (handle == None or cl.handle == handle):
-            l.append(cl)
+        if (parent is not None) and (cl.parent != parent):
+            continue
+        if (handle is not None) and (cl.handle != handle):
+            continue
+        l.append(cl)
 
     return l
 
 _cls_cache = {}
 
 def get_cls(ifindex, parent, handle=None):
-    l = []
 
-    try:
-        chain = _cls_cache[ifindex]
-    except KeyError:
-        _cls_cache[ifindex] = {}
+    chain = _cls_cache.get(ifindex, dict())
 
     try:
-        cache = _cls_cache[ifindex][parent]
+        cache = chain[parent]
     except KeyError:
         cache = ClassifierCache(ifindex, parent)
-        _cls_cache[ifindex][parent] = cache
+        chain[parent] = cache
 
     cache.refill()
 
-    for cls in cache:
-        if handle == None or cls.handle == handle:
-            l.append(cls)
+    if handle is None:
+        return [ cls for cls in cache ]
 
-    return l
+    return [ cls for cls in cache if cls.handle == handle ]