diff options
Diffstat (limited to 'src/htmltextview.py')
-rw-r--r-- | src/htmltextview.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/htmltextview.py b/src/htmltextview.py index ce7f72db5..6cca4db9f 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -241,7 +241,7 @@ def _parse_css_color(color): def style_iter(style): return (map(lambda x:x.strip(),item.split(':', 1)) for item in style.split(';') if len(item.strip())) - + class HtmlHandler(xml.sax.handler.ContentHandler): """A handler to display html to a gtk textview. @@ -280,9 +280,9 @@ class HtmlHandler(xml.sax.handler.ContentHandler): self.iter.get_attributes(attrs) self.iter.forward_char() return attrs - + else: - + # Workaround http://bugzilla.gnome.org/show_bug.cgi?id=317455 def _get_current_style_attr(self, propname, comb_oper=None): tags = [tag for tag in self.styles if tag is not None] @@ -326,7 +326,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): sign = cmp(val,0) # limits: 1% to 500% val = sign*max(1,min(abs(val),500)) - frac = val/100 + frac = val/100 if font_relative: attrs = self._get_current_attributes() font_size = attrs.font.get_size() / pango.SCALE @@ -378,7 +378,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): callback(val, *args) except Exception: warnings.warn('Unable to parse length value "%s"' % value) - + def __parse_font_size_cb(length, tag): tag.set_property('size-points', length/display_resolution) __parse_font_size_cb = staticmethod(__parse_font_size_cb) @@ -432,7 +432,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): length += styles[-1].get_property(propname) tag.set_property(propname, length) #__frac_length_tag_cb = staticmethod(__frac_length_tag_cb) - + def _parse_style_margin_left(self, tag, value): # block relative self._parse_length(value, False, True, 1, 1000, self.__frac_length_tag_cb, @@ -479,7 +479,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): warnings.warn('Invalid text-align:%s requested' % value) else: tag.set_property('justification', align) - + def _parse_style_text_decoration(self, tag, value): values = value.split(' ') if 'none' in values: @@ -497,7 +497,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): warnings.warn('text-decoration:blink not implemented') if 'overline' in values: warnings.warn('text-decoration:overline not implemented') - + def _parse_style_white_space(self, tag, value): if value == 'pre': tag.set_property('wrap_mode', gtk.WRAP_NONE) @@ -511,7 +511,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): tag.set_property(propname, value) except Exception: gajim.log.warn( "Error with prop: " + propname + " for tag: " + str(tag)) - + def _parse_style_width(self, tag, value): if value == 'auto': @@ -523,8 +523,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler): return self._parse_length(value, False, False, 1, 1000, self.__length_tag_cb, tag, "height") - - + + # build a dictionary mapping styles to methods, for greater speed __style_methods = dict() for style in ('background-color', 'color', 'font-family', 'font-size', @@ -562,20 +562,20 @@ class HtmlHandler(xml.sax.handler.ContentHandler): '''Process a img tag. ''' try: - # Wait maximum 1s for connection + # Wait maximum 1s for connection socket.setdefaulttimeout(1) - try: - f = urllib2.urlopen(attrs['src']) - except Exception, ex: + try: + f = urllib2.urlopen(attrs['src']) + except Exception, ex: gajim.log.debug('Error loading image %s ' % attrs['src'] + str(ex)) - pixbuf = None - alt = attrs.get('alt', 'Broken image') - else: - # Wait 0.1s between each byte - try: - f.fp._sock.fp._sock.settimeout(0.5) - except Exception: - pass + pixbuf = None + alt = attrs.get('alt', 'Broken image') + else: + # Wait 0.1s between each byte + try: + f.fp._sock.fp._sock.settimeout(0.5) + except Exception: + pass # Max image size = 2 MB (to try to prevent DoS) mem = '' deadline = time.time() + 3 @@ -717,7 +717,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): def _starts_line(self): return self.starting or self.iter.starts_line() - + def _flush_text(self): if not self.text: return text, self.text = self.text, '' @@ -762,7 +762,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): img = gtk.Image() img.set_from_file(self.textview.interface.emoticons[emot_ascii]) img.show() - # TODO: add alt/tooltip with the special_text (a11y) + # TODO: add alt/tooltip with the special_text (a11y) self.textview.add_child_at_anchor(img, anchor) elif af: # now print it @@ -779,7 +779,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): self.endElement('i') if index < len(text): self._insert_text(text[index:]) - + def characters(self, content): if self.preserve: self.text += content @@ -804,7 +804,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): #FIXME: if we want to use id, it needs to be unique across # the whole textview, so we need to add something like the # message-id to it. - #id_ = attrs.get('id',None) + #id_ = attrs.get('id',None) id_ = None if name == 'a': #TODO: accesskey, charset, hreflang, rel, rev, tabindex, type @@ -827,11 +827,11 @@ class HtmlHandler(xml.sax.handler.ContentHandler): tag = self._process_img(attrs) if name in element_styles: style += element_styles[name] - # so that explicit styles override implicit ones, + # so that explicit styles override implicit ones, # we add the attribute last style += ";"+attrs.get('style','') if style == '': - style = None + style = None self._begin_span(style, tag, id_) if name == 'br': @@ -917,7 +917,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler): # self.text = ' ' class HtmlTextView(gtk.TextView): - + def __init__(self): gobject.GObject.__init__(self) self.set_wrap_mode(gtk.WRAP_CHAR) @@ -992,7 +992,7 @@ class HtmlTextView(gtk.TextView): parser = xml.sax.make_parser() parser.setContentHandler(HtmlHandler(self, eob)) parser.parse(StringIO(html)) - + # too much space after :) #if not eob.starts_line(): # buffer_.insert(eob, '\n') @@ -1075,7 +1075,7 @@ if __name__ == '__main__': htmlview.display_html('<hr />') htmlview.display_html(''' <p style='font-size:large'> - <span style='font-style: italic'>O<span style='font-size:larger'>M</span>G</span>, + <span style='font-style: italic'>O<span style='font-size:larger'>M</span>G</span>, I'm <span style='color:green'>green</span> with <span style='font-weight: bold'>envy</span>! </p> @@ -1094,8 +1094,8 @@ if __name__ == '__main__': <body xmlns='http://www.w3.org/1999/xhtml'> <p style='text-align:center'>Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?</p> <p style='text-align:right'><img src='http://www.jabber.org/images/psa-license.jpg' - alt='A License to Jabber' - width='50%' height='50%' + alt='A License to Jabber' + width='50%' height='50%' /></p> </body> ''') @@ -1107,7 +1107,7 @@ if __name__ == '__main__': <li> Two </li> <li> Three </li> </ul><hr /><pre style="background-color:rgb(120,120,120)">def fac(n): - def faciter(n,acc): + def faciter(n,acc): if n==0: return acc return faciter(n-1, acc*n) if n<0: raise ValueError('Must be non-negative') |