summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Gedminas <marius@gedmin.as>2004-06-11 18:22:00 +0000
committerMarius Gedminas <marius@gedmin.as>2004-06-11 18:22:00 +0000
commit2aa287ccd0504a138dab685dc867259d685e93c7 (patch)
treee7cc3e89f0339637e90f7263f39e160ba006e535
parenta037df68947ef9c15036c02a7dc84dfd9295c14b (diff)
downloadzope-tal-2aa287ccd0504a138dab685dc867259d685e93c7.tar.gz
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.
-rw-r--r--talinterpreter.py19
-rw-r--r--tests/output/test_sa2.html8
-rw-r--r--tests/output/test_sa2.xml8
-rw-r--r--tests/test_talinterpreter.py12
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
- <!DOCTYPE> (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 <?xml?>
+ 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('<!DOCTYPE')
- if idx == -1:
- idx = s.find('<?xml')
+ idx = s.find('<?xml')
if idx >= 0 or s.isspace():
- # Do *not* preprend comments in front of the <!DOCTYPE> or
- # <?xml?> 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 <?xml?> 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 @@
-<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "DTD/xhtml1-transitional.dtd"><!--
+<!--
==============================================================================
tests/input/test_sa2.html
==============================================================================
--->
+--><!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "DTD/xhtml1-transitional.dtd">
<html>
<title>Simple test of source annotations</title>
<body>
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 @@
-<?xml version="1.0" ?>
-<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "DTD/xhtml1-transitional.dtd"><!--
+<?xml version="1.0" ?><!--
==============================================================================
tests/input/test_sa2.xml
==============================================================================
-->
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "DTD/xhtml1-transitional.dtd">
<html>
<title>Simple test of source annotations</title>
<body>
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',
- '<!DOCTYPE ...>@some text',
- ' <!DOCTYPE ...>@some text',
- '\n<!DOCTYPE ...>@some text',
- '<!DOCTYPE ...',
- '<?xml ...>@some text',
- ' <?xml ...>@some text',
- '\n<?xml ...>@some text',
+ '<?xml ...?>@some text',
+ ' <?xml ...?>@some text',
+ '\n<?xml ...?>@some text',
'<?xml ...',
- '<?xml ...?>\n<!DOCTYPE ...>@some text',
+ '<?xml ...?>@\n<!DOCTYPE ...>some text',
]
for output in test_cases:
input = output.replace('@', '')