You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2003/05/22 20:36:21 UTC

cvs commit: httpd-python/lib/python/mod_python publisher.py

grisha      2003/05/22 11:36:21

  Modified:    Doc      modpython6.tex
               lib/python/mod_python publisher.py
  Log:
  This patch will allow for easy set up of http://www.yoursite.com/ being
  handled entirely by mod_python. (In the previous ver you had to provide
  at least a module - http://www.yoursite.com/module).
  
  Revision  Changes    Path
  1.12      +39 -1     httpd-python/Doc/modpython6.tex
  
  Index: modpython6.tex
  ===================================================================
  RCS file: /home/cvs/httpd-python/Doc/modpython6.tex,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- modpython6.tex	11 Nov 2002 20:35:07 -0000	1.11
  +++ modpython6.tex	22 May 2003 18:36:21 -0000	1.12
  @@ -56,7 +56,10 @@
   to Python object within the module.
   
   If no path_info was given in the URL, the Publisher handler will use
  -the default value of "index".
  +the default value of "index". If the last element is an object inside
  +a module, and the one immediately preceeding it is a directory
  +(i.e. no module name is given), then the module name will also default
  +to "index".
   
   The traversal will stop and \constant{HTTP_NOTFOUND} will be returned to
   the client if:
  @@ -76,6 +79,41 @@
   
   If an object in the path could not be found, \constant{HTTP_NOT_FOUND}
   is returned to the client.
  +
  +For eaxmple, given the following configuration:
  +
  +\begin{verbatim}
  +DocumentRoot /some/dir
  +
  +<Directory /some/dir>
  +    SetHandler python-program
  +    PythonHandler mod_python.publisher
  +</Directory>
  +\end{verbatim}
  +
  +And the following \file{/some/dir/index.py} file:
  +
  +\begin{verbatim}
  +def index(req):
  +
  +    return "We are in index()"
  +
  +def hello(req):
  +
  +    return "We are in hello()"
  +\end{verbatim}
  +
  +Then:
  +
  +http://www.somehost/index/index will return "We are in index()"
  +
  +http://www.somehost/index/ will return "We are in index()"
  +
  +http://www.somehost/index/hello will return "We are in hello()"
  +
  +http://www.somehost/hello will return "We are in hello()"
  +
  +http://www.somehost/spam will return "404 Not Found"
   
   \subsubsection{Argument Matching and Invocation\label{hand-pub-alg-args}}
   
  
  
  
  1.28      +10 -3     httpd-python/lib/python/mod_python/publisher.py
  
  Index: publisher.py
  ===================================================================
  RCS file: /home/cvs/httpd-python/lib/python/mod_python/publisher.py,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- publisher.py	28 Dec 2002 03:43:40 -0000	1.27
  +++ publisher.py	22 May 2003 18:36:21 -0000	1.28
  @@ -150,8 +150,15 @@
       # import module (or reload if needed)
       # the [path] argument tells import_module not to allow modules whose
       # full path is not in [path] or below.
  -    module = apache.import_module(module_name, req.get_config(), [path])
  -
  +    try:
  +        module = apache.import_module(module_name, req.get_config(), [path])
  +    except ImportError:
  +        # try again, using default module, perhaps this is a
  +        # /directory/function (as opposed to /directory/module/function)
  +        func_path = module_name
  +        module_name = "index"
  +        module = apache.import_module(module_name, req.get_config(), [path])
  +        
       # does it have an __auth__?
       realm, user, passwd = process_auth(req, module)