aboutsummaryrefslogtreecommitdiffstats
path: root/src/pyexiv2.py
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-10-08 09:33:01 +0200
committerOlivier Tilloy <olivier@fluendo.com>2009-10-08 09:33:01 +0200
commit31d240d6cef0fa252f9e963cbcdf462e6092d37e (patch)
treed8a764bf9f9bb632f6b97d3a1ebcdfa8a097e583 /src/pyexiv2.py
parent4fb010247e1234925af20b10e5363ca1c3b1bc31 (diff)
downloadpyexiv2-31d240d6cef0fa252f9e963cbcdf462e6092d37e.tar.gz
Make IptcTag._convert_to_string an instance method.
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r--src/pyexiv2.py42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 88d08f2..5f17e92 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -786,7 +786,7 @@ class IptcTag(MetadataTag):
def _set_values(self, new_values):
if self.metadata is not None:
- raw_values = map(lambda x: IptcTag._convert_to_string(x, self.type), new_values)
+ raw_values = map(self._convert_to_string, new_values)
self.metadata._set_iptc_tag_values(self.key, raw_values)
# Make values a notifying list if needed
if isinstance(new_values, NotifyingList):
@@ -815,7 +815,7 @@ class IptcTag(MetadataTag):
def _convert_to_python(self, value):
"""
- Convert a raw value to its corresponding python type.
+ Convert one raw value to its corresponding python type.
@param value: the raw value to be converted
@type value: C{str}
@@ -875,47 +875,44 @@ class IptcTag(MetadataTag):
raise IptcValueError(value, self.type)
- @staticmethod
- def _convert_to_string(value, xtype):
+ def _convert_to_string(self, value):
"""
- Convert a value to its corresponding string representation, suitable to
- pass to libexiv2.
+ Convert one value to its corresponding string representation, suitable
+ to pass to libexiv2.
@param value: the value to be converted
- @type value: depends on xtype (DOCME)
- @param xtype: the IPTC type of the value
- @type xtype: C{str}
+ @type value: depends on C{self.type} (DOCME)
@return: the value converted to its corresponding string representation
@rtype: C{str}
@raise IptcValueError: if the conversion fails
"""
- if xtype == 'Short':
+ if self.type == 'Short':
if type(value) is int:
return str(value)
else:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
- elif xtype == 'String':
+ elif self.type == 'String':
if type(value) is unicode:
try:
return value.encode('utf-8')
except UnicodeEncodeError:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
elif type(value) is str:
return value
else:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
- elif xtype == 'Date':
+ elif self.type == 'Date':
if type(value) in (datetime.date, datetime.datetime):
# ISO 8601 date format
return value.strftime('%Y%m%d')
else:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
- elif xtype == 'Time':
+ elif self.type == 'Time':
if type(value) in (datetime.time, datetime.datetime):
r = value.strftime('%H%M%S')
if value.tzinfo is not None:
@@ -924,15 +921,15 @@ class IptcTag(MetadataTag):
r += '+0000'
return r
else:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
- elif xtype == 'Undefined':
+ elif self.type == 'Undefined':
if type(value) is str:
return value
else:
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
- raise IptcValueError(value, xtype)
+ raise IptcValueError(value, self.type)
def to_string(self):
"""
@@ -941,8 +938,7 @@ class IptcTag(MetadataTag):
@rtype: C{list} of C{str}
"""
- return map(lambda x: IptcTag._convert_to_string(x, self.type),
- self.values)
+ return map(self._convert_to_string, self.values)
def __str__(self):
"""