Re: [Tutor] psp_site mmods

Magnus Lycka magnus at
Wed Jun 23 15:31:16 EDT 2004

Might this excerpt from the mod_python docs be useful?


Here is an example of how PSP can be used as a templating mechanism: 

The template file: 

  <!-- This is a simple psp template called template.html -->
  <h1>Hello, <%=what%>!</h1>

The handler code: 

from mod_python import apache, psp

def handler(req):
    template = psp.PSP(req, filename='template.html'){'what':'world'})
    return apache.OK


By the way, as a general programming advice, I'd suggest that you
keep your swishE logic and your mod_python logic in different
modules. This will have two benefits:
 * It gets easier to replace mod_python with something else
   without touching your swishE code or vice versa.
 * It makes it easier to write/test/debug the swishE code without 
   having to think about mod_python problems and vice versa.

This means that your code might be something like this (entirely
untested and just guessing wildly):

from mod_python import apache, psp
import search

def results(req, searchWords):
    template = psp.PSP(req, filename='template.html')
    if not (searchWords):
        query = 'Nothing to search for.' 
        answer = 'Nothing Found'
        query = 'Looking for: %s' % searchWords
        answer = search.wordSearch(searchWords){'query':query, 'answer':answer})
    return apache.OK


  <!-- This is a simple psp template called template.html -->

and then in "":


def wordSearch(searchWords):
      handle ='/usr/local/swish-e/index.swish-e')
      search ='')
      results = search.execute(searchWords)
      files = [r.getproperty('swishdocpath') for r in results]
      if files:
          return "The files found are: %s" % files
          return "No files found."

Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65  mailto:magnus at

More information about the Tutor mailing list