From 40b493eb9be4dba3c9f45e61706070bb2f5ec5c0 Mon Sep 17 00:00:00 2001 From: Alan Yee Date: Mon, 25 Nov 2019 10:43:17 -0800 Subject: [PATCH] Update main.py -Avoid the use of dangerous default values -Send print statement into stderr -Use sys.exit instead of exit --- chevron/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chevron/main.py b/chevron/main.py index 35934ee..545b1c2 100755 --- a/chevron/main.py +++ b/chevron/main.py @@ -16,12 +16,13 @@ except (ValueError, SystemError): # python 2 from metadata import version -def main(template, data={}, **kwargs): +def main(template, data=None, **kwargs): with io.open(template, 'r', encoding='utf-8') as template_file: - if data != {}: - data_file = io.open(data, 'r', encoding='utf-8') - data = json.load(data_file) - data_file.close() + if data is not None: + with io.open(data, 'r', encoding='utf-8') as data_file: + data = json.load(data_file) + else: + data = {} args = { 'template': template_file, @@ -85,8 +86,7 @@ def cli_main(): sys.stdout.flush() except SyntaxError as e: print('Chevron: syntax error') - print(' ' + '\n '.join(e.args[0].split('\n'))) - exit(1) + sys.exit(' ' + '\n '.join(e.args[0].split('\n'))) if __name__ == '__main__': -- 2.47.3