From 2aa287ccd0504a138dab685dc867259d685e93c7 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 11 Jun 2004 18:22:00 +0000 Subject: Improved content type guessing heuristic in zope.publisher.browser. Now source annotations will not result in som epages being returned as text/plain. Removed comments implicating Mozilla which is completely innocent. Removed code that tried to work around this bug by postponing annotations after doctype declarations. Made the content-type guesser add a header X-Content-Type-Warning: guessed from content In the future all page templates should declare their content types explicitly and if they do not, a warning should be displayed in the event log. --- talinterpreter.py | 19 +++++++------------ tests/output/test_sa2.html | 8 ++++---- tests/output/test_sa2.xml | 8 ++++---- tests/test_talinterpreter.py | 12 ++++-------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/talinterpreter.py b/talinterpreter.py index af46fa8..9df6a84 100644 --- a/talinterpreter.py +++ b/talinterpreter.py @@ -102,9 +102,8 @@ class TALInterpreter: 1. setPosition bytecode follows setSourceFile, and we need position information to output the line number. - 2. Mozilla does not cope with HTML comments that occur before - (XXX file a bug into bugzilla.mozilla.org as comments - are legal there according to HTML4 spec). + 2. Comments are not allowed in XML documents before the + declaration. For performance reasons (XXX premature optimization?) instead of checking the value of _pending_source_annotation on every write to the output @@ -257,17 +256,13 @@ class TALInterpreter: self._stream_write = self.stream.write def _annotated_stream_write(self, s): - idx = s.find('= 0 or s.isspace(): - # Do *not* preprend comments in front of the or - # declaration! Although that is completely legal according - # to w3c.org, Mozilla chokes on such pages. - end_of_doctype = s.find('>', idx) + # Do not preprend comments in front of the declaration. + end_of_doctype = s.find('?>', idx) if end_of_doctype > idx: - self.stream.write(s[:end_of_doctype+1]) - s = s[end_of_doctype+1:] + self.stream.write(s[:end_of_doctype+2]) + s = s[end_of_doctype+2:] # continue else: self.stream.write(s) diff --git a/tests/output/test_sa2.html b/tests/output/test_sa2.html index 0fc0d93..4709b49 100644 --- a/tests/output/test_sa2.html +++ b/tests/output/test_sa2.html @@ -1,10 +1,10 @@ - +--> Simple test of source annotations diff --git a/tests/output/test_sa2.xml b/tests/output/test_sa2.xml index 59a3c07..30b5699 100644 --- a/tests/output/test_sa2.xml +++ b/tests/output/test_sa2.xml @@ -1,11 +1,11 @@ - - + Simple test of source annotations diff --git a/tests/test_talinterpreter.py b/tests/test_talinterpreter.py index 29251f0..fb8893f 100644 --- a/tests/test_talinterpreter.py +++ b/tests/test_talinterpreter.py @@ -410,15 +410,11 @@ class TestSourceAnnotations(unittest.TestCase): test_cases = [ '@some text', '\n', - '@some text', - ' @some text', - '\n@some text', - '@some text', - ' @some text', - '\n@some text', + '@some text', + ' @some text', + '\n@some text', '\n@some text', + '@\nsome text', ] for output in test_cases: input = output.replace('@', '') -- cgit v1.2.1