utils.py
This file
Path
click/utils.py
26 lines · 681 bytes · Python
Last changed by
Split up click into a packageArmin Ronacherbefore adoption0ed40c8
History of this fileTake it
1import sys23from ._compat import PY2, text_type456def safecall(func):7 """Wraps a function so that it swallows exceptions."""8 def wrapper(*args, **kwargs):9 try:10 return func(*args, **kwargs)11 except Exception:12 pass13 return wrapper141516def echo(message=None, file=None):17 """Prints a message to the given file or stdout."""18 if file is None:19 file = sys.stdout20 if message:21 if PY2 and isinstance(message, text_type):22 message = message.encode(getattr(file, 'encoding', None)23 or 'utf-8', 'replace')24 file.write(message)25 file.write('\n')26 file.flush()