Skip to content

Commit

Permalink
Avoid KeyError if a product metadata doesn't have a namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jteulade committed Jun 3, 2024
1 parent b79ed4f commit 0acdf1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions eoreader/products/sar/rcm_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _set_product_type(self) -> None:
"""Set products type"""
# Get MTD XML file
root, nsmap = self.read_mtd()
namespace = nsmap[None]
namespace = nsmap.get(None, "")

# Open identifier
prod_type = root.findtext(f".//{namespace}productType")
Expand Down Expand Up @@ -263,7 +263,7 @@ def _set_sensor_mode(self) -> None:
"""
# Get metadata
root, nsmap = self.read_mtd()
namespace = nsmap[None]
namespace = nsmap.get(None, "")

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

# Open identifier
acq_date = root.findtext(f".//{namespace}rawDataStartTime")
Expand Down Expand Up @@ -426,7 +426,7 @@ def get_orbit_direction(self) -> OrbitDirection:
"""
# Get MTD XML file
root, nsmap = self.read_mtd()
namespace = nsmap[None]
namespace = nsmap.get(None, "")

# Get the orbit direction
try:
Expand Down
8 changes: 4 additions & 4 deletions eoreader/products/sar/rs2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def _pre_init(self, **kwargs) -> None:

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

# Open identifier
prod_type = root.findtext(f".//{namespace}productType")
Expand Down Expand Up @@ -458,7 +458,7 @@ def _set_sensor_mode(self) -> None:
"""
# Get metadata
root, nsmap = self.read_mtd()
namespace = nsmap[None]
namespace = nsmap.get(None, "")

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

# Open identifier
acq_date = root.findtext(f".//{namespace}rawDataStartTime")
Expand Down Expand Up @@ -596,7 +596,7 @@ def get_orbit_direction(self) -> OrbitDirection:
"""
# Get MTD XML file
root, nsmap = self.read_mtd()
namespace = nsmap[None]
namespace = nsmap.get(None, "")

# Get the orbit direction
try:
Expand Down

0 comments on commit 0acdf1c

Please sign in to comment.