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