MCPcopy Index your code
hub / github.com/RustPython/RustPython / XMLParser

Class XMLParser

Lib/xml/etree/ElementTree.py:1520–1752  ·  view source on GitHub ↗

Element structure builder for XML source data based on the expat parser. *target* is an optional target object which defaults to an instance of the standard TreeBuilder class, *encoding* is an optional encoding string which if given, overrides the encoding specified in the XML file:

Source from the content-addressed store, hash-verified

1518
1519# also see ElementTree and TreeBuilder
1520class XMLParser:
1521 """Element structure builder for XML source data based on the expat parser.
1522
1523 *target* is an optional target object which defaults to an instance of the
1524 standard TreeBuilder class, *encoding* is an optional encoding string
1525 which if given, overrides the encoding specified in the XML file:
1526 http://www.iana.org/assignments/character-sets
1527
1528 """
1529
1530 def __init__(self, *, target=None, encoding=None):
1531 try:
1532 from xml.parsers import expat
1533 except ImportError:
1534 try:
1535 import pyexpat as expat
1536 except ImportError:
1537 raise ImportError(
1538 "No module named expat; use SimpleXMLTreeBuilder instead"
1539 )
1540 parser = expat.ParserCreate(encoding, "}")
1541 if target is None:
1542 target = TreeBuilder()
1543 # underscored names are provided for compatibility only
1544 self.parser = self._parser = parser
1545 self.target = self._target = target
1546 self._error = expat.error
1547 self._names = {} # name memo cache
1548 # main callbacks
1549 parser.DefaultHandlerExpand = self._default
1550 if hasattr(target, 'start'):
1551 parser.StartElementHandler = self._start
1552 if hasattr(target, 'end'):
1553 parser.EndElementHandler = self._end
1554 if hasattr(target, 'start_ns'):
1555 parser.StartNamespaceDeclHandler = self._start_ns
1556 if hasattr(target, 'end_ns'):
1557 parser.EndNamespaceDeclHandler = self._end_ns
1558 if hasattr(target, 'data'):
1559 parser.CharacterDataHandler = target.data
1560 # miscellaneous callbacks
1561 if hasattr(target, 'comment'):
1562 parser.CommentHandler = target.comment
1563 if hasattr(target, 'pi'):
1564 parser.ProcessingInstructionHandler = target.pi
1565 # Configure pyexpat: buffering, new-style attribute handling.
1566 parser.buffer_text = 1
1567 parser.ordered_attributes = 1
1568 self._doctype = None
1569 self.entity = {}
1570 try:
1571 self.version = "Expat %d.%d.%d" % expat.version_info
1572 except AttributeError:
1573 pass # unknown
1574
1575 def _setevents(self, events_queue, events_to_report):
1576 # Internal API for XMLPullParser
1577 # events_to_report: a list of events to report during parsing (same as

Callers 6

parseMethod · 0.85
__init__Method · 0.85
XMLFunction · 0.85
XMLIDFunction · 0.85
fromstringlistFunction · 0.85
canonicalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected