diff --git a/planet/api/_fatomic.py b/planet/api/_fatomic.py index 324dd8f84..3f1c17038 100644 --- a/planet/api/_fatomic.py +++ b/planet/api/_fatomic.py @@ -52,7 +52,8 @@ def atomic_open(filename, mode, *args, **kwargs): dir=os.path.dirname(filename), suffix='.tmp', delete=False) - _discard = [False] + # track: explicitly discarded, normal/abnormal completion + _discard = [None] try: if mode[0] == 'a': try: @@ -63,17 +64,18 @@ def atomic_open(filename, mode, *args, **kwargs): pass def discard(self, _discard=_discard): + # explicit discard _discard[0] = True f.discard = types.MethodType(discard, f) yield f - # ischneider addition to fatomic - catch/raise any exception thrown in with + # normal completion + if not _discard[0]: + _discard[0] = False # block and force discarding - except: - _discard = [True] - raise finally: f.close() - if _discard[0]: + # if we didn't complete or were aborted, delete + if _discard[0] is None or _discard[0]: os.unlink(f.name) else: _replace_file(f.name, filename) diff --git a/planet/api/downloader.py b/planet/api/downloader.py index ae4d50412..ad17f02d6 100644 --- a/planet/api/downloader.py +++ b/planet/api/downloader.py @@ -19,7 +19,7 @@ from planet.api.exceptions import RequestCancelled try: import Queue as queue -except: +except ImportError: # renamed in 3 import queue diff --git a/planet/scripts/item_asset_types.py b/planet/scripts/item_asset_types.py index b1968dad0..f6a76835e 100644 --- a/planet/scripts/item_asset_types.py +++ b/planet/scripts/item_asset_types.py @@ -11,7 +11,7 @@ # In case the API fails to respond or takes too long. DEFAULT_ITEM_TYPES = [ "PSScene4Band", "PSScene3Band", "REScene", "SkySatScene", - "REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G"] + "REOrthoTile", "Sentinel2L1C", "PSOrthoTile", "Landsat8L1G", "Sentinel1"] DEFAULT_ASSET_TYPES = [ "analytic", "analytic_b1", "analytic_b10", "analytic_b11", "analytic_b12", @@ -43,20 +43,16 @@ def _get_json_or_raise(url, timeout=0.7): def get_item_types(): global _item_types if _item_types is None: - try: - data = _get_json_or_raise(ITEM_TYPE_URL) - _item_types = [it['id'] for it in data['item_types']] - except: - _item_types = DEFAULT_ITEM_TYPES + _item_types = DEFAULT_ITEM_TYPES + data = _get_json_or_raise(ITEM_TYPE_URL) + _item_types = [it['id'] for it in data['item_types']] return _item_types def get_asset_types(): global _asset_types if _asset_types is None: - try: - data = _get_json_or_raise(ASSET_TYPE_URL) - _asset_types = [a['id'] for a in data['asset_types']] - except: - _asset_types = DEFAULT_ASSET_TYPES + _asset_types = DEFAULT_ASSET_TYPES + data = _get_json_or_raise(ASSET_TYPE_URL) + _asset_types = [a['id'] for a in data['asset_types']] return _asset_types diff --git a/tests/test_atomic.py b/tests/test_atomic.py index 79e53d0a3..683f2aaf3 100644 --- a/tests/test_atomic.py +++ b/tests/test_atomic.py @@ -37,7 +37,7 @@ def assert_content_is(expected): with atomic_open(outfile, 'w') as fp: fp.write('bazzy') raise Exception('drat') - except: + except Exception: assert_content_is('bar') else: assert False diff --git a/tests/test_types.py b/tests/test_types.py index 583630e7b..d2a7ed9f2 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -33,7 +33,8 @@ def test_item_type(): check('all', get_item_types()) check('psscene', ['PSScene3Band', 'PSScene4Band']) check('Sentinel2L1C', ['Sentinel2L1C']) - check('psscene,sent', ['PSScene3Band', 'PSScene4Band', 'Sentinel2L1C']) + check('psscene,sent', ['PSScene3Band', 'PSScene4Band', + 'Sentinel1', 'Sentinel2L1C']) with pytest.raises(Exception) as e: ItemType().convert('x', None, None) diff --git a/tests/test_v1_cli.py b/tests/test_v1_cli.py index da6337c00..8b5608371 100644 --- a/tests/test_v1_cli.py +++ b/tests/test_v1_cli.py @@ -39,7 +39,7 @@ def assert_success(result, expected_output, exit_code=0): pass try: assert json.loads(result.output) == expected_output - except: + except ValueError: assert result.output == expected_output