[Zope-Checkins] SVN: Zope/trunk/lib/python/ there has only been one
"right" way to import Expat for a long time now;
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Aug 24 19:43:30 EDT 2005
Log message for revision 38082:
there has only been one "right" way to import Expat for a long time now;
use it
Changed:
U Zope/trunk/lib/python/Shared/DC/xml/ppml.py
U Zope/trunk/lib/python/TAL/XMLParser.py
U Zope/trunk/lib/python/TAL/tests/utils.py
-=-
Modified: Zope/trunk/lib/python/Shared/DC/xml/ppml.py
===================================================================
--- Zope/trunk/lib/python/Shared/DC/xml/ppml.py 2005-08-24 22:05:33 UTC (rev 38081)
+++ Zope/trunk/lib/python/Shared/DC/xml/ppml.py 2005-08-24 23:43:30 UTC (rev 38082)
@@ -750,7 +750,7 @@
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 @@
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 @@
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
Modified: Zope/trunk/lib/python/TAL/XMLParser.py
===================================================================
--- Zope/trunk/lib/python/TAL/XMLParser.py 2005-08-24 22:05:33 UTC (rev 38081)
+++ Zope/trunk/lib/python/TAL/XMLParser.py 2005-08-24 23:43:30 UTC (rev 38082)
@@ -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 @@
"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))
Modified: Zope/trunk/lib/python/TAL/tests/utils.py
===================================================================
--- Zope/trunk/lib/python/TAL/tests/utils.py 2005-08-24 22:05:33 UTC (rev 38081)
+++ Zope/trunk/lib/python/TAL/tests/utils.py 2005-08-24 23:43:30 UTC (rev 38082)
@@ -10,36 +10,28 @@
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):
More information about the Zope-Checkins
mailing list