本文整理汇总了Python中xml.sax方法的典型用法代码示例。如果您正苦于以下问题:Python xml.sax方法的具体用法?Python xml.sax怎么用?Python xml.sax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml.sax方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def __init__(self, rules = None):
xml.sax.handler.ContentHandler.__init__(self)
self.body = None
self.header = None
self.attrs = {}
self._data = None
self._next = "E" # Keeping state for message validity
self._stack = [self.Frame('SOAP')]
# Make two dictionaries to store the prefix <-> URI mappings, and
# initialize them with the default
self._prem = {NS.XML_T: NS.XML}
self._prem_r = {NS.XML: NS.XML_T}
self._ids = {}
self._refs = {}
self._rules = rules
示例2: _parseSOAP
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def _parseSOAP(xml_str, rules = None):
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
parser = xml.sax.make_parser()
t = SOAPParser(rules = rules)
parser.setContentHandler(t)
e = xml.sax.handler.ErrorHandler()
parser.setErrorHandler(e)
inpsrc = xml.sax.xmlreader.InputSource()
inpsrc.setByteStream(StringIO(xml_str))
# turn on namespace mangeling
parser.setFeature(xml.sax.handler.feature_namespaces,1)
parser.setFeature(xml.sax.handler.feature_external_ges, 0)
try:
parser.parse(inpsrc)
except xml.sax.SAXParseException, e:
parser._parser = None
raise e
示例3: reset
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def reset(self):
self.pulldom = pulldom.SAX2DOM()
# This content handler relies on namespace support
self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
self.parser.setContentHandler(self.pulldom)
示例4: test_basic
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def test_basic(self):
"""Ensure SAX2DOM can parse from a stream."""
with io.StringIO(SMALL_SAMPLE) as fin:
sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
len(SMALL_SAMPLE))
for evt, node in sd:
if evt == pulldom.START_ELEMENT and node.tagName == "html":
break
# Because the buffer is the same length as the XML, all the
# nodes should have been parsed and added:
self.assertGreater(len(node.childNodes), 0)
示例5: __init__
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def __init__(self):
xml.sax.ContentHandler.__init__(self)
示例6: test_saxutils_import_usage
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def test_saxutils_import_usage(self):
python_node = self.get_ast_node(
"""
import xml.sax.saxutils
from xml.sax import saxutils
"""
)
linter = dlint.linters.BadXMLUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
示例7: __init__
# 需要导入模块: import xml [as 别名]
# 或者: from xml import sax [as 别名]
def __init__(self):
xml.sax.ContentHandler.__init__(self)
self.root = None
self.elements = []
self.element = []