Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call .decode() only for binary data #1060

Merged
merged 1 commit into from May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1060.misc.rst
@@ -0,0 +1 @@
Simplify handling of bytes and bytearray in _parser._timelex. Reported and fixed by @frenzymadness (gh issue #1060).
10 changes: 2 additions & 8 deletions dateutil/parser/_parser.py
Expand Up @@ -60,14 +60,8 @@ class _timelex(object):
_split_decimal = re.compile("([.,])")

def __init__(self, instream):
if six.PY2:
# In Python 2, we can't duck type properly because unicode has
# a 'decode' function, and we'd be double-decoding
if isinstance(instream, (bytes, bytearray)):
instream = instream.decode()
else:
if getattr(instream, 'decode', None) is not None:
instream = instream.decode()
if isinstance(instream, (bytes, bytearray)):
frenzymadness marked this conversation as resolved.
Show resolved Hide resolved
instream = instream.decode()

if isinstance(instream, text_type):
instream = StringIO(instream)
Expand Down