Skip to content

Commit

Permalink
Backported MODPYTHON-137 from trunk to branches/3.2.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamd committed Apr 12, 2006
1 parent f0297f5 commit 47f1083
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Doc/appendixc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ \chapter{Changes from Version (3.2.8)\label{app-changes}}
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
Expand Down
7 changes: 7 additions & 0 deletions Doc/modpython4.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,13 @@ \subsubsection{Server Methods\label{pyapi-mpsrv-meth}}
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
Expand Down
3 changes: 3 additions & 0 deletions lib/python/mod_python/testhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def handler(req):
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')
Expand Down
16 changes: 10 additions & 6 deletions src/mod_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,9 +1633,11 @@ static const char *directive_PythonOption(cmd_parms *cmd, void * mconfig,
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
Expand All @@ -1644,9 +1646,11 @@ static const char *directive_PythonOption(cmd_parms *cmd, void * mconfig,
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;
Expand Down
16 changes: 16 additions & 0 deletions src/serverobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ static PyObject * server_get_config(serverobject *self)
return MpTable_FromTable(conf->directives);
}

/**
** 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)
**
Expand Down Expand Up @@ -120,6 +135,7 @@ static PyObject *server_register_cleanup(serverobject *self, PyObject *args)

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 */
};
Expand Down
18 changes: 18 additions & 0 deletions test/htdocs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,24 @@ def req_sendfile3(req):
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
Expand Down
25 changes: 25 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,30 @@ def test_req_sendfile3(self):
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("*",
Expand Down Expand Up @@ -2052,6 +2076,7 @@ def testPerRequestTests(self):
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"))
Expand Down

0 comments on commit 47f1083

Please sign in to comment.