Apache/mod_python: Registering a request handler dynamically

Discussion in 'Python' started by Samuel, Dec 28, 2008.

  1. Samuel

    Samuel Guest

    Hi,

    Is there a way to dynamically overwrite the request handler from within
    mod_python scripts? Something along those lines:

    ---------------
    from mod_python import apache

    def myhandler(request):
    request.content_type = 'text/plain'
    request.write('Hello world')

    apache.set_default_handler(myhandler)
    ---------------

    I specifically want to avoid changing the Apache directive, as this code
    is supposed to function in a place where the user has no permission to
    override the Apache directive.

    The reason is that I am trying to hide the difference between different
    environments (such as mod_python or CGI) from the developer, such that
    the following is possible:

    ---------------
    #!/usr/bin/python
    import os, os.path
    os.chdir(os.path.dirname(__file__))
    from PleaseHideMyEnvironment import RequestHandler

    def index(request):
    request.write('Hello World')

    RequestHandler(index)
    ---------------

    So at the time at which RequestHandler() is created, I need a way to make
    sure that mod_python calls to the RequestHandler instead of the normal
    handler, whenever a new request is made.

    Any idea?

    -Samuel
    Samuel, Dec 28, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juan T. Llibre
    Replies:
    2
    Views:
    3,854
    =?Utf-8?B?UmljaA==?=
    Dec 16, 2006
  2. Chris Jewell
    Replies:
    7
    Views:
    363
    Noah Roberts
    Jul 21, 2006
  3. Replies:
    0
    Views:
    338
  4. joe jacob
    Replies:
    3
    Views:
    686
    joe jacob
    Aug 14, 2007
  5. Andrew Ip
    Replies:
    4
    Views:
    103
Loading...

Share This Page