O'Reilly logo

Mastering Object-oriented Python by Steven Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required