Skip to content

Commit

Permalink
splat kwargs to allow to register arbitrary elements
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Apr 19, 2024
1 parent 7b7e268 commit 9970297
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 29 deletions.
7 changes: 5 additions & 2 deletions fastkml/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"""

import logging
from typing import Any
from typing import Dict
from typing import Optional

Expand Down Expand Up @@ -115,8 +116,9 @@ def __init__(
hreflang: Optional[str] = None,
title: Optional[str] = None,
length: Optional[int] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces)
super().__init__(ns=ns, name_spaces=name_spaces, **kwargs)
self.href = href
self.rel = rel
self.type = type
Expand Down Expand Up @@ -229,8 +231,9 @@ def __init__(
name: Optional[str] = None,
uri: Optional[str] = None,
email: Optional[str] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces)
super().__init__(ns=ns, name_spaces=name_spaces, **kwargs)
self.name = name
self.uri = uri
self.email = email
Expand Down
4 changes: 3 additions & 1 deletion fastkml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
self,
ns: Optional[str] = None,
name_spaces: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> None:
"""Initialize the XML Object."""
self.ns: str = self._default_ns if ns is None else ns
Expand Down Expand Up @@ -232,9 +233,10 @@ def __init__(
name_spaces: Optional[Dict[str, str]] = None,
id: Optional[str] = None,
target_id: Optional[str] = None,
**kwargs: Any,
) -> None:
"""Initialize the KML Object."""
super().__init__(ns=ns, name_spaces=name_spaces)
super().__init__(ns=ns, name_spaces=name_spaces, **kwargs)
self.id = id
self.target_id = target_id

Expand Down
5 changes: 5 additions & 0 deletions fastkml/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""Container classes for KML elements."""
import logging
import urllib.parse as urlparse
from typing import Any
from typing import Dict
from typing import Iterable
from typing import List
Expand Down Expand Up @@ -95,6 +96,7 @@ def __init__(
extended_data: Optional[ExtendedData] = None,
# Container specific
features: Optional[Iterable[_Feature]] = None,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -116,6 +118,7 @@ def __init__(
styles=styles,
region=region,
extended_data=extended_data,
**kwargs,
)
self.features = list(features) if features else []

Expand Down Expand Up @@ -167,6 +170,7 @@ def __init__(
extended_data: Optional[ExtendedData] = None,
features: Optional[List[_Feature]] = None,
schemata: Optional[Iterable[Schema]] = None,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -189,6 +193,7 @@ def __init__(
region=region,
extended_data=extended_data,
features=features,
**kwargs,
)
self.schemata = list(schemata) if schemata else []

Expand Down
55 changes: 49 additions & 6 deletions fastkml/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
https://developers.google.com/kml/documentation/extendeddata#example
"""
import logging
from typing import Any
from typing import Dict
from typing import Iterable
from typing import List
Expand Down Expand Up @@ -89,8 +90,15 @@ def __init__(
name: Optional[str] = None,
type: Optional[DataType] = None,
display_name: Optional[str] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.name = name
self.type = type
self.display_name = display_name
Expand Down Expand Up @@ -153,11 +161,18 @@ def __init__(
target_id: Optional[str] = None,
name: Optional[str] = None,
fields: Optional[Iterable[SimpleField]] = None,
**kwargs: Any,
) -> None:
if id is None:
msg = "Id is required for schema"
raise KMLSchemaError(msg)
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.name = name
self.fields = list(fields) if fields else []

Expand Down Expand Up @@ -206,8 +221,15 @@ def __init__(
name: Optional[str] = None,
value: Optional[str] = None,
display_name: Optional[str] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.name = name
self.value = value
self.display_name = display_name
Expand Down Expand Up @@ -261,8 +283,15 @@ def __init__(
target_id: Optional[str] = None,
name: Optional[str] = None,
value: Optional[str] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.name = name
self.value = value

Expand Down Expand Up @@ -318,8 +347,15 @@ def __init__(
target_id: Optional[str] = None,
schema_url: Optional[str] = None,
data: Optional[Iterable[SimpleData]] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.schema_url = schema_url
self.data = list(data) if data else []

Expand Down Expand Up @@ -372,8 +408,15 @@ def __init__(
id: Optional[str] = None,
target_id: Optional[str] = None,
elements: Optional[Iterable[Union[Data, SchemaData]]] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.elements = list(elements) if elements else []

def __bool__(self) -> bool:
Expand Down
17 changes: 15 additions & 2 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import logging
from typing import Any
from typing import Dict
from typing import Iterable
from typing import List
Expand Down Expand Up @@ -107,8 +108,9 @@ def __init__(
name_spaces: Optional[Dict[str, str]] = None,
text: Optional[str] = None,
max_lines: Optional[int] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces)
super().__init__(ns=ns, name_spaces=name_spaces, **kwargs)
self.text = text
self.max_lines = max_lines

Expand Down Expand Up @@ -258,8 +260,15 @@ def __init__(
styles: Optional[Iterable[Union[Style, StyleMap]]] = None,
region: Optional[Region] = None,
extended_data: Optional[ExtendedData] = None,
**kwargs: Any,
) -> None:
super().__init__(ns=ns, name_spaces=name_spaces, id=id, target_id=target_id)
super().__init__(
ns=ns,
name_spaces=name_spaces,
id=id,
target_id=target_id,
**kwargs,
)
self.name = name
self.description = description
self.style_url = style_url
Expand Down Expand Up @@ -472,6 +481,7 @@ def __init__(
# Placemark specific
kml_geometry: Optional[KmlGeometry] = None,
geometry: Optional[Union[GeoType, GeoCollectionType]] = None,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -493,6 +503,7 @@ def __init__(
styles=styles,
region=region,
extended_data=extended_data,
**kwargs,
)
if kml_geometry and geometry:
msg = "You can only specify one of kml_geometry or geometry"
Expand Down Expand Up @@ -602,6 +613,7 @@ def __init__(
refresh_visibility: Optional[bool] = None,
fly_to_view: Optional[bool] = None,
link: Optional[Link] = None,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -623,6 +635,7 @@ def __init__(
styles=styles,
region=region,
extended_data=extended_data,
**kwargs,
)
self.refresh_visibility = refresh_visibility
self.fly_to_view = fly_to_view
Expand Down
19 changes: 18 additions & 1 deletion fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: Optional[AnyGeometryType] = None,
**kwargs: Any,
) -> None:
"""
Expand All @@ -132,7 +133,13 @@ def __init__(
element are interpreted.
"""
super().__init__(ns=ns, id=id, name_spaces=name_spaces, target_id=target_id)
super().__init__(
ns=ns,
id=id,
name_spaces=name_spaces,
target_id=target_id,
**kwargs,
)
self.extrude = extrude
self.tessellate = tessellate
self.altitude_mode = altitude_mode
Expand Down Expand Up @@ -282,6 +289,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: geo.Point,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -292,6 +300,7 @@ def __init__(
tessellate=tessellate,
altitude_mode=altitude_mode,
geometry=geometry,
**kwargs,
)

def etree_element(
Expand Down Expand Up @@ -342,6 +351,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: geo.LineString,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -352,6 +362,7 @@ def __init__(
tessellate=tessellate,
altitude_mode=altitude_mode,
geometry=geometry,
**kwargs,
)

def etree_element(
Expand Down Expand Up @@ -397,6 +408,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: geo.LinearRing,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -407,6 +419,7 @@ def __init__(
tessellate=tessellate,
altitude_mode=altitude_mode,
geometry=geometry,
**kwargs,
)

@classmethod
Expand Down Expand Up @@ -441,6 +454,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: geo.Polygon,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -451,6 +465,7 @@ def __init__(
tessellate=tessellate,
altitude_mode=altitude_mode,
geometry=geometry,
**kwargs,
)

def etree_element(
Expand Down Expand Up @@ -603,6 +618,7 @@ def __init__(
tessellate: Optional[bool] = None,
altitude_mode: Optional[AltitudeMode] = None,
geometry: MultiGeometryType,
**kwargs: Any,
) -> None:
super().__init__(
ns=ns,
Expand All @@ -613,6 +629,7 @@ def __init__(
tessellate=tessellate,
altitude_mode=altitude_mode,
geometry=geometry,
**kwargs,
)

def etree_element(
Expand Down
Loading

0 comments on commit 9970297

Please sign in to comment.