/usr/share/pyshared/z3c/macro/tales.py is in python-z3c.macro 1.4.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ##############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Provider tales expression registrations
$Id: tales.py 123179 2011-10-29 21:00:50Z rogerineichen $
"""
__docformat__ = 'restructuredtext'
import re
import zope.component
import zope.interface
from zope.tales import expressions
from z3c.macro import interfaces
def get_macro_template(context, view, request, name):
return zope.component.getMultiAdapter(
(context, view, request), interface=interfaces.IMacroTemplate, name=name)
class MacroExpression(expressions.StringExpr):
"""Collect named IMacroTemplate via a TAL namespace called ``macro``."""
zope.interface.implements(interfaces.IMacroExpression)
def __call__(self, econtext):
name = super(MacroExpression, self).__call__(econtext)
context = econtext.vars['context']
request = econtext.vars['request']
view = econtext.vars['view']
return get_macro_template(context, view, request, name)
try:
# define chameleon ``macro`` expression
from chameleon.tales import StringExpr
from chameleon.astutil import Static
from chameleon.astutil import Symbol
from chameleon.codegen import template
class MacroGetter(object):
"""Collect named IMacroTemplate via a TAL namespace called ``macro``."""
def __call__(self, context, request, view, name):
return zope.component.getMultiAdapter(
(context, view, request), interface=interfaces.IMacroTemplate,
name=name)
class MacroExpr(StringExpr):
traverser = Static(
template("cls()", cls=Symbol(MacroGetter), mode="eval")
)
def __call__(self, target, engine):
assignment = super(MacroExpr, self).__call__(target, engine)
return assignment + \
template(
"target = traverse(context, request, view, target.strip())",
target=target,
traverse=self.traverser,
)
except ImportError:
pass
|