[pod] Added the possibility to define several variables, in 'with' statements, separated by ';'.
This commit is contained in:
parent
da1f2699cd
commit
d5296ba321
4 changed files with 89 additions and 53 deletions
|
@ -3,9 +3,7 @@
|
|||
Python and XML.'''
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
from UserDict import UserDict
|
||||
from px_parser import PxParser, PxEnvironment
|
||||
from appy.pod.renderer import BAD_CONTEXT
|
||||
|
||||
# Exception class --------------------------------------------------------------
|
||||
class PxError(Exception): pass
|
||||
|
@ -37,16 +35,8 @@ class Px:
|
|||
self.parser.parse(self.content)
|
||||
|
||||
def __call__(self, context):
|
||||
# Get the context in a standardized form.
|
||||
evalContext = {}
|
||||
if hasattr(context, '__dict__'):
|
||||
evalContext.update(context.__dict__)
|
||||
elif isinstance(context, dict) or isinstance(context, UserDict):
|
||||
evalContext.update(context)
|
||||
else:
|
||||
raise PxError(BAD_CONTEXT)
|
||||
# Store the context on the PX environment
|
||||
self.parser.env.context = evalContext
|
||||
# p_context must be a dict. Store it in the PX environment.
|
||||
self.parser.env.context = context
|
||||
# Render the PX result and return it
|
||||
env = self.parser.env
|
||||
env.ast.evaluate()
|
||||
|
|
|
@ -56,6 +56,8 @@ class PxEnvironment(XmlEnvironment):
|
|||
class PxParser(XmlParser):
|
||||
'''PX parser that is specific for parsing PX data.'''
|
||||
|
||||
pxAttributes = ('var', 'for', 'if')
|
||||
|
||||
def __init__(self, env, caller=None):
|
||||
XmlParser.__init__(self, env, caller)
|
||||
|
||||
|
@ -63,14 +65,14 @@ class PxParser(XmlParser):
|
|||
'''A start p_elem with p_attrs is encountered in the PX.'''
|
||||
e = self.env
|
||||
self.currentElem = elem
|
||||
if attrs.has_key('for'):
|
||||
# Dump the element in a new sub-buffer
|
||||
e.addSubBuffer()
|
||||
# Create the action for this buffer
|
||||
e.currentBuffer.createPxAction(elem, 'for', attrs['for'])
|
||||
elif attrs.has_key('if'):
|
||||
e.addSubBuffer()
|
||||
e.currentBuffer.createPxAction(elem, 'if', attrs['if'])
|
||||
# See if we have a PX attribute among p_attrs.
|
||||
for name in self.pxAttributes:
|
||||
if attrs.has_key(name):
|
||||
# Dump the element in a new sub-buffer
|
||||
e.addSubBuffer()
|
||||
# Create the action for this buffer
|
||||
e.currentBuffer.createPxAction(elem, name, attrs[name])
|
||||
break
|
||||
if e.isActionElem(elem):
|
||||
# Add a temp element in the buffer (that will be unreferenced
|
||||
# later). This way, when encountering the corresponding end element,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue