MCPcopy Index your code
hub / github.com/python/cpython / parseString

Method parseString

Lib/xml/dom/expatbuilder.py:618–644  ·  view source on GitHub ↗

Parse a document fragment from a string, returning the fragment node.

(self, string)

Source from the content-addressed store, hash-verified

616 return self.parseString(file.read())
617
618 def parseString(self, string):
619 """Parse a document fragment from a string, returning the
620 fragment node."""
621 self._source = string
622 parser = self.getParser()
623 doctype = self.originalDocument.doctype
624 ident = ""
625 if doctype:
626 subset = doctype.internalSubset or self._getDeclarations()
627 if doctype.publicId:
628 ident = ('PUBLIC "%s" "%s"'
629 % (doctype.publicId, doctype.systemId))
630 elif doctype.systemId:
631 ident = 'SYSTEM "%s"' % doctype.systemId
632 else:
633 subset = ""
634 nsattrs = self._getNSattrs() # get ns decls from node's ancestors
635 document = _FRAGMENT_BUILDER_TEMPLATE % (ident, subset, nsattrs)
636 try:
637 parser.Parse(document, True)
638 except:
639 self.reset()
640 raise
641 fragment = self.fragment
642 self.reset()
643## self._parser = None
644 return fragment
645
646 def _getDeclarations(self):
647 """Re-create the internal subset from the DocumentType node.

Callers 2

parseFileMethod · 0.95
parseFragmentStringFunction · 0.95

Calls 4

_getDeclarationsMethod · 0.95
_getNSattrsMethod · 0.95
resetMethod · 0.95
getParserMethod · 0.80

Tested by

no test coverage detected