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 2006/04/12 13:16:44 UTC

svn commit: r393438 - in /httpd/mod_python/branches/3.2.x: Doc/appendixc.tex Doc/modpython4.tex lib/python/mod_python/testhandler.py src/mod_python.c src/serverobject.c test/htdocs/tests.py test/test.py

Author: grahamd
Date: Wed Apr 12 04:16:42 2006
New Revision: 393438

URL: http://svn.apache.org/viewcvs?rev=393438&view=rev
Log:
Backported MODPYTHON-137 from trunk to branches/3.2.x.

Modified:
    httpd/mod_python/branches/3.2.x/Doc/appendixc.tex
    httpd/mod_python/branches/3.2.x/Doc/modpython4.tex
    httpd/mod_python/branches/3.2.x/lib/python/mod_python/testhandler.py
    httpd/mod_python/branches/3.2.x/src/mod_python.c
    httpd/mod_python/branches/3.2.x/src/serverobject.c
    httpd/mod_python/branches/3.2.x/test/htdocs/tests.py
    httpd/mod_python/branches/3.2.x/test/test.py

Modified: httpd/mod_python/branches/3.2.x/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/Doc/appendixc.tex?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/Doc/appendixc.tex (original)
+++ httpd/mod_python/branches/3.2.x/Doc/appendixc.tex Wed Apr 12 04:16:42 2006
@@ -14,6 +14,12 @@
       These communicate direct with the Apache mod_ssl module, allowing
       it to be determined if the connection is using SSL/TLS and what the
       values of internal ssl variables are.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-137]{MODPYTHON-137})
+      New \code{req.server.get_options()} method. This returns the subset
+      of Python options set at global scope within the Apache configuration.
+      That is, outside of the context of any VirtualHost, Location, Directory
+      or Files directives.
   \end{itemize}
 
   Improvements

Modified: httpd/mod_python/branches/3.2.x/Doc/modpython4.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/Doc/modpython4.tex?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/Doc/modpython4.tex (original)
+++ httpd/mod_python/branches/3.2.x/Doc/modpython4.tex Wed Apr 12 04:16:42 2006
@@ -1380,6 +1380,13 @@
   by \code{server->module_config} Apache config vector. 
 \end{methoddesc}
 
+\begin{methoddesc}[server]{get_options}{}
+  Similar to \code{req.get_options()}, but returns a table object holding
+  only the mod_python options defined at global scope within the Apache
+  configuration. That is, outside of the context of any VirtualHost, Location,
+  Directory or Files directives.
+\end{methoddesc}
+
 \begin{methoddesc}[server]{register_cleanup}{request, callable\optional{, data}}
   Registers a cleanup. Very similar to \function{req.register_cleanup()}, except
   this cleanup will be executed at child termination time. This function

Modified: httpd/mod_python/branches/3.2.x/lib/python/mod_python/testhandler.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/lib/python/mod_python/testhandler.py?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/lib/python/mod_python/testhandler.py (original)
+++ httpd/mod_python/branches/3.2.x/lib/python/mod_python/testhandler.py Wed Apr 12 04:16:42 2006
@@ -173,6 +173,9 @@
     req.write('<h3>Server configuration</h3>\n')
     write_table(req,req.server.get_config())
 
+    req.write('<h3>Server options</h3>\n')
+    write_table(req,req.server.get_options())
+
     req.write('<h3>Server configuration tree</h3>\n<pre>')
     write_tree(req,apache.config_tree(),0)
     req.write('</pre>\n')

