From 95b2a249793d9092e9466f48ab24995d06fddf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Pievil=C3=A4inen?= Date: Sun, 19 Feb 2012 00:54:32 +0200 Subject: Fix opening files in tz --- dateutil/tz.py | 10 ++++++---- test.py | 4 ++++ 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 " __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. -- cgit v1.2.1