當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。