"""
from django import template
-from django.template import resolve_variable, FilterExpression
-from django.template.loader import get_template, get_template_from_string, find_template_source
-from django.conf import settings
+from django.template.base import FilterExpression
+from django.template.loader import get_template
import re
register = template.Library()
args = token.split_contents()
tag_name, macro_name, args = args[0], args[1], args[2:]
except IndexError:
- raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]
+ raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0])
# TODO: check that 'args' are all simple strings ([a-zA-Z0-9_]+)
r_valid_arg_name = re.compile(r'^[a-zA-Z0-9_]+$')
for arg in args:
if not r_valid_arg_name.match(arg):
- raise template.TemplateSyntaxError, "Argument '%s' to macro '%s' contains illegal characters. Only alphanumeric characters and '_' are allowed." % (arg, macro_name)
+ raise template.TemplateSyntaxError("Argument '%s' to macro '%s' contains illegal characters. Only alphanumeric characters and '_' are allowed." % (arg, macro_name))
nodelist = parser.parse(('endmacro', ))
parser.delete_first_token()
try:
tag_name, filename = token.split_contents()
except IndexError:
- raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]
+ raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0])
if filename[0] in ('"', "'") and filename[-1] == filename[0]:
filename = filename[1:-1]
t = get_template(filename)
args = token.split_contents()
tag_name, macro_name, values = args[0], args[1], args[2:]
except IndexError:
- raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]
+ raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0])
try:
macro = parser._macros[macro_name]
except (AttributeError, KeyError):
- raise template.TemplateSyntaxError, "Macro '%s' is not defined" % macro_name
+ raise template.TemplateSyntaxError("Macro '%s' is not defined" % macro_name)
if (len(values) != len(macro.args)):
- raise template.TemplateSyntaxError, "Macro '%s' was declared with %d parameters and used with %d parameter" % (
+ raise template.TemplateSyntaxError("Macro '%s' was declared with %d parameters and used with %d parameter" % (
macro_name,
len(macro.args),
- len(values))
+ len(values)))
filter_expressions = []
for val in values:
if (val[0] == "'" or val[0] == '"') and (val[0] != val[-1]):
- raise template.TemplateSyntaxError, "Non-terminated string argument: %s" % val[1:]
+ raise template.TemplateSyntaxError("Non-terminated string argument: %s" % val[1:])
filter_expressions.append(FilterExpression(val, parser))
return UseMacroNode(macro, filter_expressions)
\ No newline at end of file