Skip to content

Commit

Permalink
Update default namespaces for _XMLObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 21, 2023
1 parent 9c95ed1 commit 7a26c65
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fastkml/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class _AtomObject(_XMLObject):
The atom tag name is the class name in lower case.
"""

_default_ns = config.ATOMNS

@classmethod
def get_tag_name(cls) -> str:
"""Return the tag name."""
Expand Down
15 changes: 15 additions & 0 deletions fastkml/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def _get_kwargs(
class Data(_XMLObject):
"""Represents an untyped name/value pair with optional display name."""

_default_ns = config.KMLNS

name: Optional[str]
value: Optional[str]
display_name: Optional[str]

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -284,6 +290,11 @@ class SchemaData(_XMLObject):
in the same KML file.
"""

_default_ns = config.KMLNS

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

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -351,6 +362,10 @@ class ExtendedData(_XMLObject):
"""

_default_ns = config.KMLNS

elements: List[Union[Data, SchemaData]]

def __init__(
self,
ns: Optional[str] = None,
Expand Down
18 changes: 18 additions & 0 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pygeoif.types import GeoType

from fastkml import atom
from fastkml import config
from fastkml import gx
from fastkml.base import _BaseObject
from fastkml.base import _XMLObject
Expand Down Expand Up @@ -62,6 +63,23 @@


class Snippet(_XMLObject):
"""
A short description of the feature.
In Google Earth, this description is displayed in the Places panel
under the name of the feature.
If a Snippet is not supplied, the first two lines of the <description>
are used.
In Google Earth, if a Placemark contains both a description and a
Snippet, the <Snippet> appears beneath the Placemark in the Places
panel, and the <description> appears in the Placemark's description
balloon.
This tag does not support HTML markup.
<Snippet> has a maxLines attribute, an integer that specifies the
maximum number of lines to display.
"""

_default_ns = config.KMLNS

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

Expand Down
2 changes: 2 additions & 0 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
class KML(_XMLObject):
"""represents a KML File."""

_default_ns = config.KMLNS

_features: List[Union[Folder, Document, Placemark]]
ns: str

Expand Down
7 changes: 7 additions & 0 deletions fastkml/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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
Expand Down Expand Up @@ -222,6 +223,8 @@ class ViewVolume(_XMLObject):
https://developers.google.com/kml/documentation/kmlreference#viewvolume
"""

_default_ns = config.KMLNS

left_fow: Optional[float]
# Angle, in degrees, between the camera's viewing direction and the left side
# of the view volume.
Expand Down Expand Up @@ -409,6 +412,8 @@ class ImagePyramid(_XMLObject):
element to include specifications for which tiles to load.
"""

_default_ns = config.KMLNS

tile_size: Optional[int]
# Size of the tiles, in pixels. Tiles must be square, and <tileSize> must be a power
# of 2. A tile size of 256 (the default) or 512 is recommended.
Expand Down Expand Up @@ -789,6 +794,8 @@ class LatLonBox(_XMLObject):
Rotations are specified in a counterclockwise direction.
"""

_default_ns = config.KMLNS

north: Optional[float]
south: Optional[float]
east: Optional[float]
Expand Down
18 changes: 18 additions & 0 deletions fastkml/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,29 @@ def _get_kwargs(


class HotSpot(_XMLObject):
"""
Specifies the position within the Icon that is "anchored" to the <Point>.
x - Either the number of pixels, a fractional component of the icon,
or a pixel inset indicating the x component of a point on the icon.
y - Either the number of pixels, a fractional component of the icon,
or a pixel inset indicating the y component of a point on the icon.
xunits - Units in which the x value is specified.
A value of fraction indicates the x value is a fraction of the icon.
A value of pixels indicates the x value in pixels.
A value of insetPixels indicates the indent from the right edge of the icon.
yunits - Units in which the y value is specified.
https://developers.google.com/kml/documentation/kmlreference#hotspot
"""

x: Optional[float]
y: Optional[float]
xunits: Optional[Units]
yunits: Optional[Units]

_default_ns = config.KMLNS

def __init__(
self,
ns: Optional[str] = None,
Expand Down
5 changes: 5 additions & 0 deletions fastkml/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional
from typing import Union

from fastkml import config
from fastkml.base import _BaseObject
from fastkml.base import _XMLObject
from fastkml.enums import AltitudeMode
Expand Down Expand Up @@ -428,6 +429,8 @@ class LatLonAltBox(_XMLObject):
https://developers.google.com/kml/documentation/kmlreference#latlonaltbox
"""

_default_ns = config.KMLNS

north: Optional[float]
south: Optional[float]
east: Optional[float]
Expand Down Expand Up @@ -620,6 +623,8 @@ class Lod(_XMLObject):
https://developers.google.com/kml/documentation/kmlreference#elements-specific-to-region
"""

_default_ns = config.KMLNS

min_lod_pixels: Optional[float]
max_lod_pixels: Optional[float]
min_fade_extent: Optional[float]
Expand Down
2 changes: 1 addition & 1 deletion tests/oldunit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setup_method(self) -> None:

def test_kml(self) -> None:
"""Kml file without contents."""
k = kml.KML()
k = kml.KML(ns="")
assert k.features == []
assert (
str(k.to_string())[:51]
Expand Down

0 comments on commit 7a26c65

Please sign in to comment.