[mod_python] ANN: Vampire 1.4 is now available.

Graham Dumpleton grahamd at dscpl.com.au
Sun Jan 23 00:40:10 EST 2005


Vampire 1.4 is now available.

   http://www.dscpl.com.au/projects/vampire

   http://www.dscpl.com.au/downloads/vampire-1.4-20050123.tar.gz

See the web site for information on what Vampire is all about.

For those who have been tracking Vampire already, the main new things of
interest in this release are:

   - Vampire can now be used to intercept handlers other than that for 
the
     PythonHandler directive and it will be directed to a specific module
     indicated within the handlers section of the Vampire config file. 
Thus,
     if in your ".htaccess" file you might have:

       PythonAccessHandler vampire

     In your ".vampire" config file you might then have:

       [Handlers]

       accesshandler = %(__config_root__)s/modules/access-handler.py

     The handler function in the specified file must be the default for 
the
     particular directive, it cannot be modified like it can using "::" 
in
     the ".htaccess" file.

   - Special conventions can now be used in form arguments to denote data
     which should be translated to dictionaries and list. Specifically:

       Keys (variable names) can have subkeys, with a ``.`` and can be
       numbered with ``-``, like ``a.b-3=something`` means that the value
       ``a`` is a dictionary with a key ``b``, and ``b`` is a list, the
       third(-ish) element with the value ``something``. Numbers are used
       to sort, missing numbers are ignored.

     The code to achieve this bit of magic courtesy of some code from the
     FormEncode/Validator package made available by Ian Bicking.

   - The XmlRpcHandler class has been discarded completely. Instead, a 
much
     more low level request handler is provided whose job is only to 
parse
     the inbound request and then format the response. The actual 
execution
     of the request is passed off to a supplied callback. This callback
     must work out how to then map the request to a specific method.

     This means that in the first instance the support for XML-RPC 
requests
     is not as useful and more work is required to use it, but it opens
     things up so that more powerful things can be done. For example, a
     means of optionally having the request object also passed through to
     methods could also be implemented. For example:

       import vampire
       import types

       config = vampire.loadConfig(__req__,".vampire")
       modules = config.get("Modules","common")
       module = vampire.importModule("python-utils",modules)

       def handler(req):

         def _callback(req,name,params):
           if name[0:1] != "_":
             if module.__dict__.has_key(name):
               method = module.__dict__[name]
               if type(method) == types.FunctionType:
                 if len(method.func_code.co_varnames) != 0:
                   if method.func_code.co_varnames[0] == "req":
                     params = list(params)
                     params.insert(0,req)
                 return method(*params)
           raise Exception("Method Unavailable")

         return vampire.serviceRequest(req,_callback)

   - A cut down "req" object is now available when the Python code file
     for a handler is being imported. This will be stored in the module 
as
     "__req__". Once importing of the module has been completed it will 
be
     deleted out of the module. The cut down "req" object allows access 
to
     PythonOption variables using get_options(), other mod_python 
settings
     using get_config(), as well as attributes such as "interpreter" etc.
     The "uri" and "filename" are also supplied such that the cut down 
"req"
     object can be used on configuration file lookup during module
     importing. This is shown in practice in XML-RPC example above.

Enjoy.


--
Graham Dumpleton (grahamd at dscpl.com.au)



More information about the Mod_python mailing list