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

Class ExpatParser

Lib/xml/sax/expatreader.py:79–438  ·  view source on GitHub ↗

SAX driver for the pyexpat C module.

Source from the content-addressed store, hash-verified

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

Callers 1

create_parserFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…