Python3 fixes

This commit is contained in:
wiredfool 2013-10-07 23:30:55 -07:00
parent 0bded743f5
commit a91283061e
2 changed files with 10 additions and 9 deletions

View File

@ -46,6 +46,7 @@ __version__ = "1.3.5"
from PIL import Image, ImageFile from PIL import Image, ImageFile
from PIL import ImagePalette from PIL import ImagePalette
from PIL import _binary from PIL import _binary
from PIL._util import isStringType
import warnings import warnings
import array, sys import array, sys
@ -53,6 +54,8 @@ import collections
import itertools import itertools
import os import os
II = b"II" # little-endian (intel-style) II = b"II" # little-endian (intel-style)
MM = b"MM" # big-endian (motorola-style) MM = b"MM" # big-endian (motorola-style)
@ -494,7 +497,7 @@ class ImageFileDirectory(collections.MutableMapping):
elif typ == 7: elif typ == 7:
# untyped data # untyped data
data = value = b"".join(value) data = value = b"".join(value)
elif type(value[0]) in (str, unicode): elif isStringType(value[0]):
# string data # string data
if isinstance(value, tuple): if isinstance(value, tuple):
value = value[-1] value = value[-1]
@ -984,7 +987,8 @@ def _save(im, fp, filename):
info = im.encoderinfo.get("tiffinfo",{}) info = im.encoderinfo.get("tiffinfo",{})
if Image.DEBUG: if Image.DEBUG:
print ("Tiffinfo Keys: %s"% info.keys) print ("Tiffinfo Keys: %s"% info.keys)
for key in info.keys(): keys = list(info.keys())
for key in keys:
ifd[key] = info.get(key) ifd[key] = info.get(key)
try: try:
ifd.tagtype[key] = info.tagtype[key] ifd.tagtype[key] = info.tagtype[key]
@ -1093,14 +1097,11 @@ def _save(im, fp, filename):
# int or similar # int or similar
atts[k] = v[0] atts[k] = v[0]
continue continue
if type(v) == str: if isStringType(v):
atts[k] = v
continue
if type(v) == unicode:
atts[k] = v.encode('ascii', errors='ignore') atts[k] = v.encode('ascii', errors='ignore')
continue continue
except Exception, msg: except (Exception, msg):
# if we don't have an ifd here, just punt. # if we don't have an ifd here, just punt.
if Image.DEBUG: if Image.DEBUG:
print (msg) print (msg)

View File

@ -35,7 +35,7 @@ def test_read_metadata():
'ImageLength': (128,), 'ImageLength': (128,),
'Compression': (4,), 'Compression': (4,),
'FillOrder': (1,), 'FillOrder': (1,),
'DocumentName': u'lena.g4.tif', 'DocumentName': 'lena.g4.tif',
'RowsPerStrip': (128,), 'RowsPerStrip': (128,),
'ResolutionUnit': (1,), 'ResolutionUnit': (1,),
'PhotometricInterpretation': (0,), 'PhotometricInterpretation': (0,),
@ -46,7 +46,7 @@ def test_read_metadata():
'StripByteCounts': (1796,), 'StripByteCounts': (1796,),
'SamplesPerPixel': (1,), 'SamplesPerPixel': (1,),
'StripOffsets': (8,), 'StripOffsets': (8,),
'Software': u'ImageMagick 6.5.7-8 2012-08-17 Q16 http://www.imagemagick.org'} 'Software': 'ImageMagick 6.5.7-8 2012-08-17 Q16 http://www.imagemagick.org'}
# assert_equal is equivalent, but less helpful in telling what's wrong. # assert_equal is equivalent, but less helpful in telling what's wrong.
named = img.tag.named() named = img.tag.named()