diff options
| author | Dennis Fink | 2020-12-12 15:45:38 +0100 |
|---|---|---|
| committer | Dennis Fink | 2020-12-12 15:45:38 +0100 |
| commit | 9939e88e16c95526c6a61db45fb0a1a31568a8a0 (patch) | |
| tree | 1b68e035c3d3d1363fe5316791e5261319a38349 | |
| parent | 0748d7011016d42c6968eb70c24a6630203b93c2 (diff) | |
| download | patternutils-9939e88e16c95526c6a61db45fb0a1a31568a8a0.tar.gz patternutils-9939e88e16c95526c6a61db45fb0a1a31568a8a0.zip | |
Use utils.json_loads in tmv, targs and tln
Diffstat (limited to '')
| -rw-r--r-- | patternutils/commands/targs.py | 12 | ||||
| -rw-r--r-- | patternutils/commands/tln.py | 12 | ||||
| -rw-r--r-- | 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: |
