我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用bottle.default_app()。
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('--host', default="169.254.169.254") parser.add_argument('--port', default=80) parser.add_argument('--role-arn', help="Default role ARN.") parser.add_argument('--conf-dir', help="Directory containing configuration files named by source ip.") args = parser.parse_args() global _role_arn _role_arn = args.role_arn global _conf_dir _conf_dir = args.conf_dir app = bottle.default_app() app.run(host=args.host, port=args.port)
def bottle(body, headers): import bottle path = '/hello/<account_id>/test' @bottle.route(path) def hello(account_id): user_agent = bottle.request.headers['User-Agent'] # NOQA limit = bottle.request.query.limit or '10' # NOQA return bottle.Response(body, headers=headers) return bottle.default_app()
def ise_handler(e): eventlog.emit( 'exception', { 'message': 'Internal Server Error', 'traceback': e.traceback, }) return bottle.default_app().default_error_handler(e)
def install_request_hooks(): """Installs request hooks.""" bottle.default_app().add_hook('before_request', _api_auth_hook) bottle.default_app().add_hook('before_request', _default_headers_hook) bottle.default_app().add_hook('before_request', _protect_admin_area_hook) bottle.default_app().add_hook('before_request', _protect_before_contest_hook) bottle.default_app().add_hook('before_request', _enforce_web_rate_limit_hook) bottle.default_app().add_hook('before_request', _protect_xsrf_hook) bottle.default_app().add_hook('before_request', _require_gzip_hook)
def wsgi_app(): """Returns the application to make available through wfastcgi. This is used when the site is published to Microsoft Azure.""" return bottle.default_app()
def test_request_attrs(self): """ WSGI: POST routes""" @bottle.route('/') def test(): self.assertEqual(bottle.request.app, bottle.default_app()) self.assertEqual(bottle.request.route, bottle.default_app().routes[0]) return 'foo' self.assertBody('foo', '/')
def start(browser=False, debug=False): """ Start a bottle web server. Derived from WSGIRefServer.run() to have control over the main loop. """ global DEBUG DEBUG = debug class FixedHandler(wsgiref.simple_server.WSGIRequestHandler): def address_string(self): # Prevent reverse DNS lookups please. return self.client_address[0] def log_request(*args, **kw): if debug: return wsgiref.simple_server.WSGIRequestHandler.log_request(*args, **kw) S.server = wsgiref.simple_server.make_server( conf['network_host'], conf['network_port'], bottle.default_app(), wsgiref.simple_server.WSGIServer, FixedHandler ) S.server.timeout = 0.01 S.server.quiet = not debug if debug: bottle.debug(True) print "Internal storage root is: " + conf['rootdir'] print "Persistent storage root is: " + conf['stordir'] print "-----------------------------------------------------------------------------" print "Starting server at http://%s:%d/" % ('127.0.0.1', conf['network_port']) print "-----------------------------------------------------------------------------" driveboard.connect_withfind() # open web-browser if browser: try: webbrowser.open_new_tab('http://127.0.0.1:'+str(conf['network_port'])) except webbrowser.Error: print "Cannot open Webbrowser, please do so manually." sys.stdout.flush() # make sure everything gets flushed # start server print "INFO: Starting web server thread." S.start()