iter(dict) is equivalent to iter(dict.keys()), so simply act on the dict
instead of adding the extra call.
Inspired by Lennart Regebro's PyCon 2017 presentation "Prehistoric
Patterns in Python". Available at:
https://www.youtube.com/watch?v=V5-JH23Vk0I
Haven't excercized all of the metadata that we're allowing yet,
and there's clearly still something up with Arrays, as one
of them is still crashing and making it impossible to save a
palette with a libtiff image.
To have the old API that always returns tuples, and fractions as pairs,
set the `legacy_api` attribute of the IFD to True.
This should alleviate concerns about backwards compatibility.
Do not represent scalar tags as 1-element tuples. Keep tag
type and count information in TiffTags.TAGS. Normalize data in
ImageFileDirectory.__setitem__: wrap and unwrap tuples as needed,
convert rationals to floats. (To ensure consistency, make the "tags"
attribute private.) Interpret byte data as a series of integers rather
than a bytearray (which should only map to the "undefined" type). On
Python3, if a str is assigned to an "undefined" tag, encode it as ASCII.
Note that a large number of tags have been removed from TiffTags.TAGS
because I do not have time to figure out the type and count of each of
them. They should be restored before this gets merged in.
This obviously breaks backwards compatibility in a lot of ways...
cf. #1191.
Only TiffImagePlugin and OLEFileIO still rely on (their own) DEBUG flag.
I left TiffImagePlugin as it is because I hope #1059 gets merged in
first, and OLEFileIO because it uses its own logic.
Untested, as usual.