def build_tag(self, tag, attrs, close_tag): result = '<{}'.format(escape_html(tag)) for k, v in attrs: result += ' ' + escape_html(k) if v is not None: # If the attribute value contains a double quote, surround # with single quotes, otherwise use double quotes. if '"' in v: result += "='{}'".format(escape_html(v, quote=False)) else: result += '="{}"'.format(escape_html(v, quote=False)) if close_tag: return result + ' />' return result + '>'
def handle_endtag(self, tag): if tag == 'head': if self._in_head: self._in_head = False self._in_top_level = True elif tag == 'title': self._in_title = False self.metadata['title'] = self._data_buffer elif tag == 'body': self.body = self._data_buffer self._in_body = False self._in_top_level = True elif self._in_body: self._data_buffer += '</{}>'.format(escape_html(tag))