From 1dcdac522bdaa63142122c30426705bd4185e5e4 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 9 Dec 2007 22:53:46 +0100 Subject: [PATCH] improved python2.3 support --HG-- branch : trunk --- jinja/filters.py | 5 ++++- jinja/lexer.py | 2 +- jinja/loaders.py | 2 +- tests/test_syntax.py | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/jinja/filters.py b/jinja/filters.py index 7cd5e70..2902919 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -10,7 +10,10 @@ """ import re from random import choice -from operator import itemgetter +try: + from operator import itemgetter +except ImportError: + itemgetter = lambda a: lambda b: b[a] from urllib import urlencode, quote from jinja.utils import urlize, escape, reversed, sorted, groupby, \ get_attribute, pformat diff --git a/jinja/lexer.py b/jinja/lexer.py index 974bc39..ef0b537 100644 --- a/jinja/lexer.py +++ b/jinja/lexer.py @@ -45,7 +45,7 @@ string_re = re.compile(r"('([^'\\]*(?:\\.[^'\\]*)*)'" r'|"([^"\\]*(?:\\.[^"\\]*)*)")(?ms)') integer_re = re.compile(r'\d+') float_re = re.compile(r'\d+\.\d+') -regex_re = re.compile(r'@/([^/\\]*(?:\\.[^/\\]*)*)*/[a-z]*(?ms)') +regex_re = re.compile(r'\@/([^/\\]*(?:\\.[^/\\]*)*)*/[a-z]*(?ms)') # set of used keywords diff --git a/jinja/loaders.py b/jinja/loaders.py index b76df4f..e3dccde 100644 --- a/jinja/loaders.py +++ b/jinja/loaders.py @@ -150,7 +150,7 @@ class ControlledLoader(LoaderWrapper): try: new_method.__name__ = method.__name__ new_method.__doc__ = method.__doc__ - except AttributeError: + except: pass return new_method diff --git a/tests/test_syntax.py b/tests/test_syntax.py index abcd058..c31c0fb 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -28,7 +28,7 @@ GROUPING = '''{{ (true and false) or (false and true) and not false }}''' CONDEXPR = '''{{ 0 if true else 1 }}''' DJANGOATTR = '''{{ [1, 2, 3].0 }}''' FILTERPRIORITY = '''{{ "foo"|upper + "bar"|upper }}''' -REGEX = '''{{ @/\S+/.findall('foo bar baz') }}''' +REGEX = r'''{{ @/\S+/.findall('foo bar baz') }}''' TUPLETEMPLATES = [ '{{ () }}', '{{ (1, 2) }}', @@ -110,7 +110,7 @@ def test_inop(env): def test_literals(env): tmpl = env.from_string(LITERALS) - assert tmpl.render() == '[]|{}|()||set([])' + assert tmpl.render().lower() == '[]|{}|()||set([])' def test_bool(env): @@ -174,7 +174,7 @@ def test_tuple_expr(env): def test_trailing_comma(env): tmpl = env.from_string(TRAILINGCOMMA) - assert tmpl.render() == '(1, 2)|[1, 2]|{1: 2}|set([1, 2])' + assert tmpl.render().lower() == '(1, 2)|[1, 2]|{1: 2}|set([1, 2])' def test_extends_position(): -- 2.26.2