diff options
-rw-r--r-- | src/pyexiv2/exif.py | 9 | ||||
-rw-r--r-- | test/exif.py | 6 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/pyexiv2/exif.py b/src/pyexiv2/exif.py index 7750ff0..0afc39a 100644 --- a/src/pyexiv2/exif.py +++ b/src/pyexiv2/exif.py @@ -26,7 +26,8 @@ import libexiv2python -from pyexiv2.utils import Rational, NotifyingList, ListenerInterface +from pyexiv2.utils import Rational, NotifyingList, ListenerInterface, \ + UndefinedToString, StringToUndefined import time import datetime @@ -272,7 +273,7 @@ class ExifTag(ListenerInterface): # There is currently no charset conversion. # TODO: guess the encoding and decode accordingly into unicode # where relevant. - return self.human_value + return UndefinedToString(value) raise ExifValueError(value, self.type) @@ -358,11 +359,11 @@ class ExifTag(ListenerInterface): elif self.type == 'Undefined': if type(value) is unicode: try: - return value.encode('utf-8') + return StringToUndefined(value.encode('utf-8')) except UnicodeEncodeError: raise ExifValueError(value, self.type) elif type(value) is str: - return value + return StringToUndefined(value) else: raise ExifValueError(value, self.type) diff --git a/test/exif.py b/test/exif.py index 6cb4f77..7b73966 100644 --- a/test/exif.py +++ b/test/exif.py @@ -287,14 +287,14 @@ class TestExifTag(unittest.TestCase): # Valid values tag = ExifTag('Exif.Photo.ExifVersion', '48 49 48 48 ') self.assertEqual(tag.type, 'Undefined') - self.assertEqual(tag._convert_to_python('48 49 48 48 '), '1.00') + self.assertEqual(tag._convert_to_python('48 49 48 48 '), '0100') def test_convert_to_string_undefined(self): # Valid values tag = ExifTag('Exif.Photo.ExifVersion') self.assertEqual(tag.type, 'Undefined') - self.assertEqual(tag._convert_to_string('48 49 48 48 '), '48 49 48 48 ') - self.assertEqual(tag._convert_to_string(u'48 49 48 48 '), '48 49 48 48 ') + self.assertEqual(tag._convert_to_string('0100'), '48 49 48 48 ') + self.assertEqual(tag._convert_to_string(u'0100'), '48 49 48 48 ') # Invalid values self.failUnlessRaises(ExifValueError, tag._convert_to_string, 3) |