From 6d4828c3f76817da412c91827434d31569dba731 Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Thu, 28 Feb 2013 19:15:55 +0100 Subject: [PATCH] Rewrote factory to bring in classes from base set. --- src/idp_test/check.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/idp_test/check.py b/src/idp_test/check.py index 371ab26..5d5a72a 100644 --- a/src/idp_test/check.py +++ b/src/idp_test/check.py @@ -1,6 +1,7 @@ import inspect import sys from time import mktime +from rrtest import check from rrtest.check import Check @@ -597,13 +598,20 @@ class VerifySignedPart(Check): # ============================================================================= -def factory(cid): - for name, obj in inspect.getmembers(sys.modules[__name__]): - if inspect.isclass(obj): - try: - if obj.cid == cid: - return obj - except AttributeError: - pass +CLASS_CACHE = {} - return None + +def factory(cid, classes=CLASS_CACHE): + if len(classes) == 0: + check.factory(cid, classes) + for name, obj in inspect.getmembers(sys.modules[__name__]): + if inspect.isclass(obj): + try: + classes[obj.cid] = obj + except AttributeError: + pass + + if cid in classes: + return classes[cid] + else: + return None