From 482c602b7416db212a7dae5a2a363ef9714846c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=BD=D0=BE=D1=83=D1=82=D0=B1?= =?UTF-8?q?=D1=83=D0=BA=20=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Tue, 5 Jun 2012 23:02:10 +0600 Subject: [PATCH] Refine some places No real logick change --- python/netlink/core.py | 3 ++- python/netlink/route/tc.py | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 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 = [] + + chain = _cls_cache.get(ifindex, dict()) try: - chain = _cls_cache[ifindex] - except KeyError: - _cls_cache[ifindex] = {} - - 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 ]