Commit 5cb2eb85 authored by Fred Drake's avatar Fred Drake

there has only been one "right" way to import Expat for a long time now;

use it
parent af422b0f
......@@ -750,7 +750,7 @@ def test1():
print z, '\012'
def test2():
import xml.parsers.pyexpat
import xml.parsers.expat
c=C()
c.foo=1
c.bar=2
......@@ -778,7 +778,7 @@ def test2():
file=''
F=xmlPickler()
F.binary=0
p=xml.parsers.pyexpat.ParserCreate()
p=xml.parsers.expat.ParserCreate()
p.CharacterDataHandler=F.handle_data
p.StartElementHandler=F.unknown_starttag
p.EndElementHandler=F.unknown_endtag
......@@ -786,13 +786,13 @@ def test2():
print r, '\012'
def test3():
import xml.parsers.pyexpat
import xml.parsers.expat
data=open('Data.xml').read()
file=open('out','w'+'b')
F=xmlPickler()
F.file=file
F.binary=1
p=xml.parsers.pyexpat.ParserCreate()
p=xml.parsers.expat.ParserCreate()
p.CharacterDataHandler=F.handle_data
p.StartElementHandler=F.unknown_starttag
p.EndElementHandler=F.unknown_endtag
......
......@@ -15,8 +15,14 @@
Generic expat-based XML parser base class.
"""
import xml.parsers.expat
import zLOG
XMLParseError = xml.parsers.expat.ExpatError
class XMLParser:
ordered_attributes = 0
......@@ -63,15 +69,7 @@ class XMLParser:
"Can't set expat handler %s" % name)
def createParser(self, encoding=None):
global XMLParseError
try:
from Products.ParsedXML.Expat import pyexpat
XMLParseError = pyexpat.ExpatError
return pyexpat.ParserCreate(encoding, ' ')
except ImportError:
from xml.parsers import expat
XMLParseError = expat.ExpatError
return expat.ParserCreate(encoding, ' ')
return xml.parsers.expat.ParserCreate(encoding, ' ')
def parseFile(self, filename):
self.parseStream(open(filename))
......
......@@ -10,36 +10,28 @@ if codedir not in sys.path:
sys.path.append(codedir)
import unittest
import xml.parsers.expat
# Set skipxml to true if an XML parser could not be found.
pyexpat = None
skipxml = 0
try:
import pyexpat
except ImportError:
try:
# the C extension in PyXML
import xml.parsers.pyexpat
except ImportError:
skipxml = 1
else:
pyexpat = xml.parsers.pyexpat
# (But Python always includes one now.)
skipxml = False
# Set oldexpat if the StartDoctypeDeclHandler and XmlDeclHandler are
# not supported. The tests need to know whether the events reported
# by those handlers should be expected, but need to make sure the
# right thing is returned if they are.
oldexpat = 0
if pyexpat is not None:
p = pyexpat.ParserCreate()
# Can't use hasattr() since pyexpat supports the handler
# attributes in a broken way.
try:
p.StartDoctypeDeclHandler = None
except AttributeError:
oldexpat = 1
#
oldexpat = False
p = xml.parsers.expat.ParserCreate()
#
# Can't use hasattr() since pyexpat supports the handler
# attributes in a broken way.
try:
p.StartDoctypeDeclHandler = None
except AttributeError:
oldexpat = True
def run_suite(suite, outf=None, errf=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment