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 run(self, host=None, port=8080, debug=False): self.config.end() app = self.config.make_wsgi_app() if debug: app = EvalException(app) app = RegistryManager(app) serve(app, host, port)
def browser_command(argv=None): """Command line interface to launch the widgetbrowser""" opts, args = _parser.parse_args(argv) # Only allow passing display arguments in debug mode if args: widget_url = args[0] + '/' else: widget_url = '' app = WidgetBrowser(interactive=opts.interactive, docs_dir=opts.docs) if opts.interactive: try: from weberror.evalexception import EvalException app = EvalException(app) except ImportError: raise ImportError("You need to install WebError for interactive " "debugging") url = "http://127.0.0.1:%s/" % opts.port if opts.browser: import webbrowser webbrowser.open(url + widget_url) server = make_server('127.0.0.1', int(opts.port), app) print "Server started at " + url try: server.serve_forever() except (KeyboardInterrupt, SystemExit): pass
def DebugHandler(app, global_conf, **kwargs): footer = footer_html % (kwargs.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) return app
def main(): options, args = parser.parse_args() if not args or len(args) > 1: parser.error('You must give one PROXY_URL') proxy_url = args[0] app = JumbleMiddleware( LinkRewriterMiddleware(Proxy(proxy_url), proxy_url)) if getattr(options, 'debug', False): app = EvalException(app) app = validator(app) from paste.httpserver import serve serve(app, host=options.host, port=int(options.port))
def WSGIServer(port, application): from weberror.evalexception import EvalException application = EvalException(application, ) application = timeit_middleware(application) logging.info('\nGAME BEGIN\n\n') server = CherryPyWSGIServer(('0.0.0.0', port), application, numthreads=10) try: server.start() except KeyboardInterrupt: server.stop()
def build_wsgiapp(self): """Build the wsgiapp callable wrapping self.dispatcher with WSGI middlewares""" wsgiapp = self.dispatcher if self.debug: wsgiapp = EvalException(wsgiapp, debug=True) elif 'debug_email' in self.config: smtp_kwargs = self.config.getAttr('debug_email') if 'error_subject_prefix' not in smtp_kwargs: smtp_kwargs['error_subject_prefix'] = '[%s] ' % self.site_name smtp_kwargs['error_email'] = smtp_kwargs['error_email'].replace(';', ',').split(',') if 'smtp_use_tls' in smtp_kwargs: smtp_kwargs['smtp_use_tls'] = (smtp_kwargs['smtp_use_tls'] in (True, 'true', 't', 'True', '1', 'TRUE')) wsgiapp = ErrorMiddleware(wsgiapp, **smtp_kwargs) return wsgiapp
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)
import os import sys from paste.urlparser import StaticURLParser from paste.httpserver import serve from weberror.evalexception import EvalException from deliverance.middleware import DeliveranceMiddleware, FileRuleGetter from deliverance.security import SecurityContext base_path = os.path.join(os.path.dirname(__file__), 'example-files') app = StaticURLParser(base_path) rules_file = os.path.join(base_path, 'rules.xml') deliv_app = DeliveranceMiddleware(app, FileRuleGetter(rules_file)) full_app = SecurityContext.middleware(deliv_app, execute_pyref=True, display_logging=True, display_local_files=True, force_dev_auth=True) if __name__ == '__main__': try: port = sys.argv[1] except IndexError: port = '8080' host = '127.0.0.1' if ':' in port: host, port = port.split(':') print('See http://%s:%s/?deliv_log for the page with log messages' % (host, port)) serve(EvalException(full_app), port=port, host=host)
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))