From bfc6e84e07f34caaec60ccf4d7dc2639f50e8534 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Sat, 5 Feb 2011 18:59:44 +0000 Subject: [PATCH] Bug 4287: Fix Html.attr property for self-closing tags (e.g. ) svn: r16582 --- src/plugins/lib/libhtml.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/plugins/lib/libhtml.py b/src/plugins/lib/libhtml.py index d6b15967b..ebdcda5fe 100644 --- a/src/plugins/lib/libhtml.py +++ b/src/plugins/lib/libhtml.py @@ -270,7 +270,7 @@ class Html(list): for keyw, arg in keywargs.iteritems(): if (keyw in ['indent', 'close', 'inline'] and arg in [True, False, None]): - setattr(self,keyw, arg) + setattr(self, keyw, arg) elif keyw == 'attr': # pass attributes along attr += ' ' + arg elif keyw[-1] == '_': # avoid Python conflicts @@ -461,8 +461,14 @@ class Html(list): :param name: new HTML tag """ curtag = self.tag + + # Replace closing tag, if any + if self[-1] == '' % curtag: self[-1] = '' % newtag + + # Replace opening tag + self[0] = self[0].replace('<' + curtag, '<' + newtag) tag = property(__gettag, __settag) # @@ -473,7 +479,7 @@ class Html(list): :rtype: string :returns: HTML attributes """ - attr = self[0].strip('').split(None, 1) + attr = self[0].strip('').split(None, 1) return attr[1] if len(attr) > 1 else '' # def __setattr(self, value): @@ -483,13 +489,24 @@ class Html(list): :type name: string :param name: new HTML attributes """ - self[0] = self[0][:len(self.tag)+1] + ' ' + value + self[0][-1:] + beg = len(self.tag) + 1 + + # See if self-closed or normal + + end = -2 if self.close is False else -1 + self[0] = self[0][:beg] + ' ' + value + self[0][end:] # def __delattr(self): """ Removes HTML attributes for this object """ - self[0] = '<' + self.tag + '>' + self[0] = '<' + self.tag + ( + + # Set correct closing delimiter(s) + + ' />' if self.close is False else '>' + ) +# attr = property(__getattr, __setattr, __delattr) # def __getinside(self):