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


Python flask.request方法代码示例

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


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

示例1: token_required

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def token_required(func):
    """
    检查是否携带token,如果token未携带或无效将直接返回错误,否则将username保存到g.username中
    """
    from everyclass.server.user import service as user_service

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        token = request.headers.get("X-API-Token")
        if not token:
            return generate_error_response(None, STATUS_CODE_TOKEN_MISSING)

        username = user_service.get_username_from_jwt(token)
        if not username:
            return generate_error_response(None, STATUS_CODE_INVALID_TOKEN)

        g.username = username
        return func(*args, **kwargs)

    return wrapped 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:22,代码来源:api_helpers.py

示例2: auth

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def auth():
  # Describe the access request of the client and ask user for approval
  client_id = request.args.get('client_id')
  redirect_url = request.args.get('redirect_url')

  if None in [ client_id, redirect_url ]:
    return json.dumps({
      "error": "invalid_request"
    }), 400

  if not verify_client_info(client_id, redirect_url):
    return json.dumps({
      "error": "invalid_client"
    })

  return render_template('Implicit_grant_access.html',
                         client_id = client_id,
                         redirect_url = redirect_url) 
开发者ID:michaelawyu,项目名称:auth-server-sample,代码行数:20,代码来源:Implicit_auth_server.py

示例3: auth

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def auth():
  # Describe the access request of the client and ask user for approval
  client_id = request.args.get('client_id')
  redirect_url = request.args.get('redirect_url')
  code_challenge = request.args.get('code_challenge')

  if None in [ client_id, redirect_url, code_challenge ]:
    return json.dumps({
      "error": "invalid_request"
    }), 400

  if not verify_client_info(client_id, redirect_url):
    return json.dumps({
      "error": "invalid_client"
    })

  return render_template('AC_PKCE_grant_access.html',
                         client_id = client_id,
                         redirect_url = redirect_url,
                         code_challenge = code_challenge) 
开发者ID:michaelawyu,项目名称:auth-server-sample,代码行数:22,代码来源:AC_PKCE_auth_server.py

示例4: exchange_for_token

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def exchange_for_token():
  # Issues access token
  authorization_code = request.form.get('authorization_code')
  client_id = request.form.get('client_id')
  code_verifier = request.form.get('code_verifier')
  redirect_url = request.form.get('redirect_url')

  if None in [ authorization_code, client_id, code_verifier, redirect_url ]:
    return json.dumps({
      "error": "invalid_request"
    }), 400

  if not verify_authorization_code(authorization_code, client_id, redirect_url,
                                   code_verifier):
    return json.dumps({
      "error": "access_denied"
    }), 400

  access_token = generate_access_token()
  return json.dumps({ 
    "access_token": access_token,
    "token_type": "JWT",
    "expires_in": JWT_LIFE_SPAN
  }) 
开发者ID:michaelawyu,项目名称:auth-server-sample,代码行数:26,代码来源:AC_PKCE_auth_server.py

示例5: redirect_later

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def redirect_later():
    """302 redirect to / after the given delay.

    If delay is -1, wait until a request on redirect-later-continue is done.
    """
    global _redirect_later_event
    delay = float(flask.request.args.get('delay', '1'))
    if delay == -1:
        _redirect_later_event = threading.Event()
        ok = _redirect_later_event.wait(timeout=30 * 1000)
        assert ok
        _redirect_later_event = None
    else:
        time.sleep(delay)
    x = flask.redirect('/')
    return x 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:18,代码来源:webserver_sub.py

示例6: drip

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def drip():
    """Drip data over a duration."""
    duration = float(flask.request.args.get('duration'))
    numbytes = int(flask.request.args.get('numbytes'))
    pause = duration / numbytes

    def generate_bytes():
        for _ in range(numbytes):
            yield "*".encode('utf-8')
            time.sleep(pause)

    response = flask.Response(generate_bytes(), headers={
        "Content-Type": "application/octet-stream",
        "Content-Length": str(numbytes),
    })
    response.status_code = HTTPStatus.OK
    return response 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:19,代码来源:webserver_sub.py

示例7: test_get_scopes

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def test_get_scopes(flask_app):
    with flask_app.test_request_context("/"):
        scopes = get_scopes(flask.request)
        assert scopes == set()

    with flask_app.test_request_context("/?scope=email&scope=name"):
        scopes = get_scopes(flask.request)
        assert scopes == {Scope.NAME, Scope.EMAIL}

    # a space between email and name
    with flask_app.test_request_context("/?scope=email%20name"):
        scopes = get_scopes(flask.request)
        assert scopes == {Scope.NAME, Scope.EMAIL}

    # a comma between email and name
    with flask_app.test_request_context("/?scope=email,name"):
        scopes = get_scopes(flask.request)
        assert scopes == {Scope.NAME, Scope.EMAIL}

    # non-existent scope: raise ValueError
    with flask_app.test_request_context("/?scope=abcd"):
        with pytest.raises(ValueError):
            get_scopes(flask.request) 
开发者ID:simple-login,项目名称:app,代码行数:25,代码来源:test_oauth_models.py

示例8: test_get_response_types

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def test_get_response_types(flask_app):
    with flask_app.test_request_context("/"):
        response_types = get_response_types(flask.request)
        assert response_types == set()

    with flask_app.test_request_context("/?response_type=token&response_type=id_token"):
        response_types = get_response_types(flask.request)
        assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}

    # a space as separator
    with flask_app.test_request_context("/?response_type=token%20id_token"):
        response_types = get_response_types(flask.request)
        assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}

    # a comma as separator
    with flask_app.test_request_context("/?response_type=id_token,token"):
        response_types = get_response_types(flask.request)
        assert response_types == {ResponseType.TOKEN, ResponseType.ID_TOKEN}

    # non-existent response_type: raise ValueError
    with flask_app.test_request_context("/?response_type=abcd"):
        with pytest.raises(ValueError):
            get_response_types(flask.request) 
