Skip to content

Commit

Permalink
Imported from tarballs/SimpleTAL-3.9.tar.gz.
Browse files Browse the repository at this point in the history
  • Loading branch information
T Ar Creator authored and g2p committed Dec 11, 2011
1 parent cc86f43 commit 3ed165d
Show file tree
Hide file tree
Showing 17 changed files with 437 additions and 261 deletions.
28 changes: 27 additions & 1 deletion Changes.txt
@@ -1,6 +1,32 @@
simpleTAL / simpleTALES (Version 3.8)
simpleTAL / simpleTALES (Version 3.9)
-------------------------------------

Version 3.9
-----------
This is release is focused on improving performance. Compared to version 3.8
the performance of expanding templates is ~45-70% faster. The performance of parsing
templates is unchanged.

WARNING: IF you rely on the internal workings of SimpleTALES in your application then
there will be changes that are required to make use of this version of SimpleTAL. The API
for SimpleTAL is however unchanged.

New features:
- Introduced simpleTALUtils.FastStringOutput which can be used to capture the
output of SimpleTAL in a faster manner than StringIO.
- Introduced simpleTALES.CachedFuncResult which can be used to wrap functions in
the Context, and which cache's the result of the function call to ensure that
the function is only called once during template expansion.
- TALES no longer wraps all results in ContextVariable instances when returning
values to TAL.
- Changed copy.copy to {}.copy for performance improvement.
- Removed logging.debug() calls from performance critical paths.
- Replaced DefaultVariable class with simpleTALES.DEFAULTVALUE
- Replaced NothingVariable class with None
- Removed NoCallVariable
- Removed isDefault, isNothing, isSequence, isCallable, and isTrue from ContextVariable.


