PyRaven

A Raven Web Application Agent API for Python

You can download the source, or check out the darcs repository.

Questions to Tom.

To install the Python libraries, use distutils, as described at http://www.python.org/doc/current/inst/inst.html.

Here is a sample CGI script using the API:

#!/usr/bin/python

import sys
sys.path.append("/home/tom/Build/Python/Raven/src/")

import cgitb; cgitb.enable()

import metapaw.Raven.Handlers.CGI
import metapaw.Raven as Raven

UCam = Raven.Service('https://raven.cam.ac.uk/auth/authenticate.html',
                    {'2': '/home/tom/Incoming/Raven_test/Raven_keys/pubkey2'} )

def printBody(body):
        print 'Content-Type: text/html'
        print
        print '<html><head><title>Raven Test</title></head><body>'
        print body
        print '<p><a href="?">Try Again</a></p></body></html>'

try:
        cred = Raven.authenticate(UCam,
                                  thisURL = 'http://localhost:8000/cgi-bin/Raven_test.cgi',
                                  message = 'I do not know who you are',
                                  targetDescription = "Tom's pyraven test",
                                  pageParameters = 'These are my parameters: !"#$%^&*()',
                                  # Default values
                                  #reauthenticate = Raven.DontCare,
                                  #maximumClockSkew = 300,
                                  #ravenHandlesErrors = False
                                  # Default is to accept any method
                                  #allowedMethods = ('pwd', 'card'),
                                 )

except Exception, e:
        printBody("<p>Something went wrong: %s</p>" % repr(e)[1:-1])
        raise
else:
        printBody("<h1>This is my first Raven test</h1>" +
                  "<p>You are logged in as <span style='font-weight: bold'>%s</span>.</p>" % cred.principal +
                  "<p>The message from Raven was '%s'.</p>" % cred.message +
                  "<p>The page parameters were '%s'.</p>" % cred.pageParameters)