summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Pieviläinen <tomi.pievilainen+launchpad@iki.fi>2012-02-19 00:54:32 +0200
committerTomi Pieviläinen <tomi.pievilainen+launchpad@iki.fi>2012-02-19 00:54:32 +0200
commit95b2a249793d9092e9466f48ab24995d06fddf2f (patch)
tree4c49bb49d5b1f2c95f6916738d584cc11088d9c1
parentb6993d02819b4f927d76c15613d6648fa416bad3 (diff)
downloaddateutil-95b2a249793d9092e9466f48ab24995d06fddf2f.tar.gz
Fix opening files in tz
-rw-r--r--dateutil/tz.py10
-rwxr-xr-xtest.py4
2 files changed, 10 insertions, 4 deletions
diff --git a/dateutil/tz.py b/dateutil/tz.py
index 3dca4a9..9df184b 100644
--- a/dateutil/tz.py
+++ b/dateutil/tz.py
@@ -7,6 +7,8 @@ datetime module.
__author__ = "Gustavo Niemeyer <gustavo@niemeyer.net>"
__license__ = "Simplified BSD"
+from six import string_types
+
import datetime
import struct
import time
@@ -211,9 +213,9 @@ class tzfile(datetime.tzinfo):
# ftp://elsie.nci.nih.gov/pub/tz*.tar.gz
def __init__(self, fileobj):
- if isinstance(fileobj, str):
+ if isinstance(fileobj, string_types):
self._filename = fileobj
- fileobj = open(fileobj)
+ fileobj = open(fileobj, 'rb')
elif hasattr(fileobj, "name"):
self._filename = fileobj.name
else:
@@ -724,9 +726,9 @@ class tzical(object):
if not rrule:
from dateutil import rrule
- if isinstance(fileobj, str):
+ if isinstance(fileobj, string_types):
self._s = fileobj
- fileobj = open(fileobj)
+ fileobj = open(fileobj, 'r') # ical should be encoded in UTF-8 with CRLF
elif hasattr(fileobj, "name"):
self._s = fileobj.name
else:
diff --git a/test.py b/test.py
index eda613e..a1a4a9b 100755
--- a/test.py
+++ b/test.py
@@ -3973,6 +3973,10 @@ END:VTIMEZONE
tz = tzfile(BytesIO(base64.decodestring(self.NEW_YORK)))
self.assertEqual(datetime(2007, 3, 31, 20, 12).tzname(), None)
+ def testGettz(self):
+ # bug 892569
+ str(gettz('UTC'))
+
def testBrokenIsDstHandling(self):
# tzrange._isdst() was using a date() rather than a datetime().
# Issue reported by Lennart Regebro.