All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Lib.modjy.modjy_exceptions.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
###
#
# Copyright Alan Kennedy. 
# 
# You may contact the copyright holder at this uri:
# 
# http://www.xhaus.com/contact/modjy
# 
# The licence under which this code is released is the Apache License v2.0.
# 
# The terms and conditions of this license are listed in a file contained
# in the distribution that also contained this file, under the name
# LICENSE.txt.
# 
# You may also read a copy of the license at the following web address.
# 
# http://modjy.xhaus.com/LICENSE.txt
#
###

import sys
import StringIO
import traceback

from java.lang import IllegalStateException
from java.io import IOException
from javax.servlet import ServletException

class ModjyException(Exception): pass

class ModjyIOException(ModjyException): pass

class ConfigException(ModjyException): pass
class BadParameter(ConfigException): pass
class ApplicationNotFound(ConfigException): pass
class NoCallable(ConfigException): pass

class RequestException(ModjyException): pass

class ApplicationException(ModjyException): pass
class StartResponseNotCalled(ApplicationException): pass
class StartResponseCalledTwice(ApplicationException): pass
class ResponseCommitted(ApplicationException): pass
class HopByHopHeaderSet(ApplicationException): pass
class WrongLength(ApplicationException): pass
class BadArgument(ApplicationException): pass
class ReturnNotIterable(ApplicationException): pass
class NonStringOutput(ApplicationException): pass

class exception_handler:

    def handle(self, req, resp, environ, exc, exc_info):
        pass

    def get_status_and_message(self, req, resp, exc):
        return resp.SC_INTERNAL_SERVER_ERROR, "Server configuration error"

#
#    Special exception handler for testing
#

class testing_handler(exception_handler):

    def handle(self, req, resp, environ, exc, exc_info):
        typ, value, tb = exc_info
        err_msg = StringIO.StringIO()
        err_msg.write("%s: %s\n" % (typ, value,) )
        err_msg.write(">Environment\n")
        for k in environ.keys():
            err_msg.write("%s=%s\n" % (k, repr(environ[k])) )
        err_msg.write("TraceBack\n")
        for line in traceback.format_exception(typ, value, tb):
            err_msg.write(line)
        err_msg.write("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy