Created
August 4, 2015 07:39
-
-
Save kevinmarks/c5e6cd652ea7d21d4da2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def unknown_starttag(self, tag, attrs): | |
| # called for each start tag | |
| # attrs is a list of (attr, value) tuples | |
| # e.g. for <pre class='screen'>, tag='pre', attrs=[('class', 'screen')] | |
| if _debug: sys.stderr.write('_BaseHTMLProcessor, unknown_starttag, tag=%s\n' % tag) | |
| uattrs = [] | |
| strattrs='' | |
| if attrs: | |
| for key, value in attrs: | |
| value=value.replace('>','>').replace('<','<').replace('"','"') | |
| value = self.bare_ampersand.sub("&", value) | |
| # thanks to Kevin Marks for this breathtaking hack to deal with (valid) high-bit attribute values in UTF-8 feeds | |
| if type(value) != type(u''): | |
| try: | |
| value = unicode(value, self.encoding) | |
| except: | |
| value = unicode(value, 'iso-8859-1') | |
| uattrs.append((unicode(key, self.encoding), value)) | |
| strattrs = u''.join([u' %s="%s"' % (key, value) for key, value in uattrs]) | |
| if self.encoding: | |
| try: | |
| strattrs=strattrs.encode(self.encoding) | |
| except: | |
| pass | |
| if tag in self.elements_no_end_tag: | |
| self.pieces.append('<%(tag)s%(strattrs)s />' % locals()) | |
| else: | |
| self.pieces.append('<%(tag)s%(strattrs)s>' % locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment