Fragment builder that supports namespaces.
| 809 | |
| 810 | |
| 811 | class 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 | |
| 848 | class ParseEscape(Exception): |
no outgoing calls
no test coverage detected
searching dependent graphs…