From 0159c0a4135f267aed0586ba9d829d0a3da25da8 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 7 Jul 2019 15:59:09 -0400 Subject: It's now possible to override a TreeBuilder's cdata_list_attributes dictionary by passing in a replacement. None will disable the feature altogether. [bug=1832978] --- bs4/element.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'bs4/element.py') diff --git a/bs4/element.py b/bs4/element.py index 547b8ba..1183f77 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -861,12 +861,27 @@ class Tag(PageElement): self.setup(parent, previous) self.hidden = False - # Set up any substitutions, such as the charset in a META tag. - if builder is not None: + if builder is None: + # In the absence of a TreeBuilder, assume this tag is nothing + # special. + self.can_be_empty_element = False + self.cdata_list_attributes = None + else: + # Set up any substitutions for this tag, such as the charset in a META tag. builder.set_up_substitutions(self) + + # Ask the TreeBuilder whether this tag might be an empty-element tag. self.can_be_empty_element = builder.can_be_empty_element(name) - else: - self.can_be_empty_element = False + + # Keep track of the list of attributes of this tag that + # might need to be treated as a list. + # + # For performance reasons, we store the whole data structure + # rather than asking the question of every tag. Asking would + # require building a new data structure every time, and + # (unlike can_be_empty_element), we almost never need + # to check this. + self.cdata_list_attributes = builder.cdata_list_attributes parserClass = _alias("parser_class") # BS3 -- cgit v1.2.3