Commits

Fredrik Lundh committed 0e94e2f

Sort with key function instead of cmp function.

Comments (0)

Files changed (1)

 
 #
 # --------------------------------------------------------------------
-# Helpers
+# ImageFile base class
 
-def _tilesort(t1, t2):
+def sort_tiles(tiles):
     # sort on offset
-    return cmp(t1[2], t2[2])
-
-#
-# --------------------------------------------------------------------
-# ImageFile base class
+    key = lambda x: x[2]
+    try:
+        tiles.sort(key=key)
+    except TypeError:
+        # Python 2.2, 2.3
+        tiles[:] = [(key(tile), tile) for tile in tiles]
+        tiles.sort()
+        tiles[:] = [tile[0] for tile in seq]
 
 ##
 # Base class for image file handlers.
 
         if not self.map:
 
-            # sort tiles in file order
-            self.tile.sort(_tilesort)
+            sort_tiles(self.tile)
 
             try:
                 # FIXME: This is a hack to handle TIFF's JpegTables tag.
     im.load()
     if not hasattr(im, "encoderconfig"):
         im.encoderconfig = ()
-    tile.sort(_tilesort)
+    sort_tiles(tile)
     # FIXME: make MAXBLOCK a configuration parameter
     bufsize = max(MAXBLOCK, im.size[0] * 4) # see RawEncode.c
     try: