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/02/21 12:16:44 UTC

svn commit: r379422 - in /httpd/mod_python/trunk: Doc/appendixc.tex Doc/modpython4.tex lib/python/mod_python/__init__.py src/include/mpversion.h src/requestobject.c test/htdocs/tests.py test/httpdconf.py test/test.py

Author: grahamd
Date: Tue Feb 21 03:16:40 2006
New Revision: 379422

URL: http://svn.apache.org/viewcvs?rev=379422&view=rev
Log:
Made req.handler writable. (MODPYTHON-125)

Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    httpd/mod_python/trunk/Doc/modpython4.tex
    httpd/mod_python/trunk/lib/python/mod_python/__init__.py
    httpd/mod_python/trunk/src/include/mpversion.h
    httpd/mod_python/trunk/src/requestobject.c
    httpd/mod_python/trunk/test/htdocs/tests.py
    httpd/mod_python/trunk/test/httpdconf.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=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Tue Feb 21 03:16:40 2006
@@ -33,6 +33,11 @@
       Interpreter Lock (GIL), as described in PEP 311, can now be used. The
       only requirement is that such modules can only be used in the context
       of the \samp{main_interpreter}.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-125]{MODPYTHON-125})
+      The \code{req.handler} attribute is now writable. This allows a handler
+      executing in a phase prior to the response phase to specify which
+      Apache module will be responsible for generating the content.
   \end{itemize}
 
   Bug Fixes

Modified: httpd/mod_python/trunk/Doc/modpython4.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/modpython4.tex?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/modpython4.tex (original)
+++ httpd/mod_python/trunk/Doc/modpython4.tex Tue Feb 21 03:16:40 2006
@@ -1102,9 +1102,23 @@
 \end{memberdesc}
 
 \begin{memberdesc}[request]{handler}
-  The name of the handler currently being processed. This is the handler
-  set by mod_mime, not the mod_python handler. In most cases it will be
-  "\samp{mod_python}. \emph{(Read-Only})
+  The symbolic name of the content handler (as in module, not mod_python
+  handler) that will service the request during the response phase. When
+  the SetHandler/AddHandler directives are used to trigger mod_python, this
+  will be set to \samp{mod_python} by mod_mime. A mod_python handler executing
+  prior to the response phase may also set this to \samp{mod_python} along
+  with calling \samp{req.add_handler()} to register a mod_python handler
+  for the response phase.
+
+  \begin{verbatim}
+def typehandler(req):
+    if os.path.splitext(req.filename)[1] == ".py":
+        req.handler = "mod_python"
+        req.add_handler("PythonHandler", "mod_python.publisher")
+        return apache.OK
+    return apache.DECLINED
+  \end{verbatim}                              
+
 \end{memberdesc}
 
 \begin{memberdesc}[request]{content_encoding}

Modified: httpd/mod_python/trunk/lib/python/mod_python/__init__.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/__init__.py?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/__init__.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/__init__.py Tue Feb 21 03:16:40 2006
@@ -20,5 +20,5 @@
 __all__ = ["apache", "cgihandler", "psp",
            "publisher", "util", "python22"]
 
-version = "3.3.0-dev-20060219"
+version = "3.3.0-dev-20060221"
 

Modified: httpd/mod_python/trunk/src/include/mpversion.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mpversion.h?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mpversion.h (original)
+++ httpd/mod_python/trunk/src/include/mpversion.h Tue Feb 21 03:16:40 2006
@@ -1,5 +1,5 @@
 #define MPV_MAJOR 3
 #define MPV_MINOR 3
 #define MPV_PATCH 0
-#define MPV_BUILD 20060219
-#define MPV_STRING "3.3.0-dev-20060219"
+#define MPV_BUILD 20060221
+#define MPV_STRING "3.3.0-dev-20060221"

Modified: httpd/mod_python/trunk/src/requestobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/requestobject.c?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/requestobject.c (original)
+++ httpd/mod_python/trunk/src/requestobject.c Tue Feb 21 03:16:40 2006
@@ -1368,6 +1368,15 @@
             apr_pstrdup(self->request_rec->pool, PyString_AsString(val));
         return 0;
     }
+    else if (strcmp(name, "handler") == 0) {
+        if (! PyString_Check(val)) {
+            PyErr_SetString(PyExc_TypeError, "handler must be a string");
+            return -1;
+        }
+        self->request_rec->handler = 
+            apr_pstrdup(self->request_rec->pool, PyString_AsString(val));
+        return 0;
+    }
     
     return PyMember_SetOne((char*)self->request_rec, 
                            find_memberdef(request_rec_mbrs, (char*)name),
@@ -1553,7 +1562,7 @@
     {"read_chunked", (getter)getreq_recmbr, NULL, "Reading chunked transfer-coding", "read_chunked"},
     {"expecting_100", (getter)getreq_recmbr, NULL, "Is client waitin for a 100 response?", "expecting_100"},
     {"content_type",  (getter)getreq_recmbr, (setter)setreq_recmbr, "Content type", "content_type"},
-    {"handler",       (getter)getreq_recmbr, NULL, "The handler string", "handler"},
+    {"handler",       (getter)getreq_recmbr, (setter)setreq_recmbr, "The handler string", "handler"},
     {"content_encoding", (getter)getreq_recmbr, NULL, "How to encode the data", "content_encoding"},
     {"content_languages", (getter)getreq_rec_ah, NULL, "Content languages", "content_languages"},
     {"vlist_validator", (getter)getreq_recmbr, NULL, "Variant list validator (if negotiated)", "vlist_validator"},

Modified: httpd/mod_python/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Tue Feb 21 03:16:40 2006
@@ -804,6 +804,18 @@
     os.remove(fname)
     return apache.OK
 
+def req_handler(req):
+    if req.phase == "PythonFixupHandler":
+        req.handler = "mod_python"
+        req.add_handler("PythonHandler","tests::req_handler")
+        return apache.OK
+    elif req.phase == "PythonHandler":
+        req.write('test ok')
+        return apache.OK
+    else:
+        req.write('test failed')
+        return apache.OK
+
 def fileupload(req):
     from mod_python import util
     import md5

Modified: httpd/mod_python/trunk/test/httpdconf.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/httpdconf.py?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/httpdconf.py (original)
+++ httpd/mod_python/trunk/test/httpdconf.py Tue Feb 21 03:16:40 2006
@@ -213,6 +213,10 @@
     def __init__(self, val):
         Directive.__init__(self, self.__class__.__name__, val)
 
+class PythonFixupHandler(Directive):
+    def __init__(self, val):
+        Directive.__init__(self, self.__class__.__name__, val)
+
 class PythonImport(Directive):
     def __init__(self, val):
         Directive.__init__(self, self.__class__.__name__, val)

Modified: httpd/mod_python/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=379422&r1=379421&r2=379422&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Tue Feb 21 03:16:40 2006
@@ -983,6 +983,31 @@
         else:
             print "\n  * Skipping req.sendfile() for a file which is a symbolic link"
 
+    def test_req_handler_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_req_handler"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  PythonFixupHandler("tests::req_handler"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_req_handler(self):
+
+        print "\n  * Testing req.handler"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % PORT)
+        conn.putrequest("GET", "/", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_handler", PORT))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
     def test_fileupload_conf(self):
 
         c = VirtualHost("*",
@@ -2058,6 +2083,7 @@
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile2"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile3"))
+        perRequestSuite.addTest(PerRequestTestCase("test_req_handler"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload_embedded_cr"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload_split_boundary"))