deskbar-applet r2102 - in branches/gnome-2-22: . deskbar/handlers
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: deskbar-applet r2102 - in branches/gnome-2-22: . deskbar/handlers
- Date: Sat, 12 Apr 2008 13:18:42 +0100 (BST)
Author: sebp
Date: Sat Apr 12 13:18:42 2008
New Revision: 2102
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2102&view=rev
Log:
Catch exception that might appear during parsing and cleanup correctly in any case.
Modified:
branches/gnome-2-22/ChangeLog
branches/gnome-2-22/deskbar/handlers/yahoo.py
Modified: branches/gnome-2-22/deskbar/handlers/yahoo.py
==============================================================================
--- branches/gnome-2-22/deskbar/handlers/yahoo.py (original)
+++ branches/gnome-2-22/deskbar/handlers/yahoo.py Sat Apr 12 13:18:42 2008
@@ -3,7 +3,11 @@
from deskbar.handlers.actions.CopyToClipboardAction import CopyToClipboardAction
from deskbar.handlers.actions.ShowUrlAction import ShowUrlAction
from gettext import gettext as _
-import deskbar.interfaces.Module, deskbar.interfaces.Match, deskbar
+from xml.dom import DOMException
+from xml.parsers.expat import ExpatError
+import deskbar
+import deskbar.interfaces.Match
+import deskbar.interfaces.Module
import logging
import urllib
import xml.dom.minidom
@@ -47,39 +51,40 @@
self.server = None
def query(self, qstring):
- # Delay before we query so we *don't* make four queries
- # "s", "sp", "spa", "spam".
+ LOGGER.info('Query yahoo for: %s', qstring)
- # TODO: Missing
- #self.check_query_changed (timeout=QUERY_DELAY)
-
- LOGGER.info('Query yahoo for: '+qstring)
url = YAHOO_URL % urllib.urlencode(
{'appid': YAHOO_API_KEY,
'query': qstring,
'results': 15})
- try:
- stream = urllib.urlopen(url, proxies=get_proxy())
- except IOError, msg:
- LOGGER.error("Could not open URL %s: %s, %s" % (url, msg[0], msg[1]))
- return
-
- dom = xml.dom.minidom.parse(stream)
- LOGGER.info('Got yahoo answer for: '+qstring)
- # TODO: Missing
- #self.check_query_changed ()
+ matches = []
+ try:
+ try:
+ stream = urllib.urlopen(url, proxies=get_proxy())
+ dom = xml.dom.minidom.parse(stream)
+ except IOError, msg:
+ LOGGER.error("Could not open URL %s: %s, %s", url, msg[0], msg[1])
+ except ExpatError, e:
+ LOGGER.exception(e)
+ finally:
+ stream.close()
- # The Yahoo! search might have taken a long time
- # better check if we're still valid
- matches = [
- YahooMatch (
- name=strip_html(r.getElementsByTagName("Title")[0].firstChild.data.encode('utf8')),
- url=r.getElementsByTagName("ClickUrl")[0].firstChild.data.encode('utf8'),
- priority=self.get_priority()
- )
- for r in dom.getElementsByTagName("Result")]
- # TODO: Missing
- #self.check_query_changed ()
- LOGGER.info("Returning yahoo answer for: "+qstring)
- self._emit_query_ready(qstring, matches )
+ LOGGER.info('Got yahoo answer for: %s', qstring)
+
+ try:
+ try:
+ for r in dom.getElementsByTagName("Result"):
+ result_title = strip_html(r.getElementsByTagName("Title")[0].firstChild.data.encode('utf8'))
+ result_url = r.getElementsByTagName("ClickUrl")[0].firstChild.data.encode('utf8')
+ matches.append(
+ YahooMatch (name=result_title, url=result_url, priority=self.get_priority())
+ )
+ except DOMExecption, e:
+ LOGGER.exception(e)
+ finally:
+ # Cleanup
+ dom.unlink()
+
+ LOGGER.info("Returning yahoo answer for: %s", qstring)
+ self._emit_query_ready(qstring, matches)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]