mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 10:24:38 +08:00
Merge branch 'release_19.09' into release_20.01
This commit is contained in:
@@ -64,15 +64,20 @@ def stream_to_open_named_file(stream, fd, filename, source_encoding=None, source
|
||||
codecs.lookup(target_encoding)
|
||||
except Exception:
|
||||
target_encoding = util.DEFAULT_ENCODING # utf-8
|
||||
use_source_encoding = source_encoding is not None
|
||||
while True:
|
||||
chunk = stream.read(CHUNK_SIZE)
|
||||
if not chunk:
|
||||
break
|
||||
if source_encoding is not None:
|
||||
if use_source_encoding:
|
||||
# If a source encoding is given we use it to convert to the target encoding
|
||||
if not isinstance(chunk, text_type):
|
||||
chunk = chunk.decode(source_encoding, source_error)
|
||||
os.write(fd, chunk.encode(target_encoding, target_error))
|
||||
try:
|
||||
if not isinstance(chunk, text_type):
|
||||
chunk = chunk.decode(source_encoding, source_error)
|
||||
os.write(fd, chunk.encode(target_encoding, target_error))
|
||||
except UnicodeDecodeError:
|
||||
use_source_encoding = False
|
||||
os.write(fd, chunk)
|
||||
else:
|
||||
# Compressed files must be encoded after they are uncompressed in the upload utility,
|
||||
# while binary files should not be encoded at all.
|
||||
|
||||
Reference in New Issue
Block a user