aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-01-17 21:01:42 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-01-17 21:01:42 +0100
commit180abcdb87ba2f54c93e79b01a08fd039c95b256 (patch)
tree79a9e6d58077330b8c59da4619ebf11f5299105c
parentccd9e961b51c4d4dab0af923abef8bd4556e0236 (diff)
downloadpyexiv2-180abcdb87ba2f54c93e79b01a08fd039c95b256.tar.gz
Do not convert automatically Undefined values to their human representation,
it's a lossy conversion.
-rw-r--r--src/pyexiv2/exif.py9
-rw-r--r--test/exif.py6
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)