Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
369cbd74
Commit
369cbd74
authored
Feb 13, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
parent
ef18737b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
Lib/HTMLParser.py
Lib/HTMLParser.py
+3
-2
Lib/test/test_htmlparser.py
Lib/test/test_htmlparser.py
+24
-0
No files found.
Lib/HTMLParser.py
View file @
369cbd74
...
...
@@ -229,12 +229,13 @@ class HTMLParser(markupbase.ParserBase):
if
rawdata
[
i
:
i
+
2
]
!=
'<!'
:
self
.
error
(
'unexpected call to parse_html_declaration()'
)
if
rawdata
[
i
:
i
+
4
]
==
'<!--'
:
# this case is actually already handled in goahead()
return
self
.
parse_comment
(
i
)
elif
rawdata
[
i
:
i
+
3
]
==
'<!['
:
return
self
.
parse_marked_section
(
i
)
elif
rawdata
[
i
:
i
+
9
].
lower
()
==
'<!doctype'
:
# find the closing >
gtpos
=
rawdata
.
find
(
'>'
,
9
)
gtpos
=
rawdata
.
find
(
'>'
,
i
+
9
)
if
gtpos
==
-
1
:
return
-
1
self
.
handle_decl
(
rawdata
[
i
+
2
:
gtpos
])
...
...
@@ -427,7 +428,7 @@ class HTMLParser(markupbase.ParserBase):
pass
def
unknown_decl
(
self
,
data
):
self
.
error
(
"unknown declaration: %r"
%
(
data
,))
pass
# Internal -- helper to remove special character quoting
entitydefs
=
None
...
...
Lib/test/test_htmlparser.py
View file @
369cbd74
...
...
@@ -215,6 +215,30 @@ text
self
.
_parse_error
(
"<a foo='>'"
)
self
.
_parse_error
(
"<a foo='>"
)
def
test_valid_doctypes
(
self
):
# from http://www.w3.org/QA/2002/04/valid-dtd-list.html
dtds
=
[
'HTML'
,
# HTML5 doctype
(
'HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
'"http://www.w3.org/TR/html4/strict.dtd"'
),
(
'HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" '
'"http://www.w3.org/TR/html4/loose.dtd"'
),
(
'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"'
),
(
'html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"'
),
(
'math PUBLIC "-//W3C//DTD MathML 2.0//EN" '
'"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"'
),
(
'html PUBLIC "-//W3C//DTD '
'XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" '
'"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"'
),
(
'svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"'
),
'html PUBLIC "-//IETF//DTD HTML 2.0//EN"'
,
'html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"'
]
for
dtd
in
dtds
:
self
.
_run_check
(
"<!DOCTYPE %s>"
%
dtd
,
[(
'decl'
,
'DOCTYPE '
+
dtd
)])
def
test_declaration_junk_chars
(
self
):
self
.
_run_check
(
"<!DOCTYPE foo $ >"
,
[(
'decl'
,
'DOCTYPE foo $ '
)])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment