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


Python current_app.response_class方法代码示例

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


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

示例1: _process

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def _process(self):
        config = Config()
        config.HTMLExporter.preprocessors = [CppHighlighter]
        config.HTMLExporter.template_file = 'basic'

        with self.attachment.file.open() as f:
            notebook = nbformat.read(f, as_version=4)

        html_exporter = HTMLExporter(config=config)
        body, resources = html_exporter.from_notebook_node(notebook)
        css_code = '\n'.join(resources['inlining'].get('css', []))

        nonce = str(uuid4())
        html = render_template('previewer_jupyter:ipynb_preview.html', attachment=self.attachment,
                               html_code=body, css_code=css_code, nonce=nonce)

        response = current_app.response_class(html)
        # Use CSP to restrict access to possibly malicious scripts or inline JS
        csp_header = "script-src cdn.mathjax.org 'nonce-{}';".format(nonce)
        response.headers['Content-Security-Policy'] = csp_header
        response.headers['X-Webkit-CSP'] = csp_header
        # IE10 doesn't have proper CSP support, so we need to be more strict
        response.headers['X-Content-Security-Policy'] = "sandbox allow-same-origin;"

        return response 
开发者ID:indico,项目名称:indico-plugins,代码行数:27,代码来源:controllers.py

示例2: plistify

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def plistify(*args, **kwargs):
    """Similar to jsonify, which ships with Flask, this function wraps plistlib.dumps and sets up the correct
    mime type for the response."""
    if args and kwargs:
        raise TypeError('plistify() behavior undefined when passed both args and kwargs')
    elif len(args) == 1:  # single args are passed directly to dumps()
        data = args[0]
    else:
        data = args or kwargs

    mimetype = kwargs.get('mimetype', current_app.config['PLISTIFY_MIMETYPE'])

    return current_app.response_class(
        (plistlib.dumps(data), '\n'),
        mimetype=mimetype
    ) 
开发者ID:cmdmnt,项目名称:commandment,代码行数:18,代码来源:utils.py

示例3: support_jsonp

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def support_jsonp(f):
    """
    Wraps JSONified output for JSONP
    https://gist.github.com/richardchien/7b7c2727feb3e8993845a3ce61bad808
    """

    @wraps(f)
    def decorated_function(*args, **kwargs):
        callback = request.args.get('callback', False)
        if callback:
            content = str(callback) + '(' + f(*args, **kwargs).data.decode('utf-8') + ')'
            return current_app.response_class(content, mimetype='application/json')
        else:
            return f(*args, **kwargs)

    return decorated_function 
开发者ID:richardchien-archive,项目名称:blog-a,代码行数:18,代码来源:app.py

示例4: export_json

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def export_json(data, status, headers):
    """
    Creates a JSON response

    JSON content is encoded by utf-8, not unicode escape.

    Args:
        data: any type object that can dump to json
        status (int): http status code
        headers (dict): http headers
    """
    dumped = json.dumps(data, ensure_ascii=False)
    resp = current_app.response_class(
        dumped, status=status, headers=headers,
        content_type='application/json; charset=utf-8')
    return resp 
开发者ID:guyskk,项目名称:flask-restaction,代码行数:18,代码来源:exporters.py

示例5: stream

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def stream(self):
        """
        A view function that streams server-sent events. Ignores any
        :mailheader:`Last-Event-ID` headers in the HTTP request.
        Use a "channel" query parameter to stream events from a different
        channel than the default channel (which is "sse").
        """
        channel = request.args.get('channel') or 'sse'

        @stream_with_context
        def generator():
            for message in self.messages(channel=channel):
                yield str(message)

        return current_app.response_class(
            generator(),
            mimetype='text/event-stream',
        ) 
开发者ID:singingwolfboy,项目名称:flask-sse,代码行数:20,代码来源:flask_sse.py

示例6: _openapi_json

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def _openapi_json(self):
        """Serve JSON spec file"""
        # We don't use Flask.jsonify here as it would sort the keys
        # alphabetically while we want to preserve the order.
        return current_app.response_class(
            json.dumps(self.spec.to_dict(), indent=2),
            mimetype='application/json') 
