From 1e542e612add8dece9776c2cfc728a4d19510dea Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 28 Jun 2014 12:21:58 +0200 Subject: [PATCH] move total_seconds to utilities --- isso/config.py | 11 ++--------- isso/utils/__init__.py | 5 +++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/isso/config.py b/isso/config.py index 711dc34..fc032b4 100644 --- a/isso/config.py +++ b/isso/config.py @@ -9,16 +9,12 @@ import datetime from email.utils import parseaddr, formataddr from configparser import ConfigParser +from isso.utils import total_seconds from isso.compat import text_type as str logger = logging.getLogger("isso") -# Python 2.6 compatibility -def total_seconds(td): - return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 - - def timedelta(string): """ Parse :param string: into :class:`datetime.timedelta`, you can use any @@ -95,10 +91,7 @@ class IssoParser(ConfigParser): except ValueError: return super(IssoParser, self).getint(section, key) else: - try: - return int(delta.total_seconds()) - except AttributeError: - return int(total_seconds(delta)) + return int(total_seconds(delta)) def getlist(self, section, key): return list(map(str.strip, self.get(section, key).split(','))) diff --git a/isso/utils/__init__.py b/isso/utils/__init__.py index dfc361c..bee0b01 100644 --- a/isso/utils/__init__.py +++ b/isso/utils/__init__.py @@ -17,6 +17,11 @@ except ImportError: import ipaddr as ipaddress +# Python 2.6 compatibility +def total_seconds(td): + return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + + def anonymize(remote_addr): """ Anonymize IPv4 and IPv6 :param remote_addr: to /24 (zero'd)