home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- import re
- import traceback
- matchers = []
- URL_OPEN_IN_BROWSER = object()
-
- class URLHandlerResult(object):
- __slots__ = ('cancel_navigation', 'url')
-
- def __init__(self, url, cancel_navigation = False):
- self.url = url
- self.cancel_navigation = cancel_navigation
-
-
- def cancel(self, cancel = True):
- self.cancel_navigation = cancel
-
-
-
- def handle(url):
- result = URLHandlerResult(url)
- if not url.startswith('digsby://'):
- return result
-
- url = url[len('digsby://'):]
- for compiled_matcher, handler in matchers:
- match = compiled_matcher.match(url)
- if match is not None:
-
- try:
- handle_result = lazy_call(handler, *match.groups())
- except Exception:
- traceback.print_exc()
-
- if handle_result is not URL_OPEN_IN_BROWSER:
- result.cancel()
-
- handle_result is not URL_OPEN_IN_BROWSER
-
- return result
-
-
- def register(match_re, handler):
- matchers.append((re.compile(match_re), handler))
-
-
- def unregister(url, handler):
- global matchers
- new_matchers = []
- for compiled_matcher, url_handler in matchers:
- if url_handler is not handler or compiled_matcher.pattern != url:
- new_matchers.append((compiled_matcher, url_handler))
- continue
-
- matchers = new_matchers
-
-
- def lazy_call(handler, *args):
- if not hasattr(handler, '__call__'):
- import_function = import_function
- import util
- handler = import_function(handler)
-
- return handler(*args)
-
-