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


Python hdrs.METH_POST属性代码示例

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


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

示例1: post

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def post(path: str, **kwargs: Any) -> WebHandlerDecorator:
    return handle(hdrs.METH_POST, path, **kwargs) 
开发者ID:maubot,项目名称:maubot,代码行数:4,代码来源:web.py

示例2: process

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def process(self):
        request = self.request

        if request.method not in (hdrs.METH_GET, hdrs.METH_POST, hdrs.METH_OPTIONS):
            return web.HTTPForbidden(text="Method is not allowed")

        if self.request.method == hdrs.METH_OPTIONS:
            headers = (
                (hdrs.ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, POST"),
                (hdrs.CONTENT_TYPE, "application/javascript; charset=UTF-8"),
            )
            headers += session_cookie(request)
            headers += cors_headers(request.headers)
            headers += cache_headers()
            return web.Response(status=204, headers=headers)

        data = await request.read()
        if not data:
            return web.HTTPInternalServerError(text="Payload expected.")

        try:
            messages = loads(data.decode(ENCODING))
        except Exception:
            return web.HTTPInternalServerError(text="Broken JSON encoding.")

        await self.session._remote_messages(messages)

        headers = (
            (hdrs.CONTENT_TYPE, "text/plain; charset=UTF-8"),
            (hdrs.CACHE_CONTROL, CACHE_CONTROL),
        )
        headers += session_cookie(request)
        headers += cors_headers(request.headers)

        return web.Response(status=204, headers=headers) 
开发者ID:aio-libs,项目名称:sockjs,代码行数:37,代码来源:xhrsend.py

示例3: add_post

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def add_post(self, *args, **kwargs):
        """
        Shortcut for add_route with method POST
        """
        return self.add_route(hdrs.METH_POST, *args, **kwargs) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:7,代码来源:compat.py

示例4: test_meth_any

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def test_meth_any(swagger_docs, aiohttp_client):
    async def handler(request, param_id: int):
        """
        ---
        parameters:

          - name: param_id
            in: path
            required: true
            schema:
              type: integer

        responses:
          '200':
            description: OK.

        """
        return web.json_response({"param_id": param_id})

    swagger = swagger_docs()
    swagger.add_route("*", "/r/{param_id}", handler)

    client = await aiohttp_client(swagger._app)

    for method in (
        hdrs.METH_GET,
        hdrs.METH_POST,
        hdrs.METH_PUT,
        hdrs.METH_PATCH,
        hdrs.METH_DELETE,
    ):
        resp = await getattr(client, method.lower())("/r/10")
        assert resp.status == 200
        assert await resp.json() == {"param_id": 10} 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:36,代码来源:test_methods.py

示例5: add_post

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def add_post(
        self, path: str, handler: WebHandler, **kwargs: Any
    ) -> web.AbstractRoute:
        return self.add_route(hdrs.METH_POST, path, handler, **kwargs) 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:6,代码来源:swagger.py

示例6: post

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def post(self, url, data=None, use_json: bool = True):
        if use_json and data is not None:
            data = json.dumps(data)
        r = await self.request(METH_POST, url, headers=self.__get_headers(), data=data)
        return r 
开发者ID:arjenvrh,项目名称:audi_connect_ha,代码行数:7,代码来源:audi_api.py

示例7: _aiohttp_do_redirect

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def _aiohttp_do_redirect(session, method, url, headers, data, resp):
    # This is the redirect code from aiohttp, remove once
    # https://github.com/aio-libs/aiobotocore/issues/267 is supported

    # For 301 and 302, mimic IE, now changed in RFC
    # https://github.com/kennethreitz/requests/pull/269

    if (resp.status == 303 and
            resp.method != hdrs.METH_HEAD) \
            or (resp.status in (301, 302) and
                resp.method == hdrs.METH_POST):
        method = hdrs.METH_GET
        data = None
        if headers.get(hdrs.CONTENT_LENGTH):
            headers.pop(hdrs.CONTENT_LENGTH)

    r_url = (resp.headers.get(hdrs.LOCATION) or
             resp.headers.get(hdrs.URI))
    if r_url is None:
        return None

    r_url = URL(
        r_url, encoded=not session.requote_redirect_url)

    scheme = r_url.scheme
    if scheme not in ('http', 'https', ''):
        resp.close()
        raise ValueError(
            'Can redirect only to http or https')
    elif not scheme:
        r_url = url.join(r_url)

    url = r_url
    params = None
    resp.release()

    return method, url, headers, params, data 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:39,代码来源:endpoint.py

示例8: messages

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def messages(request):
    if request.method == METH_POST:
        # the 302 redirect is processed as an exception, so if this coroutine returns there's a form error
        form_errors = await process_form(request)
    else:
        form_errors = None

    # simple demonstration of sessions by pre-populating username if it's already been set
    session = await get_session(request)
    username = session.get('username', '')

    return {'title': 'Message board', 'form_errors': form_errors, 'username': username} 
开发者ID:aio-libs,项目名称:aiohttp-devtools,代码行数:14,代码来源:views.py

示例9: post

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def post(self, url, rel=None, **data):
        """Perform a post query to the online service."""
        if data:
            return await self._request(METH_POST, self._make_url(url, rel), json=data)
        else:
            return await self._request(METH_POST, self._make_url(url, rel)) 
开发者ID:robinostlund,项目名称:volkswagencarnet,代码行数:8,代码来源:volkswagencarnet.py

示例10: test_all_methods

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def test_all_methods(swagger_docs, aiohttp_client):
    class View(web.View):
        async def get(self):
            """
            ---

            responses:
              '200':
                description: OK.

            """
            return web.json_response()

    async def handler(request):
        """
        ---

        responses:
          '200':
            description: OK.

        """
        return web.json_response()

    swagger = swagger_docs()
    swagger.add_get("/r", handler, allow_head=False),
    swagger.add_head("/r", handler),
    swagger.add_put("/r", handler),
    swagger.add_patch("/r", handler),
    swagger.add_post("/r", handler),
    swagger.add_delete("/r", handler),
    swagger.add_options("/r", handler),
    swagger.add_view("/r2", View),

    client = await aiohttp_client(swagger._app)

    for method in (
        hdrs.METH_GET,
        hdrs.METH_HEAD,
        hdrs.METH_POST,
        hdrs.METH_PUT,
        hdrs.METH_PATCH,
        hdrs.METH_DELETE,
        hdrs.METH_OPTIONS,
    ):
        resp = await getattr(client, method.lower())("/r")
        assert resp.status == 200

    resp = await client.get("/r2")
    assert resp.status == 200 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:52,代码来源:test_methods.py

示例11: add_route

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_POST [as 别名]
def add_route(
        self,
        method: str,
        path: str,
        handler: Union[_SwaggerHandler, Type[AbstractView]],
        *,
        name: Optional[str] = None,
        expect_handler: Optional[ExpectHandler] = None,
        validate: Optional[bool] = None,
    ) -> web.AbstractRoute:
        if validate is None:
            need_validation: bool = self.validate
        else:
            need_validation = False if not self.validate else validate
        if isinstance(handler, type) and issubclass(handler, AbstractView):
            for meth in hdrs.METH_ALL:
                meth = meth.lower()
                handler_ = getattr(handler, meth, None)
                if handler_ is not None:
                    setattr(
                        handler,
                        meth,
                        self._wrap_handler(
                            meth,
                            path,
                            handler_,
                            is_method=True,
                            validate=need_validation,
                        ),
                    )
        else:
            if method == hdrs.METH_ANY:
                for meth in (
                    hdrs.METH_GET,
                    hdrs.METH_POST,
                    hdrs.METH_PUT,
                    hdrs.METH_PATCH,
                    hdrs.METH_DELETE,
                ):
                    meth = meth.lower()
                    handler = self._wrap_handler(
                        meth, path, handler, is_method=False, validate=need_validation,
                    )
            else:
                handler = self._wrap_handler(
                    method.lower(),
                    path,
                    handler,
                    is_method=False,
                    validate=need_validation,
                )

        return self._app.router.add_route(
            method, path, handler, name=name, expect_handler=expect_handler
        ) 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:57,代码来源:swagger_docs.py


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