Index: third_party/jinja2/tests.py |
diff --git a/third_party/jinja2/tests.py b/third_party/jinja2/tests.py |
index 48a3e06182973bf863a8bf979c030ef9b206a403..bb32349df0b7e67d8fedf388dad3f22cd1bd0ae1 100644 |
--- a/third_party/jinja2/tests.py |
+++ b/third_party/jinja2/tests.py |
@@ -9,9 +9,10 @@ |
:license: BSD, see LICENSE for more details. |
""" |
import re |
+from collections import Mapping |
from jinja2.runtime import Undefined |
-from jinja2._compat import text_type, string_types, mapping_types |
- |
+from jinja2._compat import text_type, string_types, integer_types |
+import decimal |
number_re = re.compile(r'^-?\d+(\.\d+)?$') |
regex_type = type(number_re) |
@@ -82,12 +83,12 @@ def test_mapping(value): |
.. versionadded:: 2.6 |
""" |
- return isinstance(value, mapping_types) |
+ return isinstance(value, Mapping) |
def test_number(value): |
"""Return true if the variable is a number.""" |
- return isinstance(value, (int, float, complex)) |
+ return isinstance(value, integer_types + (float, complex, decimal.Decimal)) |
def test_sequence(value): |
@@ -102,6 +103,28 @@ def test_sequence(value): |
return True |
+def test_equalto(value, other): |
+ """Check if an object has the same value as another object: |
+ |
+ .. sourcecode:: jinja |
+ |
+ {% if foo.expression is equalto 42 %} |
+ the foo attribute evaluates to the constant 42 |
+ {% endif %} |
+ |
+ This appears to be a useless test as it does exactly the same as the |
+ ``==`` operator, but it can be useful when used together with the |
+ `selectattr` function: |
+ |
+ .. sourcecode:: jinja |
+ |
+ {{ users|selectattr("email", "equalto", "foo@bar.invalid") }} |
+ |
+ .. versionadded:: 2.8 |
+ """ |
+ return value == other |
+ |
+ |
def test_sameas(value, other): |
"""Check if an object points to the same memory address than another |
object: |
@@ -145,5 +168,6 @@ TESTS = { |
'iterable': test_iterable, |
'callable': test_callable, |
'sameas': test_sameas, |
+ 'equalto': test_equalto, |
'escaped': test_escaped |
} |