From 629339ad9eb2ae960f046b1b2d077505e5fd05b6 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Fri, 2 Apr 2021 14:22:51 +0200 Subject: [PATCH] Fixes for tag implementation, use plural 'tags' for internal API, singular 'tag' for the XML attribute (proycon/folia#93) --- folia/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/folia/main.py b/folia/main.py index a23aacc..70da512 100644 --- a/folia/main.py +++ b/folia/main.py @@ -679,7 +679,7 @@ def __getattr__(self, attr): #overriding getattr so we can get defaults here rather than needing a copy on each element, saves memory if attr in ('set','cls','processor', 'confidence','datetime','n','href','src','speaker','begintime','endtime','xlinktype','xlinktitle','xlinklabel','xlinkrole','xlinkshow','label', 'textclass', 'metadata','exclusive', 'preservespace'): return None - elif attr == 'tag': + elif attr == 'tags': return [] elif attr == 'annotator': if self.processor: @@ -2618,9 +2618,6 @@ def xml(self, attribs = None,elements = None, skipchildren = False, form = Form. if self.metadata and self.metadata in self.doc.submetadata: attribs['metadata'] = self.metadata - if 'tag' not in attribs: #do not override if caller already set it - if self.tags: - attribs['tag'] = " ".join(self.tags) if self.XLINK: if self.href: @@ -2657,6 +2654,10 @@ def xml(self, attribs = None,elements = None, skipchildren = False, form = Form. tag = OLDTAGS_REVERSE[tag] e = E(tag,**attribs) + if self.tags: + #we have to add this after the creating because ElementMaker treats 'tag' as a reserved keyword parameter + e.attrib['tag'] = " ".join(self.tags) #XML property uses singular, API plural + if not skipchildren and self.data: #append children,