Python 3, Django 1.7+ compatilibity, some tests.
[fnpdjango.git] / fnpdjango / templatetags / macros.py
index b03e665..61b007d 100644 (file)
@@ -84,12 +84,12 @@ def do_macro(parser, token):
         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()
 
@@ -111,7 +111,7 @@ def do_loadmacros(parser, 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)
@@ -140,20 +140,20 @@ def do_usemacro(parser, token):
         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