Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Vadim Markovtsev <[email protected]>
  • Loading branch information
vmarkovtsev committed Feb 23, 2019
1 parent 32046bd commit 52845b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions smart_open/smart_open_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,15 @@ def _open_binary_stream(uri, mode, **kw):
return smart_open_s3.open(uri.bucket.name, uri.name, mode, **kw), uri.name
elif _is_stream(uri, mode):
# simply pass-through if already a file-like
# we need to return something as the file name, but we don't know what
# so we probe for uri.name (e.g., this works with tempfile.NamedTemporaryFile)
# if the value ends with COMPRESSED_EXT, we will note it in _compression_wrapper()
# if there is no such an attribute, we return "unknown" - this effectively disables
# any compression (the actual string does not matter ofc)
filename = getattr(uri, 'name', 'unknown')
return uri, filename
else:
raise TypeError('don\'t know how to handle uri %s' % repr(uri))
raise TypeError("don't know how to handle uri %r in mode %r" % (uri, mode))


def _is_stream(fileobj, mode):
Expand All @@ -405,7 +410,7 @@ def _is_stream(fileobj, mode):
if mode[0] in ('w', 'a'):
return has_write
# we should never get here
return False
assert False


def _s3_open_uri(parsed_uri, mode, **kwargs):
Expand Down

0 comments on commit 52845b9

Please sign in to comment.