mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-28 07:21:26 +03:00
update from Stphane Bidoul: python 2.1 support and improved error handler
* python/drv_libxml2.py: update from Stphane Bidoul: python 2.1 support and improved error handler registration Daniel
This commit is contained in:
parent
5ecaf7f9a7
commit
e329fc2467
@ -1,3 +1,8 @@
|
||||
Thu Jan 9 22:35:31 CET 2003 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* python/drv_libxml2.py: update from Stéphane Bidoul: python 2.1
|
||||
support and improved error handler registration
|
||||
|
||||
Thu Jan 9 14:16:38 CET 2003 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* HTMLtree.c tree.c: fixes #102920 about namespace handling in
|
||||
|
@ -34,10 +34,12 @@ TODO
|
||||
"""
|
||||
|
||||
__author__ = u"Stéphane Bidoul <sbi@skynet.be>"
|
||||
__version__ = "0.1"
|
||||
__version__ = "0.2"
|
||||
|
||||
import codecs
|
||||
from types import StringTypes
|
||||
import sys
|
||||
from types import StringType, UnicodeType
|
||||
StringTypes = (StringType,UnicodeType)
|
||||
|
||||
from xml.sax._exceptions import *
|
||||
from xml.sax import xmlreader, saxutils
|
||||
@ -54,7 +56,7 @@ from xml.sax.handler import \
|
||||
property_xml_string
|
||||
|
||||
# libxml2 returns strings as UTF8
|
||||
_decoder = codecs.getdecoder("utf8")
|
||||
_decoder = codecs.lookup("utf8")[1]
|
||||
def _d(s):
|
||||
if s is None:
|
||||
return s
|
||||
@ -64,19 +66,18 @@ def _d(s):
|
||||
try:
|
||||
import libxml2
|
||||
except ImportError, e:
|
||||
raise SAXReaderNotAvailable("libxml2 not available: " + e)
|
||||
raise SAXReaderNotAvailable("libxml2 not available: " \
|
||||
"import error was: %s" % e)
|
||||
|
||||
try:
|
||||
import libxslt
|
||||
except ImportError:
|
||||
# normal behaviour
|
||||
def _registerErrorHandler(handler):
|
||||
libxml2.registerErrorHandler(handler,"drv_libxml")
|
||||
else:
|
||||
# work around libxslt bindings bug (libxml2 bug #102181)
|
||||
def _registerErrorHandler(handler):
|
||||
libxml2.registerErrorHandler(handler,"drv_libxml")
|
||||
libxslt.registerErrorHandler(handler,"drv_libxml")
|
||||
def _registerErrorHandler(handler):
|
||||
if not sys.modules.has_key('libxslt'):
|
||||
# normal behaviour when libxslt is not imported
|
||||
libxml2.registerErrorHandler(handler,"drv_libxml2")
|
||||
else:
|
||||
# when libxslt is imported, one must
|
||||
# use libxst's error handler instead (see libxml2 bug 102181)
|
||||
import libxslt
|
||||
libxslt.registerErrorHandler(handler,"drv_libxml2")
|
||||
|
||||
class LibXml2Reader(xmlreader.XMLReader):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user