aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-01-22 21:17:50 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-01-22 21:17:50 +0100
commitec5e7507e774d9b246453ab8bdabf338a54f873b (patch)
tree546b3d7579d54a2242a477ff8badd256d0654d74
parent579511a60f05d99827223fd062b072c83a4e9744 (diff)
downloadpyexiv2-ec5e7507e774d9b246453ab8bdabf338a54f873b.tar.gz
XMP MIMEType conversion + unit tests.
-rw-r--r--src/pyexiv2.py8
-rw-r--r--unittest/xmp.py12
2 files changed, 18 insertions, 2 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 8a8f362..7a4d217 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -559,8 +559,12 @@ class XmpTag(MetadataTag):
# TODO
return value
elif xtype == 'MIMEType':
- # TODO
- return value
+ try:
+ mtype, msubtype = value.split('/', 1)
+ except ValueError:
+ return value
+ else:
+ return {'type': mtype, 'subtype': msubtype}
elif xtype == 'ProperName':
# TODO
return value
diff --git a/unittest/xmp.py b/unittest/xmp.py
index 1ed8725..53969dd 100644
--- a/unittest/xmp.py
+++ b/unittest/xmp.py
@@ -88,4 +88,16 @@ class TestXmpTag(unittest.TestCase):
# FIXME: the following test should not fail: having hours without minutes is not a valid syntax.
self.assertEqual(XmpTag._convert_to_python('2009-01-22T21', xtype), '2009-01-22T21')
+ def test_convert_to_python_mimetype(self):
+ xtype = 'MIMEType'
+ # Valid values
+ self.assertEqual(XmpTag._convert_to_python('image/jpeg', xtype),
+ {'type': 'image', 'subtype': 'jpeg'})
+ self.assertEqual(XmpTag._convert_to_python('video/ogg', xtype),
+ {'type': 'video', 'subtype': 'ogg'})
+ # Invalid values
+ self.assertEqual(XmpTag._convert_to_python('invalid', xtype), 'invalid')
+ self.assertEqual(XmpTag._convert_to_python('image-jpeg', xtype), 'image-jpeg')
+
+
# TODO: other types