Python xml.sax() Examples
The following are 14
code examples of xml.sax().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xml
, or try the search function
.
Example #1
Source File: Parser.py From p2pool-n with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: Parser.py From p2pool-n with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: test_pulldom.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: test_pulldom.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: test_pulldom.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: test_pulldom.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: reader.py From delft with Apache License 2.0 | 5 votes |
def __init__(self): xml.sax.ContentHandler.__init__(self)
Example #8
Source File: reader.py From delft with Apache License 2.0 | 5 votes |
def __init__(self, corpus_type='lemonde'): xml.sax.ContentHandler.__init__(self) self.corpus_type = corpus_type
Example #9
Source File: test_pulldom.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #10
Source File: test_pulldom.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: test_bad_xml_use.py From dlint with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #12
Source File: _tupletree.py From pywbem with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self): xml.sax.ContentHandler.__init__(self) self.root = None self.elements = [] self.element = []
Example #13
Source File: test_pulldom.py From android_universal with MIT License | 5 votes |
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)
Example #14
Source File: test_pulldom.py From android_universal with MIT License | 5 votes |
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)