Skip to content

Commit

Permalink
Update subelement_float_kwarg function in helpers.py and links.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 20, 2023
1 parent fc183b7 commit 77921b8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
17 changes: 17 additions & 0 deletions fastkml/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ def subelement_bool_kwarg(
return {}


def subelement_float_kwarg(
*,
element: Element,
ns: str,
node_name: str,
kwarg: str,
precision: Optional[int],
strict: bool,
) -> Dict[str, float]:
node = element.find(f"{ns}{node_name}")
if node is None:
return {}
if node.text and node.text.strip():
return {kwarg: float(node.text.strip())}
return {}


def subelement_enum_kwarg(
*,
element: Element,
Expand Down
63 changes: 42 additions & 21 deletions fastkml/links.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2022 Christian Ledermann
# Copyright (C) 2012-2023 Christian Ledermann
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
Expand All @@ -14,7 +14,6 @@
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import contextlib
from typing import Any
from typing import Dict
from typing import Optional
Expand All @@ -27,6 +26,7 @@
from fastkml.helpers import float_subelement
from fastkml.helpers import simple_text_subelement
from fastkml.helpers import subelement_enum_kwarg
from fastkml.helpers import subelement_float_kwarg
from fastkml.helpers import subelement_text_kwarg
from fastkml.types import Element

Expand Down Expand Up @@ -185,25 +185,46 @@ def _get_kwargs(
strict=strict,
),
)

refresh_mode = element.find(f"{ns}refreshMode")
if refresh_mode is not None:
kwargs["refresh_mode"] = RefreshMode(refresh_mode.text)
refresh_interval = element.find(f"{ns}refreshInterval")
if refresh_interval is not None:
with contextlib.suppress(ValueError):
kwargs["refresh_interval"] = float(refresh_interval.text)
view_refresh_mode = element.find(f"{ns}viewRefreshMode")
if view_refresh_mode is not None:
kwargs["view_refresh_mode"] = ViewRefreshMode(view_refresh_mode.text)
view_refresh_time = element.find(f"{ns}viewRefreshTime")
if view_refresh_time is not None:
with contextlib.suppress(ValueError):
kwargs["view_refresh_time"] = float(view_refresh_time.text)
view_bound_scale = element.find(f"{ns}viewBoundScale")
if view_bound_scale is not None:
with contextlib.suppress(ValueError):
kwargs["view_bound_scale"] = float(view_bound_scale.text)
kwargs.update(
subelement_enum_kwarg(
element=element,
ns=ns,
node_name="viewRefreshMode",
kwarg="view_refresh_mode",
enum_class=ViewRefreshMode,
strict=strict,
),
)
kwargs.update(
subelement_float_kwarg(
element=element,
ns=ns,
node_name="refreshInterval",
kwarg="refresh_interval",
precision=None,
strict=strict,
),
)
kwargs.update(
subelement_float_kwarg(
element=element,
ns=ns,
node_name="viewRefreshTime",
kwarg="view_refresh_time",
precision=None,
strict=strict,
),
)
kwargs.update(
subelement_float_kwarg(
element=element,
ns=ns,
node_name="viewBoundScale",
kwarg="view_bound_scale",
precision=None,
strict=strict,
),
)
return kwargs


Expand Down

0 comments on commit 77921b8

Please sign in to comment.