An attempt to fix #15 for Python 3.x.

TiffImagePlugin.ImageFileDirectory.__getattr__ is magical because it deletes items from "tagdata" variable and this plays badly with TiffImagePlugin.ImageFileDirectory.__iter__. Under Python 2.x items() returned a list and this wasn't a problem (because __iter__ value was evalued once); under Python 3.x items() returns a view/iterator that chains self.tags and self.tagdata and iteration begins to fail with "RuntimeError: dictionary changed size during iteration" exception because tagdata item is modified.

In this changeset I've tried to fix this by evaluating items() when the loop starts (by casting it to list), so that it doesn't matter if tagdata is changed during iteration or not.

There is no tests because _getexif is currently private. But this method is used by easy-thumbnails and sorl.thumbnails, so I think it is worth fixing it.
This commit is contained in:
Mikhail Korobov 2013-02-26 16:44:47 +06:00
parent bb4eb53859
commit ee794e1501

View File

@ -378,7 +378,7 @@ class JpegImageFile(ImageFile.ImageFile):
# process dictionary
info = TiffImagePlugin.ImageFileDirectory(head)
info.load(file)
for key, value in info.items():
for key, value in list(info.items()):
exif[key] = fixup(value)
# get exif extension
try:
@ -388,7 +388,7 @@ class JpegImageFile(ImageFile.ImageFile):
else:
info = TiffImagePlugin.ImageFileDirectory(head)
info.load(file)
for key, value in info.items():
for key, value in list(info.items()):
exif[key] = fixup(value)
# get gpsinfo extension
try:
@ -399,7 +399,7 @@ class JpegImageFile(ImageFile.ImageFile):
info = TiffImagePlugin.ImageFileDirectory(head)
info.load(file)
exif[0x8825] = gps = {}
for key, value in info.items():
for key, value in list(info.items()):
gps[key] = fixup(value)
return exif