Package commons :: Module exceps
[hide private]
[frames] | no frames]

Source Code for Module commons.exceps

 1  # -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- 
 2  # vim:ft=python:et:sw=4:ts=4 
 3   
 4  """ 
 5  Exceptions and exception handling. 
 6   
 7  @var orig_excepthook: The original excepthook (as of the time this 
 8  module is first loaded). This just serves as a backup if it needs to 
 9  be restored. 
10  """ 
11   
12  from decs import * 
13  import sys 
14   
15  orig_excepthook = sys.excepthook 
16   
17 -def handle_exceptions():
18 """ 19 The default exception handler (prints a stack trace and the 20 exception message), except it does not actually terminate the 21 thread. 22 """ 23 orig_excepthook( *sys.exc_info() )
24
25 -class FailedInvariant( Exception ): pass
26
27 -class InvariantChecker( GenericWrapper ):
28 """ 29 Wrap an object and all of its methods with per-access 30 invariants-checking. 31 32 @todo: This code is incomplete and does not actually check 33 invariants yet! 34 """
35 - def __init__( self, obj, ignore=() ):
36 def check_invariants(): 37 # TODO 38 for invariant in self.invariants: 39 if not invariant(): 40 raise FailedInvariant()
41 GenericWrapper.__init__(self, obj, None, check_invariants, ignore)
42