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


Python helpers.make_response方法代码示例

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


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

示例1: get_graph_metadata

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def get_graph_metadata(graph_id: int):
    """Returns the metadata for a single graph. This is automatically generated
    by the datasource classes.

    Parameters
    ----------
    graph_id : int
        Graph ID.

    Returns 404 if the graph ID is not found

    Returns
    -------
    Dict
        A dictionary representing the metadata of the current graph.
    """

    graph_obj = Graph.query.filter_by(id=graph_id).first()

    if not graph_obj:
        return make_response(jsonify({"message": "Graph not found"}), 404)

    response = jsonify(graph_obj.meta)

    return response 
开发者ID:yampelo,项目名称:beagle,代码行数:27,代码来源:views.py

示例2: authentication_endpoint

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def authentication_endpoint():
    # parse authentication request
    try:
        auth_req = current_app.provider.parse_authentication_request(urlencode(flask.request.args),
                                                                     flask.request.headers)
    except InvalidAuthenticationRequest as e:
        current_app.logger.debug('received invalid authn request', exc_info=True)
        error_url = e.to_error_url()
        if error_url:
            return redirect(error_url, 303)
        else:
            # show error to user
            return make_response('Something went wrong: {}'.format(str(e)), 400)

    # automagic authentication
    authn_response = current_app.provider.authorize(auth_req, 'test_user')
    response_url = authn_response.request(auth_req['redirect_uri'], should_fragment_encode(auth_req))
    return redirect(response_url, 303) 
开发者ID:IdentityPython,项目名称:pyop,代码行数:20,代码来源:views.py

示例3: token_endpoint

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def token_endpoint():
    try:
        token_response = current_app.provider.handle_token_request(flask.request.get_data().decode('utf-8'),
                                                                   flask.request.headers)
        return jsonify(token_response.to_dict())
    except InvalidClientAuthentication as e:
        current_app.logger.debug('invalid client authentication at token endpoint', exc_info=True)
        error_resp = TokenErrorResponse(error='invalid_client', error_description=str(e))
        response = make_response(error_resp.to_json(), 401)
        response.headers['Content-Type'] = 'application/json'
        response.headers['WWW-Authenticate'] = 'Basic'
        return response
    except OAuthError as e:
        current_app.logger.debug('invalid request: %s', str(e), exc_info=True)
        error_resp = TokenErrorResponse(error=e.oauth_error, error_description=str(e))
        response = make_response(error_resp.to_json(), 400)
        response.headers['Content-Type'] = 'application/json'
        return response 
开发者ID:IdentityPython,项目名称:pyop,代码行数:20,代码来源:views.py

示例4: export_move

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def export_move(id):
    move = Move.query.filter_by(id=id).first_or_404()

    if not move.public and move.user != current_user:
        return app.login_manager.unauthorized()

    if "format" in request.args:
        format = request.args.get("format").lower()
    else:
        format = "gpx"  # default

    format_handlers = {'gpx': gpx_export.gpx_export,
                       'csv': csv_export.csv_export}
    if format not in format_handlers:
        flash("Export format %s not supported" % format, 'error')
        return redirect(url_for('move', id=id))

    export_file = format_handlers[format](move)

    if not export_file:
        return redirect(url_for('move', id=id))

    # app.logger.debug("Move export (format %s):\n%s" % (format, export_file))
    response = make_response(export_file)
    date_time = move.date_time.strftime('%Y-%m-%dT%H_%M_%S')
    if move.location_raw:
        address = move.location_raw['address']
        city = get_city(address)
        country_code = address['country_code'].upper()
        filename = "Move_%s_%s_%s_%s.%s" % (date_time, country_code, city, move.activity, format)
    else:
        filename = "Move_%s_%s.%s" % (date_time, move.activity, format)

    response.headers['Content-Disposition'] = "attachment; filename=%s" % (quote_plus(filename))
    return response 
开发者ID:bwaldvogel,项目名称:openmoves,代码行数:37,代码来源:openmoves.py

示例5: get

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def get(self):
        rc, msg = reqHandler.getAllContainers()
        return make_response(json.dumps(msg), codes.herror(rc)) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:5,代码来源:agent.py

示例6: post

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def post(self, containerId):
        reqData = request.data
        rc = reqHandler.handleContainerOp(reqData, containerId)
        return make_response("", codes.herror(rc)) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:6,代码来源:agent.py

