[Checkins] SVN: zope.contenttype/trunk/ Restore detection of HTML snippets from 3.4 series.
Hanno Schlichting
hannosch at hannosch.eu
Tue Jul 26 06:02:46 EDT 2011
Log message for revision 122357:
Restore detection of HTML snippets from 3.4 series.
Changed:
U zope.contenttype/trunk/CHANGES.txt
U zope.contenttype/trunk/src/zope/contenttype/__init__.py
U zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py
-=-
Modified: zope.contenttype/trunk/CHANGES.txt
===================================================================
--- zope.contenttype/trunk/CHANGES.txt 2011-07-26 09:33:56 UTC (rev 122356)
+++ zope.contenttype/trunk/CHANGES.txt 2011-07-26 10:02:46 UTC (rev 122357)
@@ -4,6 +4,7 @@
3.5.4 (unreleased)
------------------
+* Restore detection of HTML snippets from 3.4 series.
3.5.3 (2011-03-18)
------------------
Modified: zope.contenttype/trunk/src/zope/contenttype/__init__.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/__init__.py 2011-07-26 09:33:56 UTC (rev 122356)
+++ zope.contenttype/trunk/src/zope/contenttype/__init__.py 2011-07-26 10:02:46 UTC (rev 122357)
@@ -32,17 +32,20 @@
s2 = s.lower()
if len(s) == max_tags:
-
if s2.startswith('<html>'):
return 'text/html'
-
+
if s2.startswith('<!doctype html'):
return 'text/html'
# what about encodings??
if s.startswith('<?xml'):
return 'text/xml'
-
+
+ # we also recognize small snippets of HTML
+ if '</' in s:
+ return 'text/html'
+
return 'text/plain'
Modified: zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py 2011-07-26 09:33:56 UTC (rev 122356)
+++ zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py 2011-07-26 10:02:46 UTC (rev 122357)
@@ -79,6 +79,9 @@
'"-//W3C//DTD HTML 4.01 Transitional//EN" '
'"http://www.w3.org/TR/html4/loose.dtd">'),
'text/html')
+ self.assertEqual(text_type('\n\n<!DOCTYPE html>\n'), 'text/html')
+ # we can also parse text snippets
+ self.assertEqual(text_type('<p>Hello</p>'), 'text/html')
# See https://bugs.launchpad.net/bugs/487998
self.assertEqual(text_type(' ' * 14 + HTML),
'text/html')
More information about the checkins
mailing list