From 232261937282f9101daa3606391c0ce764e5d79a Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 23 May 2013 10:33:27 -0700 Subject: [PATCH] fixed deprecation warnings for tostring on array.array --- PIL/ImagePalette.py | 6 +++++- Tests/test_imagepath.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/PIL/ImagePalette.py b/PIL/ImagePalette.py index 8356bb107..2fa051407 100644 --- a/PIL/ImagePalette.py +++ b/PIL/ImagePalette.py @@ -47,7 +47,11 @@ class ImagePalette: raise ValueError("palette contains raw palette data") if isinstance(self.palette, bytes): return self.palette - return array.array("B", self.palette).tostring() + arr = array.array("B", self.palette) + if hasattr(arr, 'tobytes'): + #py3k has a tobytes, tostring is deprecated. + return arr.tobytes() + return arr.tostring() # Declare tostring as an alias for tobytes tostring = tobytes diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index beadff10e..9e9e63c3a 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -45,5 +45,10 @@ def test_path(): assert_equal(list(p), [(0.0, 1.0)]) p = ImagePath.Path(array.array("f", [0, 1])) assert_equal(list(p), [(0.0, 1.0)]) - p = ImagePath.Path(array.array("f", [0, 1]).tostring()) + + arr = array.array("f", [0, 1]) + if hasattr(arr, 'tobytes'): + p = ImagePath.Path(arr.tobytes()) + else: + p = ImagePath.Path(arr.tostring()) assert_equal(list(p), [(0.0, 1.0)])