Skip to content

Commit

Permalink
add kwargs to only non-rb mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Jan 7, 2020
1 parent 529e995 commit 3981527
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/metpy/io/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ def open_as_needed(filename, mode='rb'):
if hasattr(filename, 'read'):
return filename

kwargs = {'errors': 'surrogateescape'} if mode is not 'rb' else {}
if filename.endswith('.bz2'):
return bz2.BZ2File(filename, mode)
elif filename.endswith('.gz'):
return gzip.GzipFile(filename, mode)
else:
return open(filename, mode, errors='surrogateescape')
return open(filename, mode, **kwargs)


class NamedStruct(Struct):
Expand Down

0 comments on commit 3981527

Please sign in to comment.