Creating a server
Let's create our toupper.py
server with the following content:
#!/usr/bin/env python3 import sys import tuxedo as t class Server: def TOUPPER(self, req): return t.tpreturn(t.TPSUCCESS, 0, req.upper()) t.run(Server(), sys.argv)
The implementation of the Tuxedo server in Python starts with a shebang line telling you to use the Python 3 interpreter to run the file. And while we're at it, the file must be executable:
chmod +x toupper.py
We import the sys
module to access command-line options and the tuxedo
module for using Tuxedo. For the book, we will use a shorter single-letter name, t
, for the tuxedo
module so that the code fits on one page without breaking the lines, but you should not sacrifice readability in your production code.
Tuxedo servers must be implemented as a class and the method name must match the desired service name. In this case, the service will be called...