当前位置: 首页>>代码示例>>Python>>正文


Python bottle.Bottle方法代码示例

本文整理汇总了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" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:23,代码来源:test_bottle.py

示例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 
开发者ID:dankilman,项目名称:awe,代码行数:22,代码来源:webserver.py

示例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 
开发者ID:EdinburghNLP,项目名称:nematus,代码行数:26,代码来源:server.py

示例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() 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:20,代码来源:bsc.py

示例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 
开发者ID:aws,项目名称:aws-xray-sdk-python,代码行数:22,代码来源:test_bottle.py

示例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) 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:19,代码来源:sm_ansible_server.py

示例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 
开发者ID:keredson,项目名称:gnomecast,代码行数:25,代码来源:gnomecast.py

示例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) 
开发者ID:agile4you,项目名称:bottle-jwt,代码行数:25,代码来源:conftest.py

示例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() 
开发者ID:aacanakin,项目名称:glim,代码行数:19,代码来源:app.py

示例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 
开发者ID:getsentry,项目名称:sentry-python,代码行数:16,代码来源:test_bottle.py

示例11: spawn

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import Bottle [as 别名]
def spawn(function, *args, **kwargs):
    return gvt.spawn(function, *args, **kwargs)

# Bottle Routes 
开发者ID:samuelhwilliams,项目名称:Eel,代码行数:6,代码来源:__init__.py

示例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) 
开发者ID:keredson,项目名称:bottle-react,代码行数:10,代码来源:test.py

示例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') 
开发者ID:keredson,项目名称:bottle-react,代码行数:7,代码来源:test.py

示例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') 
开发者ID:keredson,项目名称:bottle-react,代码行数:9,代码来源:test.py

示例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') 
开发者ID:keredson,项目名称:bottle-react,代码行数:11,代码来源:test.py


注:本文中的bottle.Bottle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。