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


Python bottle.response方法代码示例

本文整理汇总了Python中bottle.response方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.response方法的具体用法?Python bottle.response怎么用?Python bottle.response使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bottle的用法示例。


在下文中一共展示了bottle.response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_metadata_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def create_metadata_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper():
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_metadata_response(
                        uri, http_method, body, headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status,
                             resp_headers, resp_body, force_json=True)

                func_response = f()
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:25,代码来源:oauth2.py

示例2: create_introspect_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def create_introspect_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_introspect_response(
                        uri, http_method, body, headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status, resp_headers,
                             resp_body, force_json=True)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:25,代码来源:oauth2.py

示例3: create_userinfo_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def create_userinfo_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_userinfo_response(
                        uri, http_method=http_method, body=body, headers=headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code

                set_response(bottle.request, bottle.response, resp_status, resp_headers,
                             resp_body, force_json=True)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:26,代码来源:oauth2.py

示例4: get_config

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def get_config(self, screen):
        """Method to retrieve config file for screen."""

        # Define the path to the config file
        conffile = os.path.join(self.folder, "screens", screen, "conf.json")

        if os.path.isfile(conffile):

            # Get the config file
            with open(conffile, "r") as cfg_file:

                # Load the JSON object
                conf = json.load(cfg_file)

            # Return the "params" section
            result = self.api_success(conf.get("params", dict()))

        else:

            # Something's gone wrong
            result = self.api_error("No screen called: {}".format(screen))

        # Provide the response
        return json.dumps(result) 
开发者ID:elParaguayo,项目名称:RPi-InfoScreen-Kivy,代码行数:26,代码来源:webapi.py

示例5: on_new_subtitle_clicked

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def on_new_subtitle_clicked(self):
      dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
          Gtk.FileChooserAction.OPEN,
          (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
           Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

      if self.fn:
        dialog.set_current_folder(os.path.dirname(self.fn))

      filter_py = Gtk.FileFilter()
      filter_py.set_name("Subtitles")
      filter_py.add_pattern("*.srt")
      filter_py.add_pattern("*.vtt")
      dialog.add_filter(filter_py)

      response = dialog.run()
      if response == Gtk.ResponseType.OK:
          print("Open clicked")
          print("File selected: " + dialog.get_filename())
          self.select_subtitles_file(dialog.get_filename())
      elif response == Gtk.ResponseType.CANCEL:
          print("Cancel clicked")
          self.subtitle_combo.set_active(0)

      dialog.destroy() 
开发者ID:keredson,项目名称:gnomecast,代码行数:27,代码来源:gnomecast.py

示例6: on_download_subtitle_clicked

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def on_download_subtitle_clicked(self):
      dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win,
          Gtk.FileChooserAction.OPEN,
          (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
           Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

      if self.fn:
        dialog.set_current_folder(os.path.dirname(self.fn))

      filter_py = Gtk.FileFilter()
      filter_py.set_name("Subtitles")
      filter_py.add_pattern("*.srt")
      filter_py.add_pattern("*.vtt")
      dialog.add_filter(filter_py)

      response = dialog.run()
      if response == Gtk.ResponseType.OK:
          print("Open clicked")
          print("File selected: " + dialog.get_filename())
          self.select_subtitles_file(dialog.get_filename())
      elif response == Gtk.ResponseType.CANCEL:
          print("Cancel clicked")
          self.subtitle_combo.set_active(0)

      dialog.destroy() 
开发者ID:keredson,项目名称:gnomecast,代码行数:27,代码来源:gnomecast.py

示例7: error_callback

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def error_callback(self, msg):
    def f():
      dialogWindow = Gtk.MessageDialog(self.win,
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            Gtk.MessageType.INFO,
                            Gtk.ButtonsType.OK,
                            '\nGnomecast encountered an error converting your file.')
      dialogWindow.set_title('Transcoding Error')
      dialogWindow.set_default_size(1, 400)
      
      dialogBox = dialogWindow.get_content_area()
      buffer1 = Gtk.TextBuffer()
      buffer1.set_text(msg)
      text_view = Gtk.TextView(buffer=buffer1)
      text_view.set_editable(False)
      scrolled_window = Gtk.ScrolledWindow()
      scrolled_window.set_border_width(5)
      # we scroll only if needed
      scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
      scrolled_window.add(text_view)
      dialogBox.pack_end(scrolled_window, True, True, 0)
      dialogWindow.show_all()
      response = dialogWindow.run()
      dialogWindow.destroy()
    GLib.idle_add(f) 
开发者ID:keredson,项目名称:gnomecast,代码行数:27,代码来源:gnomecast.py

示例8: register_routes

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def register_routes(self):
        """
        Function creates instances of controllers, adds into bottle routes
        """
        routes = self.flatten_urls(self.urls)
        self.controllers = {}
        controller_names = set()

        for route in routes:
            cname = route['endpoint'].split('.')[0]
            controller_names.add(cname)

        for cname in controller_names:
            attr = getattr(self.mcontrollers, cname)
            instance = attr(request, response)
            self.controllers[cname] = instance

        for route in routes:
            cname, aname = route['endpoint'].split('.')
            action = getattr(self.controllers[cname], aname)
            self.wsgi.route(route['url'], route['methods'], action) 
开发者ID:aacanakin,项目名称:glim,代码行数:23,代码来源:app.py

示例9: _eel

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def _eel():
    start_geometry = {'default': {'size': _start_args['size'],
                                  'position': _start_args['position']},
                      'pages':   _start_args['geometry']}

    page = _eel_js.replace('/** _py_functions **/',
                           '_py_functions: %s,' % list(_exposed_functions.keys()))
    page = page.replace('/** _start_geometry **/',
                        '_start_geometry: %s,' % _safe_json(start_geometry))
    btl.response.content_type = 'application/javascript'
    _set_response_headers(btl.response)
    return page 
开发者ID:samuelhwilliams,项目名称:Eel,代码行数:14,代码来源:__init__.py

示例10: _static

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def _static(path):
    response = None
    if 'jinja_env' in _start_args and 'jinja_templates' in _start_args:
        template_prefix = _start_args['jinja_templates'] + '/'
        if path.startswith(template_prefix):
            n = len(template_prefix)
            template = _start_args['jinja_env'].get_template(path[n:])
            response = btl.HTTPResponse(template.render())

    if response is None:
        response = btl.static_file(path, root=root_path)

    _set_response_headers(response)
    return response 
开发者ID:samuelhwilliams,项目名称:Eel,代码行数:16,代码来源:__init__.py

示例11: _set_response_headers

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def _set_response_headers(response):
    if _start_args['disable_cache']:
        # https://stackoverflow.com/a/24748094/280852
        response.set_header('Cache-Control', 'no-store') 
开发者ID:samuelhwilliams,项目名称:Eel,代码行数:6,代码来源:__init__.py

示例12: create_token_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def create_token_response(self, credentials=None):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                # Get any additional creds
                try:
                    credentials_extra = credentials(bottle.request)
                except TypeError:
                    credentials_extra = credentials
                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_token_response(
                        uri, http_method, body, headers, credentials_extra
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status,
                             resp_headers, resp_body)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:30,代码来源:oauth2.py

示例13: create_authorization_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def create_authorization_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)
                scope = bottle.request.params.get('scope', '').split(' ')

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_authorization_response(
                        uri, http_method=http_method, body=body, headers=headers, scopes=scope
                    )
                except FatalClientError as e:
                    if self._error_uri:
                        raise bottle.HTTPResponse(status=302, headers={"Location": add_params_to_uri(
                            self._error_uri, {'error': e.error, 'error_description': e.description}
                        )})
                    raise e
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status, resp_headers, resp_body)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:31,代码来源:oauth2.py

示例14: api_success

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def api_success(self, data):
        """Base method for response to successful API calls."""

        return {"status": "success",
                  "data": data} 
开发者ID:elParaguayo,项目名称:RPi-InfoScreen-Kivy,代码行数:7,代码来源:webapi.py

示例15: api_error

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import response [as 别名]
def api_error(self, message):
        """Base method for response to unsuccessful API calls."""

        return {"status": "error",
                  "message": message} 
开发者ID:elParaguayo,项目名称:RPi-InfoScreen-Kivy,代码行数:7,代码来源:webapi.py


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