示例7: delete

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def delete(self):
        rc = reqHandler.deleteContainer(None, containerId)
        return make_response("", 200) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:5,代码来源:agent.py

示例8: get

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def get(self):
        rc, msg = reqHandler.getAllContainers()
        return make_response(msg, codes.herror(rc)) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:5,代码来源:apiserver.py

示例9: post

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def post(self):
        migreq  = json.loads(request.data)
        rc = reqHandler.migrate(migreq)
        return make_response("", codes.herror(rc)) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:6,代码来源:apiserver.py

示例10: delete

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def delete(self):
        return make_response("", 200) 
开发者ID:nadgowdas,项目名称:cargo,代码行数:4,代码来源:apiserver.py

示例11: get_category_items

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def get_category_items(category: str):  # pragma: no cover
    """Returns the set of items that exist in this category, the path to their JSON files, the comment
    made on them, as well as their metadata.

    >>> {
        comment: str,
        file_path: str,
        id: int,
        metadata: Dict[str, Any]
    }

    Returns 404 if the category is invalid.

    Parameters
    ----------
    category : str
        The category to fetch data for.

    Returns
    -------
    List[dict]
    """

    if category not in set(
        [source.category.replace(" ", "_").lower() for source in DATASOURCES.values()]
    ):
        return make_response(jsonify({"message": "Category not found"}), 404)

    # Return reversed.
    category_data = [graph.to_json() for graph in Graph.query.filter_by(category=category).all()]
    category_data = category_data[::-1]

    response = jsonify(category_data)

    return response 
开发者ID:yampelo,项目名称:beagle,代码行数:37,代码来源:views.py

示例12: get_graph

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def get_graph(graph_id: int):  # pragma: no cover - hard to test due to building path.
    """Returns the JSON object for this graph. This is a networkx node_data JSON dump:

    >>> {
        directed: boolean,
        links: [
            {...}
        ],
        multigraph: boolean,
        nodes: [
            {...}
        ]
    }

    Returns 404 if the graph is not found.

    Parameters
    ----------
    graph_id : int
        The graph ID to fetch data for

    Returns
    -------
    Dict
        See https://networkx.github.io/documentation/stable/reference/readwrite/generated/networkx.readwrite.json_graph.node_link_graph.html
    """

    graph_obj = Graph.query.filter_by(id=graph_id).first()

    if not graph_obj:
        return make_response(jsonify({"message": "Graph not found"}), 404)

    dest_path = f"{Config.get('storage', 'dir')}/{graph_obj.category}/{graph_obj.file_path}"

    json_data = json.load(open(dest_path, "r"))

    response = jsonify(json_data)

    return response 
开发者ID:yampelo,项目名称:beagle,代码行数:41,代码来源:views.py

示例13: api_key_required

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def api_key_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        api_key = request.form.get('api_key') or request.args.get('api_key')
        valid_api_key = False
        if api_key is not None:
            valid_api_key = AccessKey.query(AccessKey.access_key == api_key).get(keys_only=True) is not None
        if not valid_api_key:
            return make_response('Invalid API Key', 401, {
                'WWWAuthenticate': 'Basic realm="Login Required"',
            })
        return f(*args, **kwargs)
    return decorated_function 
开发者ID:Yelp,项目名称:love,代码行数:15,代码来源:decorators.py

示例14: make_json_response

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def make_json_response(data, *args):
    response = make_response(json.dumps(data), *args)
    response.headers['Content-Type'] = 'application/json'
    return response 
开发者ID:Yelp,项目名称:love,代码行数:6,代码来源:render.py

示例15: rp

# 需要导入模块: from flask import helpers [as 别名]
# 或者: from flask.helpers import make_response [as 别名]
def rp():
    try:
        iss = request.args['iss']
    except KeyError:
        link = ''
    else:
        link = iss

    try:
        uid = request.args['uid']
    except KeyError:
        uid = ''

    if link or uid:
        if uid:
            args = {'user_id': uid}
        else:
            args = {}

        session['op_hash'] = link
        try:
            result = current_app.rph.begin(link, **args)
        except Exception as err:
            return make_response('Something went wrong:{}'.format(err), 400)
        else:
            return redirect(result['url'], 303)
    else:
        _providers = current_app.rp_config.clients.keys()
        return render_template('opbyuid.html', providers=_providers) 
开发者ID:IdentityPython,项目名称:JWTConnect-Python-OidcRP,代码行数:31,代码来源:views.py


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