home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / hooks.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  1.9 KB  |  84 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. from peak.util.plugins import Hook
  6. import traceback
  7. __all__ = [
  8.     'register',
  9.     'reduce']
  10.  
  11. def register(hook_identifier, cb, impl = None):
  12.     return Hook(hook_identifier, impl).register(cb)
  13.  
  14.  
  15. def reduce(hook_identifier, arg, *args, **kwargs):
  16.     raise_exceptions = kwargs.pop('raise_exceptions', False)
  17.     impl = kwargs.pop('impl', None)
  18.     for hook in Hook(hook_identifier, impl):
  19.         if raise_exceptions:
  20.             arg = hook(arg, *args, **kwargs)
  21.             continue
  22.         
  23.         try:
  24.             arg = hook(arg, *args, **kwargs)
  25.         continue
  26.         except Exception:
  27.             traceback.print_exc()
  28.             continue
  29.         
  30.  
  31.     
  32.     return arg
  33.  
  34.  
  35. def notify(hook_identifier, *a, **k):
  36.     for res in each(hook_identifier, *a, **k):
  37.         pass
  38.     
  39.  
  40.  
  41. def each(hook_identifier, *a, **k):
  42.     impl = k.pop('impl', None)
  43.     for hook in Hook(hook_identifier, impl):
  44.         
  45.         try:
  46.             yield hook(*a, **k)
  47.         continue
  48.         except Exception:
  49.             traceback.print_exc()
  50.             continue
  51.         
  52.  
  53.     
  54.  
  55.  
  56. def first(hook_identifier, *a, **k):
  57.     impls = k.pop('impls', [
  58.         k.pop('impl', None)])
  59.     raise_exceptions = k.pop('raise_hook_exceptions', False)
  60.     for impl in impls:
  61.         for hook in Hook(hook_identifier, impl = impl):
  62.             
  63.             try:
  64.                 v = hook(*a, **k)
  65.                 if v is not None:
  66.                     return v
  67.             continue
  68.             except Exception:
  69.                 if raise_exceptions:
  70.                     raise 
  71.                 raise_exceptions
  72.                 traceback.print_exc()
  73.                 continue
  74.             
  75.  
  76.         
  77.     
  78.  
  79. builtin_any = any
  80.  
  81. def any(hook_identifier, *a, **k):
  82.     return builtin_any(each(hook_identifier, *a, **k))
  83.  
  84.