[mod_python] ANNOUNCE: gila, mod_python util library

Michael Owens mike at mikesclutter.com
Sun Nov 2 16:18:44 EST 2003


I have been using mod_python for over two years now, and since I first 
started, I've been adding little utility libraries here and there. I now have 
one (more or less) integrated library that supports several different things:

- PHP Style embedded python in HTML, with page caching.
    Documents with embedded python can be parsed, compiled, and cached in 
    memory that is limited by a global administrative setting on how much 
    cache mem to use. Pages are swapped out based on use. Your basic .psp 
    page looks something like this:

    #include some_header.psp
    x = 1
    print "There's no language like Python"
    <p>Shorthand printing of a variable/expression

- Shared database connections. There is a simple class which wraps the DBA API 
  connection objects for MySQL, PostgreSQL, and SAPDB. It just adds enough 
  code to transparently recover from a connection timeout.

- Session management. This includes support for
  - automatically generating session_ids for clients.
  - Authentication from a database (assigning a user_id to a session_id) and 
    maintaining it in a sessions table.
  - storing state to a database (mysql/postgresql) or to browser. State is 
    stored using a modified pickle algorithm (as pickle at the time was 
    insecure). You can basically serialize all python primitives and 
    containers (dicts, lists), and can include custom classes if you derive 
    from a simple base class.
  - Simple access/manipulation of queries, POST headers, and cookies:
    Automatically parse, read, and generate all of the above. Set/unset 
    cookies. Cookies are automatically set using the virtual host domain --- 
    you don't have to worry about which domain or vhost you are working in. 
    Pickle data stuctures into cookies using base64. Query generation from 
    dict and urlencoding.
  - Util functions: Setting page expiry's, getting client info, generating 

- Global and per virtual host configuration/resource pools. For each 
  virtual host, the core PSP handler will look for a module by that server 
  name in the Python path and import it into a virtual host namespace (if it 
  has not already been imported). This serves as a common resource pool for 
  that virtual host. When each page is processed, this pool is imported into 
  the global namespace in a dict call resource. The global resource pool is 
  first loaded on startup and vhost resources are added to it.

- HTML library. This includes support for
  - Form/widget generation. Basic HTML widgets can be created using simple 
    functions. Similar to Perl's cgi module. Generate listboxs from SQL.

- Support for OLTP gateways. There are two currently supported: SecurePay and 
  Authorize.net. This works on top of m2crypto.

There are other little bells and whistles here and there that I am sure I 
forgot about. Anyway, it has started to get too big for me to maintain on my 
own and I figure perhaps it can be helpful to others. It would be nice to 
have other good Python/mod_python programmers with more experience than me 
hacking on it.

The project is located at gila.sourceforge.net. Currently, I only have the 
code in CVS and a tarball on the home page (gila.sourceforge.net). I have 
very little documentation, but it's not hard to set up. The INSTALL should do 
it. If you have problems, email me.

Anyway, I hope some of you might find this useful.


More information about the Mod_python mailing list