| 1725 | self.decls['xmlns:'+prefix] = uri |
| 1726 | |
| 1727 | def startElementNS(self, name, qname, attrs): |
| 1728 | namespace, localname = name |
| 1729 | lowernamespace = str(namespace or '').lower() |
| 1730 | if lowernamespace.find('backend.userland.com/rss') <> -1: |
| 1731 | # match any backend.userland.com namespace |
| 1732 | namespace = 'http://backend.userland.com/rss' |
| 1733 | lowernamespace = namespace |
| 1734 | if qname and qname.find(':') > 0: |
| 1735 | givenprefix = qname.split(':')[0] |
| 1736 | else: |
| 1737 | givenprefix = None |
| 1738 | prefix = self._matchnamespaces.get(lowernamespace, givenprefix) |
| 1739 | if givenprefix and (prefix is None or (prefix == '' and lowernamespace == '')) and not self.namespacesInUse.has_key(givenprefix): |
| 1740 | raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix |
| 1741 | localname = str(localname).lower() |
| 1742 | |
| 1743 | # qname implementation is horribly broken in Python 2.1 (it |
| 1744 | # doesn't report any), and slightly broken in Python 2.2 (it |
| 1745 | # doesn't report the xml: namespace). So we match up namespaces |
| 1746 | # with a known list first, and then possibly override them with |
| 1747 | # the qnames the SAX parser gives us (if indeed it gives us any |
| 1748 | # at all). Thanks to MatejC for helping me test this and |
| 1749 | # tirelessly telling me that it didn't work yet. |
| 1750 | attrsD, self.decls = self.decls, {} |
| 1751 | if localname=='math' and namespace=='http://www.w3.org/1998/Math/MathML': |
| 1752 | attrsD['xmlns']=namespace |
| 1753 | if localname=='svg' and namespace=='http://www.w3.org/2000/svg': |
| 1754 | attrsD['xmlns']=namespace |
| 1755 | |
| 1756 | if prefix: |
| 1757 | localname = prefix.lower() + ':' + localname |
| 1758 | elif namespace and not qname: #Expat |
| 1759 | for name,value in self.namespacesInUse.items(): |
| 1760 | if name and value == namespace: |
| 1761 | localname = name + ':' + localname |
| 1762 | break |
| 1763 | if _debug: sys.stderr.write('startElementNS: qname = %s, namespace = %s, givenprefix = %s, prefix = %s, attrs = %s, localname = %s\n' % (qname, namespace, givenprefix, prefix, attrs.items(), localname)) |
| 1764 | |
| 1765 | for (namespace, attrlocalname), attrvalue in attrs._attrs.items(): |
| 1766 | lowernamespace = (namespace or '').lower() |
| 1767 | prefix = self._matchnamespaces.get(lowernamespace, '') |
| 1768 | if prefix: |
| 1769 | attrlocalname = prefix + ':' + attrlocalname |
| 1770 | attrsD[str(attrlocalname).lower()] = attrvalue |
| 1771 | for qname in attrs.getQNames(): |
| 1772 | attrsD[str(qname).lower()] = attrs.getValueByQName(qname) |
| 1773 | self.unknown_starttag(localname, attrsD.items()) |
| 1774 | |
| 1775 | def characters(self, text): |
| 1776 | self.handle_data(text) |