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 committed Oct 19, 2022
1 parent 76017a9 commit 5c7a65e
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 @@ -2902,7 +2902,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 @@ -2911,19 +2911,19 @@ def determine_how_to_feed_output(handler, encoding, decode_errors):
def process(chunk): return False # noqa: E731
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
def encode(chunk): return chunk.decode(handler.encoding, decode_errors) # noqa: E731
else:
def encode(chunk): return chunk # noqa: E731

Expand Down

0 comments on commit 5c7a65e

Please sign in to comment.