Skip to content
Myr

Make click.echo()'s 'nl=True' thread-safe

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #340.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 2324202 · Browse files · 2 files+9 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−4 removed

  • other:+9 added−4 removed

2 files+9 added−4 removed

modified:click/utils.py+7 added-4 removed
273 unmodified lines
274 # Convert non bytes/text into the native string type.275 if message is not None and not isinstance(message, echo_native_types):276 message = text_type(message)277278 if nl:279 message = message or u''280 if isinstance(message, text_type):281 message += u'\n'282 else:283 message += b'\n'284285 # If there is a message, and we're in Python 3, and the value looks286 # like bytes, we manually need to find the binary stream and write the287 # message in there. This is done separately so that most stream288 # types will work as you would expect. Eg: you can write to StringIO
2 unmodified lines
291 binary_file = _find_binary_writer(file)292 if binary_file is not None:293 file.flush()294 binary_file.write(message)288 if nl:289 binary_file.write(b'\n')295 binary_file.flush()296 return297298 # ANSI-style support. If there is no message or we are dealing with
12 unmodified lines
311 message = strip_ansi(message)312313 if message:314 file.write(message)310 if nl:311 file.write(u'\n')315 file.flush()316317318def get_binary_stream(name):
131 unmodified lines
modified:CHANGES+2 added
16 unmodified lines
17- added `get_current_context`.18- added a `meta` dictionary to the context which is shared across the19 linked list of contexts to allow click utilities to place state there.20- introduced `Context.scope`.21- The `echo` function is now threadsafe: It calls the `write` method of the22 underlying object only once.2324Version 4.125-----------26
221 unmodified lines