Version 3.8
-----------
New features:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
SimpleTAL 3.8
SimpleTAL 3.9
--------------------------------------------------------------------
Copyright (c) 2004 Colin Stewart (http://www.owlfish.com/)
All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: SimpleTAL
Version: 3.8
Version: 3.9
Summary: SimpleTAL is a stand alone Python implementation of the TAL, TALES and METAL specifications used in Zope to power HTML and XML templates.
Home-page: http://www.owlfish.com/software/simpleTAL/index.html
Author: Colin Stewart
Expand Down
2 changes: 1 addition & 1 deletion README.txt
@@ -1,4 +1,4 @@
simpleTAL / simpleTALES (Version 3.8)
simpleTAL / simpleTALES (Version 3.9)
-------------------------------------
This is an implementation of the TAL and TALES specifications
see (http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixC.stx)
Expand Down
2 changes: 1 addition & 1 deletion lib/simpletal/__init__.py
@@ -1 +1 @@
__version__ = "3.8"
__version__ = "3.9"
53 changes: 34 additions & 19 deletions lib/simpletal/simpleTAL.py
Expand Up @@ -210,9 +210,9 @@ def cmdDefine (self, command, args):
if (not foundLocals):
foundLocals = 1
self.context.pushLocals ()
self.context.setLocal (varName, result.value())
self.context.setLocal (varName, result)
else:
self.context.addGlobal (varName, result.value())
self.context.addGlobal (varName, result)
self.localVarsDefined = foundLocals
self.programCounter += 1

Expand All @@ -222,7 +222,19 @@ def cmdCondition (self, command, args):
by it.
"""
result = self.context.evaluate (args[0], self.originalAttributes)
if (result is None or not result.isTrue()):
#~ if (result is None or (not result)):
conditionFalse = 0
if (result is None):
conditionFalse = 1
else:
if (not result): conditionFalse = 1
try:
temp = len (result)
if (temp == 0): conditionFalse = 1
except:
# Result is not a sequence.
pass
if (conditionFalse):
# Nothing to output - evaluated to false.
self.outputTag = 0
self.tagContent = None
Expand All @@ -237,7 +249,8 @@ def cmdRepeat (self, command, args):
if (self.repeatVariable is not None):
# We are already part way through a repeat
# Restore any attributes that might have been changed.
self.currentAttributes = copy.copy (self.repeatAttributesCopy)
if (self.currentAttributes != self.repeatAttributesCopy):
self.currentAttributes = copy.copy (self.repeatAttributesCopy)
self.outputTag = 1
self.tagContent = None
self.movePCForward = None
Expand All @@ -261,18 +274,22 @@ def cmdRepeat (self, command, args):

# The first time through this command
result = self.context.evaluate (args[1], self.originalAttributes)
if (result is not None and result.isDefault()):
if (result is not None and result == simpleTALES.DEFAULTVALUE):
# Leave everything un-touched.
self.programCounter += 1
return
if (result is None or result.isNothing() or not result.isSequence()):
try:
isSequence = len (result)
except:
isSequence = 0
if (result is None or not isSequence):
# Delete the tags and their contents
self.outputTag = 0
self.programCounter = self.symbolTable [args[2]]
return

# We really do want to repeat - so lets do it
self.repeatSequence = result.value()
self.repeatSequence = result
self.movePCBack = self.programCounter
self.repeatVariable = simpleTALES.RepeatVariable (self.repeatSequence)
self.context.addRepeat (args[0], self.repeatVariable, self.repeatSequence[self.repeatIndex])
Expand All @@ -285,19 +302,19 @@ def cmdContent (self, command, args):
Expands content
"""
result = self.context.evaluate (args[2], self.originalAttributes)
if (result is None or result.isNothing()):
if (result is None):
if (args[0]):
# Only output tags if this is a content not a replace
self.outputTag = 0
# Output none of our content or the existing content, but potentially the tags
self.movePCForward = self.symbolTable [args[3]]
self.programCounter += 1
return
elif (not result.isDefault()):
elif (not result == simpleTALES.DEFAULTVALUE):
# We have content, so let's suppress the natural content and output this!
if (args[0]):
self.outputTag = 0
self.tagContent = (args[1], result.value())
self.tagContent = (args[1], result)
self.movePCForward = self.symbolTable [args[3]]
self.programCounter += 1
return
Expand All @@ -313,14 +330,13 @@ def cmdAttributes (self, command, args):
attsToRemove = {}
newAtts = []
for attName, attExpr in args:
result = self.context.evaluate (attExpr, self.originalAttributes)
if (result is None or result.isNothing()):
resultVal = self.context.evaluate (attExpr, self.originalAttributes)
if (resultVal is None):
# Remove this attribute from the current attributes
attsToRemove [attName]=1
elif (not result.isDefault()):
elif (not resultVal == simpleTALES.DEFAULTVALUE):
# We have a value - let's use it!
attsToRemove [attName]=1
resultVal = result.value()
if (type (resultVal) == type (u"")):
if (not self.escapeAttributes):
# XML will get escaped automatically, HTML will not...
Expand Down Expand Up @@ -354,7 +370,7 @@ def cmdOmitTag (self, command, args):
Conditionally turn off tag output
"""
result = self.context.evaluate (args, self.originalAttributes)
if (result is not None and result.isTrue()):
if (result is not None and result):
# Turn tag output off
self.outputTag = 0
self.programCounter += 1
Expand Down Expand Up @@ -458,16 +474,15 @@ def cmdUseMacro (self, command, args):
Evaluates the expression, if it resolves to a SubTemplate it then places
the slotParams into currentSlots and then jumps to the end tag
"""
result = self.context.evaluate (args[0], self.originalAttributes)
if (result is None or result.isNothing()):
value = self.context.evaluate (args[0], self.originalAttributes)
if (value is None):
# Don't output anything
self.outputTag = 0
# Output none of our content or the existing content
self.movePCForward = self.symbolTable [args[2]]
self.programCounter += 1
return
value = result.value()
if (not result.isDefault() and isinstance (value, SubTemplate)):
if (not value == simpleTALES.DEFAULTVALUE and isinstance (value, SubTemplate)):
# We have a macro, so let's use it
self.outputTag = 0
self.slotParameters = args[1]
Expand Down

0 comments on commit 3ed165d

Please sign in to comment.