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/15 11:42:58 UTC

svn commit: r386039 - in /httpd/mod_python/trunk: Doc/appendixc.tex Doc/modpython4.tex lib/python/mod_python/apache.py src/mod_python.c test/htdocs/tests.py

Author: grahamd
Date: Wed Mar 15 02:42:56 2006
New Revision: 386039

URL: http://svn.apache.org/viewcvs?rev=386039&view=rev
Log:
The apache.interpreter and apache.main_server attributes have been made
publically available. These were previously private and not part of the
public API. Bug also fixed in that the server reference wasn't always the
actual main server object. (MODPYTHON-144)

Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    httpd/mod_python/trunk/Doc/modpython4.tex
    httpd/mod_python/trunk/lib/python/mod_python/apache.py
    httpd/mod_python/trunk/src/mod_python.c
    httpd/mod_python/trunk/test/htdocs/tests.py

Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=386039&r1=386038&r2=386039&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Wed Mar 15 02:42:56 2006
@@ -54,6 +54,11 @@
       Support added for using Python in content being passed through "INCLUDES"
       output filter, or as more commonly referred to server side include (SSI)
       mechanism.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-144]{MODPYTHON-144})
+      The \samp{apache.interpreter} and \samp{apache.main_server} attributes
+      have been made publically available. These were previously private and
+      not part of the public API.
   \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=386039&r1=386038&r2=386039&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/modpython4.tex (original)
+++ httpd/mod_python/trunk/Doc/modpython4.tex Wed Mar 15 02:42:56 2006
@@ -476,6 +476,18 @@
   \end{verbatim}
 \end{funcdesc}
 
+\subsection{Attributes\label{pyapi-apmem}}
+
+\begin{memberdesc}[apache]{interpreter}
+  The name of the subinterpreter under which we're running.
+  \emph{(Read-Only)}
+\end{memberdesc}
+
+\begin{memberdesc}[apache]{main_server}
+  A \code{server} object for the main server.
+  \emph{(Read-Only})
+\end{memberdesc}
+
 \subsection{Table Object (mp_table)\obindex{table}\label{pyapi-mptable}}
 
 \index{table}

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=386039&r1=386038&r2=386039&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/apache.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/apache.py Wed Mar 15 02:42:56 2006
@@ -776,22 +776,22 @@
     sys.stdout = si
     sys.stdin = so
 
-_interpreter = None
-_server = None
+interpreter = None
+main_server = None
 _callback = None
 
-def register_cleanup(handler,data=None):
-    _apache.register_cleanup(_interpreter,_server,handler,data)
+def register_cleanup(callback, data=None):
+    _apache.register_cleanup(interpreter, main_server, callback, data)
 
-def init(name,server):
+def init(name, server):
     """
         This function is called by the server at startup time
     """
 
-    global _interpreter
-    global _server
-    _interpreter = name
-    _server = server
+    global interpreter
+    global main_server
+    interpreter = name
+    main_server = server
 
     sys.argv = ["mod_python"]
 

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=386039&r1=386038&r2=386039&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Wed Mar 15 02:42:56 2006
@@ -27,6 +27,9 @@
 
 #include "mod_python.h"
 
+/* Server object for main server as supplied to python_init(). */
+static server_rec *main_server = NULL;
+
 /* List of available Python obCallBacks/Interpreters
  * (In a Python dictionary) */
 static PyObject * interpreters = NULL;
@@ -108,7 +111,7 @@
         fflush(stderr); 
     }
     
-    if (m && ! ((obCallBack = PyObject_CallMethod(m, INITFUNC, "sO", name, MpServer_FromServer(s))))) {
+    if (m && ! ((obCallBack = PyObject_CallMethod(m, INITFUNC, "sO", name, MpServer_FromServer(main_server))))) {
         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
                      "make_obcallback: could not call %s.\n", (!INITFUNC) ? "<null>" : INITFUNC);
         PyErr_Print();
@@ -594,6 +597,9 @@
     /* Python version */
     sprintf(buff, "Python/%.200s", strtok((char *)Py_GetVersion(), " "));
     ap_add_version_component(p, buff);
+
+    /* cache main server */
+    main_server = s;
 
     /* global config */
     glb = python_create_global_config(s);

Modified: httpd/mod_python/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=386039&r1=386038&r2=386039&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Wed Mar 15 02:42:56 2006
@@ -258,8 +258,10 @@
             self.fail("req.phase should be 'PythonHandler'")
             
         log("    req.interpreter: %s" % `req.interpreter`)
+        if req.interpreter != apache.interpreter:
+            self.fail("req.interpreter should be same as apache.interpreter" % `apache.interpreter`)
         if req.interpreter != req.server.server_hostname:
-            self.fail("req.interpreter should be same as req.server_hostname: %s" % `req.server_hostname`)
+            self.fail("req.interpreter should be same as req.server.server_hostname: %s" % `req.server.server_hostname`)
             
         log("    req.content_type: %s" % `req.content_type`)
         log("        doing req.content_type = 'test/123' ...")
@@ -808,6 +810,14 @@
 def req_server_get_options(req):
 
     try:
+        server_options = apache.main_server.get_options()
+        assert(server_options.get("global","0") == "0")
+        assert(server_options.get("override","0") == "0")
+
+        server_options = req.connection.base_server.get_options()
+        assert(server_options.get("global","0") == "0")
+        assert(server_options.get("override","0") == "0")
+
         server_options = req.server.get_options()
         assert(server_options["global"] == "1")
         assert(server_options["override"] == "1")