bonzo.smtp – RequestHandler and Application classes¶
Tools for handling requests with asynchronous features.
- class bonzo.smtp.Application(handler_class, **settings)[source]¶
Bases:
objectInstances of this class are callable and can be passed directly to SMTPServer to handle messages:
async def main(): application = smtp.Application(Handler) smtp_server = server.SMTPServer(application) smtp_server.listen(2525) await asyncio.Event().wait()
- settings¶
Additional keyword arguments passed to the constructor are saved in the
settingsdictionary, and are often referred to in documentation as “application settings”. Settings are used to customize various aspects of Bonzo (although in some cases richer customization is possible by overriding methods in a subclass ofRequestHandler). Some applications also like to use thesettingsdictionary as a way to make application-specific settings available to handlers without using global variables.
- listen(port, address='', **kwargs)[source]¶
Starts an SMTP server for this handler on the given port.
This is a convenience alias for creating an
SMTPServerobject and calling its listen method. Keyword arguments not supported bySMTPServer.listenare passed to theSMTPServerconstructor. For advanced uses (e.g. multi-process mode), do not use this method; create anSMTPServerand call itsbind()/start()methods directly.Note that after calling this method you still need to run the active asyncio event loop to start the server.
- class bonzo.smtp.RequestHandler(application, request)[source]¶
Bases:
objectSubclass this class and define
data()to make a handler.- on_finish()[source]¶
Called after the end of a request.
Override this method to perform cleanup, logging, etc. This method is a counterpart to
prepare().on_finishmay not produce any output, as it is called after the response has been sent to the client.
- prepare()[source]¶
Called at the beginning of a request before
data().Override this method to perform common initialization regardless of the request method.
- property settings¶
An alias for
self.application.settings.