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/03/05 02:15:02 UTC
svn commit: r383262 - in /httpd/mod_python/trunk: 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: Sat Mar 4 17:15:01 2006
New Revision: 383262
URL: http://svn.apache.org/viewcvs?rev=383262&view=rev
Log:
Added new req.server.get_options() method. (MODPYTHON-137)
Modified:
httpd/mod_python/trunk/Doc/appendixc.tex
httpd/mod_python/trunk/Doc/modpython4.tex
httpd/mod_python/trunk/lib/python/mod_python/testhandler.py
httpd/mod_python/trunk/src/mod_python.c
httpd/mod_python/trunk/src/serverobject.c
httpd/mod_python/trunk/test/htdocs/tests.py
httpd/mod_python/trunk/test/test.py
Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sat Mar 4 17:15:01 2006
@@ -28,6 +28,12 @@
\code{req.register_output_fiter()}, \code{req.register_input_filter()}
methods. These allows the dynamic registration of filters and the
attaching of filters to the current request.
+ \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/trunk/Doc/modpython4.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/modpython4.tex?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/modpython4.tex (original)
+++ httpd/mod_python/trunk/Doc/modpython4.tex Sat Mar 4 17:15:01 2006
@@ -1474,6 +1474,13 @@
Location, Directory or Files directives.
\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/trunk/lib/python/mod_python/testhandler.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/testhandler.py?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/testhandler.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/testhandler.py Sat Mar 4 17:15:01 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/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sat Mar 4 17:15:01 2006
@@ -1638,9 +1638,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
@@ -1649,9 +1651,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/trunk/src/serverobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/serverobject.c?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/serverobject.c (original)
+++ httpd/mod_python/trunk/src/serverobject.c Sat Mar 4 17:15:01 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/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Sat Mar 4 17:15:01 2006
@@ -787,6 +787,24 @@
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/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=383262&r1=383261&r2=383262&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Sat Mar 4 17:15:01 2006
@@ -1028,6 +1028,30 @@
if (rsp != "test ok"):
self.fail(`rsp`)
+ 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("*",
@@ -2170,6 +2194,7 @@
perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile3"))
perRequestSuite.addTest(PerRequestTestCase("test_req_handler"))
perRequestSuite.addTest(PerRequestTestCase("test_req_server_get_config"))
+ 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"))