I have a small backwards compatibility patch that makes webob work
happily on Python 2.3.  It doesn't intrude into any of the code, just
adds an implementation of the 2.5 sorted builtin.  Ian, would you like
to apply this, please?

        <b
Index: webob/acceptparse.py
===================================================================
--- webob/acceptparse.py	(revision 7327)
+++ webob/acceptparse.py	(working copy)
@@ -10,6 +10,10 @@
 """
 
 import re
+try:
+    sorted
+except NameError:
+    from webob.compat import sorted
 
 part_re = re.compile(
     r',\s*([^\s;,\n]+)(?:[^,]*?;\s*q=([0-9.]*))?')
Index: webob/__init__.py
===================================================================
--- webob/__init__.py	(revision 7327)
+++ webob/__init__.py	(working copy)
@@ -20,6 +20,10 @@
 from webob.cachecontrol import CacheControl, serialize_cache_control
 from webob.acceptparse import Accept, MIMEAccept, NilAccept, MIMENilAccept, NoAccept
 from webob.byterange import Range, ContentRange
+try:
+    sorted
+except NameError:
+    from webob.compat import sorted
 
 _CHARSET_RE = re.compile(r';\s*charset=([^;]*)', re.I)
 _SCHEME_RE = re.compile(r'^[a-z]+:', re.I)
Index: webob/compat.py
===================================================================
--- webob/compat.py	(revision 0)
+++ webob/compat.py	(revision 0)
@@ -0,0 +1,23 @@
+try:
+    # This will succeed on Python 2.4, and fail on Python 2.3.
+
+    [].sort(key=lambda: None)
+
+    def sorted(iterable, cmp=None, key=None, reverse=False):
+        l = list(iterable)
+        l.sort(cmp=cmp, key=key, reverse=reverse)
+        return l
+
+except TypeError:
+    # Implementation for Python 2.3.
+    
+    def sorted(iterable, key=None, reverse=False):
+        l = list(iterable)
+        if key:
+            l = [(key(i), i) for i in l]
+        l.sort()
+        if key:
+            l = [i[1] for i in l]
+        if reverse:
+            l.reverse()
+        return l
Index: webob/cachecontrol.py
===================================================================
--- webob/cachecontrol.py	(revision 7327)
+++ webob/cachecontrol.py	(working copy)
@@ -4,6 +4,10 @@
 
 import re
 from webob.updatedict import UpdateDict
+try:
+    sorted
+except NameError:
+    from webob.compat import sorted
 
 token_re = re.compile(
     r'([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?')
_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to