From e8dd1d061114080f94949966f09a1ca611894e14 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Fri, 22 Nov 2024 13:55:24 -0500
Subject: [PATCH 1/8] Network LInk Control
---
fastkml/__init__.py | 1 +
fastkml/containers.py | 87 ++++++++++++++++++++++++++++++
fastkml/features.py | 121 +++++++++++++++++++++++++++++++++++++++++-
fastkml/kml.py | 7 +--
fastkml/times.py | 5 ++
fastkml/update.py | 36 +++++++++++++
6 files changed, 253 insertions(+), 4 deletions(-)
create mode 100644 fastkml/update.py
diff --git a/fastkml/__init__.py b/fastkml/__init__.py
index b607e08f..38a11805 100644
--- a/fastkml/__init__.py
+++ b/fastkml/__init__.py
@@ -61,6 +61,7 @@
__all__ = [
"KML",
+ "NetworkLinkControl"
"Document",
"Folder",
"GroundOverlay",
diff --git a/fastkml/containers.py b/fastkml/containers.py
index 5041d219..40acd84f 100644
--- a/fastkml/containers.py
+++ b/fastkml/containers.py
@@ -47,9 +47,12 @@
from fastkml.styles import StyleMap
from fastkml.styles import StyleUrl
from fastkml.times import TimeSpan
+from fastkml.times import KmlDateTime
from fastkml.times import TimeStamp
+from fastkml.update import Update
from fastkml.utils import find_all
from fastkml.views import Camera
+from fastkml.views import _AbstractView
from fastkml.views import LookAt
from fastkml.views import Region
@@ -323,6 +326,79 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
)
+class NetworkLinkControl(_Container):
+
+ schemata: List[Schema]
+
+ def __init__(
+ self,
+ ns: Optional[str] = None,
+ name_spaces: Optional[Dict[str, str]] = None,
+ id: Optional[str] = None,
+ target_id: Optional[str] = None,
+ min_refresh_period: Optional[float] = None,
+ max_session_length: Optional[float] = None,
+ cookie: Optional[str] = None,
+ message: Optional[str] = None,
+ link_name: Optional[str] = None,
+ link_description: Optional[str] = None,
+ link_snippet: Optional[str] = None,
+ expires: Optional[KmlDateTime] = None,
+ update:Optional[Update] = None,
+ view: Optional[Union[Camera, LookAt]] = None,
+ schemata: Optional[Iterable[Schema]] = None,
+ **kwargs: Any
+ ) -> None:
+ super().__init__(
+ ns=ns,
+ name_spaces=name_spaces,
+ id=id,
+ target_id=target_id,
+ min_refresh_period=min_refresh_period,
+ max_session_length=max_session_length,
+ cookie=cookie,
+ message=message,
+ link_name=link_name,
+ link_description=link_description,
+ link_snippet=link_snippet,
+ expires=expires,
+ update=update,
+ view=view,
+ **kwargs
+ )
+ self.schemata = list(schemata) if schemata else []
+
+ def __repr__(self) -> str:
+ """
+ Return a string representation of the NetworkLinkControl object.
+
+ Returns
+ -------
+ str: A string representation of the NetworkLinkControl object.
+
+ """
+ return (
+ f"{self.__class__.__module__}.{self.__class__.__name__}("
+ f"ns={self.ns!r}, "
+ f"name_spaces={self.name_spaces!r}, "
+ f"id={self.id!r}, "
+ f"target_id={self.target_id!r}, "
+ f"min_refresh_period={self.min_refresh_period!r}, "
+ f"max_session_length={self.max_session_length!r}, "
+ f"cookie={self.cookie!r}, "
+ f"message={self.message!r}, "
+ f"link_name={self.link_name!r}, "
+ f"link_description={self.link_description!r}, "
+ f"link_snippet={self.link_snippet!r}, "
+ f"expires={self.expires!r}, "
+ f"update={self.update!r}, "
+ f"view={self.view!r}, "
+ f"schemata={self.schemata!r}, "
+ f"**{self._get_splat()!r},"
+ ")"
+ )
+
+
registry.register(
_Container,
RegistryItem(
@@ -334,6 +410,17 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
set_element=xml_subelement_list,
),
)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="schemata",
+ node_name="Schema",
+ classes=(Schema,),
+ get_kwarg=xml_subelement_list_kwarg,
+ set_element=xml_subelement_list,
+ ),
+)
registry.register(
Document,
RegistryItem(
diff --git a/fastkml/features.py b/fastkml/features.py
index f8d091a5..83beeefa 100644
--- a/fastkml/features.py
+++ b/fastkml/features.py
@@ -43,6 +43,8 @@
from fastkml.geometry import Polygon
from fastkml.geometry import create_kml_geometry
from fastkml.helpers import attribute_int_kwarg
+from fastkml.helpers import datetime_subelement
+from fastkml.helpers import datetime_subelement_kwarg
from fastkml.helpers import bool_subelement
from fastkml.helpers import clean_string
from fastkml.helpers import int_attribute
@@ -63,8 +65,9 @@
from fastkml.styles import Style
from fastkml.styles import StyleMap
from fastkml.styles import StyleUrl
-from fastkml.times import TimeSpan
+from fastkml.times import KmlDateTime, TimeSpan
from fastkml.times import TimeStamp
+from fastkml.update import Update
from fastkml.views import Camera
from fastkml.views import LookAt
from fastkml.views import Region
@@ -222,6 +225,15 @@ class _Feature(TimeMixin, _BaseObject):
view: Union[Camera, LookAt, None]
region: Optional[Region]
extended_data: Optional[ExtendedData]
+ min_refresh_period: Optional[float] = None,
+ max_session_length: Optional[float] = None,
+ cookie: Optional[str] = None,
+ message: Optional[str] = None,
+ link_name: Optional[str] = None,
+ link_description: Optional[str] = None,
+ link_snippet: Optional[str] = None,
+ expires: Optional[KmlDateTime] = None,
+ update:Optional[Update] = None,
def __init__(
self,
@@ -244,6 +256,15 @@ def __init__(
styles: Optional[Iterable[Union[Style, StyleMap]]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
+ min_refresh_period: Optional[float] = None,
+ max_session_length: Optional[float] = None,
+ cookie: Optional[str] = None,
+ message: Optional[str] = None,
+ link_name: Optional[str] = None,
+ link_description: Optional[str] = None,
+ link_snippet: Optional[str] = None,
+ expires: Optional[KmlDateTime] = None,
+ update:Optional[Update] = None,
**kwargs: Any,
) -> None:
"""
@@ -304,6 +325,15 @@ def __init__(
self.region = region
self.extended_data = extended_data
self.times = times
+ self.min_refresh_period = min_refresh_period
+ self.max_session_length = max_session_length
+ self.cookie = cookie
+ self.message = message
+ self.link_name = link_name
+ self.link_description = link_description
+ self.link_snippet = link_snippet
+ self.expires = expires
+ self.update = update
registry.register(
@@ -407,6 +437,95 @@ def __init__(
set_element=text_subelement,
),
)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="min_refresh_period",
+ node_name="minRefreshPeriod",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="max_session_length",
+ node_name="maxSessionLength",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="cookie",
+ node_name="cookie",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="message",
+ node_name="message",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_name",
+ node_name="linkName",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_description",
+ node_name="linkDescription",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_snippet",
+ node_name="linkSnippet",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _Feature,
+ item=RegistryItem(
+ ns_ids=("kml", ),
+ classes=(KmlDateTime,),
+ attr_name="expires",
+ node_name="expires",
+ get_kwarg=datetime_subelement_kwarg,
+ set_element=datetime_subelement,
+ ),
+)
+
registry.register(
_Feature,
RegistryItem(
diff --git a/fastkml/kml.py b/fastkml/kml.py
index 0886c6ba..3edba7cb 100644
--- a/fastkml/kml.py
+++ b/fastkml/kml.py
@@ -45,6 +45,7 @@
from fastkml import validator
from fastkml.base import _XMLObject
from fastkml.containers import Document
+from fastkml.containers import NetworkLinkControl
from fastkml.containers import Folder
from fastkml.enums import Verbosity
from fastkml.features import NetworkLink
@@ -59,7 +60,7 @@
logger = logging.getLogger(__name__)
-kml_children = Union[Folder, Document, Placemark, GroundOverlay, PhotoOverlay]
+kml_children = Union[Folder, Document, Placemark, GroundOverlay, PhotoOverlay, NetworkLinkControl]
def lxml_parse_and_validate(
@@ -286,8 +287,8 @@ def write(
KML,
RegistryItem(
ns_ids=("kml",),
- classes=(Document, Folder, Placemark, GroundOverlay, PhotoOverlay, NetworkLink),
- node_name="Document,Folder,Placemark,GroundOverlay,PhotoOverlay,NetworkLink",
+ classes=(Document, Folder, Placemark, GroundOverlay, PhotoOverlay, NetworkLink, NetworkLinkControl),
+ node_name="Document,Folder,Placemark,GroundOverlay,PhotoOverlay,NetworkLink,NetworkLinkControl",
attr_name="features",
get_kwarg=xml_subelement_list_kwarg,
set_element=xml_subelement_list,
diff --git a/fastkml/times.py b/fastkml/times.py
index a2f35b5f..1f3eeabd 100644
--- a/fastkml/times.py
+++ b/fastkml/times.py
@@ -189,6 +189,11 @@ def __str__(self) -> str:
else self.dt.isoformat()
)
return self.dt.isoformat()
+
+ @classmethod
+ def get_tag_name(cls) -> str:
+ """Return the tag name."""
+ return cls.__name__.lower()
@classmethod
def parse(cls, datestr: str) -> Optional["KmlDateTime"]:
diff --git a/fastkml/update.py b/fastkml/update.py
new file mode 100644
index 00000000..b73b873a
--- /dev/null
+++ b/fastkml/update.py
@@ -0,0 +1,36 @@
+from typing import Any, Dict, List, Optional
+
+from fastkml.base import _XMLObject
+
+class Change(_XMLObject):
+
+ def __int__(
+ self,
+ target_id: str,
+ elements: List[Dict[str, Any]] = None
+ ):
+ super.__init__(
+ target_id=target_id,
+ elements=elements
+ )
+
+ def parse_children(self):
+ pass
+
+class Create(_XMLObject):
+ def __init__():
+ pass
+
+class Delete(_XMLObject):
+ def __init__():
+ pass
+
+class Update:
+
+ def __init__(
+ target_href: Optional[str] = None,
+ change: Optional[Change] = None,
+ create: Optional[Create] = None,
+ delete: Optional[Delete] = None
+ ):
+ pass
From 35b6fa50162c120d3a32d371366cec2a7cafe43f Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sun, 24 Nov 2024 04:03:50 -0500
Subject: [PATCH 2/8] Creating separate class for network control
---
fastkml/containers.py | 24 +----
fastkml/features.py | 122 +-----------------------
fastkml/network_control.py | 184 +++++++++++++++++++++++++++++++++++++
fastkml/update.py | 115 +++++++++++++++++++++--
4 files changed, 293 insertions(+), 152 deletions(-)
create mode 100644 fastkml/network_control.py
diff --git a/fastkml/containers.py b/fastkml/containers.py
index 40acd84f..b45b4f45 100644
--- a/fastkml/containers.py
+++ b/fastkml/containers.py
@@ -39,6 +39,7 @@
from fastkml.geometry import Polygon
from fastkml.helpers import xml_subelement_list
from fastkml.helpers import xml_subelement_list_kwarg
+from fastkml.network_control import _NetworkControl
from fastkml.overlays import GroundOverlay
from fastkml.overlays import PhotoOverlay
from fastkml.registry import RegistryItem
@@ -52,7 +53,6 @@
from fastkml.update import Update
from fastkml.utils import find_all
from fastkml.views import Camera
-from fastkml.views import _AbstractView
from fastkml.views import LookAt
from fastkml.views import Region
@@ -326,7 +326,7 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
)
-class NetworkLinkControl(_Container):
+class NetworkLinkControl(_NetworkControl):
schemata: List[Schema]
@@ -334,8 +334,6 @@ def __init__(
self,
ns: Optional[str] = None,
name_spaces: Optional[Dict[str, str]] = None,
- id: Optional[str] = None,
- target_id: Optional[str] = None,
min_refresh_period: Optional[float] = None,
max_session_length: Optional[float] = None,
cookie: Optional[str] = None,
@@ -346,14 +344,11 @@ def __init__(
expires: Optional[KmlDateTime] = None,
update:Optional[Update] = None,
view: Optional[Union[Camera, LookAt]] = None,
- schemata: Optional[Iterable[Schema]] = None,
**kwargs: Any
) -> None:
super().__init__(
ns=ns,
name_spaces=name_spaces,
- id=id,
- target_id=target_id,
min_refresh_period=min_refresh_period,
max_session_length=max_session_length,
cookie=cookie,
@@ -366,7 +361,6 @@ def __init__(
view=view,
**kwargs
)
- self.schemata = list(schemata) if schemata else []
def __repr__(self) -> str:
"""
@@ -381,8 +375,6 @@ def __repr__(self) -> str:
f"{self.__class__.__module__}.{self.__class__.__name__}("
f"ns={self.ns!r}, "
f"name_spaces={self.name_spaces!r}, "
- f"id={self.id!r}, "
- f"target_id={self.target_id!r}, "
f"min_refresh_period={self.min_refresh_period!r}, "
f"max_session_length={self.max_session_length!r}, "
f"cookie={self.cookie!r}, "
@@ -393,7 +385,6 @@ def __repr__(self) -> str:
f"expires={self.expires!r}, "
f"update={self.update!r}, "
f"view={self.view!r}, "
- f"schemata={self.schemata!r}, "
f"**{self._get_splat()!r},"
")"
)
@@ -410,17 +401,6 @@ def __repr__(self) -> str:
set_element=xml_subelement_list,
),
)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="schemata",
- node_name="Schema",
- classes=(Schema,),
- get_kwarg=xml_subelement_list_kwarg,
- set_element=xml_subelement_list,
- ),
-)
registry.register(
Document,
RegistryItem(
diff --git a/fastkml/features.py b/fastkml/features.py
index 83beeefa..07963b5b 100644
--- a/fastkml/features.py
+++ b/fastkml/features.py
@@ -43,8 +43,6 @@
from fastkml.geometry import Polygon
from fastkml.geometry import create_kml_geometry
from fastkml.helpers import attribute_int_kwarg
-from fastkml.helpers import datetime_subelement
-from fastkml.helpers import datetime_subelement_kwarg
from fastkml.helpers import bool_subelement
from fastkml.helpers import clean_string
from fastkml.helpers import int_attribute
@@ -65,9 +63,8 @@
from fastkml.styles import Style
from fastkml.styles import StyleMap
from fastkml.styles import StyleUrl
-from fastkml.times import KmlDateTime, TimeSpan
+from fastkml.times import TimeSpan
from fastkml.times import TimeStamp
-from fastkml.update import Update
from fastkml.views import Camera
from fastkml.views import LookAt
from fastkml.views import Region
@@ -225,15 +222,6 @@ class _Feature(TimeMixin, _BaseObject):
view: Union[Camera, LookAt, None]
region: Optional[Region]
extended_data: Optional[ExtendedData]
- min_refresh_period: Optional[float] = None,
- max_session_length: Optional[float] = None,
- cookie: Optional[str] = None,
- message: Optional[str] = None,
- link_name: Optional[str] = None,
- link_description: Optional[str] = None,
- link_snippet: Optional[str] = None,
- expires: Optional[KmlDateTime] = None,
- update:Optional[Update] = None,
def __init__(
self,
@@ -256,15 +244,6 @@ def __init__(
styles: Optional[Iterable[Union[Style, StyleMap]]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
- min_refresh_period: Optional[float] = None,
- max_session_length: Optional[float] = None,
- cookie: Optional[str] = None,
- message: Optional[str] = None,
- link_name: Optional[str] = None,
- link_description: Optional[str] = None,
- link_snippet: Optional[str] = None,
- expires: Optional[KmlDateTime] = None,
- update:Optional[Update] = None,
**kwargs: Any,
) -> None:
"""
@@ -325,16 +304,6 @@ def __init__(
self.region = region
self.extended_data = extended_data
self.times = times
- self.min_refresh_period = min_refresh_period
- self.max_session_length = max_session_length
- self.cookie = cookie
- self.message = message
- self.link_name = link_name
- self.link_description = link_description
- self.link_snippet = link_snippet
- self.expires = expires
- self.update = update
-
registry.register(
_Feature,
@@ -437,95 +406,6 @@ def __init__(
set_element=text_subelement,
),
)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="min_refresh_period",
- node_name="minRefreshPeriod",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="max_session_length",
- node_name="maxSessionLength",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="cookie",
- node_name="cookie",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="message",
- node_name="message",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_name",
- node_name="linkName",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_description",
- node_name="linkDescription",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_snippet",
- node_name="linkSnippet",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _Feature,
- item=RegistryItem(
- ns_ids=("kml", ),
- classes=(KmlDateTime,),
- attr_name="expires",
- node_name="expires",
- get_kwarg=datetime_subelement_kwarg,
- set_element=datetime_subelement,
- ),
-)
-
registry.register(
_Feature,
RegistryItem(
diff --git a/fastkml/network_control.py b/fastkml/network_control.py
new file mode 100644
index 00000000..312ce5f4
--- /dev/null
+++ b/fastkml/network_control.py
@@ -0,0 +1,184 @@
+# Copyright (C) 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
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+from typing import Any
+from typing import Dict
+from typing import Optional
+from typing import Union
+from fastkml.helpers import datetime_subelement
+from fastkml.helpers import datetime_subelement_kwarg
+from fastkml.helpers import subelement_text_kwarg
+from fastkml.helpers import text_subelement
+from fastkml.helpers import xml_subelement
+from fastkml.helpers import xml_subelement_kwarg
+from fastkml.registry import registry
+from fastkml.registry import RegistryItem
+from fastkml.base import _XMLObject
+from fastkml.times import KmlDateTime
+from fastkml.update import Update
+from fastkml.views import Camera, LookAt
+
+
+class _NetworkControl(_XMLObject):
+ """
+ Absrtact base class representing NetworkLinkControl in KML.
+ """
+ min_refresh_period: Optional[float]
+ max_session_length: Optional[float]
+ cookie: Optional[str]
+ message: Optional[str]
+ link_name: Optional[str]
+ link_description: Optional[str]
+ link_snippet: Optional[str]
+ expires: Optional[KmlDateTime]
+ view: Union[Camera, LookAt, None]
+ update:Optional[Update]
+
+ def __init__(
+ self,
+ ns: Optional[str] = None,
+ name_spaces: Optional[Dict[str, str]] = None,
+ min_refresh_period: Optional[float] = None,
+ max_session_length: Optional[float] = None,
+ cookie: Optional[str] = None,
+ message: Optional[str] = None,
+ link_name: Optional[str] = None,
+ link_description: Optional[str] = None,
+ link_snippet: Optional[str] = None,
+ expires: Optional[KmlDateTime] = None,
+ view: Optional[Union[Camera, LookAt]] = None,
+ update:Optional[Update] = None,
+ **kwargs: Any,
+ ):
+ super().__init__(
+ ns=ns,
+ name_spaces=name_spaces,
+ **kwargs,
+ )
+ self.min_refresh_period = min_refresh_period
+ self.max_session_length = max_session_length
+ self.cookie = cookie
+ self.message = message
+ self.link_name = link_name
+ self.link_description = link_description
+ self.link_snippet = link_snippet
+ self.expires = expires
+ self.view = view
+ self.update = update
+
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="min_refresh_period",
+ node_name="minRefreshPeriod",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="max_session_length",
+ node_name="maxSessionLength",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="cookie",
+ node_name="cookie",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="message",
+ node_name="message",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_name",
+ node_name="linkName",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_description",
+ node_name="linkDescription",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_snippet",
+ node_name="linkSnippet",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ _NetworkControl,
+ item=RegistryItem(
+ ns_ids=("kml", ),
+ classes=(KmlDateTime,),
+ attr_name="expires",
+ node_name="expires",
+ get_kwarg=datetime_subelement_kwarg,
+ set_element=datetime_subelement,
+ ),
+)
+
+registry.register(
+ _NetworkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="view",
+ node_name="Camera,LookAt",
+ classes=(
+ Camera,
+ LookAt,
+ ),
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
+ ),
+)
\ No newline at end of file
diff --git a/fastkml/update.py b/fastkml/update.py
index b73b873a..948e02a4 100644
--- a/fastkml/update.py
+++ b/fastkml/update.py
@@ -1,15 +1,41 @@
-from typing import Any, Dict, List, Optional
+# Copyright (C) 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
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+from typing import Any
+from typing import Union
+from typing import Dict
+from typing import Iterable
+from typing import List
+from typing import Optional
+# from fastkml.containers import Folder
+from fastkml.helpers import xml_subelement
+from fastkml.helpers import xml_subelement_kwarg
+from fastkml.registry import registry
+from fastkml.registry import RegistryItem
from fastkml.base import _XMLObject
+from fastkml.times import TimeSpan
class Change(_XMLObject):
def __int__(
self,
target_id: str,
- elements: List[Dict[str, Any]] = None
+ elements: Optional[Union[TimeSpan]] = None
):
- super.__init__(
+ super().__init__(
target_id=target_id,
elements=elements
)
@@ -18,19 +44,90 @@ def parse_children(self):
pass
class Create(_XMLObject):
- def __init__():
+ def __int__(
+ self,
+ target_id: str,
+ elements: Optional[Union[TimeSpan]] = None
+ ):
+ super().__init__(
+ target_id=target_id,
+ elements=elements
+ )
+
+ def parse_children(self):
pass
class Delete(_XMLObject):
- def __init__():
+ def __int__(
+ self,
+ target_id: str,
+ elements: Optional[Union[TimeSpan]] = None
+ ):
+ super().__init__(
+ target_id=target_id,
+ elements=elements
+ )
+
+ def parse_children(self):
pass
class Update:
def __init__(
target_href: Optional[str] = None,
- change: Optional[Change] = None,
- create: Optional[Create] = None,
- delete: Optional[Delete] = None
+ change: Optional[Iterable[Change]] = None,
+ create: Optional[Iterable[Create]] = None,
+ delete: Optional[Iterable[Delete]] = None
):
- pass
+ super().__init__(
+ target_href=target_href,
+ change=change,
+ create=create,
+ delete=delete
+ )
+
+registry.register(
+ Update,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="change",
+ node_name="TimeSpan",
+ classes=(
+ # PhotoOverlay,
+ # Folder,
+ TimeSpan,
+ ),
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
+ )
+)
+registry.register(
+ Update,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="create",
+ node_name="TimeSpan",
+ classes=(
+ # PhotoOverlay,
+ # Folder,
+ TimeSpan,
+ ),
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
+ )
+)
+registry.register(
+ Update,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="delete",
+ node_name="TimeSpan",
+ classes=(
+ # PhotoOverlay,
+ # Folder,
+ TimeSpan,
+ ),
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
+ )
+)
\ No newline at end of file
From 15516aedda0c1ff0a9d9d0c632e9ac55fd9d4b45 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Thu, 28 Nov 2024 20:36:02 -0500
Subject: [PATCH 3/8] requested change
---
fastkml/containers.py | 175 +++++++++++++++++++++++++++++------
fastkml/features.py | 1 +
fastkml/network_control.py | 184 -------------------------------------
fastkml/times.py | 5 -
4 files changed, 149 insertions(+), 216 deletions(-)
delete mode 100644 fastkml/network_control.py
diff --git a/fastkml/containers.py b/fastkml/containers.py
index 3a9b3984..3343bb29 100644
--- a/fastkml/containers.py
+++ b/fastkml/containers.py
@@ -25,7 +25,9 @@
from typing import Union
from fastkml import atom
+from fastkml import config
from fastkml import gx
+from fastkml.base import _XMLObject
from fastkml.data import ExtendedData
from fastkml.data import Schema
from fastkml.features import NetworkLink
@@ -37,6 +39,12 @@
from fastkml.geometry import MultiGeometry
from fastkml.geometry import Point
from fastkml.geometry import Polygon
+from fastkml.helpers import datetime_subelement
+from fastkml.helpers import datetime_subelement_kwarg
+from fastkml.helpers import subelement_text_kwarg
+from fastkml.helpers import text_subelement
+from fastkml.helpers import xml_subelement
+from fastkml.helpers import xml_subelement_kwarg
from fastkml.helpers import xml_subelement_list
from fastkml.helpers import xml_subelement_list_kwarg
from fastkml.network_control import _NetworkControl
@@ -328,11 +336,55 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
None,
)
+registry.register(
+ _Container,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="features",
+ node_name=(
+ "Folder,Placemark,Document,GroundOverlay,PhotoOverlay,ScreenOverlay,"
+ "NetworkLink"
+ ),
+ classes=(
+ Document,
+ Folder,
+ Placemark,
+ GroundOverlay,
+ PhotoOverlay,
+ ScreenOverlay,
+ NetworkLink,
+ ),
+ get_kwarg=xml_subelement_list_kwarg,
+ set_element=xml_subelement_list,
+ ),
+)
+registry.register(
+ Document,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="schemata",
+ node_name="Schema",
+ classes=(Schema,),
+ get_kwarg=xml_subelement_list_kwarg,
+ set_element=xml_subelement_list,
+ ),
+)
-class NetworkLinkControl(_NetworkControl):
+class NetworkLinkControl(_XMLObject):
+
+ _default_nsid = config.KML
+
+ min_refresh_period: Optional[float]
+ max_session_length: Optional[float]
+ cookie: Optional[str]
+ message: Optional[str]
+ link_name: Optional[str]
+ link_description: Optional[str]
+ link_snippet: Optional[str]
+ expires: Optional[KmlDateTime]
+ view: Union[Camera, LookAt, None]
+ update:Optional[Update]
- schemata: List[Schema]
-
def __init__(
self,
ns: Optional[str] = None,
@@ -392,37 +444,106 @@ def __repr__(self) -> str:
")"
)
-
registry.register(
- _Container,
+ NetworkLinkControl,
RegistryItem(
ns_ids=("kml",),
- attr_name="features",
- node_name=(
- "Folder,Placemark,Document,GroundOverlay,PhotoOverlay,ScreenOverlay,"
- "NetworkLink"
- ),
- classes=(
- Document,
- Folder,
- Placemark,
- GroundOverlay,
- PhotoOverlay,
- ScreenOverlay,
- NetworkLink,
- ),
- get_kwarg=xml_subelement_list_kwarg,
- set_element=xml_subelement_list,
+ attr_name="min_refresh_period",
+ node_name="minRefreshPeriod",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
),
)
registry.register(
- Document,
+ NetworkLinkControl,
RegistryItem(
ns_ids=("kml",),
- attr_name="schemata",
- node_name="Schema",
- classes=(Schema,),
- get_kwarg=xml_subelement_list_kwarg,
- set_element=xml_subelement_list,
+ attr_name="max_session_length",
+ node_name="maxSessionLength",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="cookie",
+ node_name="cookie",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="message",
+ node_name="message",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_name",
+ node_name="linkName",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_description",
+ node_name="linkDescription",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_snippet",
+ node_name="linkSnippet",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ item=RegistryItem(
+ ns_ids=("kml", ),
+ classes=(KmlDateTime,),
+ attr_name="expires",
+ node_name="expires",
+ get_kwarg=datetime_subelement_kwarg,
+ set_element=datetime_subelement,
),
)
+
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="view",
+ node_name="Camera,LookAt",
+ classes=(
+ Camera,
+ LookAt,
+ ),
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
+ ),
+)
\ No newline at end of file
diff --git a/fastkml/features.py b/fastkml/features.py
index f8c8e34d..e8635bd2 100644
--- a/fastkml/features.py
+++ b/fastkml/features.py
@@ -305,6 +305,7 @@ def __init__(
self.extended_data = extended_data
self.times = times
+
registry.register(
_Feature,
RegistryItem(
diff --git a/fastkml/network_control.py b/fastkml/network_control.py
deleted file mode 100644
index 312ce5f4..00000000
--- a/fastkml/network_control.py
+++ /dev/null
@@ -1,184 +0,0 @@
-# Copyright (C) 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
-# Software Foundation; either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-from typing import Any
-from typing import Dict
-from typing import Optional
-from typing import Union
-from fastkml.helpers import datetime_subelement
-from fastkml.helpers import datetime_subelement_kwarg
-from fastkml.helpers import subelement_text_kwarg
-from fastkml.helpers import text_subelement
-from fastkml.helpers import xml_subelement
-from fastkml.helpers import xml_subelement_kwarg
-from fastkml.registry import registry
-from fastkml.registry import RegistryItem
-from fastkml.base import _XMLObject
-from fastkml.times import KmlDateTime
-from fastkml.update import Update
-from fastkml.views import Camera, LookAt
-
-
-class _NetworkControl(_XMLObject):
- """
- Absrtact base class representing NetworkLinkControl in KML.
- """
- min_refresh_period: Optional[float]
- max_session_length: Optional[float]
- cookie: Optional[str]
- message: Optional[str]
- link_name: Optional[str]
- link_description: Optional[str]
- link_snippet: Optional[str]
- expires: Optional[KmlDateTime]
- view: Union[Camera, LookAt, None]
- update:Optional[Update]
-
- def __init__(
- self,
- ns: Optional[str] = None,
- name_spaces: Optional[Dict[str, str]] = None,
- min_refresh_period: Optional[float] = None,
- max_session_length: Optional[float] = None,
- cookie: Optional[str] = None,
- message: Optional[str] = None,
- link_name: Optional[str] = None,
- link_description: Optional[str] = None,
- link_snippet: Optional[str] = None,
- expires: Optional[KmlDateTime] = None,
- view: Optional[Union[Camera, LookAt]] = None,
- update:Optional[Update] = None,
- **kwargs: Any,
- ):
- super().__init__(
- ns=ns,
- name_spaces=name_spaces,
- **kwargs,
- )
- self.min_refresh_period = min_refresh_period
- self.max_session_length = max_session_length
- self.cookie = cookie
- self.message = message
- self.link_name = link_name
- self.link_description = link_description
- self.link_snippet = link_snippet
- self.expires = expires
- self.view = view
- self.update = update
-
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="min_refresh_period",
- node_name="minRefreshPeriod",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="max_session_length",
- node_name="maxSessionLength",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="cookie",
- node_name="cookie",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="message",
- node_name="message",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_name",
- node_name="linkName",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_description",
- node_name="linkDescription",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_snippet",
- node_name="linkSnippet",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- _NetworkControl,
- item=RegistryItem(
- ns_ids=("kml", ),
- classes=(KmlDateTime,),
- attr_name="expires",
- node_name="expires",
- get_kwarg=datetime_subelement_kwarg,
- set_element=datetime_subelement,
- ),
-)
-
-registry.register(
- _NetworkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="view",
- node_name="Camera,LookAt",
- classes=(
- Camera,
- LookAt,
- ),
- get_kwarg=xml_subelement_kwarg,
- set_element=xml_subelement,
- ),
-)
\ No newline at end of file
diff --git a/fastkml/times.py b/fastkml/times.py
index 58ca8987..8f7a451e 100644
--- a/fastkml/times.py
+++ b/fastkml/times.py
@@ -193,11 +193,6 @@ def __str__(self) -> str:
else self.dt.isoformat()
)
return self.dt.isoformat()
-
- @classmethod
- def get_tag_name(cls) -> str:
- """Return the tag name."""
- return cls.__name__.lower()
@classmethod
def parse(cls, datestr: str) -> Optional["KmlDateTime"]:
From aa307b5c751a3c85e79fb6d903c5379ef972f2d4 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sat, 30 Nov 2024 23:53:59 -0500
Subject: [PATCH 4/8] removing update
---
docs/network.kml | 16 +++
fastkml/__init__.py | 3 +-
fastkml/containers.py | 190 +-------------------------------
fastkml/kml.py | 2 +-
fastkml/network_link_control.py | 190 ++++++++++++++++++++++++++++++++
fastkml/update.py | 133 ----------------------
6 files changed, 210 insertions(+), 324 deletions(-)
create mode 100644 docs/network.kml
create mode 100644 fastkml/network_link_control.py
delete mode 100644 fastkml/update.py
diff --git a/docs/network.kml b/docs/network.kml
new file mode 100644
index 00000000..48f6004d
--- /dev/null
+++ b/docs/network.kml
@@ -0,0 +1,16 @@
+
+
+
+ 43200
+ -1
+
+ A snippet of XHTML
+ ]]>
+
+ 2008-05-30
+
+
\ No newline at end of file
diff --git a/fastkml/__init__.py b/fastkml/__init__.py
index b9936355..e364876b 100644
--- a/fastkml/__init__.py
+++ b/fastkml/__init__.py
@@ -31,6 +31,7 @@
from fastkml.atom import Link as AtomLink
from fastkml.containers import Document
from fastkml.containers import Folder
+from fastkml.network_link_control import NetworkLinkControl
from fastkml.data import Data
from fastkml.data import ExtendedData
from fastkml.data import Schema
@@ -84,7 +85,7 @@
__all__ = [
"KML",
- "NetworkLinkControl"
+ "NetworkLinkControl",
"AtomAuthor",
"AtomContributor",
"AtomLink",
diff --git a/fastkml/containers.py b/fastkml/containers.py
index 3343bb29..8d0f6cfe 100644
--- a/fastkml/containers.py
+++ b/fastkml/containers.py
@@ -25,9 +25,7 @@
from typing import Union
from fastkml import atom
-from fastkml import config
from fastkml import gx
-from fastkml.base import _XMLObject
from fastkml.data import ExtendedData
from fastkml.data import Schema
from fastkml.features import NetworkLink
@@ -39,15 +37,8 @@
from fastkml.geometry import MultiGeometry
from fastkml.geometry import Point
from fastkml.geometry import Polygon
-from fastkml.helpers import datetime_subelement
-from fastkml.helpers import datetime_subelement_kwarg
-from fastkml.helpers import subelement_text_kwarg
-from fastkml.helpers import text_subelement
-from fastkml.helpers import xml_subelement
-from fastkml.helpers import xml_subelement_kwarg
from fastkml.helpers import xml_subelement_list
from fastkml.helpers import xml_subelement_list_kwarg
-from fastkml.network_control import _NetworkControl
from fastkml.overlays import GroundOverlay
from fastkml.overlays import PhotoOverlay
from fastkml.overlays import ScreenOverlay
@@ -57,9 +48,7 @@
from fastkml.styles import StyleMap
from fastkml.styles import StyleUrl
from fastkml.times import TimeSpan
-from fastkml.times import KmlDateTime
from fastkml.times import TimeStamp
-from fastkml.update import Update
from fastkml.utils import find_all
from fastkml.views import Camera
from fastkml.views import LookAt
@@ -336,6 +325,7 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
None,
)
+
registry.register(
_Container,
RegistryItem(
@@ -369,181 +359,3 @@ def get_style_by_url(self, style_url: str) -> Optional[Union[Style, StyleMap]]:
set_element=xml_subelement_list,
),
)
-
-class NetworkLinkControl(_XMLObject):
-
- _default_nsid = config.KML
-
- min_refresh_period: Optional[float]
- max_session_length: Optional[float]
- cookie: Optional[str]
- message: Optional[str]
- link_name: Optional[str]
- link_description: Optional[str]
- link_snippet: Optional[str]
- expires: Optional[KmlDateTime]
- view: Union[Camera, LookAt, None]
- update:Optional[Update]
-
- def __init__(
- self,
- ns: Optional[str] = None,
- name_spaces: Optional[Dict[str, str]] = None,
- min_refresh_period: Optional[float] = None,
- max_session_length: Optional[float] = None,
- cookie: Optional[str] = None,
- message: Optional[str] = None,
- link_name: Optional[str] = None,
- link_description: Optional[str] = None,
- link_snippet: Optional[str] = None,
- expires: Optional[KmlDateTime] = None,
- update:Optional[Update] = None,
- view: Optional[Union[Camera, LookAt]] = None,
- **kwargs: Any
- ) -> None:
- super().__init__(
- ns=ns,
- name_spaces=name_spaces,
- min_refresh_period=min_refresh_period,
- max_session_length=max_session_length,
- cookie=cookie,
- message=message,
- link_name=link_name,
- link_description=link_description,
- link_snippet=link_snippet,
- expires=expires,
- update=update,
- view=view,
- **kwargs
- )
-
- def __repr__(self) -> str:
- """
- Return a string representation of the NetworkLinkControl object.
-
- Returns
- -------
- str: A string representation of the NetworkLinkControl object.
-
- """
- return (
- f"{self.__class__.__module__}.{self.__class__.__name__}("
- f"ns={self.ns!r}, "
- f"name_spaces={self.name_spaces!r}, "
- f"min_refresh_period={self.min_refresh_period!r}, "
- f"max_session_length={self.max_session_length!r}, "
- f"cookie={self.cookie!r}, "
- f"message={self.message!r}, "
- f"link_name={self.link_name!r}, "
- f"link_description={self.link_description!r}, "
- f"link_snippet={self.link_snippet!r}, "
- f"expires={self.expires!r}, "
- f"update={self.update!r}, "
- f"view={self.view!r}, "
- f"**{self._get_splat()!r},"
- ")"
- )
-
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="min_refresh_period",
- node_name="minRefreshPeriod",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="max_session_length",
- node_name="maxSessionLength",
- classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="cookie",
- node_name="cookie",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="message",
- node_name="message",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_name",
- node_name="linkName",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_description",
- node_name="linkDescription",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="link_snippet",
- node_name="linkSnippet",
- classes=(str,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
- ),
-)
-registry.register(
- NetworkLinkControl,
- item=RegistryItem(
- ns_ids=("kml", ),
- classes=(KmlDateTime,),
- attr_name="expires",
- node_name="expires",
- get_kwarg=datetime_subelement_kwarg,
- set_element=datetime_subelement,
- ),
-)
-
-registry.register(
- NetworkLinkControl,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="view",
- node_name="Camera,LookAt",
- classes=(
- Camera,
- LookAt,
- ),
- get_kwarg=xml_subelement_kwarg,
- set_element=xml_subelement,
- ),
-)
\ No newline at end of file
diff --git a/fastkml/kml.py b/fastkml/kml.py
index 3edba7cb..121044f5 100644
--- a/fastkml/kml.py
+++ b/fastkml/kml.py
@@ -45,7 +45,7 @@
from fastkml import validator
from fastkml.base import _XMLObject
from fastkml.containers import Document
-from fastkml.containers import NetworkLinkControl
+from fastkml.network_link_control import NetworkLinkControl
from fastkml.containers import Folder
from fastkml.enums import Verbosity
from fastkml.features import NetworkLink
diff --git a/fastkml/network_link_control.py b/fastkml/network_link_control.py
new file mode 100644
index 00000000..42a599a0
--- /dev/null
+++ b/fastkml/network_link_control.py
@@ -0,0 +1,190 @@
+from typing import Any
+from typing import Dict
+from typing import Optional
+from typing import Union
+from fastkml import config
+from fastkml.base import _XMLObject
+from fastkml.helpers import datetime_subelement
+from fastkml.helpers import datetime_subelement_kwarg
+from fastkml.helpers import subelement_text_kwarg
+from fastkml.helpers import text_subelement
+from fastkml.helpers import xml_subelement_list
+from fastkml.helpers import xml_subelement_list_kwarg
+from fastkml.registry import RegistryItem
+from fastkml.registry import registry
+from fastkml.times import KmlDateTime
+from fastkml.views import Camera, LookAt
+
+
+class NetworkLinkControl(_XMLObject):
+
+ _default_nsid = config.KML
+
+ min_refresh_period: Optional[float]
+ max_session_length: Optional[float]
+ cookie: Optional[str]
+ message: Optional[str]
+ link_name: Optional[str]
+ link_description: Optional[str]
+ link_snippet: Optional[str]
+ expires: Optional[KmlDateTime]
+ view: Union[Camera, LookAt, None] # TODO: Add Update field to the parameters
+
+ def __init__(
+ self,
+ ns: Optional[str] = None,
+ name_spaces: Optional[Dict[str, str]] = None,
+ min_refresh_period: Optional[float] = None,
+ max_session_length: Optional[float] = None,
+ cookie: Optional[str] = None,
+ message: Optional[str] = None,
+ link_name: Optional[str] = None,
+ link_description: Optional[str] = None,
+ link_snippet: Optional[str] = None,
+ expires: Optional[KmlDateTime] = None,
+ view: Optional[Union[Camera, LookAt]] = None,
+ **kwargs: Any
+ ) -> None:
+ super().__init__(
+ ns=ns,
+ name_spaces=name_spaces,
+ min_refresh_period=min_refresh_period,
+ max_session_length=max_session_length,
+ cookie=cookie,
+ message=message,
+ link_name=link_name,
+ link_description=link_description,
+ link_snippet=link_snippet,
+ expires=expires,
+ view=view,
+ **kwargs
+ )
+
+ def __repr__(self) -> str:
+ """
+ Return a string representation of the NetworkLinkControl object.
+
+ Returns
+ -------
+ str: A string representation of the NetworkLinkControl object.
+
+ """
+ return (
+ f"{self.__class__.__module__}.{self.__class__.__name__}("
+ f"ns={self.ns!r}, "
+ f"name_spaces={self.name_spaces!r}, "
+ f"min_refresh_period={self.min_refresh_period!r}, "
+ f"max_session_length={self.max_session_length!r}, "
+ f"cookie={self.cookie!r}, "
+ f"message={self.message!r}, "
+ f"link_name={self.link_name!r}, "
+ f"link_description={self.link_description!r}, "
+ f"link_snippet={self.link_snippet!r}, "
+ f"expires={self.expires!r}, "
+ f"view={self.view!r}, "
+ f"**{self._get_splat()!r},"
+ ")"
+ )
+
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="min_refresh_period",
+ node_name="minRefreshPeriod",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="max_session_length",
+ node_name="maxSessionLength",
+ classes=(float,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="cookie",
+ node_name="cookie",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="message",
+ node_name="message",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_name",
+ node_name="linkName",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_description",
+ node_name="linkDescription",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="link_snippet",
+ node_name="linkSnippet",
+ classes=(str,),
+ get_kwarg=subelement_text_kwarg,
+ set_element=text_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ item=RegistryItem(
+ ns_ids=("kml", ),
+ classes=(KmlDateTime,),
+ attr_name="expires",
+ node_name="expires",
+ get_kwarg=datetime_subelement_kwarg,
+ set_element=datetime_subelement,
+ ),
+)
+registry.register(
+ NetworkLinkControl,
+ RegistryItem(
+ ns_ids=("kml",),
+ attr_name="view",
+ node_name="Camera,LookAt",
+ classes=(
+ Camera,
+ LookAt,
+ ),
+ get_kwarg=xml_subelement_list_kwarg,
+ set_element=xml_subelement_list,
+ ),
+)
diff --git a/fastkml/update.py b/fastkml/update.py
deleted file mode 100644
index 948e02a4..00000000
--- a/fastkml/update.py
+++ /dev/null
@@ -1,133 +0,0 @@
-# Copyright (C) 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
-# Software Foundation; either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-from typing import Any
-from typing import Union
-from typing import Dict
-from typing import Iterable
-from typing import List
-from typing import Optional
-# from fastkml.containers import Folder
-from fastkml.helpers import xml_subelement
-from fastkml.helpers import xml_subelement_kwarg
-from fastkml.registry import registry
-from fastkml.registry import RegistryItem
-from fastkml.base import _XMLObject
-from fastkml.times import TimeSpan
-
-class Change(_XMLObject):
-
- def __int__(
- self,
- target_id: str,
- elements: Optional[Union[TimeSpan]] = None
- ):
- super().__init__(
- target_id=target_id,
- elements=elements
- )
-
- def parse_children(self):
- pass
-
-class Create(_XMLObject):
- def __int__(
- self,
- target_id: str,
- elements: Optional[Union[TimeSpan]] = None
- ):
- super().__init__(
- target_id=target_id,
- elements=elements
- )
-
- def parse_children(self):
- pass
-
-class Delete(_XMLObject):
- def __int__(
- self,
- target_id: str,
- elements: Optional[Union[TimeSpan]] = None
- ):
- super().__init__(
- target_id=target_id,
- elements=elements
- )
-
- def parse_children(self):
- pass
-
-class Update:
-
- def __init__(
- target_href: Optional[str] = None,
- change: Optional[Iterable[Change]] = None,
- create: Optional[Iterable[Create]] = None,
- delete: Optional[Iterable[Delete]] = None
- ):
- super().__init__(
- target_href=target_href,
- change=change,
- create=create,
- delete=delete
- )
-
-registry.register(
- Update,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="change",
- node_name="TimeSpan",
- classes=(
- # PhotoOverlay,
- # Folder,
- TimeSpan,
- ),
- get_kwarg=xml_subelement_kwarg,
- set_element=xml_subelement,
- )
-)
-registry.register(
- Update,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="create",
- node_name="TimeSpan",
- classes=(
- # PhotoOverlay,
- # Folder,
- TimeSpan,
- ),
- get_kwarg=xml_subelement_kwarg,
- set_element=xml_subelement,
- )
-)
-registry.register(
- Update,
- RegistryItem(
- ns_ids=("kml",),
- attr_name="delete",
- node_name="TimeSpan",
- classes=(
- # PhotoOverlay,
- # Folder,
- TimeSpan,
- ),
- get_kwarg=xml_subelement_kwarg,
- set_element=xml_subelement,
- )
-)
\ No newline at end of file
From 4f4a3f0ac184081702cf7ee72d920d5d33e43fd5 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sun, 1 Dec 2024 01:24:49 -0500
Subject: [PATCH 5/8] test cases
---
fastkml/network_link_control.py | 24 +++++++++
tests/network_link_control_test.py | 85 ++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+)
create mode 100644 tests/network_link_control_test.py
diff --git a/fastkml/network_link_control.py b/fastkml/network_link_control.py
index 42a599a0..d65569f2 100644
--- a/fastkml/network_link_control.py
+++ b/fastkml/network_link_control.py
@@ -1,3 +1,20 @@
+# Copyright (C) 2012-2024 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
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import logging
+
from typing import Any
from typing import Dict
from typing import Optional
@@ -16,6 +33,13 @@
from fastkml.views import Camera, LookAt
+__all__ = [
+ "NetworkLinkControl",
+]
+
+logger = logging.getLogger(__name__)
+
+
class NetworkLinkControl(_XMLObject):
_default_nsid = config.KML
diff --git a/tests/network_link_control_test.py b/tests/network_link_control_test.py
new file mode 100644
index 00000000..4a5ffe98
--- /dev/null
+++ b/tests/network_link_control_test.py
@@ -0,0 +1,85 @@
+# Copyright (C) 2021 - 2022 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
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Test the Network Link Control classes."""
+
+import datetime
+
+import pytest
+
+from fastkml.kml import KML
+from fastkml.network_link_control import NetworkLinkControl
+from fastkml.times import KmlDateTime
+from tests.base import StdLibrary
+from fastkml import views
+
+class TestStdLibrary(StdLibrary):
+ """Test with the standard library."""
+
+ def test_network_link_control_obj(self) -> None:
+ dt = datetime.datetime.now()
+ kml_datetime = KmlDateTime(dt=dt)
+ view = views.Camera()
+
+ network_control_obj = NetworkLinkControl(
+ min_refresh_period=1.1,
+ max_session_length=100.1,
+ cookie="cookie",
+ message="message",
+ link_name="link_name",
+ link_description="link_description",
+ link_snippet="link_snippet",
+ expires=kml_datetime,
+ view=view
+ )
+
+ assert network_control_obj.min_refresh_period == 1.1
+ assert network_control_obj.max_session_length == 100.1
+ assert network_control_obj.cookie == "cookie"
+ assert network_control_obj.message == "message"
+ assert network_control_obj.link_name == "link_name"
+ assert network_control_obj.link_description == "link_description"
+ assert network_control_obj.link_snippet == "link_snippet"
+ assert network_control_obj.expires == kml_datetime
+
+ assert network_control_obj.view == view
+
+ def test_network_link_control_kml(self) -> None:
+ doc = (
+ ''
+ "43200"
+ "-1"
+ "A Snippet"
+ "2008-05-30"
+ ""
+ )
+
+ network_control = NetworkLinkControl.from_string(doc)
+
+ dt = datetime.date(2008, 5, 30)
+ kml_datetime = KmlDateTime(dt=dt)
+
+ network_control_obj = NetworkLinkControl(
+ min_refresh_period=43200,
+ max_session_length=-1,
+ link_snippet="A Snippet",
+ expires=kml_datetime,
+ )
+
+ assert network_control.min_refresh_period == str(network_control_obj.min_refresh_period)
+ assert network_control.max_session_length == str(network_control_obj.max_session_length)
+ assert network_control.link_snippet == network_control_obj.link_snippet
+ assert network_control.expires == network_control_obj.expires
\ No newline at end of file
From 5f37b544daa49c3c3d253e9a3031b903a6f05b64 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sun, 1 Dec 2024 02:06:51 -0500
Subject: [PATCH 6/8] mypt fixes
---
fastkml/kml.py | 24 +++++++++++++++++++++---
fastkml/network_link_control.py | 16 ++++++++++------
tests/network_link_control_test.py | 20 +++++++++-----------
3 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/fastkml/kml.py b/fastkml/kml.py
index 121044f5..a5712482 100644
--- a/fastkml/kml.py
+++ b/fastkml/kml.py
@@ -60,7 +60,14 @@
logger = logging.getLogger(__name__)
-kml_children = Union[Folder, Document, Placemark, GroundOverlay, PhotoOverlay, NetworkLinkControl]
+kml_children = Union[
+ Folder,
+ Document,
+ Placemark,
+ GroundOverlay,
+ PhotoOverlay,
+ NetworkLinkControl
+ ]
def lxml_parse_and_validate(
@@ -287,8 +294,19 @@ def write(
KML,
RegistryItem(
ns_ids=("kml",),
- classes=(Document, Folder, Placemark, GroundOverlay, PhotoOverlay, NetworkLink, NetworkLinkControl),
- node_name="Document,Folder,Placemark,GroundOverlay,PhotoOverlay,NetworkLink,NetworkLinkControl",
+ classes=(
+ Document,
+ Folder,
+ Placemark,
+ GroundOverlay,
+ PhotoOverlay,
+ NetworkLink,
+ NetworkLinkControl
+ ),
+ node_name=(
+ "Document,Folder,Placemark,GroundOverlay,PhotoOverlay,NetworkLink,"
+ "NetworkLinkControl"
+ ),
attr_name="features",
get_kwarg=xml_subelement_list_kwarg,
set_element=xml_subelement_list,
diff --git a/fastkml/network_link_control.py b/fastkml/network_link_control.py
index d65569f2..ab812fbe 100644
--- a/fastkml/network_link_control.py
+++ b/fastkml/network_link_control.py
@@ -22,6 +22,8 @@
from fastkml import config
from fastkml.base import _XMLObject
from fastkml.helpers import datetime_subelement
+from fastkml.helpers import float_subelement
+from fastkml.helpers import subelement_float_kwarg
from fastkml.helpers import datetime_subelement_kwarg
from fastkml.helpers import subelement_text_kwarg
from fastkml.helpers import text_subelement
@@ -41,7 +43,7 @@
class NetworkLinkControl(_XMLObject):
-
+
_default_nsid = config.KML
min_refresh_period: Optional[float]
@@ -54,6 +56,7 @@ class NetworkLinkControl(_XMLObject):
expires: Optional[KmlDateTime]
view: Union[Camera, LookAt, None] # TODO: Add Update field to the parameters
+
def __init__(
self,
ns: Optional[str] = None,
@@ -83,7 +86,7 @@ def __init__(
view=view,
**kwargs
)
-
+
def __repr__(self) -> str:
"""
Return a string representation of the NetworkLinkControl object.
@@ -110,6 +113,7 @@ def __repr__(self) -> str:
")"
)
+
registry.register(
NetworkLinkControl,
RegistryItem(
@@ -117,8 +121,8 @@ def __repr__(self) -> str:
attr_name="min_refresh_period",
node_name="minRefreshPeriod",
classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
+ get_kwarg=subelement_float_kwarg,
+ set_element=float_subelement,
),
)
registry.register(
@@ -128,8 +132,8 @@ def __repr__(self) -> str:
attr_name="max_session_length",
node_name="maxSessionLength",
classes=(float,),
- get_kwarg=subelement_text_kwarg,
- set_element=text_subelement,
+ get_kwarg=subelement_float_kwarg,
+ set_element=float_subelement,
),
)
registry.register(
diff --git a/tests/network_link_control_test.py b/tests/network_link_control_test.py
index 4a5ffe98..5fc9720e 100644
--- a/tests/network_link_control_test.py
+++ b/tests/network_link_control_test.py
@@ -18,14 +18,12 @@
import datetime
-import pytest
-
-from fastkml.kml import KML
from fastkml.network_link_control import NetworkLinkControl
from fastkml.times import KmlDateTime
from tests.base import StdLibrary
from fastkml import views
+
class TestStdLibrary(StdLibrary):
"""Test with the standard library."""
@@ -60,26 +58,26 @@ def test_network_link_control_obj(self) -> None:
def test_network_link_control_kml(self) -> None:
doc = (
''
- "43200"
+ "432000"
"-1"
"A Snippet"
"2008-05-30"
""
)
- network_control = NetworkLinkControl.from_string(doc)
+ nc = NetworkLinkControl.from_string(doc)
dt = datetime.date(2008, 5, 30)
kml_datetime = KmlDateTime(dt=dt)
- network_control_obj = NetworkLinkControl(
- min_refresh_period=43200,
+ nc_obj = NetworkLinkControl(
+ min_refresh_period=432000,
max_session_length=-1,
link_snippet="A Snippet",
expires=kml_datetime,
)
- assert network_control.min_refresh_period == str(network_control_obj.min_refresh_period)
- assert network_control.max_session_length == str(network_control_obj.max_session_length)
- assert network_control.link_snippet == network_control_obj.link_snippet
- assert network_control.expires == network_control_obj.expires
\ No newline at end of file
+ assert nc.min_refresh_period == nc_obj.min_refresh_period
+ assert nc.max_session_length == nc_obj.max_session_length
+ assert nc.link_snippet == nc_obj.link_snippet
+ assert nc.expires == nc_obj.expires
From 9ece33b45951e3ebc7b5aee482db30bce178afbd Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sun, 1 Dec 2024 02:08:34 -0500
Subject: [PATCH 7/8] typo
---
fastkml/network_link_control.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fastkml/network_link_control.py b/fastkml/network_link_control.py
index ab812fbe..1e9d05bd 100644
--- a/fastkml/network_link_control.py
+++ b/fastkml/network_link_control.py
@@ -54,8 +54,7 @@ class NetworkLinkControl(_XMLObject):
link_description: Optional[str]
link_snippet: Optional[str]
expires: Optional[KmlDateTime]
- view: Union[Camera, LookAt, None] # TODO: Add Update field to the parameters
-
+ view: Union[Camera, LookAt, None] # TODO: Add Update field to the parameters
def __init__(
self,
From 10ebe81d2cb1ff7a1142ae1aaefe801e8fe896a0 Mon Sep 17 00:00:00 2001
From: apurvabanka
Date: Sun, 1 Dec 2024 17:35:14 -0500
Subject: [PATCH 8/8] requested changes
---
fastkml/__init__.py | 4 ++--
fastkml/kml.py | 2 +-
fastkml/network_link_control.py | 22 ++++++++++++----------
tests/network_link_control_test.py | 10 +++-------
4 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/fastkml/__init__.py b/fastkml/__init__.py
index 0c9fb66f..e94dae15 100644
--- a/fastkml/__init__.py
+++ b/fastkml/__init__.py
@@ -31,7 +31,6 @@
from fastkml.atom import Link as AtomLink
from fastkml.containers import Document
from fastkml.containers import Folder
-from fastkml.network_link_control import NetworkLinkControl
from fastkml.data import Data
from fastkml.data import ExtendedData
from fastkml.data import Schema
@@ -59,6 +58,7 @@
from fastkml.model import Orientation
from fastkml.model import ResourceMap
from fastkml.model import Scale
+from fastkml.network_link_control import NetworkLinkControl
from fastkml.overlays import GroundOverlay
from fastkml.overlays import ImagePyramid
from fastkml.overlays import LatLonBox
@@ -91,7 +91,6 @@
__all__ = [
"KML",
- "NetworkLinkControl",
"Alias",
"AtomAuthor",
"AtomContributor",
@@ -121,6 +120,7 @@
"Model",
"MultiGeometry",
"NetworkLink",
+ "NetworkLinkControl",
"Orientation",
"OuterBoundaryIs",
"OverlayXY",
diff --git a/fastkml/kml.py b/fastkml/kml.py
index b858e40f..70d1b8ec 100644
--- a/fastkml/kml.py
+++ b/fastkml/kml.py
@@ -66,7 +66,7 @@
Placemark,
GroundOverlay,
PhotoOverlay,
- NetworkLinkControl
+ NetworkLinkControl,
]
diff --git a/fastkml/network_link_control.py b/fastkml/network_link_control.py
index 1e9d05bd..feeec67d 100644
--- a/fastkml/network_link_control.py
+++ b/fastkml/network_link_control.py
@@ -14,26 +14,26 @@
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import logging
-
from typing import Any
from typing import Dict
from typing import Optional
from typing import Union
+
from fastkml import config
from fastkml.base import _XMLObject
from fastkml.helpers import datetime_subelement
+from fastkml.helpers import datetime_subelement_kwarg
from fastkml.helpers import float_subelement
from fastkml.helpers import subelement_float_kwarg
-from fastkml.helpers import datetime_subelement_kwarg
from fastkml.helpers import subelement_text_kwarg
from fastkml.helpers import text_subelement
-from fastkml.helpers import xml_subelement_list
-from fastkml.helpers import xml_subelement_list_kwarg
+from fastkml.helpers import xml_subelement
+from fastkml.helpers import xml_subelement_kwarg
from fastkml.registry import RegistryItem
from fastkml.registry import registry
from fastkml.times import KmlDateTime
-from fastkml.views import Camera, LookAt
-
+from fastkml.views import Camera
+from fastkml.views import LookAt
__all__ = [
"NetworkLinkControl",
@@ -69,7 +69,7 @@ def __init__(
link_snippet: Optional[str] = None,
expires: Optional[KmlDateTime] = None,
view: Optional[Union[Camera, LookAt]] = None,
- **kwargs: Any
+ **kwargs: Any,
) -> None:
super().__init__(
ns=ns,
@@ -83,7 +83,7 @@ def __init__(
link_snippet=link_snippet,
expires=expires,
view=view,
- **kwargs
+ **kwargs,
)
def __repr__(self) -> str:
@@ -122,6 +122,7 @@ def __repr__(self) -> str:
classes=(float,),
get_kwarg=subelement_float_kwarg,
set_element=float_subelement,
+ default=0,
),
)
registry.register(
@@ -133,6 +134,7 @@ def __repr__(self) -> str:
classes=(float,),
get_kwarg=subelement_float_kwarg,
set_element=float_subelement,
+ default=-1,
),
)
registry.register(
@@ -211,7 +213,7 @@ def __repr__(self) -> str:
Camera,
LookAt,
),
- get_kwarg=xml_subelement_list_kwarg,
- set_element=xml_subelement_list,
+ get_kwarg=xml_subelement_kwarg,
+ set_element=xml_subelement,
),
)
diff --git a/tests/network_link_control_test.py b/tests/network_link_control_test.py
index 5fc9720e..b348ee52 100644
--- a/tests/network_link_control_test.py
+++ b/tests/network_link_control_test.py
@@ -51,9 +51,8 @@ def test_network_link_control_obj(self) -> None:
assert network_control_obj.link_name == "link_name"
assert network_control_obj.link_description == "link_description"
assert network_control_obj.link_snippet == "link_snippet"
- assert network_control_obj.expires == kml_datetime
-
- assert network_control_obj.view == view
+ assert str(network_control_obj.expires) == str(kml_datetime)
+ assert str(network_control_obj.view) == str(view)
def test_network_link_control_kml(self) -> None:
doc = (
@@ -77,7 +76,4 @@ def test_network_link_control_kml(self) -> None:
expires=kml_datetime,
)
- assert nc.min_refresh_period == nc_obj.min_refresh_period
- assert nc.max_session_length == nc_obj.max_session_length
- assert nc.link_snippet == nc_obj.link_snippet
- assert nc.expires == nc_obj.expires
+ assert nc == nc_obj