def __getattr__(self, item): """If attribute is not a class member, get the value of the EXIF tag of the same name.""" try: attribute_id = ATTRIBUTE_ID_MAP[item] except KeyError: raise AttributeError("unknown image attribute {0}".format(item)) try: ifd_tag = self.ifd_tags[attribute_id] except KeyError: raise AttributeError(ERROR_IMG_NO_ATTR.format(item)) return ifd_tag.read()
def __setattr__(self, key, value): try: # Determine if attribute is an IFD tag accessor. attribute_id = ATTRIBUTE_ID_MAP[key] except KeyError: # Attribute is a class member. Set natively. super(App1MetaData, self).__setattr__(key, value) else: try: ifd_tag = self.ifd_tags[attribute_id] except KeyError: raise AttributeError(ERROR_IMG_NO_ATTR.format(key)) ifd_tag.modify(value)
def __delattr__(self, item): try: # Determine if attribute is an IFD tag accessor. attribute_id = ATTRIBUTE_ID_MAP[item] except KeyError: # pragma: no cover # Coverage and behavior tested by Image class. # Attribute is a class member. Delete natively. super(App1MetaData, self).__delattr__(item) else: # Attribute is not a class member. Delete EXIF tag value. try: ifd_tag = self.ifd_tags[attribute_id] except KeyError: raise AttributeError(ERROR_IMG_NO_ATTR.format(item)) self._delete_ifd_tag(ifd_tag)