aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2011-08-17 19:09:53 +0200
committerOlivier Tilloy <olivier@tilloy.net>2011-08-17 19:09:53 +0200
commit235aec27487a8a247269a444be0198f6b47731cb (patch)
tree14dfbf0ec7bb8341e8e7efe7b130ec0a1525964e
parent7457fbcbd52fdb8f0be56b80e4dc889d46faad59 (diff)
downloadpyexiv2-235aec27487a8a247269a444be0198f6b47731cb.tar.gz
Be flexible and allow setting the value of a LangAlt tag to a string,
in which case it is automatically converted to {'x-default': value}.
-rw-r--r--src/pyexiv2/xmp.py2
-rw-r--r--test/xmp.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/pyexiv2/xmp.py b/src/pyexiv2/xmp.py
index 2b3149e..76e0df2 100644
--- a/src/pyexiv2/xmp.py
+++ b/src/pyexiv2/xmp.py
@@ -225,6 +225,8 @@ class XmpTag(object):
stype = stype[17:]
self.raw_value = map(lambda x: self._convert_to_string(x, stype), value)
elif type == 'LangAlt':
+ if isinstance(value, basestring):
+ value = {'x-default': value}
if not isinstance(value, dict):
raise TypeError('Expecting a dictionary mapping language codes to values')
raw_value = {}
diff --git a/test/xmp.py b/test/xmp.py
index 294cdc2..6183277 100644
--- a/test/xmp.py
+++ b/test/xmp.py
@@ -374,7 +374,13 @@ class TestXmpTag(unittest.TestCase):
tag = XmpTag('Xmp.dc.description')
self.failUnlessEqual(tag.type, 'Lang Alt')
self.failUnlessRaises(TypeError, tag._set_value, None)
- self.failUnlessRaises(TypeError, tag._set_value, 'bleh')
+ self.failUnlessRaises(TypeError, tag._set_value, ['bleh'])
+
+ def test_set_value_basestring_for_langalt(self):
+ tag = XmpTag('Xmp.dc.description')
+ self.failUnlessEqual(tag.type, 'Lang Alt')
+ tag.value = 'bleh'
+ self.failUnlessEqual(tag.value, {'x-default': 'bleh'})
class TestXmpNamespaces(unittest.TestCase):