[Zope3-dev] "Hello World" CGI surprise for zope.publisher

Phillip J. Eby pje@telecommunity.com
Mon, 14 Apr 2003 14:53:06 -0400


As a test of the usability (and self-containedness) of 'zope.publisher' for 
creating simple published applications, I wrote the following short CGI 
script.  All it does it dump a sorted list of module names from 
'sys.modules', in order to show what gets imported in order to execute the 
script.  The results were somewhat surprising.  First, here's the script:

===============================================================
#!/usr/bin/env python2.2

import sys, os

def hello():
     d={}
     for m in sys.modules.values():
         d[getattr(m,'__name__','None')] = 1
     mods = d.keys()
     mods.sort()
     return '\n'.join(mods)  #"Hello, %s!!!" % who

from zope.publisher.browser import BrowserRequest
from zope.publisher.publish import publish
from zope.publisher.base import DefaultPublication

publication = DefaultPublication(hello)
request = BrowserRequest(sys.stdin,sys.stdout,os.environ)
request.setPublication(publication)

publish(request)
===============================================================

Pop quiz: Anybody care to guess at the output of this script?  Or more 
simply, anybody care to guess at how many *digits* there are in the number 
of *lines* this script outputs?  How many modules would you expect to come 
from the 'zope' package alone?  Are you as surprised as I was?