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


Python request.mimetype方法代码示例

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


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

示例1: parse_body

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def parse_body(self):
        # We use mimetype here since we don't need the other
        # information provided by content_type
        content_type = request.mimetype
        if content_type == "application/graphql":
            return {"query": request.data.decode("utf8")}

        elif content_type == "application/json":
            return load_json_body(request.data.decode("utf8"))

        elif content_type in (
            "application/x-www-form-urlencoded",
            "multipart/form-data",
        ):
            return request.form

        return {} 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:19,代码来源:graphqlview.py

示例2: get_data

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def get_data(self):
        """
        Get request data based on request.method and request.mimetype

        Returns:
            A regular dict which can be modified(scheme will modify data
            on validating)
        """
        if request.method in ['GET', 'DELETE']:
            return request.args.to_dict()
        else:
            if request.mimetype == 'application/json':
                data = request.get_json()
                if not isinstance(data, collections.Mapping):
                    self.handle_error('JSON content must be object')
                return data
            else:
                return request.form.to_dict() 
开发者ID:NetEaseGame,项目名称:git-webhook,代码行数:20,代码来源:validator.py

示例3: parse_body

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def parse_body(self):
        """Handle multipart request spec for multipart/form-data"""
        content_type = request.mimetype
        if content_type == 'multipart/form-data':
            operations = load_json_body(request.form.get('operations', '{}'))
            files_map = load_json_body(request.form.get('map', '{}'))
            return place_files_in_operations(
                operations,
                files_map,
                request.files
            )
        return super(FileUploadGraphQLView, self).parse_body() 
开发者ID:lmcgartland,项目名称:graphene-file-upload,代码行数:14,代码来源:__init__.py

示例4: parse_command_args

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def parse_command_args(response: 'Response') -> typing.Tuple[str, str]:
    """

    :param response:
        The response object to modify with status or error data
    :return:
        A tuple where the first element if the name of the command
        to execute, and the second is a string representing the arguments
        to apply to that command.
    """

    cmd = None
    parts = None
    name = None
    args = None
    request_args = arguments.from_request()

    try:
        cmd = request_args.get('command', '')
        parts = [x.strip() for x in cmd.split(' ', 1)]
        name = parts[0].lower()

        args = request_args.get('args', '')
        if not isinstance(args, str):
            args = ' '.join(args)
        args += ' {}'.format(parts[1] if len(parts) > 1 else '').strip()
    except Exception as err:
        response.fail(
            code='INVALID_COMMAND',
            message='Unable to parse command',
            cmd=cmd if cmd else '',
            parts=parts,
            name=name,
            args=args,
            error=err,
            mime_type='{}'.format(request.mimetype),
            request_data='{}'.format(request.data),
            request_args=request_args
        )

    return name, args 
开发者ID:sernst,项目名称:cauldron,代码行数:43,代码来源:execution.py

示例5: parse_body

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def parse_body(self):
        # We use mimetype here since we don't need the other
        # information provided by content_type
        content_type = request.mimetype
        if content_type == 'application/graphql':
            return {'query': request.data.decode('utf8')}

        elif content_type == 'application/json':
            return load_json_body(request.data.decode('utf8'))

        elif content_type in ('application/x-www-form-urlencoded', 'multipart/form-data'):
            return request.form

        return {} 
开发者ID:graphql-python,项目名称:flask-graphql,代码行数:16,代码来源:graphqlview.py

示例6: apimethod

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def apimethod(return_type, *arg_types, **options):
    def wrap(wrapped):
        # adapted from wsmeext.flask (MIT-licensed)
        wsme.signature(return_type, *arg_types, **options)(wrapped)
        funcdef = wsme.api.FunctionDefinition.get(wrapped)
        funcdef.resolve_types(wsme.types.registry)

        @functools.wraps(wrapped)
        def replacement(*args, **kwargs):
            data_only = kwargs.pop('_data_only_', False)
            if data_only:
                return wrapped(*args, **kwargs)

            try:
                args, kwargs = wsme.rest.args.get_args(
                    funcdef, args, kwargs,
                    request.args, request.form,
                    request.data, request.mimetype)
            except wsme.exc.ClientSideError as e:
                raise BadRequest(e.faultstring)
            result = wrapped(*args, **kwargs)
            # if this is a Response (e.g., a redirect), just return it
            if isinstance(result, werkzeug.Response):
                return result

            # parse the result, if it was a tuple
            code = 200
            headers = {}
            if isinstance(result, tuple):
                if len(result) == 2:
                    if isinstance(result[1], dict):
                        result, headers = result
                    else:
                        result, code = result
                else:
                    result, code, headers = result
                assert 200 <= code < 299

            # convert the objects into jsonable simple types, also checking
            # the type at the same time
            result = wsme.rest.json.tojson(funcdef.return_type, result)

            # and hand to render_response, which will actually
            # generate the appropriate string form
            h = _get_handler()
            return h.render_response(result, code, headers)
        replacement.__apidoc__ = wrapped.__doc__
        return replacement
    return wrap 
开发者ID:mozilla,项目名称:build-relengapi,代码行数:51,代码来源:api.py

示例7: __call__

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import mimetype [as 别名]
def __call__(self):
        """Handles OAuth2 authentication"""

        # get grant_type
        if request.is_json:
            grant_type = request.json.get("grant_type")
        elif request.mimetype == "application/x-www-form-urlencoded":
            grant_type = request.form.get("grant_type")
        else:
            grant_type = request.headers.get("grant_type")

        if grant_type == "password":
            # password grant
            if request.is_json:
                username = request.json.get("username")
                password = request.json.get("password")
            elif request.mimetype == "application/x-www-form-urlencoded":
                username = request.form.get("username")
                password = request.form.get("password")
            else:
                username = request.headers.get("username")
                password = request.headers.get("password")

            if username is None:
                raise InvalidRequest('Request was missing the "username" parameter.')
            if password is None:
                raise InvalidRequest('Request was missing the "password" parameter.')

            return self.password_grant(username, password)

        if grant_type == "refresh_token":
            # refresh token grant
            if request.is_json:
                refresh_token = request.json.get("refresh_token")
            elif request.mimetype == "application/x-www-form-urlencoded":
                refresh_token = request.form.get("refresh_token")
            else:
                refresh_token = request.headers.get("refresh_token")

            if refresh_token is None:
                raise InvalidRequest(
                    'Request was missing the "refresh_token" parameter.'
                )

            try:
                refresh_token = UUID(refresh_token)
            except ValueError:
                raise InvalidGrant("Refresh token is invalid.")

            return self.refresh_token_grant(refresh_token)
        # unknown grant
        raise UnsupportedGrantType(
            "{} is not a supported grant type.".format(grant_type)
        ) 
开发者ID:openzim,项目名称:zimfarm,代码行数:56,代码来源:oauth2.py


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