diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-12-08 17:44:04 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-12-08 17:44:04 +0100 |
commit | 59b713f002d87be71e504f769428baf837e52ca5 (patch) | |
tree | cd0907e6569429fc47eb1621d6ddf57a8ee1a347 /src | |
parent | 7cb0035390da451bde8ebe534ad28dceeaa1c967 (diff) | |
download | pyexiv2-59b713f002d87be71e504f769428baf837e52ca5.tar.gz |
Raise an IOError with a relevant error message when trying to access the metadata of an image that has not been read() yet.
Previously, a misleading AttributeError would be raised (this was a regression from the 0.1.x series).
Diffstat (limited to 'src')
-rw-r--r-- | src/pyexiv2/metadata.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index a121286..8adeab6 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -61,7 +61,7 @@ class ImageMetadata(MutableMapping): self.filename = filename if filename is not None: self.filename = filename.encode(sys.getfilesystemencoding()) - self._image = None + self.__image = None self._keys = {'exif': None, 'iptc': None, 'xmp': None} self._tags = {'exif': {}, 'iptc': {}, 'xmp': {}} self._exif_thumbnail = None @@ -86,9 +86,15 @@ class ImageMetadata(MutableMapping): :type buffer: string """ obj = cls(None) - obj._image = libexiv2python._Image(buffer, len(buffer)) + obj.__image = libexiv2python._Image(buffer, len(buffer)) return obj + @property + def _image(self): + if self.__image is None: + raise IOError('Image metadata has not been read yet') + return self.__image + def read(self): """ Read the metadata embedded in the associated image. @@ -96,9 +102,9 @@ class ImageMetadata(MutableMapping): the metadata (an exception will be raised if trying to access metadata before calling this method). """ - if self._image is None: - self._image = self._instantiate_image(self.filename) - self._image._readMetadata() + if self.__image is None: + self.__image = self._instantiate_image(self.filename) + self.__image._readMetadata() def write(self, preserve_timestamps=False): """ |