fastkml icon indicating copy to clipboard operation
fastkml copied to clipboard

abstractmethod for etree_element and from_element?

Open martimpassos opened this issue 3 years ago • 5 comments

@abstractmethod
    def from_element(self, element, subelements):
        # subelements = ["altitude", "altitudeMode", {LatLonBox: ["north", "south", "east", "west", "rotation"]}]
        super().from_element(element)
        for subelement in subelements:
            if isinstance(subelement, dict):
                self.from_element(element, subelement.values()[0])
            else:
                value = element.find(f"{self.ns}{subelement}")
                if value:
                    setattr(self, subelement, value.text)

Just an idea to reduce code duplication, of course this sketch doesn't deal with class specifics like instantiating Geometry objects (Placemark), parsing dates (_TimePrimitives) or iterating through multiple child objects (_Containers), but I believe the general search-and-set behaviour could be abstracted throughout the project

martimpassos avatar Feb 04 '22 17:02 martimpassos

Hey Martim @martimpassos Now would be a good time to have a second look at this

cleder avatar Nov 25 '23 01:11 cleder

Hi @cleder, its been a while so I don't recall precisely how fastkml operates and why exactly I proposed the method above. I'll look into re-familiarizing myself with the code.

martimpassos avatar Nov 29 '23 12:11 martimpassos

The code has changed quite a bit since you last looked at. There is still quite some clean-up to do before V1.0. You don't have to get involved in contributing code if you do not have the time, but I'd appreciate your feedback, criticism, thoughts and pointers ;-)

cleder avatar Nov 29 '23 13:11 cleder

Implementation (WIP) in https://github.com/cleder/fastkml/tree/registry

cleder avatar Dec 30 '23 00:12 cleder

In https://github.com/cleder/fastkml/tree/registry I introduce a 'registry' which takes care of the most common use cases, some work is still to be done for some of the remaining occurrences of etree_element and _get_kwargs

cleder avatar Dec 31 '23 16:12 cleder