Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_write_and_truncate_functions(output):
if output is None:
def write(s):
stderr = sys.stderr
try:
stderr.write(s)
except UnicodeEncodeError:
# God damn Python 2
stderr.write(utils.shitcode(s))
truncate = None
elif isinstance(output, (pycompat.PathLike, str)):
def write(s):
with open(six.text_type(output), 'a') as output_file:
output_file.write(s)
def truncate():
with open(six.text_type(output), 'w') as output_file:
pass
elif callable(output):
write = output
truncate = None
else:
assert isinstance(output, utils.WritableStream)
def write(s):
output.write(s)
truncate = None
return (write, truncate)