Kaydet (Commit) c6730e17 authored tarafından Fred Drake's avatar Fred Drake

move the xml package implementation to xmlcore, and adjust the tests to

test that package, not the xmlcore/PyXML switcheroo fiasco in the xml
module/package
üst cc117dbb
This diff is collapsed.
# regression test for SAX 2.0 -*- coding: iso-8859-1 -*-
# $Id$
from xml.sax import make_parser, ContentHandler, \
SAXException, SAXReaderNotAvailable, SAXParseException
from xmlcore.sax import make_parser, ContentHandler, \
SAXException, SAXReaderNotAvailable, SAXParseException
try:
make_parser()
except SAXReaderNotAvailable:
# don't try to test this module if we cannot create a parser
raise ImportError("no XML parsers available")
from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \
XMLFilterBase
from xml.sax.expatreader import create_parser
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from xmlcore.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \
XMLFilterBase
from xmlcore.sax.expatreader import create_parser
from xmlcore.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from cStringIO import StringIO
from test.test_support import verify, verbose, TestFailed, findfile
import os
......@@ -36,17 +36,17 @@ def test_make_parser2():
# Creating parsers several times in a row should succeed.
# Testing this because there have been failures of this kind
# before.
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
from xml.sax import make_parser
from xmlcore.sax import make_parser
p = make_parser()
except:
return 0
......@@ -108,7 +108,7 @@ def test_make_parser():
try:
# Creating a parser should succeed - it should fall back
# to the expatreader
p = make_parser(['xml.parsers.no_such_parser'])
p = make_parser(['xmlcore.parsers.no_such_parser'])
except:
return 0
else:
......
# xml.etree test. This file contains enough tests to make sure that
# xmlcore.etree test. This file contains enough tests to make sure that
# all included components work as they should. For a more extensive
# test suite, see the selftest script in the ElementTree distribution.
......@@ -30,9 +30,9 @@ def sanity():
"""
Import sanity.
>>> from xml.etree import ElementTree
>>> from xml.etree import ElementInclude
>>> from xml.etree import ElementPath
>>> from xmlcore.etree import ElementTree
>>> from xmlcore.etree import ElementInclude
>>> from xmlcore.etree import ElementPath
"""
def check_method(method):
......@@ -59,7 +59,7 @@ def interface():
"""
Test element tree interface.
>>> from xml.etree import ElementTree as ET
>>> from xmlcore.etree import ElementTree as ET
>>> element = ET.Element("tag", key="value")
>>> tree = ET.ElementTree(element)
......@@ -108,7 +108,7 @@ def find():
"""
Test find methods (including xpath syntax).
>>> from xml.etree import ElementTree as ET
>>> from xmlcore.etree import ElementTree as ET
>>> elem = ET.XML(SAMPLE_XML)
>>> elem.find("tag").tag
......@@ -176,7 +176,7 @@ def find():
def parseliteral():
r"""
>>> from xml.etree import ElementTree as ET
>>> from xmlcore.etree import ElementTree as ET
>>> element = ET.XML("<html><body>text</body></html>")
>>> ET.ElementTree(element).write(sys.stdout)
......@@ -273,7 +273,7 @@ def xinclude_loader(href, parse="xml", encoding=None):
except KeyError:
raise IOError("resource not found")
if parse == "xml":
from xml.etree.ElementTree import XML
from xmlcore.etree.ElementTree import XML
return XML(data)
return data
......@@ -281,8 +281,8 @@ def xinclude():
r"""
Basic inclusion example (XInclude C.1)
>>> from xml.etree import ElementTree as ET
>>> from xml.etree import ElementInclude
>>> from xmlcore.etree import ElementTree as ET
>>> from xmlcore.etree import ElementInclude
>>> document = xinclude_loader("C1.xml")
>>> ElementInclude.include(document, xinclude_loader)
......
......@@ -16,6 +16,8 @@ etree -- The ElementTree XML library. This is a subset of the full
"""
import sys
import xmlcore
__all__ = ["dom", "parsers", "sax", "etree"]
......@@ -27,11 +29,10 @@ __version__ = "$Revision$".split()[-2:][0]
_MINIMUM_XMLPLUS_VERSION = (0, 8, 4)
try:
import _xmlplus
except ImportError:
pass
sys.modules[__name__] = xmlcore
else:
try:
v = _xmlplus.version_info
......@@ -40,8 +41,7 @@ else:
pass
else:
if v >= _MINIMUM_XMLPLUS_VERSION:
import sys
_xmlplus.__path__.extend(__path__)
_xmlplus.__path__.extend(xmlcore.__path__)
sys.modules[__name__] = _xmlplus
else:
del v
......@@ -2,7 +2,7 @@
directly. Instead, the functions getDOMImplementation and
registerDOMImplementation should be imported from xml.dom."""
from xml.dom.minicompat import * # isinstance, StringTypes
from xmlcore.dom.minicompat import * # isinstance, StringTypes
# This is a list of well-known implementations. Well-known names
# should be published by posting to xml-sig@python.org, and are
......
......@@ -27,13 +27,13 @@ This avoids all the overhead of SAX and pulldom to gain performance.
# calling any methods on the node object if it exists. (A rather
# nice speedup is achieved this way as well!)
from xml.dom import xmlbuilder, minidom, Node
from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE
from xml.parsers import expat
from xml.dom.minidom import _append_child, _set_attribute_node
from xml.dom.NodeFilter import NodeFilter
from xmlcore.dom import xmlbuilder, minidom, Node
from xmlcore.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE
from xmlcore.parsers import expat
from xmlcore.dom.minidom import _append_child, _set_attribute_node
from xmlcore.dom.NodeFilter import NodeFilter
from xml.dom.minicompat import *
from xmlcore.dom.minicompat import *
TEXT_NODE = Node.TEXT_NODE
CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE
......
......@@ -50,7 +50,7 @@
__all__ = ["NodeList", "EmptyNodeList", "NewStyle",
"StringTypes", "defproperty", "GetattrMagic"]
import xml.dom
import xmlcore.dom
try:
unicode
......@@ -100,7 +100,7 @@ if list is type([]):
return len(self)
def _set_length(self, value):
raise xml.dom.NoModificationAllowedErr(
raise xmlcore.dom.NoModificationAllowedErr(
"attempt to modify read-only attribute 'length'")
length = property(_get_length, _set_length,
......@@ -132,7 +132,7 @@ if list is type([]):
return 0
def _set_length(self, value):
raise xml.dom.NoModificationAllowedErr(
raise xmlcore.dom.NoModificationAllowedErr(
"attempt to modify read-only attribute 'length'")
length = property(_get_length, _set_length,
......@@ -171,7 +171,7 @@ else:
def defproperty(klass, name, doc):
get = getattr(klass, ("_get_" + name)).im_func
def set(self, value, name=name):
raise xml.dom.NoModificationAllowedErr(
raise xmlcore.dom.NoModificationAllowedErr(
"attempt to modify read-only attribute " + repr(name))
assert not hasattr(klass, "_set_" + name), \
"expected not to find _set_" + name
......
import xml.sax
import xml.sax.handler
import xmlcore.sax
import xmlcore.sax.handler
import types
try:
......@@ -16,12 +16,12 @@ PROCESSING_INSTRUCTION = "PROCESSING_INSTRUCTION"
IGNORABLE_WHITESPACE = "IGNORABLE_WHITESPACE"
CHARACTERS = "CHARACTERS"
class PullDOM(xml.sax.ContentHandler):
class PullDOM(xmlcore.sax.ContentHandler):
_locator = None
document = None
def __init__(self, documentFactory=None):
from xml.dom import XML_NAMESPACE
from xmlcore.dom import XML_NAMESPACE
self.documentFactory = documentFactory
self.firstEvent = [None, None]
self.lastEvent = self.firstEvent
......@@ -164,8 +164,8 @@ class PullDOM(xml.sax.ContentHandler):
def startDocument(self):
if self.documentFactory is None:
import xml.dom.minidom
self.documentFactory = xml.dom.minidom.Document.implementation
import xmlcore.dom.minidom
self.documentFactory = xmlcore.dom.minidom.Document.implementation
def buildDocument(self, uri, tagname):
# Can't do that in startDocument, since we need the tagname
......@@ -219,7 +219,7 @@ class DOMEventStream:
def reset(self):
self.pulldom = PullDOM()
# This content handler relies on namespace support
self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
self.parser.setFeature(xmlcore.sax.handler.feature_namespaces, 1)
self.parser.setContentHandler(self.pulldom)
def __getitem__(self, pos):
......@@ -335,7 +335,7 @@ def parse(stream_or_string, parser=None, bufsize=None):
else:
stream = stream_or_string
if not parser:
parser = xml.sax.make_parser()
parser = xmlcore.sax.make_parser()
return DOMEventStream(stream, parser, bufsize)
def parseString(string, parser=None):
......@@ -347,5 +347,5 @@ def parseString(string, parser=None):
bufsize = len(string)
buf = StringIO(string)
if not parser:
parser = xml.sax.make_parser()
parser = xmlcore.sax.make_parser()
return DOMEventStream(buf, parser, bufsize)
"""Implementation of the DOM Level 3 'LS-Load' feature."""
import copy
import xml.dom
import xmlcore.dom
from xml.dom.minicompat import *
from xmlcore.dom.minicompat import *
from xml.dom.NodeFilter import NodeFilter
from xmlcore.dom.NodeFilter import NodeFilter
__all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"]
......@@ -80,13 +80,13 @@ class DOMBuilder:
try:
settings = self._settings[(_name_xform(name), state)]
except KeyError:
raise xml.dom.NotSupportedErr(
raise xmlcore.dom.NotSupportedErr(
"unsupported feature: %r" % (name,))
else:
for name, value in settings:
setattr(self._options, name, value)
else:
raise xml.dom.NotFoundErr("unknown feature: " + repr(name))
raise xmlcore.dom.NotFoundErr("unknown feature: " + repr(name))
def supportsFeature(self, name):
return hasattr(self._options, _name_xform(name))
......@@ -177,7 +177,7 @@ class DOMBuilder:
or options.create_entity_ref_nodes
or options.entities
or options.cdata_sections))
raise xml.dom.NotFoundErr("feature %s not known" % repr(name))
raise xmlcore.dom.NotFoundErr("feature %s not known" % repr(name))
def parseURI(self, uri):
if self.entityResolver:
......@@ -202,8 +202,8 @@ class DOMBuilder:
raise NotImplementedError("Haven't written this yet...")
def _parse_bytestream(self, stream, options):
import xml.dom.expatbuilder
builder = xml.dom.expatbuilder.makeBuilder(options)
import xmlcore.dom.expatbuilder
builder = xmlcore.dom.expatbuilder.makeBuilder(options)
return builder.parseFile(stream)
......@@ -342,7 +342,7 @@ class DocumentLS:
return False
def _set_async(self, async):
if async:
raise xml.dom.NotSupportedErr(
raise xmlcore.dom.NotSupportedErr(
"asynchronous document loading is not supported")
def abort(self):
......@@ -361,7 +361,7 @@ class DocumentLS:
if snode is None:
snode = self
elif snode.ownerDocument is not self:
raise xml.dom.WrongDocumentErr()
raise xmlcore.dom.WrongDocumentErr()
return snode.toxml()
......@@ -371,12 +371,12 @@ class DOMImplementationLS:
def createDOMBuilder(self, mode, schemaType):
if schemaType is not None:
raise xml.dom.NotSupportedErr(
raise xmlcore.dom.NotSupportedErr(
"schemaType not yet supported")
if mode == self.MODE_SYNCHRONOUS:
return DOMBuilder()
if mode == self.MODE_ASYNCHRONOUS:
raise xml.dom.NotSupportedErr(
raise xmlcore.dom.NotSupportedErr(
"asynchronous builders are not supported")
raise ValueError("unknown value for mode")
......
......@@ -1109,7 +1109,7 @@ class XMLTreeBuilder:
def __init__(self, html=0, target=None):
try:
from xml.parsers import expat
from xmlcore.parsers import expat
except ImportError:
raise ImportError(
"No module named expat; use SimpleXMLTreeBuilder instead"
......@@ -1191,7 +1191,7 @@ class XMLTreeBuilder:
try:
self._target.data(self.entity[text[1:-1]])
except KeyError:
from xml.parsers import expat
from xmlcore.parsers import expat
raise expat.error(
"undefined entity %s: line %d, column %d" %
(text, self._parser.ErrorLineNumber,
......
......@@ -51,12 +51,12 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
# this is the parser list used by the make_parser function if no
# alternatives are given as parameters to the function
default_parser_list = ["xml.sax.expatreader"]
default_parser_list = ["xmlcore.sax.expatreader"]
# tell modulefinder that importing sax potentially imports expatreader
_false = 0
if _false:
import xml.sax.expatreader
import xmlcore.sax.expatreader
import os, sys
if os.environ.has_key("PY_SAX_PARSER"):
......
......@@ -5,27 +5,27 @@ pyexpat.__version__ == '2.22'.
version = "0.20"
from xml.sax._exceptions import *
from xml.sax.handler import feature_validation, feature_namespaces
from xml.sax.handler import feature_namespace_prefixes
from xml.sax.handler import feature_external_ges, feature_external_pes
from xml.sax.handler import feature_string_interning
from xml.sax.handler import property_xml_string, property_interning_dict
# xml.parsers.expat does not raise ImportError in Jython
from xmlcore.sax._exceptions import *
from xmlcore.sax.handler import feature_validation, feature_namespaces
from xmlcore.sax.handler import feature_namespace_prefixes
from xmlcore.sax.handler import feature_external_ges, feature_external_pes
from xmlcore.sax.handler import feature_string_interning
from xmlcore.sax.handler import property_xml_string, property_interning_dict
# xmlcore.parsers.expat does not raise ImportError in Jython
import sys
if sys.platform[:4] == "java":
raise SAXReaderNotAvailable("expat not available in Java", None)
del sys
try:
from xml.parsers import expat
from xmlcore.parsers import expat
except ImportError:
raise SAXReaderNotAvailable("expat not supported", None)
else:
if not hasattr(expat, "ParserCreate"):
raise SAXReaderNotAvailable("expat not supported", None)
from xml.sax import xmlreader, saxutils, handler
from xmlcore.sax import xmlreader, saxutils, handler
AttributesImpl = xmlreader.AttributesImpl
AttributesNSImpl = xmlreader.AttributesNSImpl
......@@ -407,8 +407,8 @@ def create_parser(*args, **kwargs):
# ---
if __name__ == "__main__":
import xml.sax
import xmlcore.sax
p = create_parser()
p.setContentHandler(xml.sax.XMLGenerator())
p.setErrorHandler(xml.sax.ErrorHandler())
p.setContentHandler(xmlcore.sax.XMLGenerator())
p.setErrorHandler(xmlcore.sax.ErrorHandler())
p.parse("../../../hamlet.xml")
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