Abstract Base Classes¶
Abstract routing¶
aiohttp has abstract classes for managing web interfaces.
The most part of aiohttp.web is not intended to be inherited
but few of them are.
aiohttp.web is built on top of few concepts: application, router, request and response.
router is a plugable part: a library user may build a router from scratch, all other parts should work with new router seamlessly.
aiohttp.abc.AbstractRouter has the only mandatory method:
aiohttp.abc.AbstractRouter.resolve() coroutine. It must return an
aiohttp.abc.AbstractMatchInfo instance.
If the requested URL handler is found
aiohttp.abc.AbstractMatchInfo.handler() is a web-handler for
requested URL and aiohttp.abc.AbstractMatchInfo.http_exception is None.
Otherwise aiohttp.abc.AbstractMatchInfo.http_exception is an instance of
HTTPException like 404: NotFound or 405: Method
Not Allowed. aiohttp.abc.AbstractMatchInfo.handler() raises
http_exception on call.
- class aiohttp.abc.AbstractRouter[source]¶
Abstract router,
aiohttp.web.Applicationaccepts it as router parameter and returns asaiohttp.web.Application.router.- coroutine resolve(request)[source]¶
Performs URL resolving. It’s an abstract method, should be overridden in router implementation.
- Parameters:
request –
aiohttp.web.Requestinstance for resolving, the request hasaiohttp.web.Request.match_infoequals toNoneat resolving stage.- Returns:
aiohttp.abc.AbstractMatchInfoinstance.
- class aiohttp.abc.AbstractMatchInfo[source]¶
Abstract match info, returned by
aiohttp.abc.AbstractRouter.resolve()call.- http_exception¶
aiohttp.web.HTTPExceptionif no match was found,Noneotherwise.
- coroutine handler(request)¶
Abstract method performing web-handler processing.
- Parameters:
request –
aiohttp.web.Requestinstance for resolving, the request hasaiohttp.web.Request.match_infoequals toNoneat resolving stage.- Returns:
aiohttp.web.StreamResponseor descendants.- Raise:
aiohttp.web.HTTPExceptionon error
- coroutine expect_handler(request)¶
Abstract method for handling 100-continue processing.
Abstract Class Based Views¶
For class based view support aiohttp has abstract
AbstractView class which is awaitable (may be uses like
await Cls() or yield from Cls() and has a request as an
attribute.
- class aiohttp.abc.AbstractView[source]¶
An abstract class, base for all class based views implementations.
Methods
__iter__and__await__should be overridden.- request¶
aiohttp.web.Requestinstance for performing the request.
Abstract Access Logger¶
- class aiohttp.abc.AbstractAccessLogger[source]¶
An abstract class, base for all
aiohttp.web.RequestHandleraccess_loggerimplementationsMethod
logshould be overridden.- log(request, response, time)[source]¶
- Parameters:
request –
aiohttp.web.Requestobject.response –
aiohttp.web.Responseobject.time (float) – Time taken to serve the request.