MCPcopy Index your code
hub / github.com/clips/pattern / _StrictFeedParser

Class _StrictFeedParser

pattern/web/feed/feedparser.py:1779–1873  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1777
1778if _XML_AVAILABLE:
1779 class _StrictFeedParser(_FeedParserMixin, xml.sax.handler.ContentHandler):
1780 def __init__(self, baseuri, baselang, encoding):
1781 xml.sax.handler.ContentHandler.__init__(self)
1782 _FeedParserMixin.__init__(self, baseuri, baselang, encoding)
1783 self.bozo = 0
1784 self.exc = None
1785 self.decls = {}
1786
1787 def startPrefixMapping(self, prefix, uri):
1788 if not uri:
1789 return
1790 # Jython uses '' instead of None; standardize on None
1791 prefix = prefix or None
1792 self.trackNamespace(prefix, uri)
1793 if prefix and uri == 'http://www.w3.org/1999/xlink':
1794 self.decls['xmlns:' + prefix] = uri
1795
1796 def startElementNS(self, name, qname, attrs):
1797 namespace, localname = name
1798 lowernamespace = str(namespace or '').lower()
1799 if lowernamespace.find(u'backend.userland.com/rss') <> -1:
1800 # match any backend.userland.com namespace
1801 namespace = u'http://backend.userland.com/rss'
1802 lowernamespace = namespace
1803 if qname and qname.find(':') > 0:
1804 givenprefix = qname.split(':')[0]
1805 else:
1806 givenprefix = None
1807 prefix = self._matchnamespaces.get(lowernamespace, givenprefix)
1808 if givenprefix and (prefix == None or (prefix == '' and lowernamespace == '')) and givenprefix not in self.namespacesInUse:
1809 raise UndeclaredNamespace, "'%s' is not associated with a namespace" % givenprefix
1810 localname = str(localname).lower()
1811
1812 # qname implementation is horribly broken in Python 2.1 (it
1813 # doesn't report any), and slightly broken in Python 2.2 (it
1814 # doesn't report the xml: namespace). So we match up namespaces
1815 # with a known list first, and then possibly override them with
1816 # the qnames the SAX parser gives us (if indeed it gives us any
1817 # at all). Thanks to MatejC for helping me test this and
1818 # tirelessly telling me that it didn't work yet.
1819 attrsD, self.decls = self.decls, {}
1820 if localname=='math' and namespace=='http://www.w3.org/1998/Math/MathML':
1821 attrsD['xmlns']=namespace
1822 if localname=='svg' and namespace=='http://www.w3.org/2000/svg':
1823 attrsD['xmlns']=namespace
1824
1825 if prefix:
1826 localname = prefix.lower() + ':' + localname
1827 elif namespace and not qname: #Expat
1828 for name,value in self.namespacesInUse.items():
1829 if name and value == namespace:
1830 localname = name + ':' + localname
1831 break
1832
1833 for (namespace, attrlocalname), attrvalue in attrs.items():
1834 lowernamespace = (namespace or '').lower()
1835 prefix = self._matchnamespaces.get(lowernamespace, '')
1836 if prefix:

Callers 1

parseFunction · 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…