Bug 1197791 - tz.tzstr('EST5EDT') fails with AttributeError: 'str' object has no attribute 'read'
Summary: tz.tzstr('EST5EDT') fails with AttributeError: 'str' object has no attribute ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-dateutil
Version: 22
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jef Spaleta
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1183382
TreeView+ depends on / blocked
 
Reported: 2015-03-02 15:49 UTC by Adrian Likins
Modified: 2015-03-09 08:24 UTC (History)
4 users (show)

Fixed In Version: python-dateutil-2.4.0-3.fc22
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-03-09 08:24:50 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1331576 0 None None None Never

Description Adrian Likins 2015-03-02 15:49:52 UTC
Description of problem:

The tz.tzstr() class fails on some timezone strings, including 'EST5EDT' which is straight from the documentation at
https://dateutil.readthedocs.org/en/latest/examples.html#tzstr-examples


https://bugs.launchpad.net/dateutil/+bug/1331576 is the upstream bug for this.

Found while trying to address https://bugzilla.redhat.com/show_bug.cgi?id=1183382

One of our unittests uses:

mock_tz.return_value = tzstr('EST5EDT')

which fails with:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/freezegun/api.py", line 244, in wrapper
    result = func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/adrian/src/subscription-manager/test/test_format_time.py", line 30, in test_system_dst
    mock_tz.return_value = tzstr('EST5EDT')
  File "/usr/lib/python2.7/site-packages/dateutil/tz.py", line 595, in __init__
    res = parser._parsetz(s)
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 923, in _parsetz
    return DEFAULTTZPARSER.parse(tzstr)
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 767, in parse
    l = _timelex.split(tzstr)
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 139, in split
    return list(cls(s))
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 136, in next
    return self.__next__()  # Python 2.x support
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 130, in __next__
    token = self.get_token()
  File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 61, in get_token
    nextchar = self.instream.read(1)
AttributeError: 'str' object has no attribute 'read'




Version-Release number of selected component (if applicable):
python-dateutil-2.4.0-2.fc22.noarch.rpm

How reproducible:
Steps to Reproduce:

$ python
import dateutil.tz
dateutil.tz.tzstr('EST5EDT')

throws AttributeError


Additional info:

We don't use tzstr() in in the installed code, only unittests, so we could work around it, but it seems likely to impact other code.

Comment 1 Adrian Likins 2015-03-02 16:12:07 UTC
Looks like this only fails 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


So likely only fails on python2 with non unicode strings passed to tzstr()

Comment 2 Fedora Update System 2015-03-03 20:47:45 UTC
python-dateutil-2.4.0-3.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/python-dateutil-2.4.0-3.fc22

Comment 3 Fedora Update System 2015-03-04 21:09:35 UTC
Package python-dateutil-2.4.0-3.fc22:
* should fix your issue,
* was pushed to the Fedora 22 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing python-dateutil-2.4.0-3.fc22'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-3147/python-dateutil-2.4.0-3.fc22
then log in and leave karma (feedback).

Comment 4 Fedora Update System 2015-03-09 08:24:50 UTC
python-dateutil-2.4.0-3.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.