本文整理汇总了Python中aiohttp.hdrs.METH_PUT属性的典型用法代码示例。如果您正苦于以下问题:Python hdrs.METH_PUT属性的具体用法?Python hdrs.METH_PUT怎么用?Python hdrs.METH_PUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类aiohttp.hdrs
的用法示例。
在下文中一共展示了hdrs.METH_PUT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [as 别名]
def put(path: str, **kwargs: Any) -> WebHandlerDecorator:
return handle(hdrs.METH_PUT, path, **kwargs)
示例2: add_put
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [as 别名]
def add_put(self, *args, **kwargs):
"""
Shortcut for add_route with method PUT
"""
return self.add_route(hdrs.METH_PUT, *args, **kwargs)
示例3: test_meth_any
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [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}
示例4: add_put
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [as 别名]
def add_put(
self, path: str, handler: WebHandler, **kwargs: Any
) -> web.AbstractRoute:
return self.add_route(hdrs.METH_PUT, path, handler, **kwargs)
示例5: put
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [as 别名]
def put(self, url, data=None, headers=None):
full_headers = self.__get_headers()
full_headers.update(headers)
r = await self.request(METH_PUT, url, headers=headers, data=data)
return r
示例6: test_all_methods
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [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
示例7: add_route
# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_PUT [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
)