def make_app(global_conf, **app_conf): """Create a WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ logging.config.fileConfig(global_conf['__file__']) app_ctx = context.Context() app_ctx.conf = configuration.load_configuration(global_conf, app_conf) app_ctx.templates = templates.load_templates(app_ctx) app = controllers.make_router() app = context.make_add_context_to_request(app, app_ctx) if not app_ctx.conf['debug']: app = ErrorMiddleware( app, error_email=app_ctx.conf['email_to'], error_log=app_ctx.conf.get('error_log', None), error_message=app_ctx.conf.get('error_message', 'An internal server error occurred'), error_subject_prefix=app_ctx.conf.get('error_subject_prefix', 'Web application error: '), from_address=app_ctx.conf['from_address'], smtp_server=app_ctx.conf.get('smtp_server', 'localhost'), ) app = Cascade([StaticURLParser(os.path.join(app_ctx.conf['app_dir'], 'static')), app]) app.ctx = app_ctx return app
def exception_handler(self, exc, environ): ErrorMiddleware.exception_handler(self, exc, environ) line = '' name = '' file = '' tb = exc[2] while tb is not None: if tb.tb_next is None: line = tb.tb_lineno co = tb.tb_frame.f_code file = co.co_filename name = co.co_name tb = tb.tb_next return '<pre>Exception %s in %s (%s line %s)</pre>' % (exc[1], name, os.path.basename(file), line)
def ErrorHandler(app, global_conf, **errorware): """ErrorHandler Toggle If debug is enabled, this function will return the app wrapped in the WebError ``EvalException`` middleware which displays interactive debugging sessions when a traceback occurs. Otherwise, the app will be wrapped in the WebError ``ErrorMiddleware``, and the ``errorware`` dict will be passed into it. The ``ErrorMiddleware`` handles sending an email to the address listed in the .ini file, under ``email_to``. """ if 'error_template' in errorware: del errorware['error_template'] warnings.warn(pylons.legacy.error_template_warning, DeprecationWarning, 2) if asbool(global_conf.get('debug')): footer = footer_html % (pylons.config.get( 'traceback_host', 'pylonshq.com'), pylons.__version__) py_media = dict(pylons=media_path) app = EvalException(app, global_conf, templating_formatters=template_error_formatters, media_paths=py_media, head_html=head_html, footer_html=footer, libraries=report_libs) else: app = ErrorMiddleware(app, global_conf, **errorware) return app
def make_app(global_conf, **app_conf): """Create a WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ conf = configuration.load_configuration(global_conf, app_conf) logging.basicConfig(level=conf['log_level'], stream=sys.stdout) app = router.make_router(conf) if not conf['debug']: app = ErrorMiddleware( app, error_email=conf['email_to'], error_log=conf.get('error_log', None), error_message=conf.get('error_message', 'An internal server error occurred'), error_subject_prefix=conf.get('error_subject_prefix', 'Web application error: '), from_address=conf['from_address'], smtp_server=conf.get('smtp_server', 'localhost'), ) return app
def make_app(global_conf, **app_conf): """Create a WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the environment and fill conf dictionary. environment.load_environment(global_conf, app_conf) # Dispatch request to controllers. app = controllers.make_router() # Init request-dependant environment app = environment_setter(app) # Set X-API-Version response header app = x_api_version_header_setter(app) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Handle Python exceptions if conf['debug'] and ipdb is not None: app = launch_debugger_on_exception(app) app = exception_to_json(app) if not conf['debug']: app = ErrorMiddleware(app, global_conf, **conf['errorware']) return app
def do_request(app, expect_status=500): app = lint.middleware(app) app = ErrorMiddleware(app, {}, debug=True) app = clear_middleware(app) testapp = TestApp(app) res = testapp.get('', status=expect_status, expect_errors=True) return res
def ErrorMiddleware(*args, **kw): warnings.warn( 'weberror.exceptions.errormiddleware.ErrorMiddleware has been moved ' 'to weberror.errormiddleware.ErrorMiddleware', DeprecationWarning, stacklevel=2) from weberror.errormiddleware import ErrorMiddleware return ErrorMiddleware(*args, **kw)
def make_app(global_conf, **app_conf): """Create a WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ app_ctx = context.Context() app_ctx.conf = configuration.load_configuration(global_conf, app_conf) app_ctx.load_assets() logging.basicConfig(level=app_ctx.conf['log_level'], stream=sys.stdout) app_ctx.db = database.load_database(app_ctx) app_ctx.db_webrokeit = database.load_database_webrokeit(app_ctx) app_ctx.templates = templates.load_templates(app_ctx) database.ensure_indexes(app_ctx) #model.init_xxx(app_ctx) app = controllers.make_router() app = context.make_add_context_to_request(app, app_ctx) if not app_ctx.conf['debug']: app = ErrorMiddleware( app, error_email=app_ctx.conf['email_to'], error_log=app_ctx.conf.get('error_log', None), error_message=app_ctx.conf.get('error_message', 'An internal server error occurred'), error_subject_prefix=app_ctx.conf.get('error_subject_prefix', 'Web application error: '), from_address=app_ctx.conf['from_address'], smtp_server=app_ctx.conf.get('smtp_server', 'localhost'), ) if app_ctx.conf['static_files']: # Serve static files. app = Cascade([StaticURLParser(app_ctx.conf['static_files_dir']), app]) app.ctx = app_ctx return app
def run_command(rule_filename, debug=False, interactive_debugger=False, debug_headers=False, profile=False, memory_profile=False, garbage_collect=False): """Actually runs the command from the parsed arguments""" settings = ProxySettings.parse_file(rule_filename) app = ReloadingApp(rule_filename, settings) if profile: try: from repoze.profile.profiler import AccumulatingProfileMiddleware except ImportError: print('Error: you must manually install repoze.profiler to use --profile') sys.exit(1) app = AccumulatingProfileMiddleware( app, log_filename='/tmp/deliverance-proxy-profiling.log', discard_first_request=True, flush_at_shutdown=True, path='/.deliverance/profile') if memory_profile: try: from dozer import Dozer except ImportError: print('Error: you must manually install Dozer to use --memory-profile') sys.exit(1) app = Dozer(app) if interactive_debugger: from weberror.evalexception import EvalException app = EvalException(app, debug=True) else: from weberror.errormiddleware import ErrorMiddleware app = ErrorMiddleware(app, debug=debug) if debug_headers: from wsgifilter.proxyapp import DebugHeaders app = DebugHeaders(app, show_body=debug_headers > 1) if garbage_collect: from deliverance.garbagecollect import GarbageCollectingMiddleware app = GarbageCollectingMiddleware(app) print('To see logging, visit %s/.deliverance/login' % settings.base_url) print(' after login go to %s/?deliv_log' % settings.base_url) if profile: print('To see profiling information visit %s/.deliverance/profile' % settings.base_url) serve(app, host=settings.host, port=settings.port)
def wrap_app(app): """Encapsulate main WSGI application within WSGI middlewares.""" # Initialize request-dependant environment. app = environment_setter(app) app = language_detector(app) # Repair badly encoded query in request URL. app = request_query_encoding_fixer(app) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Handle Python exceptions if not conf['debug']: app = ErrorMiddleware(app, conf['global_conf'], **conf['errorware']) if conf['static_files']: # Serve static files static_app = StaticURLParser(conf['static_files_dir']) app = Cascade([static_app, app]) return app
def make_app(global_conf, **app_conf): """Create a WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the environment and fill conf dictionary. environment.load_environment(global_conf, app_conf) # Dispatch request to controllers. app = controllers.make_router() # Init request-dependant environment app = language_detector(app) app = environment_setter(app) # Repair badly encoded query in request URL. app = request_query_encoding_fixer(app) # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) # Handle Python exceptions if not conf['debug']: app = ErrorMiddleware(app, global_conf, **conf['errorware']) if conf['static_files']: # Serve static files static_app = StaticURLParser(conf['static_files_dir']) app = Cascade([static_app, app]) return app
controller = SiteController() output = controller(environ,start_response) except Exception as e: start_response('200 OK',[('Content-Type','text/html')]) output = """<html><body> <b>Error</b> = %s<br> %s<p> <b>Path</b> = %s<p> <b>Diag</b> = %s </body> </html> """ diag = "Diagnosic data:<br>\n" for v in environ: diag += v + " : " + repr(environ[v])+"<br>\n" output = output % (repr(e), traceback.format_exc().replace('\n','<br>\n'), repr(sys.path), diag) return [output.encode()] # Define WSGI application if weberror_imported: application = ErrorMiddleware(app, debug = True, error_message = 'HAWC Viewer Error') else: application = errapp # Call main for the application to be callable as cgi script if __name__ == '__main__': CGIHandler().run(application)
def __init__(self, *args, **kwargs): ErrorMiddleware.__init__(self, *args, **kwargs) self.log = logging.getLogger('evasion.web.middleware.ErrorHandler') self._logTheTraceback = False
help='SMTP server to use') parser.add_option('--smtp-username', metavar='USERNAME', dest='smtp_username', help='SMTP username') parser.add_option('--smtp-password', metavar='PASSWORD', dest='smtp_password', help='SMTP password') parser.add_option('--smtp-use-tls', dest='smtp_use_tls', action='store_true', help='Use TLS (SSL) for SMTP server') options, args = parser.parse_args() from paste.httpserver import serve if options.no_eval or options.email: from weberror.errormiddleware import ErrorMiddleware if not options.email_from: options.email_from = options.email app = ErrorMiddleware( error_application, debug=True, error_email=options.email, smtp_server=options.smtp_server, smtp_username=options.smtp_username, smtp_password=options.smtp_password, smtp_use_tls=options.smtp_use_tls, from_address=options.email_from) else: app = EvalException(error_application) serve(app, port=int(options.port))