aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2011-10-24 09:41:16 +0200
committerOlivier Tilloy <olivier@tilloy.net>2011-10-24 09:41:16 +0200
commit888799070314b6a3b7067ba9b21e5f21bbb39c98 (patch)
tree206f15c579634ebec8ddfabe542f0e2096c63fc7
parentdd401698544b81ba345591467e508d5d6d47620e (diff)
parent9426a35dbba4d8ca61a59cfff472dbb7e6782157 (diff)
downloadpyexiv2-888799070314b6a3b7067ba9b21e5f21bbb39c98.tar.gz
Fix a couple of regressions that had bumped the dependency on Python ≥ 2.7.
pyexiv2 0.3 is now compatible with Python ≥ 2.6 again.
-rw-r--r--src/pyexiv2/utils.py8
-rw-r--r--test/iptc.py7
-rw-r--r--test/xmp.py7
3 files changed, 19 insertions, 3 deletions
diff --git a/src/pyexiv2/utils.py b/src/pyexiv2/utils.py
index 9473aff..0325699 100644
--- a/src/pyexiv2/utils.py
+++ b/src/pyexiv2/utils.py
@@ -28,6 +28,9 @@
Utilitary classes and functions.
"""
+# Enable true division.
+from __future__ import division
+
import datetime
import re
@@ -601,7 +604,10 @@ class DateTimeFormatter(object):
``±%H:%M``
:rtype: string
"""
- seconds = t.total_seconds()
+ # timedelta.total_seconds() is only available starting with Python 2.7
+ # (http://docs.python.org/library/datetime.html#datetime.timedelta.total_seconds)
+ #seconds = t.total_seconds()
+ seconds = (t.microseconds + (t.seconds + t.days * 24 * 3600) * 10**6) / 10**6
hours = int(seconds / 3600)
minutes = abs(int((seconds - hours * 3600) / 60))
return '%+03d:%02d' % (hours, minutes)
diff --git a/test/iptc.py b/test/iptc.py
index 872990a..ed1b2f6 100644
--- a/test/iptc.py
+++ b/test/iptc.py
@@ -182,8 +182,13 @@ class TestIptcTag(unittest.TestCase):
# Invalid values
self.failUnlessRaises(IptcValueError, tag._convert_to_string, 'invalid')
- @unittest.skipIf(pytz is None, 'install python-tz to run this test')
def test_convert_to_string_time_with_real_timezones(self):
+ if pytz is None:
+ # Poor man’s test skipping. Starting with Python 2.7, decorators are
+ # available to implement this in a cleaner fashion
+ # (http://docs.python.org/library/unittest.html#unittest-skipping).
+ print 'Install python-tz to run this test. Skipping.'
+ return
tag = IptcTag('Iptc.Envelope.TimeSent')
self.assertEqual(tag.type, 'Time')
t = pytz.timezone('UTC').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))
diff --git a/test/xmp.py b/test/xmp.py
index ba5b0b6..70e0980 100644
--- a/test/xmp.py
+++ b/test/xmp.py
@@ -184,8 +184,13 @@ class TestXmpTag(unittest.TestCase):
self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Date')
self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'Date')
- @unittest.skipIf(pytz is None, 'install python-tz to run this test')
def test_convert_to_string_date_with_real_timezones(self):
+ if pytz is None:
+ # Poor man’s test skipping. Starting with Python 2.7, decorators are
+ # available to implement this in a cleaner fashion
+ # (http://docs.python.org/library/unittest.html#unittest-skipping).
+ print 'Install python-tz to run this test. Skipping.'
+ return
tag = XmpTag('Xmp.xmp.CreateDate')
self.assertEqual(tag.type, 'Date')
t = pytz.timezone('UTC').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))