コード例 #1
0
def talEval(expression, context, extra=None):
    """
    Perform a TAL eval on the expression.
    """
    # First, account for the possibility that it is merely TALES; if there are
    # no <tal> in it at all (nor the ${python:} you can do with this function),
    # just send it to talesEval
    isTales = '<tal' not in expression and '${python:' not in expression
    if isTales:
        return talesEvalStr(expression, context, extra)

    # Next, as a convenience, replace all ${} blocks that aren't inside a <tal>
    # with <tal:block content="..."/> equivalent
    chunks = TAG.split(expression)
    modified = []
    for chunk in chunks:
        if chunk.startswith('<tal'):
            modified.append(chunk)
        else:
            modified.append(TPLBLOCK.sub(_chunk_repl, chunk))
    expression = ''.join(modified)

    # Finally, compile the expression and apply context
    gen = TALGenerator(Engine, xml=0)
    parser = HTMLTALParser(gen)
    parser.parseString(expression)
    program, macros = parser.getCode()
    output = cStringIO.StringIO()
    context = Engine.getContext(context)
    TALInterpreter(program, macros, context, output, tal=True)()
    return output.getvalue()
コード例 #2
0
ファイル: request.py プロジェクト: tlotze/ophelia
    def build_headers(self):
        self.compiled_headers = {}
        tales_context = TALESEngine.getContext(self.tales_namespace())

        for name, expression in self.response_headers.iteritems():
            __traceback_info__ = "Header %s: %s" % (name, expression)
            self.compiled_headers[name] = tales_context.evaluate(expression)
コード例 #3
0
def talEval(expression, context, extra=None):
    """
    Perform a TAL eval on the expression.
    """
    # First, account for the possibility that it is merely TALES; if there are
    # no <tal> in it at all (nor the ${python:} you can do with this function),
    # just send it to talesEval
    isTales = '<tal' not in expression and '${python:' not in expression
    if isTales:
        return talesEvalStr(expression, context, extra)

    # Next, as a convenience, replace all ${} blocks that aren't inside a <tal>
    # with <tal:block content="..."/> equivalent
    chunks = TAG.split(expression)
    modified = []
    for chunk in chunks:
        if chunk.startswith('<tal'):
            modified.append(chunk)
        else:
            modified.append(TPLBLOCK.sub(_chunk_repl, chunk))
    expression = ''.join(modified)

    # Finally, compile the expression and apply context
    gen = TALGenerator(Engine, xml=0)
    parser = HTMLTALParser(gen)
    parser.parseString(expression)
    program, macros = parser.getCode()
    output = cStringIO.StringIO()
    context = Engine.getContext(context)
    TALInterpreter(program, macros, context, output, tal=True)()
    return output.getvalue()
コード例 #4
0
ファイル: category.py プロジェクト: CGTIC/Plone_SP
 def _getExprContext(self):
     """A plone specific expression context"""
     context = self.context
     portal = getToolByName(context, 'portal_url').getPortalObject()
     pm = getToolByName(context, 'portal_membership')
     return Engine.getContext({'context': context,
                               'user': self._get_user(),
                               'portal': portal,
                               'checkPermission': pm.checkPermission})
コード例 #5
0
 def _getExprContext(self):
     """A plone specific expression context"""
     context = self.context
     portal = getToolByName(context, 'portal_url').getPortalObject()
     pm = getToolByName(context, 'portal_membership')
     return Engine.getContext({
         'context': context,
         'user': self._get_user(),
         'portal': portal,
         'checkPermission': pm.checkPermission
     })
コード例 #6
0
ファイル: category.py プロジェクト: CGTIC/Plone_SP
 def _getExprContext(self):
     """Dumb tal expression context, please override"""
     return Engine.getContext({'context': self.context,
                               'user': self._get_user()})
コード例 #7
0
 def _getExprContext(self):
     """Dumb tal expression context, please override"""
     return Engine.getContext({
         'context': self.context,
         'user': self._get_user()
     })