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