fixed deprecation warnings for tostring on array.array

This commit is contained in:
wiredfool 2013-05-23 10:33:27 -07:00
parent 94d9218dd0
commit 2322619372
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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)])