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

Class PullDOM

Lib/xml/dom/pulldom.py:13–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11CHARACTERS = "CHARACTERS"
12
13class PullDOM(xml.sax.ContentHandler):
14 _locator = None
15 document = None
16
17 def __init__(self, documentFactory=None):
18 from xml.dom import XML_NAMESPACE
19 self.documentFactory = documentFactory
20 self.firstEvent = [None, None]
21 self.lastEvent = self.firstEvent
22 self.elementStack = []
23 self.push = self.elementStack.append
24 try:
25 self.pop = self.elementStack.pop
26 except AttributeError:
27 # use class' pop instead
28 pass
29 self._ns_contexts = [{XML_NAMESPACE:'xml'}] # contains uri -> prefix dicts
30 self._current_context = self._ns_contexts[-1]
31 self.pending_events = []
32
33 def pop(self):
34 result = self.elementStack[-1]
35 del self.elementStack[-1]
36 return result
37
38 def setDocumentLocator(self, locator):
39 self._locator = locator
40
41 def startPrefixMapping(self, prefix, uri):
42 if not hasattr(self, '_xmlns_attrs'):
43 self._xmlns_attrs = []
44 self._xmlns_attrs.append((prefix or 'xmlns', uri))
45 self._ns_contexts.append(self._current_context.copy())
46 self._current_context[uri] = prefix or None
47
48 def endPrefixMapping(self, prefix):
49 self._current_context = self._ns_contexts.pop()
50
51 def startElementNS(self, name, tagName , attrs):
52 # Retrieve xml namespace declaration attributes.
53 xmlns_uri = 'http://www.w3.org/2000/xmlns/'
54 xmlns_attrs = getattr(self, '_xmlns_attrs', None)
55 if xmlns_attrs is not None:
56 for aname, value in xmlns_attrs:
57 attrs._attrs[(xmlns_uri, aname)] = value
58 self._xmlns_attrs = []
59 uri, localname = name
60 if uri:
61 # When using namespaces, the reader may or may not
62 # provide us with the original name. If not, create
63 # *a* valid tagName from the current context.
64 if tagName is None:
65 prefix = self._current_context[uri]
66 if prefix:
67 tagName = prefix + ":" + localname
68 else:
69 tagName = localname
70 if self.document:

Callers 1

resetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…