From 1f1fa7d03e28c2ec2cdcb741cdece027b0402c6a Mon Sep 17 00:00:00 2001 From: Catherine Devlin Date: Tue, 22 Apr 2014 14:47:21 -0400 Subject: [PATCH] Used ``futurize`` in ``future`` module to make 2/3 compatible --- pytimeparse/testtimeparse.py | 4 ++-- pytimeparse/timeparse.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pytimeparse/testtimeparse.py b/pytimeparse/testtimeparse.py index 43bc044..eae41c2 100644 --- a/pytimeparse/testtimeparse.py +++ b/pytimeparse/testtimeparse.py @@ -10,7 +10,7 @@ Unit tests for the `timeparse` module. import doctest import re -import timeparse +from pytimeparse import timeparse import unittest class TestTimeparse(unittest.TestCase): @@ -58,7 +58,7 @@ class TestTimeparse(unittest.TestCase): '''Test parsing time expression.''' self.assertGreater( set(re.match(timeparse.TIMEFORMATS[0] + r'\s*$', - '16h32m64s ').groupdict().iteritems()), + '16h32m64s ').groupdict().items()), set([('hours', '16'), ('mins', '32'), ('secs', '64')])) def test_timeparse_multipliers(self): diff --git a/pytimeparse/timeparse.py b/pytimeparse/timeparse.py index b713926..69a1f7b 100644 --- a/pytimeparse/timeparse.py +++ b/pytimeparse/timeparse.py @@ -1,3 +1,5 @@ +from future.builtins import dict +from future.builtins import int #!/usr/bin/env python # -*- coding: utf-8 -*- @@ -105,9 +107,9 @@ def timeparse(sval): if match and match.group(0).strip(): mdict = match.groupdict() # if all of the fields are integer numbers - if all(v.isdigit() for v in mdict.values() if v): + if all(v.isdigit() for v in list(mdict.values()) if v): return sum([MULTIPLIERS[k] * int(v, 10) for (k, v) in - mdict.items() if v is not None]) + list(mdict.items()) if v is not None]) # if SECS is an integer number elif ('secs' not in mdict or mdict['secs'] is None or @@ -115,9 +117,9 @@ def timeparse(sval): # we will return an integer return ( int(sum([MULTIPLIERS[k] * float(v) for (k, v) in - mdict.items() if k != 'secs' and v is not None])) + + list(mdict.items()) if k != 'secs' and v is not None])) + (int(mdict['secs'], 10) if mdict['secs'] else 0)) else: # SECS is a float, we will return a float return sum([MULTIPLIERS[k] * float(v) for (k, v) in - mdict.items() if v is not None]) + list(mdict.items()) if v is not None])