Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: third_party/jinja2/tests.py

Issue 2316103002: binding: Updates Jinja2 from 2.7.1 to 2.8. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/jinja2/sandbox.py ('k') | third_party/jinja2/utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
}
« no previous file with comments | « third_party/jinja2/sandbox.py ('k') | third_party/jinja2/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698