Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 2170

Show
Ignore:
Timestamp:
03/30/09 12:08:36
Author:
jaraco
Message:

Adding proposed fix for exception handling out of the exception scope

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/python3/cherrypy/process/wspbus.py

    r2169 r2170  
    7474 
    7575 
     76class ChannelFailures(Exception): 
     77    delimiter = '\n' 
     78     
     79    def __init__(self): 
     80        self._exceptions = list() 
     81     
     82    def handle_exception(self): 
     83        self._exceptions.append(sys.exc_info()) 
     84     
     85    def get_instances(self): 
     86        return [instance for cls, instance, traceback in self._exceptions] 
     87     
     88    def __str__(self): 
     89        exception_strings = map(str, self.get_instances()) 
     90        return self.delimiter.join(exception_strings) 
     91     
     92    def __bool__(self): 
     93        return bool(self._exceptions) 
     94 
    7695# Use a flag to indicate the state of the bus. 
    7796class _StateEnum(object): 
     
    137156            return [] 
    138157         
    139         exc = None 
     158        exc = ChannelFailures() 
    140159        output = [] 
    141160         
     
    155174                raise 
    156175            except: 
    157                 exc = sys.exc_info()[1] 
     176                exc.handle_exception() 
    158177                if channel == 'log': 
    159178                    # Assume any further messages to 'log' will fail. 
     
    163182                             level=40, traceback=True) 
    164183        if exc: 
    165             raise 
     184            raise exc 
    166185        return output 
    167186     

Hosted by WebFaction

Log in as guest/cpguest to create tickets