Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py2.7.3] Fix for new parse_bogus_comments change

  • Loading branch information...
commit 6f39e5fcb60701a3967ed2b5bf39ad00729db472 1 parent cdf715a
@mattbasta authored
View
12 tests/test_l10n_dtd.py
@@ -1,3 +1,5 @@
+from nose.tools import eq_
+
import validator.testcases.l10n.dtd as dtd
@@ -45,13 +47,13 @@ def test_broken_file():
def _inspect_file_results(parser):
"""Inspect the output of the DTD file tests."""
- assert len(parser) == 7
+ eq_(len(parser), 7)
assert "foo" in parser.entities
- assert parser.entities["foo"] == "bar"
+ eq_(parser.entities["foo"], "bar")
assert "overwrite" in parser.entities
- assert parser.entities["overwrite"] == "bar"
+ eq_(parser.entities["overwrite"], "bar")
assert "two" in parser.entities
- assert parser.entities["two"] == "per"
+ eq_(parser.entities["two"], "per")
assert "line" in parser.entities
- assert parser.entities["line"] == "woot"
+ eq_(parser.entities["line"], "woot")
View
2  tests/test_markup_markuptester.py
@@ -365,7 +365,7 @@ def test_proper_line_numbers():
<script>
eval("OWOWOWOWOWOWOWOW");
</script>
- </foo>""", "foo.xul", should_fail=True)
+ </foo>""", "foo.xul")
assert err.warnings
warning = err.warnings[0]
View
19 validator/testcases/l10n/dtd.py
@@ -3,9 +3,9 @@
from validator.contextgenerator import ContextGenerator
try:
- from HTMLParser import HTMLParser
-except ImportError: # pragma: no cover
from html.parser import HTMLParser
+except ImportError: # pragma: no cover
+ from HTMLParser import HTMLParser
class DTDParser(object):
@@ -41,14 +41,12 @@ def __len__(self):
def _parse(self, data):
"Parses the DTD data and stores it in an aggregate format."
- split = data.split("\n")
parser = DTDXMLParser()
# Feed the DTD file in line-by-line.
- for line in split:
- line += "\n"
+ for split_line in data.split("\n"):
try:
- parser.feed(line)
- except Exception:
+ parser.feed(split_line + "\n")
+ except Exception as e:
parser = DTDXMLParser()
else:
if parser.out_buffer:
@@ -65,6 +63,10 @@ def __init__(self):
HTMLParser.__init__(self)
self.out_buffer = []
+ # Support for py2.7/3k
+ def handle_comment(self, data):
+ self.unknown_decl(data)
+
def unknown_decl(self, decl):
"Handles non-DOCTYPE SGML declarations in *ML documents."
@@ -74,7 +76,6 @@ def unknown_decl(self, decl):
if not split_decl[0] == "ENTITY" or len(split_decl) < 3:
# Interestingly enough, it legitimately IS an unknown
# declaration. Funny thing, you know?
- # TODO: Log an error?
return
self.out_buffer.append((split_decl[1],
@@ -84,5 +85,3 @@ def unknown_decl(self, decl):
def clear_buffer(self):
"Clears the return buffer."
self.out_buffer = []
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.