diff options
author | Коренберг Марк (ноутбук дома) <socketpair@gmail.com> | 2012-06-05 17:02:10 (GMT) |
---|---|---|
committer | Коренберг Марк (ноутбук дома) <socketpair@gmail.com> | 2012-06-08 16:26:35 (GMT) |
commit | 482c602b7416db212a7dae5a2a363ef9714846c8 (patch) | |
tree | eaa5b7e407392583c5912a5fe7f42887ff9b7359 /python | |
parent | 454ea4a5b46e84830151796eeab1a57503577776 (diff) | |
download | libnl-482c602b7416db212a7dae5a2a363ef9714846c8.zip libnl-482c602b7416db212a7dae5a2a363ef9714846c8.tar.gz libnl-482c602b7416db212a7dae5a2a363ef9714846c8.tar.bz2 |
Refine some places
No real logick change
Diffstat (limited to 'python')
-rw-r--r-- | python/netlink/core.py | 3 | ||||
-rw-r--r-- | python/netlink/route/tc.py | 36 |
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 ] |