Looks like this only fails on python2 if a non-unicode string is used as the tzstr arg.
dateutil.tz.tzstr('EST5EDT') FAILS
dateutil.tz.tzstr(u'EST5EDT') PASSES
dateutil.parser._timelex.__init__:35 seems to do it.
def __init__(self, instream): if isinstance(instream, text_type): instream = StringIO(instream) self.instream = instream
The isinstance() check fails for a non unicode string.
>>> import six >>> a = 'EST' >>> isinstance(a, six.text_type) False >>> a = u'EST' >>> isinstance(a, six.text_type) True
texttype is from 'six' and gets defined as 'unicode' on python2.
So likely only fails on python2 with non unicode strings passed to tzstr().
test.py has tests for similar usage, but test.py has:
from __future__ import unicode_literals
Turning that off makes the tzstr tests fail. Our code doesn't use unicode_literals, so str literals passed in cause the errors mentioned.
Something like this (untested) snippet should work:
if isinstance(instream, basestring): instream = StringIO(instream)
Looks like this only fails on python2 if a non-unicode string is used as the tzstr arg.
dateutil. tz.tzstr( 'EST5EDT' )
FAILS
dateutil. tz.tzstr( u'EST5EDT' )
PASSES
dateutil. parser. _timelex. __init_ _:35 seems to do it.
def __init__(self, instream): instream, text_type):
instream = StringIO(instream)
self.instream = instream
if isinstance(
The isinstance() check fails for a non unicode string.
>>> import six
>>> a = 'EST'
>>> isinstance(a, six.text_type)
False
>>> a = u'EST'
>>> isinstance(a, six.text_type)
True
texttype is from 'six' and gets defined as 'unicode' on python2.
So likely only fails on python2 with non unicode strings passed to tzstr().
test.py has tests for similar usage, but test.py has:
from __future__ import unicode_literals
Turning that off makes the tzstr tests fail. Our code doesn't use unicode_literals, so
str literals passed in cause the errors mentioned.
Something like this (untested) snippet should work:
if isinstance( instream, basestring):
instream = StringIO(instream)