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

Class FragmentBuilderNS

Lib/xml/dom/expatbuilder.py:811–845  ·  view source on GitHub ↗

Fragment builder that supports namespaces.

Source from the content-addressed store, hash-verified

809
810
811class FragmentBuilderNS(Namespaces, FragmentBuilder):
812 """Fragment builder that supports namespaces."""
813
814 def reset(self):
815 FragmentBuilder.reset(self)
816 self._initNamespaces()
817
818 def _getNSattrs(self):
819 """Return string of namespace attributes from this element and
820 ancestors."""
821 # XXX This needs to be re-written to walk the ancestors of the
822 # context to build up the namespace information from
823 # declarations, elements, and attributes found in context.
824 # Otherwise we have to store a bunch more data on the DOM
825 # (though that *might* be more reliable -- not clear).
826 attrs = ""
827 context = self.context
828 L = []
829 while context:
830 if hasattr(context, '_ns_prefix_uri'):
831 for prefix, uri in context._ns_prefix_uri.items():
832 # add every new NS decl from context to L and attrs string
833 if prefix in L:
834 continue
835 L.append(prefix)
836 if prefix:
837 declname = "xmlns:" + prefix
838 else:
839 declname = "xmlns"
840 if attrs:
841 attrs = "%s\n %s='%s'" % (attrs, declname, uri)
842 else:
843 attrs = " %s='%s'" % (declname, uri)
844 context = context.parentNode
845 return attrs
846
847
848class ParseEscape(Exception):

Callers 2

parseFragmentFunction · 0.85
parseFragmentStringFunction · 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…