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 nl...@apache.org on 2005/11/12 19:11:22 UTC

svn commit: r332807 - in /httpd/mod_python/trunk: lib/python/mod_python/apache.py src/_apachemodule.c test/htdocs/tests.py test/test.py

Author: nlehuen
Date: Sat Nov 12 10:11:14 2005
New Revision: 332807

URL: http://svn.apache.org/viewcvs?rev=332807&view=rev
Log:
This should resolve MODPYTHON-89 : add new apache.exists_config_define() function.

Modified:
    httpd/mod_python/trunk/lib/python/mod_python/apache.py
    httpd/mod_python/trunk/src/_apachemodule.c
    httpd/mod_python/trunk/test/htdocs/tests.py
    httpd/mod_python/trunk/test/test.py

Modified: httpd/mod_python/trunk/lib/python/mod_python/apache.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/apache.py?rev=332807&r1=332806&r2=332807&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/apache.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/apache.py Sat Nov 12 10:11:14 2005
@@ -760,6 +760,7 @@
 config_tree = _apache.config_tree
 server_root = _apache.server_root
 mpm_query = _apache.mpm_query
+exists_config_define = _apache.exists_config_define
 
 ## Some constants
 

Modified: httpd/mod_python/trunk/src/_apachemodule.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/_apachemodule.c?rev=332807&r1=332806&r2=332807&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/_apachemodule.c (original)
+++ httpd/mod_python/trunk/src/_apachemodule.c Sat Nov 12 10:11:14 2005
@@ -653,18 +653,43 @@
     return Py_None;
 }
 
+/**
+ ** exists_config_define(name)
+ **
+ *  Check for a definition from the server command line.
+ */
+
+static PyObject *exists_config_define(PyObject *self, PyObject *args)
+{
+
+    char *name = NULL;
+
+    if (! PyArg_ParseTuple(args, "s", &name))
+        return NULL; 
+
+    if(ap_exists_config_define(name)) {
+        Py_INCREF(Py_True);
+        return Py_True;
+    }
+    else {
+        Py_INCREF(Py_False);
+        return Py_False;
+    }
+}
+
 /* methods of _apache */
 struct PyMethodDef _apache_module_methods[] = {
-    {"config_tree",               (PyCFunction)config_tree,      METH_NOARGS},
-    {"log_error",                 (PyCFunction)mp_log_error,     METH_VARARGS},
-    {"mpm_query",                 (PyCFunction)mpm_query,        METH_O},
-    {"parse_qs",                  (PyCFunction)parse_qs,         METH_VARARGS},
-    {"parse_qsl",                 (PyCFunction)parse_qsl,        METH_VARARGS},
-    {"server_root",               (PyCFunction)server_root,      METH_NOARGS},
-    {"register_cleanup",          (PyCFunction)register_cleanup, METH_VARARGS},
-    {"_global_lock",              (PyCFunction)_global_lock,     METH_VARARGS},
-    {"_global_trylock",           (PyCFunction)_global_trylock,  METH_VARARGS},
-    {"_global_unlock",            (PyCFunction)_global_unlock,   METH_VARARGS},
+    {"config_tree",           (PyCFunction)config_tree,          METH_NOARGS},
+    {"log_error",             (PyCFunction)mp_log_error,         METH_VARARGS},
+    {"mpm_query",             (PyCFunction)mpm_query,            METH_O},
+    {"parse_qs",              (PyCFunction)parse_qs,             METH_VARARGS},
+    {"parse_qsl",             (PyCFunction)parse_qsl,            METH_VARARGS},
+    {"server_root",           (PyCFunction)server_root,          METH_NOARGS},
+    {"register_cleanup",      (PyCFunction)register_cleanup,     METH_VARARGS},
+    {"exists_config_define",  (PyCFunction)exists_config_define, METH_VARARGS},
+    {"_global_lock",          (PyCFunction)_global_lock,         METH_VARARGS},
+    {"_global_trylock",       (PyCFunction)_global_trylock,      METH_VARARGS},
+    {"_global_unlock",        (PyCFunction)_global_unlock,       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=332807&r1=332806&r2=332807&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Sat Nov 12 10:11:14 2005
@@ -741,6 +741,13 @@
 
     return apache.OK
 
+def apache_exists_config_define(req):
+    if apache.exists_config_define('FOOBAR'):
+        req.write('FOOBAR')
+    else:
+        req.write('NO_FOOBAR')
+    return apache.OK
+
 def util_fieldstorage(req):
 
     from mod_python import util

Modified: httpd/mod_python/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=332807&r1=332806&r2=332807&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Sat Nov 12 10:11:14 2005
@@ -251,12 +251,12 @@
         f.write("\n# --APPENDED-- \n\n"+append)
         f.close()
 
-    def startHttpd(self):
+    def startHttpd(self,extra=''):
 
         print "  Starting Apache...."
         httpd = quoteIfSpace(HTTPD)
         config = quoteIfSpace(CONFIG)
-        cmd = '%s -k start -f %s' % (httpd, config)
+        cmd = '%s %s -k start -f %s' % (httpd, extra, config)
         print "    ", cmd
         os.system(cmd)
         time.sleep(1)
@@ -1686,6 +1686,7 @@
         self.failUnless(server_hdr.find("Python") > -1,
                         "%s does not appear to load, Server header does not contain Python"
                         % MOD_PYTHON_SO)
+
     def test_global_lock(self):
 
         print "\n  * Testing _global_lock"
@@ -1722,7 +1723,7 @@
         t2 = time.time()
         if (t2 - t1) < 5:
             self.fail("global_lock is broken (too quick)")
-         
+
     def testPerRequestTests(self):
 
         print "\n* Running the per-request test suite..."
@@ -1838,12 +1839,46 @@
         if log.find("test 2 ok") == -1:
             self.fail("Could not find test message in error_log")
 
+    def test_apache_exists_config_define(self):
+
+        print "\n* Testing apache.exists_config_define()..."
+
+        c = Directory(DOCUMENT_ROOT,
+                      SetHandler("mod_python"),
+                      PythonHandler("tests::apache_exists_config_define"),
+                      PythonDebug("On"))
+
+        self.makeConfig(str(c))
+
+        self.startHttpd()
+
+        f = urllib.urlopen("http://127.0.0.1:%s/tests.py" % PORT)
+        rsp = f.read()
+        f.close()
+
+        self.stopHttpd()
+        
+        if rsp != 'NO_FOOBAR':
+            self.fail('Failure on apache.exists_config_define() : %s'%rsp)
+
+        self.startHttpd(extra="-DFOOBAR")
+
+        f = urllib.urlopen("http://127.0.0.1:%s/tests.py" % PORT)
+        rsp = f.read()
+        f.close()
+
+        self.stopHttpd()
+        
+        if rsp != 'FOOBAR':
+            self.fail('Failure on apache.exists_config_define() : %s'%rsp)
+
 def suite():
 
     mpTestSuite = unittest.TestSuite()
     mpTestSuite.addTest(PerInstanceTestCase("testLoadModule"))
     mpTestSuite.addTest(PerInstanceTestCase("test_srv_register_cleanup"))
     mpTestSuite.addTest(PerInstanceTestCase("test_apache_register_cleanup"))
+    mpTestSuite.addTest(PerInstanceTestCase("test_apache_exists_config_define"))
     # XXX comment out until ab is fixed, or we have another way
 ##     mpTestSuite.addTest(PerInstanceTestCase("test_global_lock"))
     mpTestSuite.addTest(PerInstanceTestCase("testPerRequestTests"))