From d45cb60c0ff04aea65fb85108434ac291d290375 Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Thu, 17 Sep 1998 10:12:20 +0000 Subject: [PATCH] Improved algorithm for calling objects. --- pDocumentTemplate.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/pDocumentTemplate.py b/pDocumentTemplate.py index 461ece6..e5abc35 100644 --- a/pDocumentTemplate.py +++ b/pDocumentTemplate.py @@ -54,8 +54,8 @@ __doc__='''Python implementations of document template some features -$Id: pDocumentTemplate.py,v 1.19 1998/09/16 20:19:12 jim Exp $''' -__version__='$Revision: 1.19 $'[11:-2] +$Id: pDocumentTemplate.py,v 1.20 1998/09/17 10:12:20 jim Exp $''' +__version__='$Revision: 1.20 $'[11:-2] import string, sys, types from string import join @@ -64,7 +64,7 @@ TupleType=type(()) isFunctionType={} for name in ['BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', - 'FunctionType', 'LambdaType', 'MethodType']: + 'FunctionType', 'LambdaType', 'MethodType', 'UnboundMethodType']: try: isFunctionType[getattr(types,name)]=1 except: pass @@ -76,6 +76,14 @@ isFunctionType=isFunctionType.has_key +isSimpleType={} +for n in dir(types): + if (n[-4:]=='Type' and n != 'InstanceType' and + not isFunctionType(getattr(types, n))): + isSimpleType[getattr(types, n)]=1 + +isSimpleType=isSimpleType.has_key + class InstanceDict: validate=None @@ -151,33 +159,24 @@ def __init__(self): except: pass def __getitem__(self,key,call=1, - simple={ - type(''): 1, type(0): 1, type(0.0): 1, - type([]): 1, type(()): 1, - }.has_key): + simple=isSimpleType, + isFunctionType=isFunctionType, + ): v=self.dicts[key] if call and not simple(type(v)): - if hasattr(v,'isDocTemp') and v.isDocTemp: - v=v(None, self) + if hasattr(v,'isDocTemp') and v.isDocTemp: return v(None, self) + elif isFunctionType(type(v)): return v() else: try: return v() except AttributeError, ev: try: tb=sys.exc_traceback if hasattr(sys, 'exc_info'): tb=sys.exc_info()[2] - if isFunctionType(type(v)): - raise AttributeError, ev, tb if hasattr(v,'__call__'): raise AttributeError, ev, tb finally: tb=None - except TypeError, ev: - try: - tb=sys.exc_traceback - if hasattr(sys, 'exc_info'): tb=sys.exc_info()[2] - if isFunctionType(type(v)): - raise AttributeError, ev, tb - finally: tb=None + except TypeError: pass return v