Skip to content

Commit 920b8d6

Browse files
committed
Avoid KeyError if a product metadata doesn't have a namespace
1 parent 83f1cca commit 920b8d6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

eoreader/products/sar/rcm_product.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _set_product_type(self) -> None:
228228
"""Set products type"""
229229
# Get MTD XML file
230230
root, nsmap = self.read_mtd()
231-
namespace = nsmap[None]
231+
namespace = nsmap.get(None, "")
232232

233233
# Open identifier
234234
prod_type = root.findtext(f".//{namespace}productType")
@@ -263,7 +263,7 @@ def _set_sensor_mode(self) -> None:
263263
"""
264264
# Get metadata
265265
root, nsmap = self.read_mtd()
266-
namespace = nsmap[None]
266+
namespace = nsmap.get(None, "")
267267

268268
# Get sensor mode
269269
# WARNING: this word may differ from the Enum !!! (no docs available)
@@ -303,7 +303,7 @@ def get_datetime(self, as_datetime: bool = False) -> Union[str, datetime]:
303303
"""
304304
# Get MTD XML file
305305
root, nsmap = self.read_mtd()
306-
namespace = nsmap[None]
306+
namespace = nsmap.get(None, "")
307307

308308
# Open identifier
309309
acq_date = root.findtext(f".//{namespace}rawDataStartTime")
@@ -426,7 +426,7 @@ def get_orbit_direction(self) -> OrbitDirection:
426426
"""
427427
# Get MTD XML file
428428
root, nsmap = self.read_mtd()
429-
namespace = nsmap[None]
429+
namespace = nsmap.get(None, "")
430430

431431
# Get the orbit direction
432432
try:

eoreader/products/sar/rs2_product.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def _pre_init(self, **kwargs) -> None:
379379

380380
# SNAP can process non-complex archive
381381
root, nsmap = self.read_mtd()
382-
namespace = nsmap[None]
382+
namespace = nsmap.get(None, "")
383383

384384
# Open identifier
385385
prod_type = root.findtext(f".//{namespace}productType")
@@ -458,7 +458,7 @@ def _set_sensor_mode(self) -> None:
458458
"""
459459
# Get metadata
460460
root, nsmap = self.read_mtd()
461-
namespace = nsmap[None]
461+
namespace = nsmap.get(None, "")
462462

463463
# Get sensor mode
464464
# WARNING: this word may differ from the Enum !!! (no docs available)
@@ -499,7 +499,7 @@ def get_datetime(self, as_datetime: bool = False) -> Union[str, datetime]:
499499
if self.datetime is None:
500500
# Get MTD XML file
501501
root, nsmap = self.read_mtd()
502-
namespace = nsmap[None]
502+
namespace = nsmap.get(None, "")
503503

504504
# Open identifier
505505
acq_date = root.findtext(f".//{namespace}rawDataStartTime")
@@ -596,7 +596,7 @@ def get_orbit_direction(self) -> OrbitDirection:
596596
"""
597597
# Get MTD XML file
598598
root, nsmap = self.read_mtd()
599-
namespace = nsmap[None]
599+
namespace = nsmap.get(None, "")
600600

601601
# Get the orbit direction
602602
try:

0 commit comments

Comments
 (0)