1010
1111import _markupbase
1212import re
13+ import warnings
1314
1415# Regular expressions used for parsing
1516
@@ -113,14 +114,16 @@ class HTMLParser(_markupbase.ParserBase):
113114
114115 CDATA_CONTENT_ELEMENTS = ("script" , "style" )
115116
116- def __init__ (self , strict = True ):
117+ def __init__ (self , strict = False ):
117118 """Initialize and reset this instance.
118119
119- If strict is set to True (the default), errors are raised when invalid
120- HTML is encountered. If set to False, an attempt is instead made to
121- continue parsing, making "best guesses" about the intended meaning, in
122- a fashion similar to what browsers typically do.
120+ If strict is set to False (the default) the parser will parse invalid
121+ markup, otherwise it will raise an error. Note that the strict mode
122+ is deprecated.
123123 """
124+ if strict :
125+ warnings .warn ("The strict mode is deprecated." ,
126+ DeprecationWarning , stacklevel = 2 )
124127 self .strict = strict
125128 self .reset ()
126129
@@ -271,8 +274,8 @@ def goahead(self, end):
271274 # See also parse_declaration in _markupbase
272275 def parse_html_declaration (self , i ):
273276 rawdata = self .rawdata
274- if rawdata [i :i + 2 ] != '<!' :
275- self . error ( 'unexpected call to parse_html_declaration()' )
277+ assert rawdata [i :i + 2 ] == '<!' , ( 'unexpected call to '
278+ ' parse_html_declaration()' )
276279 if rawdata [i :i + 4 ] == '<!--' :
277280 # this case is actually already handled in goahead()
278281 return self .parse_comment (i )
@@ -292,8 +295,8 @@ def parse_html_declaration(self, i):
292295 # see http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state
293296 def parse_bogus_comment (self , i , report = 1 ):
294297 rawdata = self .rawdata
295- if rawdata [i :i + 2 ] not in ('<!' , '</' ):
296- self . error ( 'unexpected call to parse_comment()' )
298+ assert rawdata [i :i + 2 ] in ('<!' , '</' ), ( 'unexpected call to '
299+ ' parse_comment()' )
297300 pos = rawdata .find ('>' , i + 2 )
298301 if pos == - 1 :
299302 return - 1
0 commit comments