Skip to content

Commit

Permalink
Rearrange code to easier see patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 11, 2023
1 parent ce5a71e commit 86fb9a9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
98 changes: 49 additions & 49 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,28 @@ def etree_element(
verbosity: Verbosity = Verbosity.normal,
) -> Element:
element = super().etree_element(precision=precision, verbosity=verbosity)
if self._times is not None:
element.append(self._times.etree_element())
if self._atom_link is not None:
element.append(self._atom_link.etree_element())
if self._atom_author is not None:
element.append(self._atom_author.etree_element())
if self.extended_data is not None:
element.append(self.extended_data.etree_element())
if self._view is not None:
element.append(self._view.etree_element())
if self._style_url is not None:
element.append(self._style_url.etree_element())
for style in self.styles():
element.append(style.etree_element())
if self.snippet:
snippet = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}Snippet",
)
snippet.text = self.snippet.text
if self.snippet.max_lines:
snippet.set("maxLines", str(self.snippet.max_lines))
if self.name:
name = config.etree.SubElement( # type: ignore[attr-defined]
element,
Expand All @@ -302,8 +324,6 @@ def etree_element(
f"{self.ns}description",
)
description.text = self.description
if self._view is not None:
element.append(self._view.etree_element())
if self.visibility is not None:
visibility = config.etree.SubElement( # type: ignore[attr-defined]
element,
Expand All @@ -316,26 +336,6 @@ def etree_element(
f"{self.ns}open",
)
isopen.text = str(int(self.isopen))
if self._style_url is not None:
element.append(self._style_url.etree_element())
for style in self.styles():
element.append(style.etree_element())
if self.snippet:
snippet = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}Snippet",
)
snippet.text = self.snippet.text
if self.snippet.max_lines:
snippet.set("maxLines", str(self.snippet.max_lines))
elif self._times is not None:
element.append(self._times.etree_element())
if self._atom_link is not None:
element.append(self._atom_link.etree_element())
if self._atom_author is not None:
element.append(self._atom_author.etree_element())
if self.extended_data is not None:
element.append(self.extended_data.etree_element())
if self._address is not None:
address = config.etree.SubElement( # type: ignore[attr-defined]
element,
Expand Down Expand Up @@ -367,18 +367,6 @@ def _get_kwargs(
)
name_spaces = kwargs["name_spaces"]
assert name_spaces is not None
name = element.find(f"{ns}name")
if name is not None:
kwargs["name"] = name.text
description = element.find(f"{ns}description")
if description is not None:
kwargs["description"] = description.text
visibility = element.find(f"{ns}visibility")
if visibility is not None and visibility.text:
kwargs["visibility"] = visibility.text in ["1", "true"]
isopen = element.find(f"{ns}open")
if isopen is not None:
kwargs["isopen"] = isopen.text in ["1", "true"]
style_url = element.find(f"{ns}styleUrl")
if style_url is not None:
kwargs["style_url"] = StyleUrl.class_from_element(
Expand Down Expand Up @@ -410,15 +398,6 @@ def _get_kwargs(
strict=strict,
),
)
snippet = element.find(f"{ns}Snippet")
if snippet is not None:
max_lines = snippet.get("maxLines")
if max_lines is not None:
kwargs["snippet"] = Snippet(text=snippet.text, max_lines=int(max_lines))
else:
kwargs["snippet"] = Snippet( # type: ignore[unreachable]
text=snippet.text,
)
timespan = element.find(f"{ns}TimeSpan")
if timespan is not None:
kwargs["times"] = TimeSpan.class_from_element(
Expand Down Expand Up @@ -459,12 +438,6 @@ def _get_kwargs(
element=extended_data,
strict=strict,
)
address = element.find(f"{ns}address")
if address is not None:
kwargs["address"] = address.text
phone_number = element.find(f"{ns}phoneNumber")
if phone_number is not None:
kwargs["phone_number"] = phone_number.text
camera = element.find(f"{ns}Camera")
if camera is not None:
kwargs["view"] = Camera.class_from_element(
Expand All @@ -481,6 +454,33 @@ def _get_kwargs(
element=lookat,
strict=strict,
)
name = element.find(f"{ns}name")
if name is not None:
kwargs["name"] = name.text
description = element.find(f"{ns}description")
if description is not None:
kwargs["description"] = description.text
visibility = element.find(f"{ns}visibility")
if visibility is not None and visibility.text:
kwargs["visibility"] = visibility.text in ["1", "true"]
isopen = element.find(f"{ns}open")
if isopen is not None:
kwargs["isopen"] = isopen.text in ["1", "true"]
address = element.find(f"{ns}address")
if address is not None:
kwargs["address"] = address.text
phone_number = element.find(f"{ns}phoneNumber")
if phone_number is not None:
kwargs["phone_number"] = phone_number.text
snippet = element.find(f"{ns}Snippet")
if snippet is not None:
max_lines = snippet.get("maxLines")
if max_lines is not None:
kwargs["snippet"] = Snippet(text=snippet.text, max_lines=int(max_lines))
else:
kwargs["snippet"] = Snippet( # type: ignore[unreachable]
text=snippet.text,
)
return kwargs


Expand Down
30 changes: 15 additions & 15 deletions fastkml/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,18 @@ def etree_element(
verbosity: Verbosity = Verbosity.normal,
) -> Element:
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.rotation is not None:
rotation = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}rotation",
)
rotation.text = str(self.rotation)
if self.view_volume:
element.append(self.view_volume.etree_element())
if self.image_pyramid:
element.append(self.image_pyramid.etree_element())
if self.point:
element.append(self.point.etree_element())
if self.rotation is not None:
rotation = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}rotation",
)
rotation.text = str(self.rotation)
if self.shape:
shape = config.etree.SubElement( # type: ignore[attr-defined]
element,
Expand All @@ -612,9 +612,6 @@ def _get_kwargs(
element=element,
strict=strict,
)
rotation = element.find(f"{ns}rotation")
if rotation is not None:
kwargs["rotation"] = float(rotation.text)
view_volume = element.find(f"{ns}ViewVolume")
if view_volume is not None:
kwargs["view_volume"] = cast(
Expand Down Expand Up @@ -648,6 +645,9 @@ def _get_kwargs(
strict=strict,
),
)
rotation = element.find(f"{ns}rotation")
if rotation is not None:
kwargs["rotation"] = float(rotation.text)
shape = element.find(f"{ns}shape")
if shape is not None:
kwargs["shape"] = Shape(shape.text)
Expand Down Expand Up @@ -883,12 +883,12 @@ def etree_element(
f"{self.ns}altitude",
)
altitude.text = str(self.altitude)
if self.altitude_mode:
altitude_mode = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}altitudeMode",
)
altitude_mode.text = self.altitude_mode.value
if self.altitude_mode:
altitude_mode = config.etree.SubElement( # type: ignore[attr-defined]
element,
f"{self.ns}altitudeMode",
)
altitude_mode.text = self.altitude_mode.value
if self.lat_lon_box:
element.append(self.lat_lon_box.etree_element())
return element
Expand Down
2 changes: 1 addition & 1 deletion fastkml/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_kwargs(


@dataclass(frozen=True)
class HotSpot:
class HotSpot: # XXX, make this a _XMLObject
x: float
y: float
xunits: Units
Expand Down

0 comments on commit 86fb9a9

Please sign in to comment.