Skip to content

Commit 50fd4b3

Browse files
Make the setter method private.
1 parent e4f13a8 commit 50fd4b3

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

Doc/library/html.parser.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@ The output will then be:
121121
attributes can be preserved, etc.).
122122

123123

124-
.. method:: HTMLParser.support_cdata(flag)
125-
126-
Sets how the parser will parse CDATA declarations.
127-
If *flag* is true, then the :meth:`unknown_decl` method will be called
128-
for the CDATA section ``<![CDATA[...]]>``.
129-
If *flag* is false, then the :meth:`handle_comment` method will be called
130-
for ``<![CDATA[...>``.
131-
132-
.. versionadded:: 3.13.6
133-
134-
135124
The following methods are called when data or markup elements are encountered
136125
and they are meant to be overridden in a subclass. The base class
137126
implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`):

Lib/html/parser.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,17 @@ def clear_cdata_mode(self):
184184
self.cdata_elem = None
185185
self._escapable = True
186186

187-
def support_cdata(self, flag=True):
187+
def _set_support_cdata(self, flag=True):
188+
"""Enable or disable support of the CDATA sections.
189+
If enabled, "<[CDATA[" starts a CDATA section which ends with "]]>".
190+
If disabled, "<[CDATA[" starts a bogus comments which ends with ">".
191+
192+
This method is not called by default. Its purpose is to be called
193+
in custom handle_starttag() and handle_endtag() methods, with
194+
value that depends on the adjusted current node.
195+
See https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
196+
for details.
197+
"""
188198
self._support_cdata = flag
189199

190200
# Internal -- handle data as far as reasonable. May leave state

Lib/test/test_htmlparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, *args, autocdata=False, **kw):
1616
self.append = self.events.append
1717
html.parser.HTMLParser.__init__(self, *args, **kw)
1818
if autocdata:
19-
self.support_cdata(False)
19+
self._set_support_cdata(False)
2020

2121
def get_events(self):
2222
# Normalize the list of events so that buffer artefacts don't
@@ -38,15 +38,15 @@ def get_events(self):
3838
def handle_starttag(self, tag, attrs):
3939
self.append(("starttag", tag, attrs))
4040
if self.autocdata and tag == 'svg':
41-
self.support_cdata(True)
41+
self._set_support_cdata(True)
4242

4343
def handle_startendtag(self, tag, attrs):
4444
self.append(("startendtag", tag, attrs))
4545

4646
def handle_endtag(self, tag):
4747
self.append(("endtag", tag))
4848
if self.autocdata and tag == 'svg':
49-
self.support_cdata(False)
49+
self._set_support_cdata(False)
5050

5151
# all other markup
5252

0 commit comments

Comments
 (0)