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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from gettext import gettext as _
  5. import re
  6. import os
  7. import gobject
  8. import gnomevfs
  9. import deskbar.Handler as deskbar
  10. import deskbar.Match as deskbar
  11. from deskbar.defs import VERSION
  12. HANDLERS = {
  13.     'WebAddressHandler': {
  14.         'name': _('Web'),
  15.         'description': _('Open web pages and send emails by typing a complete address'),
  16.         'version': VERSION } }
  17. AUTH_REGEX = re.compile('[a-zA-Z]+://\\w+(:\\w+)?@([\\w\\-]+\\.)+[\\w\\-]+(:\\d+)?(/.*)?')
  18. HTTP_REGEX = re.compile('^(?P<method>[a-zA-Z]+://)?([\\w\\-]+\\.)+[\\w\\-]+(:\\d+)?(/.*)?$')
  19. MAIL_REGEX = re.compile('^([\\w\\-]+\\.)*[\\w\\-]+@([\\w\\-]+\\.)*[\\w\\-]+$')
  20.  
  21. class WebAddressMatch(deskbar.Match.Match):
  22.     
  23.     def __init__(self, backend, name = None, has_method = True, **args):
  24.         deskbar.Match.Match.__init__(self, backend, name = name, **args)
  25.         self.has_method = has_method
  26.         if not has_method and not self.name.startswith('http://'):
  27.             self.name = 'http://' + name
  28.         
  29.  
  30.     
  31.     def action(self, text = None):
  32.         if self.name.startswith('http'):
  33.             gnomevfs.url_show(self.name)
  34.         else:
  35.             gobject.spawn_async([
  36.                 'nautilus',
  37.                 self.name], flags = gobject.SPAWN_SEARCH_PATH)
  38.  
  39.     
  40.     def get_category(self):
  41.         return 'web'
  42.  
  43.     
  44.     def get_verb(self):
  45.         if not self.has_method:
  46.             return _('Open the web page %s') % '<b>%(name)s</b>'
  47.         else:
  48.             return _('Open the location %s') % '<b>%(name)s</b>'
  49.  
  50.     
  51.     def get_hash(self, text = None):
  52.         return self.name
  53.  
  54.  
  55.  
  56. class EmailAddressMatch(deskbar.Match.Match):
  57.     
  58.     def __init__(self, backend, **args):
  59.         deskbar.Match.Match.__init__(self, backend, icon = 'stock_mail', **args)
  60.  
  61.     
  62.     def action(self, text = None):
  63.         gnomevfs.url_show('mailto:' + self.name)
  64.  
  65.     
  66.     def get_category(self):
  67.         return 'people'
  68.  
  69.     
  70.     def get_verb(self):
  71.         return _('Send Email to %s') % '<b>%(name)s</b>'
  72.  
  73.     
  74.     def get_hash(self, text = None):
  75.         return self.name
  76.  
  77.  
  78.  
  79. class WebAddressHandler(deskbar.Handler.Handler):
  80.     
  81.     def __init__(self):
  82.         deskbar.Handler.Handler.__init__(self, 'stock_internet')
  83.  
  84.     
  85.     def query(self, query):
  86.         result = self.query_http(query)
  87.         result += self.query_mail(query)
  88.         return result
  89.  
  90.     
  91.     def query_http(self, query):
  92.         match = AUTH_REGEX.match(query)
  93.         if match != None:
  94.             return [
  95.                 WebAddressMatch(self, query)]
  96.         
  97.         match = HTTP_REGEX.match(query)
  98.         if match != None:
  99.             return [
  100.                 WebAddressMatch(self, query, match.group('method') != None)]
  101.         
  102.         return []
  103.  
  104.     
  105.     def query_mail(self, query):
  106.         if MAIL_REGEX.match(query) != None:
  107.             return [
  108.                 EmailAddressMatch(self, name = query)]
  109.         else:
  110.             return []
  111.  
  112.  
  113.