[mod_python] Access-Handler based on a Variable

Graham Dumpleton graham.dumpleton at gmail.com
Mon Aug 6 05:20:14 EDT 2007


On 06/08/07, Christian Klinger <cklinger at novareto.de> wrote:
> Hi mod_python Users,
>
> i am new to mod_python so sorry for stupid questions.
>
>
> I try to write an access handler for an xml-rpc connection.
> The access handler should check if a key in the xml-rpc
> data is correct.
>
> Here my questions:
> Is this possible with mod_python?
> Has anyone an example?
> How can i access the (12) of getResults in the accesshandler.
>
>
> Christian
>
> Here is my code:
> --------------------------------------------------------
> <VirtualHost *:80>
>      ServerName dummy-host.example.com
>      ServerAlias www.dummy-host.example.com
>
>     <Proxy *>
>        AuthBasicAuthoritative Off
>         AddHandler mod_python .py
>         PythonHandler myscript.py
>         PythonAccessHandler myscript
>         PythonDebug On
>         PythonEnablePdb On
>       </Proxy>
>
>          RewriteEngine On
>          RewriteRule ^/(.*)
> http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/extraNet/VirtualHostRoot/$1
> [L,P]
>
> </VirtualHost>
>
>
> myscript.py
> def accesshandler(req):
>      apache.log_error("accesshandler -%s" %req)
>      if key == "OK"
>          return apache.OK
>      return
>
>
> the client:
> portal = xmlrpclib.Server('http://192.168.2.23/extraNet')
> print portal
> print portal.getResult(12)

An access handler or other handler phase prior to the actual content
handler should not as a rule be consuming the request content. If this
is done, it can cause problems when certain features of Apache are
being used.

All I can suggest is not to use an access handler, but instead use a
stacked content handler.

         PythonHandler myscript::prehandler myscript::handler

The prehandler could decode the actual XML-RPC request and check for
any required parameters it may pass. If the required parameter is
missing it should return the appropriate error status, otherwise it
would store the decoded request content as req.data and return
apache.DECLINED as the result. Provide apache.DECLINED is returned as
the result, the real handler would then still be called and it can
access the decode request from the prehandler as req.data.

Graham


More information about the Mod_python mailing list