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