开发者ID:marshmallow-code,项目名称:flask-smorest,代码行数:9,代码来源:__init__.py

示例7: token

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def token(ttype=None):
    """
    This is a special token function. Each token type can define an
    additional API call, that does not need authentication on the REST API
    level.

    :return: Token Type dependent
    """
    tokenc = get_token_class(ttype)
    res = tokenc.api_endpoint(request, g)
    serial = getParam(request.all_data, "serial")
    user = get_user_from_param(request.all_data)
    g.audit_object.log({"success": 1,
                        "user": user.login,
                        "realm": user.realm,
                        "serial": serial,
                        "token_type": ttype})
    if res[0] == "json":
        return jsonify(res[1])
    elif res[0] in ["html", "plain"]:
        return current_app.response_class(res[1], mimetype="text/{0!s}".format(res[0]))
    elif len(res) == 2:
        return current_app.response_class(json.dumps(res[1]),
                                          mimetype="application/{0!s}".format(res[0]))
    else:
        return current_app.response_class(res[1], mimetype="application/octet-binary",
                                          headers=res[2]) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:29,代码来源:ttype.py

示例8: get_actions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def get_actions():
    """
    Returns the possible actions configured on the system.
    """
    return current_app.response_class(
        json.dumps([
            action.to_dict(domain=g.domain, user=g.user) for action in actions
        ]),
        mimetype='application/json') 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:11,代码来源:api.py

示例9: jsonify

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def jsonify(obj, status=200):
    json_string = pjson.dumps(format_json(obj, camel_case=True))
    return current_app.response_class(json_string, mimetype='application/json', status=status)


# Custom AMQP json encoding
# http://stackoverflow.com/questions/21631878/celery-is-there-a-way-to-write-custom-json-encoder-decoder
# Encoder function 
开发者ID:MacroConnections,项目名称:DIVE-backend,代码行数:10,代码来源:serialization.py

示例10: result_response

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def result_response(serializer, data):
    """Construct flask response."""
    return current_app.response_class(
        response=serializer.dumps({'result': data}),
        mimetype='application/json'
    ) 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:8,代码来源:__init__.py

示例11: error_response

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def error_response(code, reason):
    """Construct error response."""
    return current_app.response_class(
        response=JsonRPCResponse().dumps({
            'error': {
                'code': code,
                'reason': reason
            }
        }),
        mimetype='application/json'
    ) 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:13,代码来源:__init__.py

示例12: client

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def client(self):
        return HookClient(current_app, current_app.response_class) 
开发者ID:getsentry,项目名称:freight,代码行数:4,代码来源:base.py

示例13: setUp

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def setUp(self):
        self.client = AuthenticatedTestClient(current_app, current_app.response_class)
        super(TestCase, self).setUp() 
开发者ID:getsentry,项目名称:freight,代码行数:5,代码来源:cases.py

示例14: _check_access

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def _check_access(self):
        from indico_storage_s3.plugin import S3StoragePlugin
        auth = request.authorization
        if not S3StoragePlugin.settings.get('bucket_info_enabled'):
            raise NotFound
        username = S3StoragePlugin.settings.get('username')
        password = S3StoragePlugin.settings.get('password')
        if not auth or not auth.password or auth.username != username or auth.password != password:
            response = current_app.response_class('Authorization required', 401,
                                                  {'WWW-Authenticate': 'Basic realm="Indico - S3 Buckets"'})
            raise Unauthorized(response=response) 
开发者ID:indico,项目名称:indico-plugins,代码行数:13,代码来源:controllers.py

示例15: json_response

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import response_class [as 别名]
def json_response(data, code):

    json_data = json.dumps(data, indent=None)
    response = current_app.response_class(json_data, mimetype='application/json; charset=UTF-8')
    response.status_code = code

    return response 
开发者ID:internap,项目名称:netman,代码行数:9,代码来源:api_utils.py


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