home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / deskbar-applet / handlers / yahoo.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  2.9 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from deskbar.Utils import strip_html
  5. from gettext import gettext as _
  6. from deskbar.defs import VERSION
  7. import urllib
  8. import cgi
  9. import gnomevfs
  10. import deskbar.Handler as deskbar
  11. import deskbar.Match as deskbar
  12. import deskbar
  13. import xml.dom.minidom as xml
  14. YAHOO_API_KEY = 'deskbar-applet'
  15. YAHOO_URL = 'http://api.search.yahoo.com/WebSearchService/V1/webSearch?%s'
  16. MAX_QUERIES = 10
  17. QUERY_DELAY = 1
  18. HANDLERS = {
  19.     'YahooHandler': {
  20.         'name': _('Yahoo! Search'),
  21.         'description': _('Search Yahoo! as you type'),
  22.         'version': VERSION } }
  23.  
  24. class YahooMatch(deskbar.Match.Match):
  25.     
  26.     def __init__(self, handler, url = None, **args):
  27.         deskbar.Match.Match.__init__(self, handler, **args)
  28.         self.url = url
  29.  
  30.     
  31.     def get_verb(self):
  32.         return '%(name)s'
  33.  
  34.     
  35.     def action(self, text = None):
  36.         gnomevfs.url_show(self.url)
  37.  
  38.     
  39.     def get_category(self):
  40.         return 'web'
  41.  
  42.     
  43.     def get_hash(self, text = None):
  44.         return self.url
  45.  
  46.  
  47.  
  48. class YahooHandler(deskbar.Handler.AsyncHandler):
  49.     
  50.     def __init__(self):
  51.         deskbar.Handler.AsyncHandler.__init__(self, 'yahoo.png')
  52.         self.server = None
  53.  
  54.     
  55.     def query(self, qstring):
  56.         self.check_query_changed(timeout = QUERY_DELAY)
  57.         print 'Query yahoo for:', qstring
  58.         stream = urllib.urlopen(YAHOO_URL % urllib.urlencode({
  59.             'appid': YAHOO_API_KEY,
  60.             'query': qstring,
  61.             'results': 15 }))
  62.         dom = xml.dom.minidom.parse(stream)
  63.         print 'Got yahoo answer for:', qstring
  64.         self.check_query_changed()
  65.         matches = [ YahooMatch(self, name = cgi.escape(strip_html(r.getElementsByTagName('Title')[0].firstChild.data.encode('utf8'))), url = r.getElementsByTagName('ClickUrl')[0].firstChild.data.encode('utf8')) for r in dom.getElementsByTagName('Result') ]
  66.         self.check_query_changed()
  67.         print 'Returning yahoo answer for:', qstring
  68.         return matches
  69.  
  70.  
  71.