Commit 0be860ae authored by Jim Fulton's avatar Jim Fulton

Optimized TemplateDict __getitem__ by removing some exception usage

and by adding test to short circuit rendering of common simple objects
like strings and numbers.
parent b2316f74
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
__doc__='''Python implementations of document template some features __doc__='''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.12 1998/05/13 20:36:02 jim Exp $''' $Id: pDocumentTemplate.py,v 1.13 1998/05/14 16:27:49 jim Exp $'''
__version__='$Revision: 1.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
import regex, string, sys import regex, string, sys
from string import join from string import join
...@@ -154,15 +154,18 @@ class TemplateDict: ...@@ -154,15 +154,18 @@ class TemplateDict:
try: self.keys=m.keys try: self.keys=m.keys
except: pass except: pass
def __getitem__(self,key,call=1): def __getitem__(self,key,call=1,
simple={
type(''): 1, type(0): 1, type(0.0): 1,
type([]): 1, type(()): 1,
}.has_key):
v=self.dicts[key] v=self.dicts[key]
if call: if call and not simple(type(v)):
try: isDocTemp=v.isDocTemp if hasattr(v,'isDocTemp') and v.isDocTemp:
except: isDocTemp=None v=v(None, self)
if isDocTemp: v=v(None,self) else:
else: try: v=v()
try: v=v()
except (AttributeError,TypeError): pass except (AttributeError,TypeError): pass
return v return v
...@@ -227,6 +230,11 @@ def render_blocks(blocks, md): ...@@ -227,6 +230,11 @@ def render_blocks(blocks, md):
############################################################################## ##############################################################################
# #
# $Log: pDocumentTemplate.py,v $ # $Log: pDocumentTemplate.py,v $
# Revision 1.13 1998/05/14 16:27:49 jim
# Optimized TemplateDict __getitem__ by removing some exception usage
# and by adding test to short circuit rendering of common simple objects
# like strings and numbers.
#
# Revision 1.12 1998/05/13 20:36:02 jim # Revision 1.12 1998/05/13 20:36:02 jim
# Slightly simpler solution to exception dilema. # Slightly simpler solution to exception dilema.
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment