aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pyexiv2.py11
-rw-r--r--unittest/exif.py8
2 files changed, 17 insertions, 2 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 9102011..fbb638c 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -567,8 +567,15 @@ class ExifTag(MetadataTag):
raise ExifValueError(value, xtype)
elif xtype == 'Undefined':
- # TODO
- raise NotImplementedError('EXIF conversion for type [%s]' % xtype)
+ if type(value) is unicode:
+ try:
+ return value.encode('utf-8')
+ except UnicodeEncodeError:
+ raise ExifValueError(value, xtype)
+ elif type(value) is str:
+ return value
+ else:
+ raise ExifValueError(value, xtype)
# TODO: other types
diff --git a/unittest/exif.py b/unittest/exif.py
index 0f7df8f..419b2dd 100644
--- a/unittest/exif.py
+++ b/unittest/exif.py
@@ -174,3 +174,11 @@ class TestExifTag(unittest.TestCase):
u'Digital still camera')
# Invalid values
self.failUnlessRaises(ExifValueError, ExifTag._convert_to_python, 'abc', xtype, None)
+
+ def test_convert_to_string_undefined(self):
+ xtype = 'Undefined'
+ # Valid values
+ self.assertEqual(ExifTag._convert_to_string('48 49 48 48 ', xtype), '48 49 48 48 ')
+ self.assertEqual(ExifTag._convert_to_string(u'48 49 48 48 ', xtype), '48 49 48 48 ')
+ # Invalid values
+ self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, 3, xtype)