Skip to content

Commit

Permalink
Improved algorithm for calling objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Sep 17, 1998
1 parent 5dc174e commit d45cb60
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions pDocumentTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d45cb60

Please sign in to comment.