[Image-SIG] Python 2.1 issues

Fredrik Lundh fredrik@pythonware.com
Wed, 18 Apr 2001 11:42:09 +0200


PIL 1.1.1 works well under 2.1 final, but there are some old code
in there that results in warnings under 2.1.

one problem is that PIL 1.1.1 uses the old "regex" module in a few places.
this module is deprecated in 2.1, and will be phased out in future versions.

in 2.1, the easiest workaround is to filter out that group of warnings:

import warnings
warnings.filterwarnings(action = 'ignore',
                        message='.*regex module is deprecated',
                        category=DeprecationWarning)

(from http://www.amk.ca/python/2.1/index.html)

the other warning is a real bug under 2.1 and earlier: the ImagePalette.random
function assumed that Python already had nested scopes (!).  here's a patch:

--- Imaging-1.1.1/PIL/ImagePalette.py   Wed Jun  7 15:17:04 2000
+++ Imaging-1.2a3/PIL/ImagePalette.py   Wed Apr 18 10:06:09 2001
@@ -62,8 +63,9 @@
     return ImagePalette(mode, palette * len(mode))

 def random(mode = "RGB"):
-    from whrandom import randint
-    palette = map(lambda a: randint(0, 255), [0]*256*len(mode))
+    from random import randint
+    palette = map(lambda a, randint=randint:
+                  randint(0, 255), [0]*256*len(mode))
     return ImagePalette(mode, palette)

 def wedge(mode = "RGB"):

--- end ---

we plan to release a maintenance release some time next week (should
have been this week, but paying customers got in the way ;-)

Cheers /F

PS. for pil plus customers who missed our announcement, another PIL 1.2
prerelease was released yesterday.  see our site for more info.