我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用xml.dom.pulldom.parse()。
def parse(self, _): h = self._handler h.startDocument() # The next two items ensure that items preceding the first # start_element are properly stored and emitted: h.comment("a comment") h.processingInstruction("target", "data") h.startElement("html", AttributesImpl({})) h.comment("a comment") h.processingInstruction("target", "data") h.startElement("p", AttributesImpl({"class": "paraclass"})) h.characters("text") h.endElement("p") h.endElement("html") h.endDocument()
def parse(file, parser=None, bufsize=None): """Parse a file into a DOM by filename or file object.""" if parser is None and not bufsize: from xml.dom import expatbuilder return expatbuilder.parse(file) else: from xml.dom import pulldom return _do_pulldom_parse(pulldom.parse, (file,), {'parser': parser, 'bufsize': bufsize})
def __init__(self, stream_or_string, **options): super(Deserializer, self).__init__(stream_or_string, **options) self.event_stream = pulldom.parse(self.stream, self._make_parser()) self.db = options.pop('using', DEFAULT_DB_ALIAS) self.ignore = options.pop('ignorenonexistent', False)
def parse(stream_or_string, parser=None, bufsize=None, forbid_dtd=False, forbid_entities=True, forbid_external=True): if parser is None: parser = make_parser() parser.forbid_dtd = forbid_dtd parser.forbid_entities = forbid_entities parser.forbid_external = forbid_external return _parse(stream_or_string, parser, bufsize)
def test_parse(self): """Minimal test of DOMEventStream.parse()""" # This just tests that parsing from a stream works. Actual parser # semantics are tested using parseString with a more focused XML # fragment. # Test with a filename: handler = pulldom.parse(tstfile) self.addCleanup(handler.stream.close) list(handler) # Test with a file object: with open(tstfile, "rb") as fin: list(pulldom.parse(fin))
def test_thorough_parse(self): """Test some of the hard-to-reach parts of PullDOM.""" self._test_thorough(pulldom.parse(None, parser=SAXExerciser()))
def parse(self, _): h = self._handler h.startDocument() h.startElement("html", AttributesImpl({})) h.comment("a comment") h.processingInstruction("target", "data") h.startElement("p", AttributesImpl({"class": "paraclass"})) h.characters("text") h.endElement("p") h.endElement("html") h.endDocument()
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)
def __init__(self, stream_or_string, **options): super(Deserializer, self).__init__(stream_or_string, **options) self.event_stream = pulldom.parse(self.stream) self.db = options.pop('using', DEFAULT_DB_ALIAS)
def __init__(self, stream_or_string, **options): self.rawImportRecordBuffer = [] self.options = options if isinstance(stream_or_string, six.string_types): self.stream = six.StringIO(stream_or_string) else: self.stream = stream_or_string self.event_stream = pulldom.parse(self.stream, self._make_parser()) self.thin = options.pop('thin', 0)