开发者ID:simple-login,项目名称:app,代码行数:25,代码来源:test_oauth_models.py

示例9: do_get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def do_get(self):
        is_valid, msg, json = self.validate_json()
        if not is_valid:
            logger.error('invalid json: %s' % msg)
            return dict()

        if json is None:
            return environ.env.db.get_banned_users()

        if 'users' not in json:
            return dict()
        logger.debug('GET request: %s' % str(json))

        output = dict()
        for user_id in json['users']:
            output[user_id] = self.do_get_with_params(user_id)
        return output 
开发者ID:thenetcircle,项目名称:dino,代码行数:19,代码来源:roles.py

示例10: do_post

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def do_post(self):
        is_valid, msg, json = self.validate_json()
        if not is_valid:
            logger.error('invalid json: %s' % msg)
            raise RuntimeError('invalid json')

        if json is None:
            raise RuntimeError('no json in request')
        if not isinstance(json, dict):
            raise RuntimeError('need a dict')
        logger.debug('POST request: %s' % str(json))

        if 'id' not in json:
            raise RuntimeError('no id parameter in request')

        user_id = json.get('id')
        try:
            environ.env.db.remove_global_moderator(user_id)
        except Exception as e:
            logger.error('could not remove global moderator with id "%s": %s' % (str(user_id), str(e)))
            logger.exception(traceback.format_exc())
            raise RuntimeError('could not remove global moderator with id "%s": %s' % (str(user_id), str(e))) 
开发者ID:thenetcircle,项目名称:dino,代码行数:24,代码来源:remove_admin.py

示例11: do_get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def do_get(self):
        the_json = self.validate_json()
        logger.debug('GET request: %s' % str(the_json))

        room_id = the_json.get('room_id', '')
        limit = the_json.get('limit', 100)

        try:
            messages = self.do_get_with_params(room_id, limit)
            for message in messages:
                message['from_user_name'] = b64e(message['from_user_name'])
                message['body'] = b64e(message['body'])
                message['target_name'] = b64e(message['target_name'])
                message['channel_name'] = b64e(message['channel_name'])
            return messages
        except Exception as e:
            logger.error('could not get messages: %s' % str(e))
            raise e 
开发者ID:thenetcircle,项目名称:dino,代码行数:20,代码来源:latest_history.py

示例12: _do_post

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def _do_post(self, json_data: dict):
        logger.debug('POST request: %s' % str(json_data))

        room_id = json_data.get('room_id')
        action = json_data.get('action')
        acl_type = json_data.get('acl_type')
        acl_value = json_data.get('acl_value')

        try:
            channel_id = self.env.db.channel_for_room(room_id)
            self.acl_manager.update_room_acl(channel_id, room_id, action, acl_type, acl_value)
        except Exception as e:
            logger.error('could update acls in room {} with action={}, type={}, value="{}": {}'.format(
                room_id, action, acl_type, acl_value, str(e))
            )
            logger.exception(traceback.format_exc())
            self.env.capture_exception(sys.exc_info()) 
开发者ID:thenetcircle,项目名称:dino,代码行数:19,代码来源:acl.py

示例13: _validate_params

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def _validate_params(self):
        is_valid, msg, json_data = self.validate_json(self.request, silent=False)
        if not is_valid:
            raise RuntimeError('invalid json: %s' % msg)

        if json_data is None:
            raise RuntimeError('no json in request')
        if not isinstance(json_data, dict):
            raise RuntimeError('need a dict')

        if 'room_id' not in json_data:
            raise KeyError('missing parameter room_id for in request')
        if 'action' not in json_data:
            raise KeyError('missing parameter action for in request')
        if 'acl_type' not in json_data:
            raise KeyError('missing parameter acl_type for in request')
        if 'acl_value' not in json_data:
            raise KeyError('missing parameter acl_value for in request')

        return json_data 
开发者ID:thenetcircle,项目名称:dino,代码行数:22,代码来源:acl.py

示例14: do_get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def do_get(self):
        is_valid, msg, json = self.validate_json(self.request, silent=True)
        if not is_valid:
            logger.error('invalid json: %s' % msg)
            return dict()

        if json is None:
            return environ.env.db.get_banned_users()

        if 'users' not in json:
            return dict()
        logger.debug('GET request: %s' % str(json))

        output = dict()
        for user_id in json['users']:
            output[user_id] = self.do_get_with_params(user_id)
        return output 
开发者ID:thenetcircle,项目名称:dino,代码行数:19,代码来源:banned.py

示例15: do_post

# 需要导入模块: import flask [as 别名]
# 或者: from flask import request [as 别名]
def do_post(self):
        the_json = self.validate_json()
        logger.debug('POST request: %s' % str(the_json))

        user_id = the_json.get('user_id')
        from_time = the_json.get('from_time', None)
        to_time = the_json.get('to_time', None)

        try:
            messages = self.do_post_with_params(user_id, from_time, to_time)
            for message in messages:
                message['from_user_name'] = b64e(message['from_user_name'])
                message['body'] = b64e(message['body'])
                message['target_name'] = b64e(message['target_name'])
                message['channel_name'] = b64e(message['channel_name'])
            return messages
        except Exception as e:
            logger.error('could not get messages: %s' % str(e))
            raise e 
开发者ID:thenetcircle,项目名称:dino,代码行数:21,代码来源:full_history.py


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