[Twisted-web] Turkey Questions 1-5

Jp Calderone exarkun at divmod.com
Thu Jul 7 19:00:54 MDT 2005

On Thu, 7 Jul 2005 16:03:31 -0400 (EDT), lloyd at paisite.com wrote:
>I've changed the thread from "Re: Introduction, newbie confusion plus an
>offer" to "Turkey Questions 1-5" to start the Q&A.
>Goal: Create the world's simplest web-server
>My first set of questions are based on "Configuring and Using the
>Twisted.Web Server in "Twisted.Web Documentation."
> [snip]
>1) Why did mktap write web.tap to my home directory rather than

You didn't specify a path to a tap file to write, so it picked a reasonable-seeming default.  The surprisingly named --append option lets you specify the name of the tap to write (as well as letting you add a new application to an existing tap).  For example,

  mktap --append ~/twisted/www/web.tap web ...

> [snip]
>3) How can I see the source for the server created by mktap?

  TAP stands for Twisted Application Pickle.  Its contents are a Python pickle of a Twisted Application instance (twisted.application.service.Application) configured to do whatever you specified on the mktap command line.

  You can inspect it using pickle interactively:

    exarkun at boson:~$ python
    Python 2.4.1 (#2, Mar 30 2005, 21:51:10) 
    [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pickle
    >>> app = pickle.load(file('web.tap', 'rb'))
    >>> print app
    <twisted.python.components.Componentized instance at 0xb7e05b8c>
    >>> from twisted.application import service
    >>> svc = service.IService(app)
    >>> print svc
    <twisted.application.service.MultiService instance at 0xb7e11d0c>
    >>> list(svc)
    [<twisted.application.service.MultiService instance at 0xb7ae126c>]
    >>> list(svc)[0]
    <twisted.application.service.MultiService instance at 0xb7ae126c>
    >>> list(list(svc)[0])
    [<twisted.application.internet.TCPServer instance at 0xb7a54d8c>]
    >>> list(list(svc)[0])[0].args
    (8080, <twisted.web.server.Site instance at 0xb7a5a66c>)

  There are some other formats mktap can write, but they are generally more fragile than pickle.  If you want to explore, try the `--type' argument to mktap (eg, mktap --type source web).

The key here is that mktap outputs configuration, not code.  Of course, if you asked "How can I view the configuration for the server generated by mktap?" I wouldn't have a better answer for you ;)


More information about the Twisted-web mailing list