summaryrefslogtreecommitdiff
path: root/iso8601
diff options
context:
space:
mode:
authorMichael Twomey <michael.twomey@fieldaware.com>2013-08-29 15:25:29 +0100
committerMichael Twomey <michael.twomey@fieldaware.com>2013-08-29 15:25:29 +0100
commitb7dc65d503d0255cdbd585e4629cbbf191c38e59 (patch)
tree2f2149e28f3a7db22fea5011ad963fba7e9f1301 /iso8601
parent86a3f1b2ed85b06d7540b9fc696d606d37be3b3b (diff)
downloadpyiso8601-b7dc65d503d0255cdbd585e4629cbbf191c38e59.tar.gz
Applied python 3 support patch from https://code.google.com/p/pyiso8601/issues/detail?id=23
Also updated to use tox and py.test
Diffstat (limited to 'iso8601')
-rw-r--r--iso8601/__init__.py2
-rw-r--r--iso8601/iso8601.py9
-rw-r--r--iso8601/test_iso8601.py10
3 files changed, 15 insertions, 6 deletions
diff --git a/iso8601/__init__.py b/iso8601/__init__.py
index e72e356..11b1adc 100644
--- a/iso8601/__init__.py
+++ b/iso8601/__init__.py
@@ -1 +1 @@
-from iso8601 import *
+from .iso8601 import *
diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py
index f923938..38266c3 100644
--- a/iso8601/iso8601.py
+++ b/iso8601/iso8601.py
@@ -9,10 +9,17 @@ datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.iso8601.Utc ...>)
"""
from datetime import datetime, timedelta, tzinfo
+import sys
import re
__all__ = ["parse_date", "ParseError"]
+if sys.version_info >= (3, 0, 0):
+ _basestring = str
+else:
+ _basestring = basestring
+
+
# Adapted from http://delete.me.uk/2005/03/iso8601.html
ISO8601_REGEX = re.compile(r"(?P<year>[0-9]{4})(-(?P<month>[0-9]{1,2})(-(?P<day>[0-9]{1,2})"
r"((?P<separator>.)(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?"
@@ -86,7 +93,7 @@ def parse_date(datestring, default_timezone=UTC):
default timezone specified in default_timezone is used. This is UTC by
default.
"""
- if not isinstance(datestring, basestring):
+ if not isinstance(datestring, _basestring):
raise ParseError("Expecting a string %r" % datestring)
m = ISO8601_REGEX.match(datestring)
if not m:
diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py
index ff9e273..44cdc77 100644
--- a/iso8601/test_iso8601.py
+++ b/iso8601/test_iso8601.py
@@ -1,4 +1,6 @@
-import iso8601
+from __future__ import absolute_import
+
+from iso8601 import iso8601
def test_iso8601_regex():
assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
@@ -32,7 +34,7 @@ def test_parse_date_fraction():
def test_parse_date_fraction_2():
"""From bug 6
-
+
"""
d = iso8601.parse_date("2007-5-7T11:43:55.328Z'")
assert d.year == 2007
@@ -76,7 +78,7 @@ def test_parse_invalid_date2():
def test_parse_no_timezone():
"""issue 4 - Handle datetime string without timezone
-
+
This tests what happens when you parse a date with no timezone. While not
strictly correct this is quite common. I'll assume UTC for the time zone
in this case.
@@ -98,7 +100,7 @@ def test_parse_no_timezone_different_default():
def test_space_separator():
"""Handle a separator other than T
-
+
"""
d = iso8601.parse_date("2007-06-23 06:40:34.00Z")
assert d.year == 2007