Using Callable classes for WSGI applications
We can implement WSGI applications as Callable
objects instead of standalone functions. This allows us to have stateful processing in our WSGI server without the potential confusion of global variables. In our previous example, the get_spin()
WSGI application relied on two global variables, american
and european
. The binding between the application and global can be mysterious.
The point of defining a class is to encapsulate the processing and data into a single package. We can use Callable
objects to encapsulate our applications in a better manner. This can make the binding between stateful Wheel
and WSGI applications clearer. Here is an extension to the Wheel
class that makes it into a callable WSGI ...
Get Mastering Object-oriented Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.