Feature request: Inherit ImageMetadata from collections.MutableMapping

Asked by Antti Siira


would it be possible to make ImageMetadata inherit from collections.MutableMapping and provide the two missing class functions __len__ and __iter__. This way you get a bundle of nice features such as metadata.get(key, default), metadata.iteritems(), 'Some.Tag.Name' in metadata, [key for key in metadata] and so forth.

Example implementations for missing functions:
def __iter__(self):
    for key in self.exif_keys:
        yield key
    for key in self.iptc_keys:
        yield key
    for key in self.xmp_keys:
        yield key

def __len__(self):
    return len( [key for key in self] )

Question information

English Edit question
pyexiv2 Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Olivier Tilloy (osomon) said :

This looks like a very interesting additional feature. I turned it into a bug report (bug #648624) to track its future implementation.
Of course a full-fledged implementation including unit tests is more than welcome!

Revision history for this message
Olivier Tilloy (osomon) said :

This has been implemented by Antti Siira and merged into the trunk at revision 327.
Many thanks Antti!

Can you help with this problem?

Provide an answer of your own, or ask Antti Siira for more information if necessary.

To post a message you must log in.