-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network LInk Control #392
Merged
cleder
merged 13 commits into
cleder:390-network-link-control
from
apurvabanka:network_link_control
Dec 1, 2024
Merged
Network LInk Control #392
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e8dd1d0
Network LInk Control
apurvabanka 35b6fa5
Creating separate class for network control
apurvabanka 1ca395f
Merge branch 'develop' into network_link_control
cleder 48c7589
Merge branch 'develop' of https://github.com/apurvabanka/fastkml into…
apurvabanka 15516ae
requested change
apurvabanka 5ae7454
Merge branch 'network_link_control' of https://github.com/apurvabanka…
apurvabanka aa307b5
removing update
apurvabanka 4f4a3f0
test cases
apurvabanka 5f37b54
mypt fixes
apurvabanka 9ece33b
typo
apurvabanka 2405308
Merge branch 'develop' of https://github.com/apurvabanka/fastkml into…
apurvabanka 471384c
Merge branch '390-network-link-control' into network_link_control
apurvabanka 10ebe81
requested changes
apurvabanka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<kml xmlns="http://www.opengis.net/kml/2.2" | ||
xmlns:atom="http://www.w3.org/2005/Atom" | ||
xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" | ||
hint="A processing hint for a KML consumer"> | ||
<NetworkLinkControl> | ||
<minRefreshPeriod>43200</minRefreshPeriod> | ||
<maxSessionLength>-1</maxSessionLength> | ||
<linkSnippet> | ||
<![CDATA[ | ||
<p xmlns="http://www.w3.org/1999/xhtml">A snippet of <a href="http://www.w3.org/TR/xhtml-basic/">XHTML</a></p> | ||
]]> | ||
</linkSnippet> | ||
<expires>2008-05-30</expires> | ||
</NetworkLinkControl> | ||
</kml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
# 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 | ||
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 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 RegistryItem | ||
from fastkml.registry import registry | ||
from fastkml.times import KmlDateTime | ||
from fastkml.views import Camera | ||
from fastkml.views import LookAt | ||
|
||
__all__ = [ | ||
"NetworkLinkControl", | ||
] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
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_float_kwarg, | ||
set_element=float_subelement, | ||
cleder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default=0, | ||
), | ||
) | ||
registry.register( | ||
NetworkLinkControl, | ||
RegistryItem( | ||
ns_ids=("kml",), | ||
attr_name="max_session_length", | ||
node_name="maxSessionLength", | ||
classes=(float,), | ||
get_kwarg=subelement_float_kwarg, | ||
set_element=float_subelement, | ||
default=-1, | ||
), | ||
cleder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
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, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 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 | ||
|
||
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 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 = ( | ||
'<kml:NetworkLinkControl xmlns:kml="http://www.opengis.net/kml/2.2">' | ||
"<kml:minRefreshPeriod>432000</kml:minRefreshPeriod>" | ||
"<kml:maxSessionLength>-1</kml:maxSessionLength>" | ||
"<kml:linkSnippet>A Snippet</kml:linkSnippet>" | ||
"<kml:expires>2008-05-30</kml:expires>" | ||
"</kml:NetworkLinkControl>" | ||
) | ||
|
||
nc = NetworkLinkControl.from_string(doc) | ||
|
||
dt = datetime.date(2008, 5, 30) | ||
kml_datetime = KmlDateTime(dt=dt) | ||
|
||
nc_obj = NetworkLinkControl( | ||
min_refresh_period=432000, | ||
max_session_length=-1, | ||
link_snippet="A Snippet", | ||
expires=kml_datetime, | ||
) | ||
|
||
cleder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert nc == nc_obj |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider introducing helper functions to abstract common registry field patterns.
The registration code can be simplified by introducing helper functions for common field types while maintaining the same functionality. Here's how:
This approach: