]> Devi Nivas Git - chevron.git/commitdiff
Update main.py
authorAlan Yee <alanyee@users.noreply.github.com>
Mon, 25 Nov 2019 18:43:17 +0000 (10:43 -0800)
committerGitHub <noreply@github.com>
Mon, 25 Nov 2019 18:43:17 +0000 (10:43 -0800)
-Avoid the use of dangerous default values
-Send print statement into stderr
-Use sys.exit instead of exit

chevron/main.py

index 35934ee6ff4f6128e49b167b417fc318d378878c..545b1c206b70c84f97c555ffbb7802d297e72e7a 100755 (executable)
@@ -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__':