Skip to content

Commit

Permalink
Make fd/file_chunk_consumer respect decode_errors
Browse files Browse the repository at this point in the history
This fixes the example I provided at
#556 (comment)
by making fd/file_chunk_consumer respect decode_errors just like the
other consumers.
  • Loading branch information
felixonmars authored and amoffat committed Feb 8, 2023
1 parent 3e5e9a4 commit 95f60ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ def determine_how_to_feed_output(handler, encoding, decode_errors):
process, finish = get_stringio_chunk_consumer(handler, encoding, decode_errors)

elif hasattr(handler, "write"):
process, finish = get_file_chunk_consumer(handler)
process, finish = get_file_chunk_consumer(handler, decode_errors)

else:
try:
Expand All @@ -2991,21 +2991,21 @@ def finish():
return None # noqa: E731

else:
process, finish = get_fd_chunk_consumer(handler)
process, finish = get_fd_chunk_consumer(handler, decode_errors)

return process, finish


def get_fd_chunk_consumer(handler):
def get_fd_chunk_consumer(handler, decode_errors):
handler = fdopen(handler, "w", closefd=False)
return get_file_chunk_consumer(handler)
return get_file_chunk_consumer(handler, decode_errors)


def get_file_chunk_consumer(handler):
def get_file_chunk_consumer(handler, decode_errors):
if getattr(handler, "encoding", None):

def encode(chunk):
return chunk.decode(handler.encoding) # noqa: E731
return chunk.decode(handler.encoding, decode_errors) # noqa: E731

else:

Expand Down

0 comments on commit 95f60ea

Please sign in to comment.