Merge pull request #3 from catherinedevlin/py3

Used ``futurize`` in ``future`` module to make 2/3 compatible
This commit is contained in:
Will Roberts 2014-04-23 03:18:18 +02:00
commit 2a9363becc
2 changed files with 8 additions and 6 deletions

View File

@ -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):

View File

@ -1,3 +1,5 @@
from future.builtins import dict
from future.builtins import int
#!/usr/bin/env python
# -*- coding: utf-8 -*-
@ -110,9 +112,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
@ -120,9 +122,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])