Esempio n. 1
0
class TileExpression(StringExpr):
    render_tile = Static(
        template("cls()", cls=Symbol(TileProviderTraverser), mode='eval'))

    def __call__(self, target, engine):
        assignment = super(TileExpression, self).__call__(target, engine)
        return assignment + template(
            'target = render_tile(context, request, target.strip())',
            target=target,
            render_tile=self.render_tile)
Esempio n. 2
0
class TrustedPathExpr(PathExpr):
    traverser = Static(
        template("cls()",
                 cls=Symbol(TrustedBoboAwareZopeTraverse),
                 mode="eval"))
Esempio n. 3
0
class PathExpr(expressions.PathExpr):
    exceptions = zope2_exceptions

    traverser = Static(
        template("cls()", cls=Symbol(BoboAwareZopeTraverse), mode="eval"))
Esempio n. 4
0
def static(obj):
    return Static(template("obj", obj=Symbol(obj), mode="eval"))
    The compilation result is cached in ``_zt_expr_registry``.
    """
    if engine is None:
        engine = econtext["__zt_engine__"]
    key = id(engine), type, expression
    # cache lookup does not need to be protected by locking
    #  (but we could potentially prevent unnecessary computations)
    expr = _zt_expr_registry.get(key)
    if expr is None:
        expr = engine.types[type](type, expression, engine)
        _zt_expr_registry[key] = expr
    return expr


_compile_zt_expr_node = Static(Symbol(_compile_zt_expr))


class _C2ZContextWrapper(Context):
    """Behaves like "zope" context with vars from "chameleon" context."""
    def __init__(self, c_context):
        self.__c_context = c_context
        self.__z_context = c_context["__zt_context__"]

    # delegate to ``__c_context``
    @property
    def vars(self):
        return self

    def __getitem__(self, key):
        try:
Esempio n. 6
0
    The compilation result is cached in ``_zt_expr_registry``.
    """
    if engine is None:
        engine = econtext["__zt_engine__"]
    key = id(engine), type, expression
    # cache lookup does not need to be protected by locking
    #  (but we could potentially prevent unnecessary computations)
    expr = _zt_expr_registry.get(key)
    if expr is None:
        expr = engine.types[type](type, expression, engine)
        _zt_expr_registry[key] = expr
    return expr


_compile_zt_expr_node = Static(Symbol(_compile_zt_expr))

# map context class to context wrapper class
_context_class_registry = {}


def _with_vars_from_chameleon(context):
    """prepare *context* to get its ``vars`` from ``chameleon``."""
    cc = context.__class__
    wc = _context_class_registry.get(cc)
    if wc is None:

        class ContextWrapper(_C2ZContextWrapperBase, cc):
            pass

        wc = _context_class_registry[cc] = ContextWrapper