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

Class ExpatParser

Lib/xml/sax/expatreader.py:81–440  ·  view source on GitHub ↗

SAX driver for the pyexpat C module.

Source from the content-addressed store, hash-verified

79# --- ExpatParser
80
81class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
82 """SAX driver for the pyexpat C module."""
83
84 def __init__(self, namespaceHandling=0, bufsize=2**16-20):
85 xmlreader.IncrementalParser.__init__(self, bufsize)
86 self._source = xmlreader.InputSource()
87 self._parser = None
88 self._namespaces = namespaceHandling
89 self._lex_handler_prop = None
90 self._parsing = False
91 self._entity_stack = []
92 self._external_ges = 0
93 self._interning = None
94
95 # XMLReader methods
96
97 def parse(self, source):
98 "Parse an XML document from a URL or an InputSource."
99 source = saxutils.prepare_input_source(source)
100
101 self._source = source
102 try:
103 self.reset()
104 self._cont_handler.setDocumentLocator(ExpatLocator(self))
105 xmlreader.IncrementalParser.parse(self, source)
106 except:
107 # bpo-30264: Close the source on error to not leak resources:
108 # xml.sax.parse() doesn't give access to the underlying parser
109 # to the caller
110 self._close_source()
111 raise
112
113 def prepareParser(self, source):
114 if source.getSystemId() is not None:
115 self._parser.SetBase(source.getSystemId())
116
117 # Redefined setContentHandler to allow changing handlers during parsing
118
119 def setContentHandler(self, handler):
120 xmlreader.IncrementalParser.setContentHandler(self, handler)
121 if self._parsing:
122 self._reset_cont_handler()
123
124 def getFeature(self, name):
125 if name == feature_namespaces:
126 return self._namespaces
127 elif name == feature_string_interning:
128 return self._interning is not None
129 elif name in (feature_validation, feature_external_pes,
130 feature_namespace_prefixes):
131 return 0
132 elif name == feature_external_ges:
133 return self._external_ges
134 raise SAXNotRecognizedException("Feature '%s' not recognized" % name)
135
136 def setFeature(self, name, state):
137 if self._parsing:
138 raise SAXNotSupportedException("Cannot set features while parsing")

Callers 1

create_parserFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected