[mod_python] [Fwd: Defining classes using mod_python]

Matt H matt at proweb.co.uk
Fri Mar 8 11:06:10 EST 2002


On Fri, 08 Mar 2002 11:19:10 +0000
"Luis Sousa" <llsousa at ualg.pt> wrote:

> What do you use then ??

something like this :
--- httpd.conf ----------
<Directory /www/python>
  AddHandler python-program .py
  PythonHandler contentAdmin
  PythonDebug On
</Directory>
-------------------------



------- contentAdmin.py -

from mod_python import apache
from mod_python import util

def handler(request):
        global req
        req = request
        req.content_type = "text/html"
        req.send_http_header()

        req.write(getTheHTML())
	

        return apache.OK

-------------------------

I also use this inside a <VirtualHost
---------httpd.conf----------------
	<Location /profile>
                AddHandler python-program .py
                PythonAuthenHandler authHandler
                PythonDebug On
	</Location>
----------

(Directory is a class of my own)

---- authHandler.py --
import Directory
import md5

from mod_python import apache
from mod_python import util


def authenhandler(req):
        pwd = req.get_basic_auth_pw()
        usr = req.connection.user
        if pwd and usr :
                d = Directory.Directory("/www/Users/" + usr)
                mdu = d.getLines('md5')
                if mdu[0][:-1] == md5.new(pwd).hexdigest() :
                         return apache.OK
                else :
                         return apache.HTTP_UNAUTHORIZED
        return apache.HTTP_UNAUTHORIZED


-------------------------



More information about the Mod_python mailing list