[Checkins] SVN: five.pt/trunk/ Re-added ``same_type`` function to the default context.
Malthe Borch
mborch at gmail.com
Fri Jul 15 02:12:59 EDT 2011
Log message for revision 122251:
Re-added ``same_type`` function to the default context.
Changed:
U five.pt/trunk/CHANGES.txt
U five.pt/trunk/src/five/pt/patches.py
-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt 2011-07-14 20:28:36 UTC (rev 122250)
+++ five.pt/trunk/CHANGES.txt 2011-07-15 06:12:58 UTC (rev 122251)
@@ -1,6 +1,11 @@
Changelog
=========
+In next release ...
+
+- Added the ``same_type`` function to the provided context.
+ [malthe]
+
2.1 (2011-07-14)
~~~~~~~~~~~~~~~~
Modified: five.pt/trunk/src/five/pt/patches.py
===================================================================
--- five.pt/trunk/src/five/pt/patches.py 2011-07-14 20:28:36 UTC (rev 122250)
+++ five.pt/trunk/src/five/pt/patches.py 2011-07-15 06:12:58 UTC (rev 122251)
@@ -97,6 +97,17 @@
self._v_errors = ()
+def same_type(arg1, *args):
+ """Compares the class or type of two or more objects. Copied from
+ RestrictedPython.
+ """
+ t = getattr(arg1, '__class__', type(arg1))
+ for arg in args:
+ if getattr(arg, '__class__', type(arg)) is not t:
+ return False
+ return True
+
+
def test(condition, a, b):
if condition:
return a
@@ -133,6 +144,7 @@
# the turnary operator in place of calls to the test
# function.
context.setdefault('test', test)
+ context.setdefault('same_type', same_type)
result = self.template.render(**context)
More information about the checkins
mailing list