Skip to content

Commit

Permalink
remove awkward namespace handling in helpers #318
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Jun 19, 2024
1 parent 40bee72 commit 6055f57
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
7 changes: 0 additions & 7 deletions fastkml/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from typing import Optional
from typing import Union

from fastkml import config
from fastkml.enums import DataType
from fastkml.exceptions import KMLSchemaError
from fastkml.helpers import attribute_enum_kwarg
Expand Down Expand Up @@ -240,8 +239,6 @@ def append(self, field: SimpleField) -> None:
class Data(_BaseObject):
"""Represents an untyped name/value pair with optional display name."""

_default_ns = config.KMLNS

name: Optional[str]
value: Optional[str]
display_name: Optional[str]
Expand Down Expand Up @@ -402,8 +399,6 @@ class SchemaData(_BaseObject):
in the same KML file.
"""

_default_ns = config.KMLNS

schema_url: Optional[str]
data: List[SimpleData]

Expand Down Expand Up @@ -481,8 +476,6 @@ class ExtendedData(_BaseObject):
"""

_default_ns = config.KMLNS

elements: List[Union[Data, SchemaData]]

def __init__(
Expand Down
7 changes: 2 additions & 5 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from pygeoif.types import GeoType

from fastkml import atom
from fastkml import config
from fastkml import gx
from fastkml.base import _XMLObject
from fastkml.data import ExtendedData
Expand Down Expand Up @@ -97,8 +96,6 @@ class Snippet(_XMLObject):
maximum number of lines to display.
"""

_default_ns = config.KMLNS

text: Optional[str]
max_lines: Optional[int] = None

Expand Down Expand Up @@ -363,7 +360,7 @@ def __repr__(self) -> str:
registry.register(
_Feature,
RegistryItem(
ns_ids=("kml",),
ns_ids=("atom",),
attr_name="atom_link",
node_name="atom:link",
classes=(atom.Link,),
Expand All @@ -374,7 +371,7 @@ def __repr__(self) -> str:
registry.register(
_Feature,
RegistryItem(
ns_ids=("kml",),
ns_ids=("atom",),
attr_name="atom_author",
node_name="atom:author",
classes=(atom.Author,),
Expand Down
10 changes: 4 additions & 6 deletions fastkml/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,11 @@ def xml_subelement_kwarg(
) -> Dict[str, _XMLObject]:
for cls in classes:
assert issubclass(cls, _XMLObject)
namespace = ns if cls._default_ns == ns else cls._default_ns
subelement = element.find(f"{namespace}{cls.get_tag_name()}")
subelement = element.find(f"{ns}{cls.get_tag_name()}")
if subelement is not None:
return {
kwarg: cls.class_from_element(
ns=namespace,
ns=ns,
name_spaces=name_spaces,
element=subelement,
strict=strict,
Expand All @@ -640,12 +639,11 @@ def xml_subelement_list_kwarg(
assert name_spaces is not None
for obj_class in classes:
assert issubclass(obj_class, _XMLObject)
namespace = ns if obj_class._default_ns == ns else obj_class._default_ns
if subelements := element.findall(f"{namespace}{obj_class.get_tag_name()}"):
if subelements := element.findall(f"{ns}{obj_class.get_tag_name()}"):
args_list.extend(
[
obj_class.class_from_element(
ns=namespace,
ns=ns,
name_spaces=name_spaces,
element=subelement,
strict=strict,
Expand Down

0 comments on commit 6055f57

Please sign in to comment.