aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-01-28 23:41:04 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-01-28 23:41:04 +0100
commit9f315477dacd0df820a6912e7218f63e7601ccec (patch)
tree5c3df6c71b311c2301c8ce7cd6b40bc1e371642d /src
parent926a9db178e8d62b4bb15940c5df80d8814c4d11 (diff)
downloadpyexiv2-9f315477dacd0df820a6912e7218f63e7601ccec.tar.gz
XMP Text to string conversion + unit tests.
Diffstat (limited to 'src')
-rw-r--r--src/pyexiv2.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index a147340..8fa4a48 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -643,16 +643,30 @@ class XmpTag(MetadataTag):
def _convert_to_string(value, xtype):
"""
Convert a value to its corresponding string representation.
- Fallback to str(value) if no standard-compliant conversion can be done.
+
+ @param value: the value to be converted
+ @type value: depends on xtype (DOCME)
+ @param xtype: the XMP type of the value
+ @type xtype: C{str}
+
+ @return: the value converted to its corresponding string representation
+ @rtype: C{str}
+
+ @raise L{XmpValueError}: if the conversion fails
"""
- if xtype == 'Boolean':
- if value == True:
- return 'True'
- elif value == False:
- return 'False'
+ if xtype == 'Boolean' and type(value) is bool:
+ return str(value)
+
+ elif xtype == 'Text':
+ if type(value) is unicode:
+ try:
+ return value.encode('utf-8')
+ except UnicodeEncodeError:
+ raise XmpValueError(value, xtype)
+ elif type(value) is str:
+ return value
- # Default fallback conversion
- return str(value)
+ raise XmpValueError(value, xtype)
def __str__(self):
"""