Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inner = nodes.UseExternalMacro(
nodes.Value(use_macro), slots, False
)
macro_name = use_macro
else:
inner = nodes.UseExternalMacro(
nodes.Value(extend_macro), slots, True
)
macro_name = extend_macro
# While the macro executes, it should have access to the name it was
# called with as 'macroname'. Splitting on / mirrors zope.tal and is a
# concession to the path expression syntax.
macro_name = macro_name.rsplit('/', 1)[-1]
inner = nodes.Define(
[nodes.Assignment(["macroname"], Static(ast.Str(macro_name)), True)],
inner,
)
# -or- include tag
else:
content = nodes.Sequence(body)
# tal:content
try:
clause = ns[TAL, 'content']
except KeyError:
pass
else:
key, value = tal.parse_substitution(clause)
translate = ns.get((I18N, 'translate')) == ''
content = self._make_content_node(
value, content, key, translate,
names = [attr[0] for attr in prepared]
filtering = [[]]
for i, (name, text, quote, space, eq, expr) in enumerate(prepared):
implicit_i18n = (
name is not None and
name.lower() in self.implicit_i18n_attributes
)
char_escape = ('&', '<', '>', quote)
# Use a provided default text as the default marker
# (aliased to the name ``default``), otherwise use the
# program's default marker value.
if text is not None:
default_marker = ast.Str(s=text)
else:
default_marker = self.default_marker
msgid = I18N_ATTRIBUTES.get(name, missing)
# If (by heuristic) ``text`` contains one or more
# interpolation expressions, apply interpolation
# substitution to the text
if expr is None and text is not None and '${' in text:
expr = nodes.Substitution(text, char_escape)
translation = implicit_i18n and msgid is missing
value = nodes.Interpolation(expr, True, translation)
default_marker = self.default_marker
# If the expression is non-trivial, the attribute is
# dynamic (computed).
def subscript(name, value, ctx):
return ast.Subscript(
value=value,
slice=ast.Index(value=ast.Str(s=name)),
ctx=ctx,
)
def marker(name):
return ast.Str(s="__%s" % name)
if text is not None:
default = default_marker
else:
default = None
value = nodes.Substitution(
decode_htmlentities(expr),
char_escape,
default
)
# Otherwise, it's a static attribute. We don't include it
# here if there's one or more "computed" attributes
# (dynamic, from one or more dict values).
else:
value = ast.Str(s=text)
if msgid is missing and implicit_i18n:
msgid = text
if name is not None:
# If translation is required, wrap in a translation
# clause
if msgid is not missing:
value = nodes.Translate(msgid, value)
space = self._maybe_trim(space)
fs = filtering[-1]
attribute = nodes.Attribute(name, value, quote, eq, space, fs)
if not isinstance(value, ast.Str):
# Always define a ``default`` alias for non-static
# expressions.