summaryrefslogtreecommitdiff
path: root/bs4/builder/__init__.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-07-07 15:59:09 -0400
committerLeonard Richardson <leonardr@segfault.org>2019-07-07 15:59:09 -0400
commit0159c0a4135f267aed0586ba9d829d0a3da25da8 (patch)
tree78f20c40c74910109651bb7fb0a1b6dc1a29a621 /bs4/builder/__init__.py
parent0c3c1970dcb93bbe591707e43cfba9b24de45d05 (diff)
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]
Diffstat (limited to 'bs4/builder/__init__.py')
-rw-r--r--bs4/builder/__init__.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/bs4/builder/__init__.py b/bs4/builder/__init__.py
index 4207750..9dad920 100644
--- a/bs4/builder/__init__.py
+++ b/bs4/builder/__init__.py
@@ -96,11 +96,15 @@ class TreeBuilder(object):
# A value for these tag/attribute combinations is a space- or
# comma-separated list of CDATA, rather than a single CDATA.
- cdata_list_attributes = {}
+ DEFAULT_CDATA_LIST_ATTRIBUTES = {}
-
- def __init__(self):
+ USE_DEFAULT = object()
+
+ def __init__(self, cdata_list_attributes=USE_DEFAULT):
self.soup = None
+ if cdata_list_attributes is self.USE_DEFAULT:
+ cdata_list_attributes = self.DEFAULT_CDATA_LIST_ATTRIBUTES
+ self.cdata_list_attributes = cdata_list_attributes
def initialize_soup(self, soup):
"""The BeautifulSoup object has been initialized and is now
@@ -131,7 +135,7 @@ class TreeBuilder(object):
if self.empty_element_tags is None:
return True
return tag_name in self.empty_element_tags
-
+
def feed(self, markup):
raise NotImplementedError()
@@ -259,7 +263,7 @@ class HTMLTreeBuilder(TreeBuilder):
# encounter one of these attributes, we will parse its value into
# a list of values if possible. Upon output, the list will be
# converted back into a string.
- cdata_list_attributes = {
+ DEFAULT_CDATA_LIST_ATTRIBUTES = {
"*" : ['class', 'accesskey', 'dropzone'],
"a" : ['rel', 'rev'],
"link" : ['rel', 'rev'],