mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
Another round of fixes for older versions of Python
This commit is contained in:
committed by
Daniel Veillard
parent
e71dce18a1
commit
6dd7775f35
@ -40,14 +40,12 @@ __version__ = "0.3"
|
|||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
if sys.version < "3":
|
if sys.version_info[0] < 3:
|
||||||
__author__ = codecs.unicode_escape_decode(__author__)[0]
|
__author__ = codecs.unicode_escape_decode(__author__)[0]
|
||||||
|
|
||||||
from types import StringType, UnicodeType
|
StringTypes = (str, unicode)
|
||||||
StringTypes = (StringType,UnicodeType)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
StringTypes = (str)
|
StringTypes = str
|
||||||
|
|
||||||
from xml.sax._exceptions import *
|
from xml.sax._exceptions import *
|
||||||
from xml.sax import xmlreader, saxutils
|
from xml.sax import xmlreader, saxutils
|
||||||
@ -73,9 +71,9 @@ def _d(s):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import libxml2
|
import libxml2
|
||||||
except ImportError as e:
|
except ImportError:
|
||||||
raise SAXReaderNotAvailable("libxml2 not available: " \
|
raise SAXReaderNotAvailable("libxml2 not available: " \
|
||||||
"import error was: %s" % e)
|
"import error was: %s" % sys.exc_info()[1])
|
||||||
|
|
||||||
class Locator(xmlreader.Locator):
|
class Locator(xmlreader.Locator):
|
||||||
"""SAX Locator adapter for libxml2.xmlTextReaderLocator"""
|
"""SAX Locator adapter for libxml2.xmlTextReaderLocator"""
|
||||||
@ -142,7 +140,7 @@ class LibXml2Reader(xmlreader.XMLReader):
|
|||||||
self.__parsing = 1
|
self.__parsing = 1
|
||||||
try:
|
try:
|
||||||
# prepare source and create reader
|
# prepare source and create reader
|
||||||
if type(source) in StringTypes:
|
if isinstance(source, StringTypes):
|
||||||
reader = libxml2.newTextReaderFilename(source)
|
reader = libxml2.newTextReaderFilename(source)
|
||||||
else:
|
else:
|
||||||
source = saxutils.prepare_input_source(source)
|
source = saxutils.prepare_input_source(source)
|
||||||
|
Reference in New Issue
Block a user