aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-08-07 10:09:24 +0200
committerOlivier Tilloy <olivier@tilloy.net>2009-08-07 10:09:24 +0200
commitd9cb2ac5e54b6126119c9f34f7268a1fc4deb3ad (patch)
tree592da754b0a541c4743be9e993fe0ffdd48cab5e /src
parentbedad87240fdc63dc37c1fd859642284eed63a74 (diff)
downloadpyexiv2-d9cb2ac5e54b6126119c9f34f7268a1fc4deb3ad.tar.gz
Rational's numerator and denominator are read-only properties.
This will avoid setting the attributes of a tag's Rational value where the metadata container wouldn't be notified of the changes.
Diffstat (limited to 'src')
-rw-r--r--src/pyexiv2.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 991421a..0bd180e 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -199,6 +199,8 @@ class Rational(object):
"""
A class representing a rational number.
+
+ Its numerator and denominator are read-only properties.
"""
_format_re = re.compile(r'(?P<numerator>-?\d+)/(?P<denominator>\d+)')
@@ -217,8 +219,16 @@ class Rational(object):
if denominator == 0:
msg = 'Denominator of a rational number cannot be zero.'
raise ZeroDivisionError(msg)
- self.numerator = long(numerator)
- self.denominator = long(denominator)
+ self._numerator = long(numerator)
+ self._denominator = long(denominator)
+
+ @property
+ def numerator(self):
+ return self._numerator
+
+ @property
+ def denominator(self):
+ return self._denominator
@staticmethod
def from_string(string):
@@ -245,7 +255,7 @@ class Rational(object):
@return: a floating point number approximation of the value
@rtype: C{float}
"""
- return float(self.numerator) / self.denominator
+ return float(self._numerator) / self._denominator
def __eq__(self, other):
"""
@@ -259,14 +269,14 @@ class Rational(object):
@return: C{True} if equal, C{False} otherwise
@rtype: C{bool}
"""
- return (self.numerator * other.denominator) == \
- (other.numerator * self.denominator)
+ return (self._numerator * other._denominator) == \
+ (other._numerator * self._denominator)
def __str__(self):
"""
Return a string representation of the rational number.
"""
- return '%d/%d' % (self.numerator, self.denominator)
+ return '%d/%d' % (self._numerator, self._denominator)
class ListenerInterface(object):