diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-02-24 09:37:53 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-02-24 09:37:53 +0100 |
commit | 6cb7e04dbde3309e575223ec5dc09cc85e61ff11 (patch) | |
tree | b5203151c843ef29caff7cb5d5469e8ba5e65754 | |
parent | e1ced824d8897bf1a44922e51823592e43988db5 (diff) | |
download | pyexiv2-6cb7e04dbde3309e575223ec5dc09cc85e61ff11.tar.gz |
IPTC String conversion.
-rw-r--r-- | src/pyexiv2.py | 6 | ||||
-rw-r--r-- | unittest/iptc.py | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index fa1b3a2..b4d783f 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -488,6 +488,12 @@ class IptcTag(MetadataTag): except ValueError: raise IptcValueError(value, xtype) + elif xtype == 'String': + try: + return unicode(value, 'utf-8') + except TypeError: + raise IptcValueError(value, xtype) + # TODO: other types raise NotImplementedError('IPTC conversion for type [%s]' % xtype) diff --git a/unittest/iptc.py b/unittest/iptc.py index 4ed0dc3..035b435 100644 --- a/unittest/iptc.py +++ b/unittest/iptc.py @@ -42,4 +42,13 @@ class TestIptcTag(unittest.TestCase): self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, '47.0001', xtype) self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, '1E3', xtype) + def test_convert_to_python_string(self): + xtype = 'String' + # Valid values + self.assertEqual(IptcTag._convert_to_python('Some text.', xtype), u'Some text.') + self.assertEqual(IptcTag._convert_to_python('Some text with exotic chàräctérʐ.', xtype), + u'Some text with exotic chàräctérʐ.') + # Invalid values + self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, None, xtype) + # TODO: other types |