summaryrefslogtreecommitdiffstats
path: root/python/netlink
diff options
context:
space:
mode:
authorКоренберг Марк (ноутбук дома) <socketpair@gmail.com>2012-06-05 17:02:10 (GMT)
committerКоренберг Марк (ноутбук дома) <socketpair@gmail.com>2012-06-08 16:26:35 (GMT)
commit482c602b7416db212a7dae5a2a363ef9714846c8 (patch)
treeeaa5b7e407392583c5912a5fe7f42887ff9b7359 /python/netlink
parent454ea4a5b46e84830151796eeab1a57503577776 (diff)
downloadlibnl-482c602b7416db212a7dae5a2a363ef9714846c8.zip
libnl-482c602b7416db212a7dae5a2a363ef9714846c8.tar.gz
libnl-482c602b7416db212a7dae5a2a363ef9714846c8.tar.bz2
Refine some places
No real logick change
Diffstat (limited to 'python/netlink')
-rw-r--r--python/netlink/core.py3
-rw-r--r--python/netlink/route/tc.py36
2 files changed, 20 insertions, 19 deletions
diff --git a/python/netlink/core.py b/python/netlink/core.py
index 3aa69c4..ecb02c3 100644
--- a/python/netlink/core.py
+++ b/python/netlink/core.py
@@ -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
diff --git a/python/netlink/route/tc.py b/python/netlink/route/tc.py
index 3700585..a79f31e 100644
--- a/python/netlink/route/tc.py
+++ b/python/netlink/route/tc.py
@@ -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 ]