home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / common / urlhandler.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  2.1 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  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.     url = url[len('digsby://'):]
  27.     for compiled_matcher, handler in matchers:
  28.         match = compiled_matcher.match(url)
  29.         if match is not None:
  30.             
  31.             try:
  32.                 handle_result = lazy_call(handler, *match.groups())
  33.             except Exception:
  34.                 url.startswith('digsby://')
  35.                 url.startswith('digsby://')
  36.                 traceback.print_exc()
  37.             except:
  38.                 url.startswith('digsby://')
  39.  
  40.             if handle_result is not URL_OPEN_IN_BROWSER:
  41.                 result.cancel()
  42.             
  43.         handle_result is not URL_OPEN_IN_BROWSER
  44.     
  45.     return result
  46.  
  47.  
  48. def register(match_re, handler):
  49.     matchers.append((re.compile(match_re), handler))
  50.  
  51.  
  52. def unregister(url, handler):
  53.     global matchers
  54.     new_matchers = []
  55.     for compiled_matcher, url_handler in matchers:
  56.         if url_handler is not handler or compiled_matcher.pattern != url:
  57.             new_matchers.append((compiled_matcher, url_handler))
  58.             continue
  59.     
  60.     matchers = new_matchers
  61.  
  62.  
  63. def lazy_call(handler, *args):
  64.     if not hasattr(handler, '__call__'):
  65.         import_function = import_function
  66.         import util
  67.         handler = import_function(handler)
  68.     
  69.     return handler(*args)
  70.  
  71.