Use the logging module instead wanings in htmlview.py
This commit is contained in:
parent
a87540ddc0
commit
5aefe64736
|
@ -40,7 +40,6 @@ import pango
|
||||||
import gtk
|
import gtk
|
||||||
import xml.sax, xml.sax.handler
|
import xml.sax, xml.sax.handler
|
||||||
import re
|
import re
|
||||||
import warnings
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
@ -56,7 +55,8 @@ if __name__ == '__main__':
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
|
||||||
import tooltips
|
import tooltips
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger('gajim.htmlview')
|
||||||
|
|
||||||
__all__ = ['HtmlTextView']
|
__all__ = ['HtmlTextView']
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
val = sign*max(minl, min(abs(val), maxl))
|
val = sign*max(minl, min(abs(val), maxl))
|
||||||
callback(val, *args)
|
callback(val, *args)
|
||||||
except Exception:
|
except Exception:
|
||||||
warnings.warn('Unable to parse length value "%s"' % value)
|
log.warning('Unable to parse length value "%s"' % value)
|
||||||
|
|
||||||
def __parse_font_size_cb(length, tag):
|
def __parse_font_size_cb(length, tag):
|
||||||
tag.set_property('size-points', length/display_resolution)
|
tag.set_property('size-points', length/display_resolution)
|
||||||
|
@ -348,7 +348,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
'oblique': pango.STYLE_OBLIQUE,
|
'oblique': pango.STYLE_OBLIQUE,
|
||||||
} [value]
|
} [value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
warnings.warn('unknown font-style %s' % value)
|
log.warning('unknown font-style %s' % value)
|
||||||
else:
|
else:
|
||||||
tag.set_property('style', style)
|
tag.set_property('style', style)
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
'bold': pango.WEIGHT_BOLD,
|
'bold': pango.WEIGHT_BOLD,
|
||||||
} [value]
|
} [value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
warnings.warn('unknown font-style %s' % value)
|
log.warning('unknown font-style %s' % value)
|
||||||
else:
|
else:
|
||||||
tag.set_property('weight', weight)
|
tag.set_property('weight', weight)
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
'justify': gtk.JUSTIFY_FILL,
|
'justify': gtk.JUSTIFY_FILL,
|
||||||
} [value]
|
} [value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
warnings.warn('Invalid text-align:%s requested' % value)
|
log.warning('Invalid text-align:%s requested' % value)
|
||||||
else:
|
else:
|
||||||
tag.set_property('justification', align)
|
tag.set_property('justification', align)
|
||||||
|
|
||||||
|
@ -420,9 +420,9 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
else:
|
else:
|
||||||
tag.set_property('strikethrough', False)
|
tag.set_property('strikethrough', False)
|
||||||
if 'blink' in values:
|
if 'blink' in values:
|
||||||
warnings.warn('text-decoration:blink not implemented')
|
log.warning('text-decoration:blink not implemented')
|
||||||
if 'overline' in values:
|
if 'overline' in values:
|
||||||
warnings.warn('text-decoration:overline not implemented')
|
log.warning('text-decoration:overline not implemented')
|
||||||
|
|
||||||
def _parse_style_white_space(self, tag, value):
|
def _parse_style_white_space(self, tag, value):
|
||||||
if value == 'pre':
|
if value == 'pre':
|
||||||
|
@ -436,7 +436,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
try:
|
try:
|
||||||
tag.set_property(propname, value)
|
tag.set_property(propname, value)
|
||||||
except Exception:
|
except Exception:
|
||||||
gajim.log.warn( "Error with prop: " + propname + " for tag: " + str(tag))
|
log.warning( "Error with prop: " + propname + " for tag: " + str(tag))
|
||||||
|
|
||||||
|
|
||||||
def _parse_style_width(self, tag, value):
|
def _parse_style_width(self, tag, value):
|
||||||
|
@ -460,7 +460,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
try:
|
try:
|
||||||
method = locals()['_parse_style_%s' % style.replace('-', '_')]
|
method = locals()['_parse_style_%s' % style.replace('-', '_')]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
warnings.warn('Style attribute "%s" not yet implemented' % style)
|
log.warning('Style attribute "%s" not yet implemented' % style)
|
||||||
else:
|
else:
|
||||||
__style_methods[style] = method
|
__style_methods[style] = method
|
||||||
del style
|
del style
|
||||||
|
@ -496,7 +496,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
req.add_header('User-Agent', 'Gajim ' + gajim.version)
|
req.add_header('User-Agent', 'Gajim ' + gajim.version)
|
||||||
f = urllib2.urlopen(req)
|
f = urllib2.urlopen(req)
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
gajim.log.debug('Error loading image %s ' % attrs['src'] + str(ex))
|
log.debug('Error loading image %s ' % attrs['src'] + str(ex))
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
alt = attrs.get('alt', 'Broken image')
|
alt = attrs.get('alt', 'Broken image')
|
||||||
else:
|
else:
|
||||||
|
@ -509,7 +509,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
deadline = time.time() + 3
|
deadline = time.time() + 3
|
||||||
while True:
|
while True:
|
||||||
if time.time() > deadline:
|
if time.time() > deadline:
|
||||||
gajim.log.debug(str('Timeout loading image %s ' % \
|
log.debug(str('Timeout loading image %s ' % \
|
||||||
attrs['src'] + ex))
|
attrs['src'] + ex))
|
||||||
mem = ''
|
mem = ''
|
||||||
alt = attrs.get('alt', '')
|
alt = attrs.get('alt', '')
|
||||||
|
@ -520,7 +520,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
try:
|
try:
|
||||||
temp = f.read(100)
|
temp = f.read(100)
|
||||||
except socket.timeout, ex:
|
except socket.timeout, ex:
|
||||||
gajim.log.debug('Timeout loading image %s ' % \
|
log.debug('Timeout loading image %s ' % \
|
||||||
attrs['src'] + str(ex))
|
attrs['src'] + str(ex))
|
||||||
alt = attrs.get('alt', '')
|
alt = attrs.get('alt', '')
|
||||||
if alt:
|
if alt:
|
||||||
|
@ -596,7 +596,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
else:
|
else:
|
||||||
self._insert_text('[IMG: %s]' % alt)
|
self._insert_text('[IMG: %s]' % alt)
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
gajim.log.error('Error loading image ' + str(ex))
|
log.error('Error loading image ' + str(ex))
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
alt = attrs.get('alt', 'Broken image')
|
alt = attrs.get('alt', 'Broken image')
|
||||||
try:
|
try:
|
||||||
|
@ -620,7 +620,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
try:
|
try:
|
||||||
method = self.__style_methods[attr]
|
method = self.__style_methods[attr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
warnings.warn('Style attribute "%s" requested '
|
log.warning('Style attribute "%s" requested '
|
||||||
'but not yet implemented' % attr)
|
'but not yet implemented' % attr)
|
||||||
else:
|
else:
|
||||||
method(self, tag, val)
|
method(self, tag, val)
|
||||||
|
@ -755,7 +755,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
elif name in INLINE:
|
elif name in INLINE:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
warnings.warn('Unhandled element "%s"' % name)
|
log.warning('Unhandled element "%s"' % name)
|
||||||
|
|
||||||
def endElement(self, name):
|
def endElement(self, name):
|
||||||
endPreserving = False
|
endPreserving = False
|
||||||
|
@ -771,7 +771,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
#self._insert_text(u'\u2550'*40)
|
#self._insert_text(u'\u2550'*40)
|
||||||
self._jump_line()
|
self._jump_line()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
gajim.log.debug(str('Error in hr'+e))
|
log.debug(str('Error in hr'+e))
|
||||||
elif name in LIST_ELEMS:
|
elif name in LIST_ELEMS:
|
||||||
self.list_counters.pop()
|
self.list_counters.pop()
|
||||||
elif name == 'li':
|
elif name == 'li':
|
||||||
|
@ -790,7 +790,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
if name == 'pre':
|
if name == 'pre':
|
||||||
endPreserving = True
|
endPreserving = True
|
||||||
else:
|
else:
|
||||||
warnings.warn("Unhandled element '%s'" % name)
|
log.warning("Unhandled element '%s'" % name)
|
||||||
self._flush_text()
|
self._flush_text()
|
||||||
if endPreserving:
|
if endPreserving:
|
||||||
self.preserve = False
|
self.preserve = False
|
||||||
|
@ -935,17 +935,7 @@ if __name__ == '__main__':
|
||||||
from conversation_textview import ConversationTextview
|
from conversation_textview import ConversationTextview
|
||||||
import gajim as gaj
|
import gajim as gaj
|
||||||
|
|
||||||
class log(object):
|
log = logging.getLogger()
|
||||||
|
|
||||||
def debug(self, text):
|
|
||||||
print "debug:", text
|
|
||||||
def warn(self, text):
|
|
||||||
print "warn;", text
|
|
||||||
def error(self, text):
|
|
||||||
print "error;", text
|
|
||||||
|
|
||||||
gajim.log=log()
|
|
||||||
|
|
||||||
gaj.Interface()
|
gaj.Interface()
|
||||||
|
|
||||||
htmlview = ConversationTextview(None)
|
htmlview = ConversationTextview(None)
|
||||||
|
|
Loading…
Reference in New Issue