[wwwsearch-commits] r36173 - wwwsearch/ClientForm/trunk
jjlee at codespeak.net
jjlee at codespeak.net
Fri Jan 5 23:12:36 CET 2007
Author: jjlee
Date: Fri Jan 5 23:12:34 2007
New Revision: 36173
Modified:
wwwsearch/ClientForm/trunk/ClientForm.py
Log:
For backwards compatibility, make ParseError derive from the exceptions that used to be raised during parsing
Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py (original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py Fri Jan 5 23:12:34 2007
@@ -103,6 +103,19 @@
htmlentitydefs, re, random
from cStringIO import StringIO
+import sgmllib
+# monkeypatch to fix http://www.python.org/sf/803422 :-(
+sgmllib.charref = re.compile("&#(x?[0-9a-fA-F]+)[^0-9a-fA-F]")
+
+# HTMLParser.HTMLParser is recent, so live without it if it's not available
+# (also, sgmllib.SGMLParser is much more tolerant of bad HTML)
+try:
+ import HTMLParser
+except ImportError:
+ HAVE_MODULE_HTMLPARSER = False
+else:
+ HAVE_MODULE_HTMLPARSER = True
+
try:
import warnings
except ImportError:
@@ -426,8 +439,16 @@
class ItemCountError(ValueError): pass
-
-class ParseError(Exception): pass
+# for backwards compatibility, ParseError derives from exceptions that were
+# raised by versions of ClientForm <= 0.2.5
+if HAVE_MODULE_HTMLPARSER:
+ class ParseError(sgmllib.SGMLParser,
+ HTMLParser.HTMLParser,
+ ):
+ pass
+else:
+ class ParseError(sgmllib.SGMLParser):
+ pass
class _AbstractFormParser:
@@ -748,11 +769,7 @@
def unknown_charref(self, ref): self.handle_data("&#%s;" % ref)
-# HTMLParser.HTMLParser is recent, so live without it if it's not available
-# (also, htmllib.HTMLParser is much more tolerant of bad HTML)
-try:
- import HTMLParser
-except ImportError:
+if not HAVE_MODULE_HTMLPARSER:
class XHTMLCompatibleFormParser:
def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING):
raise ValueError("HTMLParser could not be imported")
@@ -807,9 +824,6 @@
def unescape_attrs_if_required(self, attrs):
return attrs # ditto
-import sgmllib
-# monkeypatch to fix http://www.python.org/sf/803422 :-(
-sgmllib.charref = re.compile("&#(x?[0-9a-fA-F]+)[^0-9a-fA-F]")
class _AbstractSgmllibParser(_AbstractFormParser):
More information about the wwwsearch-commits
mailing list