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 pluggable part: a library user may build a router from scratch, all other parts should work with new router seamlessly.
AbstractRouter has the only mandatory method:
AbstractRouter.resolve() coroutine. It must return an
AbstractMatchInfo instance.
If the requested URL handler is found
AbstractMatchInfo.handler() is a web-handler for
requested URL and AbstractMatchInfo.http_exception is None.
Otherwise AbstractMatchInfo.http_exception is an instance of
HTTPException like 404: NotFound or 405: Method
Not Allowed. AbstractMatchInfo.handler() raises
http_exception on call.
-
class
aiohttp.abc.AbstractRouter¶ Abstract router,
aiohttp.web.Applicationaccepts it as router parameter and returns asaiohttp.web.Application.router.-
coroutine
resolve(request)¶ 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: AbstractMatchInfoinstance.
-
coroutine
-
class
aiohttp.abc.AbstractMatchInfo¶ Abstract match info, returned by
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.AbstractView¶ 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 Cookie Jar¶
-
class
aiohttp.abc.AbstractCookieJar¶ The cookie jar instance is available as
ClientSession.cookie_jar.The jar contains
Morselitems for storing internal cookie data.API provides a count of saved cookies:
len(session.cookie_jar)
These cookies may be iterated over:
for cookie in session.cookie_jar: print(cookie.key) print(cookie["domain"])
An abstract class for cookie storage. Implements
collections.abc.Iterableandcollections.abc.Sized.Update cookies returned by server in
Set-Cookieheader.Parameters: - cookies – a
collections.abc.Mapping(e.g.dict,SimpleCookie) or iterable of pairs with cookies returned by server’s response. - response_url (str) – URL of response,
Nonefor shared cookies. Regular cookies are coupled with server’s URL and are sent only to this server, shared ones are sent in every client request.
- cookies – a
Return jar’s cookies acceptable for URL and available in
Cookieheader for sending client requests for given URL.Parameters: response_url (str) – request’s URL for which cookies are asked. Returns: http.cookies.SimpleCookiewith filtered cookies for given URL.
Abstract Abstract Access Logger¶
-
class
aiohttp.abc.AbstractAccessLogger¶ An abstract class, base for all
RequestHandleraccess_loggerimplementationsMethod
logshould be overridden.-
log(request, response, time)¶ Parameters: - request –
aiohttp.web.Requestobject. - response –
aiohttp.web.Responseobject. - time (float) – Time taken to serve the request.
- request –
-