home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / common / urlhandler.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.1 KB  |  68 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import re
  5. import traceback
  6. matchers = []
  7. URL_OPEN_IN_BROWSER = object()
  8.  
  9. class URLHandlerResult(object):
  10.     __slots__ = ('cancel_navigation', 'url')
  11.     
  12.     def __init__(self, url, cancel_navigation = False):
  13.         self.url = url
  14.         self.cancel_navigation = cancel_navigation
  15.  
  16.     
  17.     def cancel(self, cancel = True):
  18.         self.cancel_navigation = cancel
  19.  
  20.  
  21.  
  22. def handle(url):
  23.     result = URLHandlerResult(url)
  24.     if not url.startswith('digsby://'):
  25.         return result
  26.     
  27.     url = url[len('digsby://'):]
  28.     for compiled_matcher, handler in matchers:
  29.         match = compiled_matcher.match(url)
  30.         if match is not None:
  31.             
  32.             try:
  33.                 handle_result = lazy_call(handler, *match.groups())
  34.             except Exception:
  35.                 traceback.print_exc()
  36.  
  37.             if handle_result is not URL_OPEN_IN_BROWSER:
  38.                 result.cancel()
  39.             
  40.         handle_result is not URL_OPEN_IN_BROWSER
  41.     
  42.     return result
  43.  
  44.  
  45. def register(match_re, handler):
  46.     matchers.append((re.compile(match_re), handler))
  47.  
  48.  
  49. def unregister(url, handler):
  50.     global matchers
  51.     new_matchers = []
  52.     for compiled_matcher, url_handler in matchers:
  53.         if url_handler is not handler or compiled_matcher.pattern != url:
  54.             new_matchers.append((compiled_matcher, url_handler))
  55.             continue
  56.     
  57.     matchers = new_matchers
  58.  
  59.  
  60. def lazy_call(handler, *args):
  61.     if not hasattr(handler, '__call__'):
  62.         import_function = import_function
  63.         import util
  64.         handler = import_function(handler)
  65.     
  66.     return handler(*args)
  67.  
  68.