aboutsummaryrefslogtreecommitdiffstats
path: root/src/pyexiv2.py
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-03-09 09:19:16 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-03-09 09:19:16 +0100
commit3c23acdb070d2c3230f3ecf497b4fbd760f5a10e (patch)
treeed4b492f1a821fb315f4fd55439b4300df179a6a /src/pyexiv2.py
parent4b0b859dd1d0884da54d633cf6dec8c5f4d8318f (diff)
downloadpyexiv2-3c23acdb070d2c3230f3ecf497b4fbd760f5a10e.tar.gz
EXIF Rational and SRational conversion.
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r--src/pyexiv2.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 4f23757..9102011 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -283,6 +283,7 @@ def StringToTime(string):
return localTime
+
class Rational(object):
"""
@@ -485,6 +486,16 @@ class ExifTag(MetadataTag):
except ValueError:
raise ExifValueError(value, xtype)
+ elif xtype in ('Rational', 'SRational'):
+ try:
+ r = Rational.from_string(value)
+ except (ValueError, ZeroDivisionError):
+ raise ExifValueError(value, xtype)
+ else:
+ if xtype == 'Rational' and r.numerator < 0:
+ raise ExifValueError(value, xtype)
+ return r
+
elif xtype == 'Undefined':
try:
return unicode(fvalue, 'utf-8')
@@ -543,6 +554,22 @@ class ExifTag(MetadataTag):
else:
raise ExifValueError(value, xtype)
+ elif xtype == 'Rational':
+ if type(value) is Rational and value.numerator >= 0:
+ return str(value)
+ else:
+ raise ExifValueError(value, xtype)
+
+ elif xtype == 'SRational':
+ if type(value) is Rational:
+ return str(value)
+ else:
+ raise ExifValueError(value, xtype)
+
+ elif xtype == 'Undefined':
+ # TODO
+ raise NotImplementedError('EXIF conversion for type [%s]' % xtype)
+
# TODO: other types
raise ExifValueError(value, xtype)