本文整理汇总了Python中bottle.Bottle方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.Bottle方法的具体用法?Python bottle.Bottle怎么用?Python bottle.Bottle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle
的用法示例。
在下文中一共展示了bottle.Bottle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logging
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_logging(sentry_init, capture_events, app, get_client):
# ensure that Bottle's logger magic doesn't break ours
sentry_init(
integrations=[
bottle_sentry.BottleIntegration(),
LoggingIntegration(event_level="ERROR"),
]
)
@app.route("/")
def index():
app.logger.error("hi")
return "ok"
events = capture_events()
client = get_client()
client.get("/")
(event,) = events
assert event["level"] == "error"
示例2: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self, exporter, host, port, websocket_port, custom_component, encoder, api):
self._api = api
self._host = host
self._port = port
self._websocket_port = websocket_port
self._exporter = exporter
self._custom_component = custom_component
self._encoder = encoder
self._get_initial_state = exporter.get_initial_state
self._client_root = exporter.client_root
self._content_root = os.path.join(os.path.dirname(__file__), 'resources', self._client_root)
self._app = bottle.Bottle()
self._app.get('/', callback=self._index)
self._app.get('/initial-state', callback=self._initial_state)
self._app.get('/export', callback=self._export)
self._app.get('/static/<path:path>', callback=self._get_static_file)
self._app.get('/custom-components', callback=self._components)
self._api.register(self._app)
self._thread = threading.Thread(target=self._run)
self._thread.daemon = True
示例3: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self, server_settings):
"""
Loads a translation model and initialises the webserver.
@param server_settings: see `settings.py`
"""
self._style = server_settings.style
self._host = server_settings.host
self._port = server_settings.port
self._threads = server_settings.threads
self._debug = server_settings.verbose
self._models = server_settings.models
self._num_processes = server_settings.num_processes
self._status = self.STATUS_LOADING
# start webserver
self._server = Bottle()
self._server.config['logging.level'] = 'DEBUG' if server_settings.verbose else 'WARNING'
self._server.config['logging.format'] = '%(levelname)s: %(message)s'
self._server.install(LoggingPlugin(self._server.config))
logging.info("Starting Nematus Server")
# start translation workers
logging.info("Loading translation models")
self._translator = Translator(server_settings)
self._status = self.STATUS_OK
示例4: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self, logger_manager, host, port):
'''
Args:
logger_manager:
Instance of :class:`StreamCaptureManager` which the
server will use to manage logger instances.
host:
The host for webserver configuration.
port:
The port for webserver configuration.
'''
self._host = host
self._port = port
self._logger_manager = logger_manager
self._app = Bottle()
self._route()
示例5: test_lambda_default_ctx
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_lambda_default_ctx():
# Track to make sure that Bottle will default to generating segments if context is not the lambda context
new_recorder = get_new_stubbed_recorder()
new_recorder.configure(service='test', sampling=False)
new_app = Bottle()
@new_app.route('/segment')
def segment_():
# Test in between request and make sure Lambda that uses default context generates a segment.
assert new_recorder.current_segment()
assert type(new_recorder.current_segment()) == segment_model.Segment
return 'ok'
new_app.install(XRayMiddleware(new_recorder))
app_client = WebApp(new_app)
path = '/segment'
app_client.get(path)
segment = recorder.emitter.pop()
assert not segment # Segment should be none because it's created and ended by the plugin
示例6: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self, args_str=None):
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
self._smgr_log.log(self._smgr_log.INFO, "Starting SM Ansible Server")
if not args_str:
args_str = sys.argv[1:]
self._parse_args(args_str)
self.joinq = Queue.Queue()
self.joiner = Joiner(self.joinq)
self.joiner.start()
self._smgr_log.log(self._smgr_log.INFO, 'Initializing Bottle App')
self.app = bottle.app()
bottle.route('/run_ansible_playbooks', 'POST',
self.start_ansible_playbooks)
示例7: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self):
self.ip = (([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + [None])[0]
with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('0.0.0.0', 0))
self.port = s.getsockname()[1]
self.app = bottle.Bottle()
self.cast = None
self.last_known_player_state = None
self.last_known_current_time = None
self.last_time_current_time = None
self.fn = None
self.video_stream = None
self.audio_stream = None
self.last_fn_played = None
self.transcoder = None
self.duration = None
self.subtitles = None
self.seeking = False
self.last_known_volume_level = None
bus = dbus.SessionBus() if DBUS_AVAILABLE else None
self.saver_interface = find_screensaver_dbus_iface(bus)
self.inhibit_screensaver_cookie = None
self.autoplay = False
示例8: bottle_app
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def bottle_app(backend):
"""pytest fixture for `bottle.Bottle` instance.
"""
app = bottle.Bottle()
jwt_plugin = JWTProviderPlugin(
keyword='jwt',
auth_endpoint='/auth',
backend=backend,
fields=('username', 'password'),
secret='my_secret',
ttl=3
)
app.install(jwt_plugin)
@app.get('/')
@jwt_auth_required
def private_resource():
return {'user': bottle.request.get_user()}
return webtest.TestApp(app)
示例9: __init__
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def __init__(self, commandadapter, mconfig=None, mroutes=None, mcontrollers=None, env='default', before=None):
# register app
self.commandadapter = commandadapter
self.config = mconfig.config
self.urls = mroutes.urls
self.mcontrollers = mcontrollers;
self.wsgi = Bottle()
self.register_config()
self.register_log()
self.register_extensions()
self.register_ssl_context()
self.register_routes()
self.before = before
self.before()
示例10: app
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def app(sentry_init):
app = Bottle()
@app.route("/message")
def hi():
capture_message("hi")
return "ok"
@app.route("/message-named-route", name="hi")
def named_hi():
capture_message("hi")
return "ok"
yield app
示例11: spawn
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def spawn(function, *args, **kwargs):
return gvt.spawn(function, *args, **kwargs)
# Bottle Routes
示例12: test_hello_world
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_hello_world(self):
app = bottle.Bottle()
br = bottlereact.BottleReact(app, prod=True)
html = br.render_html(br.HelloWorld())
self.assertTrue(html.startswith('<html>'))
self.assertTrue('-bottlereact.js"></script>' in html)
self.assertTrue('-hello_world.js"></script>' in html)
self.assertTrue('React.createElement(bottlereact.HelloWorld,{},[])' in html)
示例13: test_kwarg
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_kwarg(self):
app = bottle.Bottle()
br = bottlereact.BottleReact(app, prod=True)
html = br.render_html(br.HelloWorld(), template='title', title='xyz').strip()
self.assertEqual(html, 'xyz')
示例14: test_default_kwarg
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_default_kwarg(self):
app = bottle.Bottle()
br = bottlereact.BottleReact(app, prod=True, default_render_html_kwargs={'title':'abc'})
html = br.render_html(br.HelloWorld(), template='title').strip()
self.assertEqual(html, 'abc')
html = br.render_html(br.HelloWorld(), template='title', title='xyz').strip()
self.assertEqual(html, 'xyz')
示例15: test_default_kwarg_func
# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def test_default_kwarg_func(self):
def default_render_html_kwargs():
return {'title':'abc'}
app = bottle.Bottle()
br = bottlereact.BottleReact(app, prod=True, default_render_html_kwargs=default_render_html_kwargs)
html = br.render_html(br.HelloWorld(), template='title').strip()
self.assertEqual(html, 'abc')
html = br.render_html(br.HelloWorld(), template='title', title='xyz').strip()
self.assertEqual(html, 'xyz')