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


Python request.accept_mimetypes方法代码示例

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


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

示例1: request_wants_html

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def request_wants_html(self):
        best = request.accept_mimetypes.best_match(["application/json", "text/html"])
        return (
            best == "text/html"
            and request.accept_mimetypes[best]
            > request.accept_mimetypes["application/json"]
        ) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:9,代码来源:graphqlview.py

示例2: _accepts

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def _accepts(self, mime):
        types = request.accept_mimetypes
        best = types.best_match([mime, 'text/html'])

        return best == mime and types[best] > types['text/html'] 
开发者ID:aaronbassett,项目名称:Bad-Tools,代码行数:7,代码来源:views.py

示例3: wants_json_response

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def wants_json_response():
    """Data type json response request."""
    return request.accept_mimetypes['application/json'] >= request.accept_mimetypes['text/html'] 
开发者ID:AUCR,项目名称:AUCR,代码行数:5,代码来源:handlers.py

示例4: download

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def download(package):
	release = package.getDownloadRelease()

	if release is None:
		if "application/zip" in request.accept_mimetypes and \
				not "text/html" in request.accept_mimetypes:
			return "", 204
		else:
			flash("No download available.", "danger")
			return redirect(package.getDetailsURL())
	else:
		return redirect(release.getDownloadURL(), code=302) 
开发者ID:minetest,项目名称:contentdb,代码行数:14,代码来源:packages.py

示例5: shouldReturnJson

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def shouldReturnJson():
	return "application/json" in request.accept_mimetypes and \
			not "text/html" in request.accept_mimetypes 
开发者ID:minetest,项目名称:contentdb,代码行数:5,代码来源:utils.py

示例6: render

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def render(obj, template=None):
    mimetypes = request.accept_mimetypes
    best = mimetypes.best_match(['text/html', 'application/json'], 'application/json')
    if best == 'application/json':
        json_obj = recursive_encoder(obj)
        return jsonify(json_obj)
    return render_template(template, data=obj) 
开发者ID:yeti-platform,项目名称:yeti,代码行数:9,代码来源:api.py

示例7: _rewrite_schema_if_necessary

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def _rewrite_schema_if_necessary(namespace_name, repo_name, tag_name, manifest):
    # As per the Docker protocol, if the manifest is not schema version 1 and the manifest's
    # media type is not in the Accept header, we return a schema 1 version of the manifest for
    # the amd64+linux platform, if any, or None if none.
    # See: https://docs.docker.com/registry/spec/manifest-v2-2
    mimetypes = [mimetype for mimetype, _ in request.accept_mimetypes]
    if manifest.media_type in mimetypes:
        return manifest.internal_manifest_bytes, manifest.digest, manifest.media_type

    # Short-circuit check: If the mimetypes is empty or just `application/json`, verify we have
    # a schema 1 manifest and return it.
    if not mimetypes or mimetypes == ["application/json"]:
        if manifest.media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
            return manifest.internal_manifest_bytes, manifest.digest, manifest.media_type

    logger.debug(
        "Manifest `%s` not compatible against %s; checking for conversion",
        manifest.digest,
        request.accept_mimetypes,
    )
    converted = registry_model.convert_manifest(
        manifest, namespace_name, repo_name, tag_name, mimetypes, storage
    )
    if converted is not None:
        return converted.bytes, converted.digest, converted.media_type

    # For back-compat, we always default to schema 1 if the manifest could not be converted.
    schema1 = registry_model.get_schema1_parsed_manifest(
        manifest, namespace_name, repo_name, tag_name, storage
    )
    if schema1 is None:
        return None, None, None

    return schema1.bytes, schema1.digest, schema1.media_type 
开发者ID:quay,项目名称:quay,代码行数:36,代码来源:manifest.py

示例8: _doesnt_accept_schema_v1

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def _doesnt_accept_schema_v1():
    # If the client doesn't specify anything, still give them Schema v1.
    return (
        len(request.accept_mimetypes) != 0
        and DOCKER_SCHEMA1_MANIFEST_CONTENT_TYPE not in request.accept_mimetypes
    ) 
开发者ID:quay,项目名称:quay,代码行数:8,代码来源:manifest.py

示例9: is_accept_json

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def is_accept_json(or_post=True):
    """
    用于确定是否返回 JSON 响应体
    替代 request.xhr

    :type or_post: bool, True 时 POST 请求也返回真
    :return: bool
    """
    return 'application/json' in str(request.accept_mimetypes) or \
           request.environ.get('HTTP_X_REQUESTED_WITH', '').lower() == 'xmlhttprequest' or \
           or_post and request.method == 'POST' 
开发者ID:fufuok,项目名称:FF.PyAdmin,代码行数:13,代码来源:helper.py

示例10: request_wants_json

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def request_wants_json():
    best = request.accept_mimetypes \
        .best_match(['application/json',
                     'application/json; charset=utf-8',
                     'text/html'])
    return best == 'application/json' and \
        request.accept_mimetypes[best] > \
        request.accept_mimetypes['text/html'] 
开发者ID:ibmjstart,项目名称:bluemix-python-eve-sample,代码行数:10,代码来源:home.py

示例11: get_response_mimetype

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def get_response_mimetype(self, response, accept=None, request=request):
        if accept is None:
            if request and has_request_context():
                accept = map(itemgetter(0), request.accept_mimetypes)
        return super(API, self).get_response_mimetype(response, accept) 
开发者ID:salsita,项目名称:flask-raml,代码行数:7,代码来源:flask_raml.py

示例12: wants_json_response

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def wants_json_response():
    return request.accept_mimetypes['application/json'] >= request.accept_mimetypes['text/html'] 
开发者ID:evereux,项目名称:flicket,代码行数:4,代码来源:handlers.py

示例13: request_wants_html

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import accept_mimetypes [as 别名]
def request_wants_html(self):
        best = request.accept_mimetypes \
            .best_match(['application/json', 'text/html'])
        return best == 'text/html' and \
            request.accept_mimetypes[best] > \
            request.accept_mimetypes['application/json'] 
开发者ID:graphql-python,项目名称:flask-graphql,代码行数:8,代码来源:graphqlview.py


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