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