Modified: httpd/mod_python/branches/3.2.x/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/src/mod_python.c?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/src/mod_python.c (original)
+++ httpd/mod_python/branches/3.2.x/src/mod_python.c Wed Apr 12 04:16:42 2006
@@ -1633,9 +1633,11 @@
     if(val!=NULL) {
         apr_table_set(conf->options, key, val);
 
-        conf = ap_get_module_config(cmd->server->module_config,
-                                    &python_module);
-        apr_table_set(conf->options, key, val);
+        if (!cmd->path) {
+            conf = ap_get_module_config(cmd->server->module_config,
+                                        &python_module);
+            apr_table_set(conf->options, key, val);
+        }
     }
     else {
     	/** We don't remove the value, but set it
@@ -1644,9 +1646,11 @@
     	    an entry string precisely means 'remove the value' */
         apr_table_set(conf->options, key, "");
 
-        conf = ap_get_module_config(cmd->server->module_config,
-                                    &python_module);
-        apr_table_set(conf->options, key, "");
+        if (!cmd->path) {
+            conf = ap_get_module_config(cmd->server->module_config,
+                                        &python_module);
+            apr_table_set(conf->options, key, "");
+        }
     }
 
     return NULL;

Modified: httpd/mod_python/branches/3.2.x/src/serverobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/src/serverobject.c?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/src/serverobject.c (original)
+++ httpd/mod_python/branches/3.2.x/src/serverobject.c Wed Apr 12 04:16:42 2006
@@ -67,6 +67,21 @@
 }
 
 /**
+ ** server.get_options(server self)
+ **
+ *     Returns the options set through PythonOption directives.
+ *     unlike req.get_options, this one returns the per-server config
+ */
+
+static PyObject * server_get_options(serverobject *self)
+{
+    py_config *conf =
+        (py_config *) ap_get_module_config(self->server->module_config,
+                                           &python_module);
+    return MpTable_FromTable(conf->options);
+}
+
+/**
  ** server.register_cleanup(req, handler, data)
  **
  *    same as request.register_cleanup, except the server pool is used.
@@ -120,6 +135,7 @@
 
 static PyMethodDef server_methods[] = {
     {"get_config",           (PyCFunction) server_get_config,        METH_NOARGS},
+    {"get_options",          (PyCFunction) server_get_options,       METH_NOARGS},
     {"register_cleanup",     (PyCFunction) server_register_cleanup,  METH_VARARGS},
     { NULL, NULL } /* sentinel */
 };

Modified: httpd/mod_python/branches/3.2.x/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/test/htdocs/tests.py?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/test/htdocs/tests.py (original)
+++ httpd/mod_python/branches/3.2.x/test/htdocs/tests.py Wed Apr 12 04:16:42 2006
@@ -762,6 +762,24 @@
     os.remove(fname)
     return apache.OK
 
+def req_server_get_options(req):
+
+    try:
+        server_options = req.server.get_options()
+        assert(server_options["global"] == "1")
+        assert(server_options["override"] == "1")
+
+        request_options = req.get_options()
+        assert(request_options["global"] == "1")
+        assert(request_options["override"] == "2")
+        assert(request_options["local"] == "1")
+    except:
+        req.write('test failed')
+    else:
+        req.write('test ok')
+
+    return apache.OK
+
 def fileupload(req):
     from mod_python import util
     import md5

Modified: httpd/mod_python/branches/3.2.x/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/test/test.py?rev=393438&r1=393437&r2=393438&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/test/test.py (original)
+++ httpd/mod_python/branches/3.2.x/test/test.py Wed Apr 12 04:16:42 2006
@@ -940,6 +940,30 @@
         else:
             print "\n  * Skipping req.sendfile() for a file which is a symbolic link"
 
+    def test_req_server_get_options_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_req_server_get_options"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        PythonDebug("Off"),
+                        PythonOption("global 1"),
+                        PythonOption("override 1"),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("tests::req_server_get_options"),
+                                  PythonOption("local 1"),
+                                  PythonOption("override 2"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_req_server_get_options(self):
+
+        print "\n  * Testing req.server.get_options()"
+
+        rsp = self.vhost_get("test_req_server_get_options")
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
     def test_fileupload_conf(self):
 
         c = VirtualHost("*",
@@ -2052,6 +2076,7 @@
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile2"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile3"))
+        perRequestSuite.addTest(PerRequestTestCase("test_req_server_get_options"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload_embedded_cr"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload_split_boundary"))