From 9939e88e16c95526c6a61db45fb0a1a31568a8a0 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:45:38 +0100 Subject: Use utils.json_loads in tmv, targs and tln --- patternutils/commands/targs.py | 12 ++++-------- patternutils/commands/tln.py | 12 ++++-------- patternutils/commands/tmv.py | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 6478377..5c5a063 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -80,14 +80,10 @@ def targs( verbose: bool, ) -> None: - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index b70ce32..0dec44b 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -101,14 +101,10 @@ def tln( verbose: bool, ) -> None: - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 4e93ff4..1f39cc0 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -99,14 +99,10 @@ def tmv( the templating engine to generate the new filename. """ - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: -- cgit v1.3.1