Skip to content

Commit

Permalink
Add useful message to the ParseError exception.
Browse files Browse the repository at this point in the history
Sometimes, I would like to be able to catch ParseError, and output its
message immediately.  Set the exception's message to the parser error
message.
  • Loading branch information
jdufresne authored and gsnedders committed Apr 28, 2015
1 parent f644865 commit 325aeaa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion html5lib/html5parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .constants import tokenTypes, ReparseException, namespaces
from .constants import htmlIntegrationPointElements, mathmlTextIntegrationPointElements
from .constants import adjustForeignAttributes as adjustForeignAttributesMap
from .constants import E


def parse(doc, treebuilder="etree", encoding=None,
Expand Down Expand Up @@ -256,7 +257,7 @@ def parseError(self, errorcode="XXX-undefined-error", datavars={}):
# XXX The idea is to make errorcode mandatory.
self.errors.append((self.tokenizer.stream.position(), errorcode, datavars))
if self.strict:
raise ParseError
raise ParseError(E[errorcode] % datavars)

def normalizeToken(self, token):
""" HTML5 specific normalizations to the token stream """
Expand Down

0 comments on commit 325aeaa

Please sign in to comment.