From 758a463f30389a280aa8e6a12201b48aba4bcaa8 Mon Sep 17 00:00:00 2001 From: Patrick Sanderson Date: Wed, 20 Nov 2024 19:53:20 +0000 Subject: [PATCH] Element creator tagging methods Added class variable to store a creator tag so that the tag can be applied easily in scopes that do not have access to the service instance. --- clixon/element.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/clixon/element.py b/clixon/element.py index 609ff1e..bdffc28 100644 --- a/clixon/element.py +++ b/clixon/element.py @@ -6,6 +6,7 @@ class Element(object): + _creatortag = None def __init__( self, name: Optional[str] = "root", @@ -466,6 +467,29 @@ def findall(self, name: str) -> list: return self.get_elements(name=name, recursive=True) + def set_creator(self,creator: str) -> None: + """ + Set the creator tag to all class instances + :creator string: Valid XPath creator tag + :return: None + :rtype: None + """ + Element._creatortag = creator + + def tag_creator(self) -> None: + """ + Apply creator tag to Element + :return: self + :rtype: Element + """ + if Element._creatortag: + attribs = self.get_attributes() + attribs['cl:creator'] = Element._creatortag + self.set_attributes(attribs) + return self + else: + raise("Creator tag not defined") + def __getitem__(self, key: str) -> Optional[dict]: """ Return the attributes of the element.