예제 #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
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()
예제 #3
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)
예제 #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
파일: request.py 프로젝트: tlotze/ophelia
 def tales_namespace(self, file_context={}):
     tales_ns = Namespace(
         innerslot=self.innerslot,
         macros=self.macros,
         )
     tales_ns.update(TALESEngine.getBaseNames())
     tales_ns.update(self.context)
     tales_ns.update(file_context)
     tales_ns.pop("__builtins__", None)
     return tales_ns
예제 #6
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
     })
예제 #7
0
파일: slotexpr.py 프로젝트: goschtl/zope
def registerSlotExprType():
    # Register the 'slot:' expression type.

    # Register with Products.PageTemplates.
    try:
        from Products.PageTemplates.Expressions import getEngine
    except ImportError:
        log.exception("Unable to register the slot expression type")
    else:
        engine = getEngine()
        if not engine.getTypes().has_key('slot'):
            engine.registerType('slot', SlotExpr)

    # Register with zope.tales.
    try:
        from zope.tales.engine import Engine
    except ImportError:
        log.exception("Unable to register the slot expression type")
    else:
        if not Engine.getTypes().has_key('slot'):
            Engine.registerType('slot', SlotExpr)
예제 #8
0
def registerSlotExprType():
    # Register the 'slot:' expression type.

    # Register with Products.PageTemplates.
    try:
        from Products.PageTemplates.Expressions import getEngine
    except ImportError:
        log.exception("Unable to register the slot expression type")
    else:
        engine = getEngine()
        if not engine.getTypes().has_key('slot'):
            engine.registerType('slot', SlotExpr)

    # Register with zope.tales.
    try:
        from zope.tales.engine import Engine
    except ImportError:
        log.exception("Unable to register the slot expression type")
    else:
        if not Engine.getTypes().has_key('slot'):
            Engine.registerType('slot', SlotExpr)
예제 #9
0
 def _getExprContext(self):
     """Dumb tal expression context, please override"""
     return Engine.getContext({
         'context': self.context,
         'user': self._get_user()
     })
예제 #10
0
파일: category.py 프로젝트: CGTIC/Plone_SP
 def write(self):
     if not self.write_expr:
         return None
     return Engine.compile(self.write_expr)
예제 #11
0
파일: category.py 프로젝트: CGTIC/Plone_SP
 def read(self):
     if not self.read_expr:
         return None
     return Engine.compile(self.read_expr)
예제 #12
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()})
예제 #13
0
 def write(self):
     if not self.write_expr:
         return None
     return Engine.compile(self.write_expr)
예제 #14
0
 def read(self):
     if not self.read_expr:
         return None
     return Engine.compile(self.read_expr)
예제 #15
0
파일: __init__.py 프로젝트: jean/zptlint
def registerTALESExpressionType(name, handler):
    Engine.registerType(name, handler)
예제 #16
0
파일: __init__.py 프로젝트: eea/zptlint
def registerTALESExpressionType(name, handler):
    Engine.registerType(name, handler)
예제 #17
0
def register(name, handler):
    """Register tales expression type."""
    Engine.registerType(name, handler)