def handle(request, message=None, redirect=None, ignore=False, escalate=False, log_level=None, force_log=None):
 (exc_type, exc_value, exc_traceback) = sys.exc_info()
 log_method = getattr(LOG, (log_level or 'exception'))
 force_log = (force_log or os.environ.get('HORIZON_TEST_RUN', False))
 force_silence = getattr(exc_value, 'silence_logging', False)
 handled = issubclass(exc_type, HandledException)
 wrap = False
 if handled:
  (exc_type, exc_value, exc_traceback) = exc_value.wrapped
  wrap = True
 if issubclass(exc_type, HorizonException):
  message = exc_value
 elif getattr(exc_value, '_safe_message', None):
  message = exc_value._safe_message
 elif (message and ('%(exc)s' in message)):
  message = (message % {'exc': exc_value})
 if issubclass(exc_type, UNAUTHORIZED):
  if ignore:
   return NotAuthorized
  if ((not force_silence) and (not handled)):
   log_method(error_color(('Unauthorized: %s' % exc_value)))
  if (not handled):
   if message:
    message = (_('Unauthorized: %s') % message)
   fallback = _('Unauthorized. Please try logging in again.')
   messages.error(request, (message or fallback))
  if escalate:
   logout(request)
   raise NotAuthorized
  return NotAuthorized
 if issubclass(exc_type, NOT_FOUND):
  wrap = True
  if ((not force_silence) and (not handled) and ((not ignore) or force_log)):
   log_method(error_color(('Not Found: %s' % exc_value)))
  if ((not ignore) and (not handled)):
   messages.error(request, (message or exc_value))
  if redirect:
   raise Http302(redirect)
  if (not escalate):
   return NotFound
 if issubclass(exc_type, RECOVERABLE):
  wrap = True
  if ((not force_silence) and (not handled) and ((not ignore) or force_log)):
   log_method = getattr(LOG, (log_level or 'warning'))
   log_method(error_color(('Recoverable error: %s' % exc_value)))
  if ((not ignore) and (not handled)):
   messages.error(request, (message or exc_value))
  if redirect:
   raise Http302(redirect)
  if (not escalate):
   return RecoverableError
 if wrap:
  raise HandledException([exc_type, exc_value, exc_traceback])
 raise exc_type, exc_value, exc_traceback

def handle ( request , message = None , redirect = None , ignore = False , escalate = False , log_level = None , force_log = None ) : ( exc_type , exc_value , exc_traceback ) = sys . exc_info ( ) log_method = getattr ( LOG , ( log_level or 'exception' ) ) force_log = ( force_log or os . environ . get ( 'HORIZON_TEST_RUN' , False ) ) force_silence = getattr ( exc_value , 'silence_logging' , False ) handled = issubclass ( exc_type , HandledException ) wrap = False if handled : ( exc_type , exc_value , exc_traceback ) = exc_value . wrapped wrap = True if issubclass ( exc_type , HorizonException ) : message = exc_value elif getattr ( exc_value , '_safe_message' , None ) : message = exc_value . _safe_message elif ( message and ( '%(exc)s' in message ) ) : message = ( message % { 'exc' : exc_value } ) if issubclass ( exc_type , UNAUTHORIZED ) : if ignore : return NotAuthorized if ( ( not force_silence ) and ( not handled ) ) : log_method ( error_color ( ( 'Unauthorized: %s' % exc_value ) ) ) if ( not handled ) : if message : message = ( _ ( 'Unauthorized: %s' ) % message ) fallback = _ ( 'Unauthorized. Please try logging in again.' ) messages . error ( request , ( message or fallback ) ) if escalate : logout ( request ) raise NotAuthorized return NotAuthorized if issubclass ( exc_type , NOT_FOUND ) : wrap = True if ( ( not force_silence ) and ( not handled ) and ( ( not ignore ) or force_log ) ) : log_method ( error_color ( ( 'Not Found: %s' % exc_value ) ) ) if ( ( not ignore ) and ( not handled ) ) : messages . error ( request , ( message or exc_value ) ) if redirect : raise Http302 ( redirect ) if ( not escalate ) : return NotFound if issubclass ( exc_type , RECOVERABLE ) : wrap = True if ( ( not force_silence ) and ( not handled ) and ( ( not ignore ) or force_log ) ) : log_method = getattr ( LOG , ( log_level or 'warning' ) ) log_method ( error_color ( ( 'Recoverable error: %s' % exc_value ) ) ) if ( ( not ignore ) and ( not handled ) ) : messages . error ( request , ( message or exc_value ) ) if redirect : raise Http302 ( redirect ) if ( not escalate ) : return RecoverableError if wrap : raise HandledException ( [ exc_type , exc_value , exc_traceback ] ) raise exc_type , exc_value , exc_traceback
main program execution handler .