Gregory (Grisha) Trubetskoy
grisha at modpython.org
Mon Dec 2 16:52:26 EST 2002
Stephane - Yes, it looks like server.register_cleanup was left forgotten.... Try applying this set of patches (this includes patches to the test suite), I'll add this to HEAD. RCS file: /home/cvs/httpd-python/src/serverobject.c,v retrieving revision 1.13 diff -u -r1.13 serverobject.c --- src/serverobject.c 8 Nov 2002 00:15:11 -0000 1.13 +++ src/serverobject.c 2 Dec 2002 21:47:52 -0000 @@ -117,30 +117,20 @@ cleanup_info *ci; PyObject *handler = NULL; PyObject *data = NULL; - PyObject *Req = NULL; requestobject *req = NULL; - if (! PyArg_ParseTuple(args, "OO|O", &Req, &handler, &data)) + if (! PyArg_ParseTuple(args, "OO|O", &req, &handler, &data)) return NULL; - if (! PyObject_HasAttrString(Req, "_req")) { - PyErr_SetString(PyExc_ValueError, "first argument must be a Request object"); - return NULL; + if (! MpRequest_Check(req)) { + PyErr_SetString(PyExc_ValueError, + "first argument must be a request object"); + return NULL; } - else { - - req = (requestobject *) PyObject_GetAttrString(Req, "_req"); - - if (! MpRequest_Check(req)) { - PyErr_SetString(PyExc_ValueError, - "first argument must be a request object"); - return NULL; - } - else if(!PyCallable_Check(handler)) { - PyErr_SetString(PyExc_ValueError, - "second argument must be a callable object"); - return NULL; - } + else if(!PyCallable_Check(handler)) { + PyErr_SetString(PyExc_ValueError, + "second argument must be a callable object"); + return NULL; } ci = (cleanup_info *)malloc(sizeof(cleanup_info)); Index: test/test.py =================================================================== RCS file: /home/cvs/httpd-python/test/test.py,v retrieving revision 1.20 diff -u -r1.20 test.py --- test/test.py 29 Oct 2002 21:52:18 -0000 1.20 +++ test/test.py 2 Dec 2002 21:47:52 -0000 @@ -776,12 +776,39 @@ self.failUnless(result.wasSuccessful()) + def test_srv_register_cleanup(self): + + print "\n* Testing server.register_cleanup()..." + + c = Directory(DOCUMENT_ROOT, + SetHandler("python-program"), + PythonHandler("tests::srv_register_cleanup"), + PythonDebug("On")) + + self.makeConfig(str(c)) + + self.startHttpd() + + f = urllib.urlopen("http://127.0.0.1:%s/tests.py" % PORT) + f.read() + f.close() + + self.stopHttpd() + + # see what's in the log now + time.sleep(1) + f = open(os.path.join(SERVER_ROOT, "logs/error_log")) + log = f.read() + f.close() + if log.find("test ok") == -1: + self.fail("Could not find test message in error_log") def suite(): mpTestSuite = unittest.TestSuite() mpTestSuite.addTest(PerInstanceTestCase("testLoadModule")) mpTestSuite.addTest(PerInstanceTestCase("testPerRequestTests")) + mpTestSuite.addTest(PerInstanceTestCase("test_srv_register_cleanup")) return mpTestSuite tr = unittest.TextTestRunner() Index: test/htdocs/tests.py =================================================================== RCS file: /home/cvs/httpd-python/test/htdocs/tests.py,v retrieving revision 1.19 diff -u -r1.19 tests.py --- test/htdocs/tests.py 29 Oct 2002 21:52:18 -0000 1.19 +++ test/htdocs/tests.py 2 Dec 2002 21:47:52 -0000 @@ -505,6 +505,14 @@ data.log_error(data.cleanup_data) +def srv_register_cleanup(req): + + req.cleanup_data = "test ok" + req.server.register_cleanup(req, cleanup, req) + req.write("registered server cleanup that will write to log") + + return apache.OK + def util_fieldstorage(req): from mod_python import util Grisha On Mon, 2 Dec 2002, StИphane Bidoul wrote: > Hi Grisha, > > I'm back using mod_python, on a real project this time. > We've been using 3.0 beta for a few weeks and it works great! > > Now I'm trying to use mp_server.register_cleanup, and that fails > with a "ValueError: first argument must be a Request object". > > My first diagnostic (unless I'm doing something silly) > is that it's a remnant of mod_python 2.x, > since the Request class seems to have disappeared > from apache.py. > > Is that an easy fix for you? > Or should I dig it a little bit more? > > -sbi > > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://www.modpython.org/mailman/listinfo/mod_python >
|