changeset 2596:86295432620c

add missing files for 2595:5e7b45489430
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 03 Aug 2007 16:51:56 +0200
parents 5e7b45489430
children 8d3760a0daeb 13f0331f3a42
files MoinMoin/support/python_compatibility.py
diffstat 1 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/support/python_compatibility.py	Fri Aug 03 16:51:56 2007 +0200
@@ -0,0 +1,54 @@
+"""
+    MoinMoin - Support Package
+
+    Stuff for compatibility with older pytohn versions
+
+    @copyright: 2007 Heinrich Wendel <heinrich.wendel@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+"""
+This is a feature from python 2.4, needed for compatibility with python 2.3,
+although it may not be 100% compatible.
+"""
+try:
+    sorted = sorted
+except NameError:
+    def sorted(l, *args, **kw):
+        if type(l) == dict:
+            l = l.keys()
+        l = l[:]
+        # py2.3 is a bit different
+        if 'cmp' in kw:
+            args = (kw['cmp'], )
+
+        l.sort(*args)
+        return l
+
+"""
+This is a feature from python 2.4, needed for compatibility with python 2.3,
+although it may not be 100% compatible.
+"""
+try:
+    set = set
+except NameError:
+    from sets import Set as set
+
+"""
+This is a feature from python 2.5, needed for compatibility with python 2.3 and 2.4.
+"""
+try:
+    from functools import partial
+except (NameError, ImportError):
+    class partial(object):
+        def __init__(*args, **kw):
+            self = args[0]
+            self.fn, self.args, self.kw = (args[1], args[2:], kw)
+
+        def __call__(self, *args, **kw):
+            if kw and self.kw:
+                d = self.kw.copy()
+                d.update(kw)
+            else:
+                d = kw or self.kw
+            return self.fn(*(self.args + args), **d)