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/07/30 12:27:03 UTC

svn commit: r426882 - in /httpd/mod_python/trunk: lib/python/mod_python/ src/ src/include/

Author: grahamd
Date: Sun Jul 30 03:27:00 2006
New Revision: 426882

URL: http://svn.apache.org/viewvc?rev=426882&view=rev
Log:
(MODPYTHON-155) Modifications to handler and filter lists so that
references can be maintained back to parent handler of a handler/filter
which was registered dynamically. This is necessary within the scheme of
how the new module importer works. Specifically, where a directory isn't
specified when adding a handler or registering a filter, the directory
associated with the parent up the chain has to be used instead. In the old
importer it was relying on fact that directory of parent had already been
added to the Python sys.path, although this didn't actually work reliably.
The new module importer doesn't add directories to sys.path and so the need
to properly work out directory associated with a parent so that it can be
used when required.


Modified:
    httpd/mod_python/trunk/lib/python/mod_python/importer.py
    httpd/mod_python/trunk/src/filterobject.c
    httpd/mod_python/trunk/src/hlist.c
    httpd/mod_python/trunk/src/hlistobject.c
    httpd/mod_python/trunk/src/include/filterobject.h
    httpd/mod_python/trunk/src/include/hlist.h
    httpd/mod_python/trunk/src/include/mod_python.h
    httpd/mod_python/trunk/src/include/mod_python.h.in
    httpd/mod_python/trunk/src/mod_python.c
    httpd/mod_python/trunk/src/requestobject.c

Modified: httpd/mod_python/trunk/lib/python/mod_python/importer.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/lib/python/mod_python/importer.py?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/importer.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/importer.py Sun Jul 30 03:27:00 2006
@@ -1176,13 +1176,23 @@
     try:
 
         try:
-            # Cache the server configuration for the
-            # current request so that it will be
-            # available from within 'import_module()'.
-
             directory = filter.dir
             handler = filter.handler
 
+            # If directory for filter is not set,
+            # then search back through parents and
+            # inherit value from parent if found.
+
+            if directory is None:
+                parent = filter.parent
+                while parent is not None:
+                    if parent.directory is not None:
+                        directory = parent.directory
+                        break
+                    parent = parent.parent
+
+            # Expand relative addressing shortcuts.
+
             if type(handler) == types.StringType:
 
                 if handler[:2] == './':
@@ -1193,6 +1203,10 @@
                     if directory is not None:
                         handler = os.path.join(directory, handler)
 
+            # Cache the server configuration for the
+            # current request so that it will be
+            # available from within 'import_module()'.
+
             config = filter.req.get_config()
             cache = _setup_config_cache(config, directory)
 
@@ -1286,15 +1300,25 @@
         while not aborted and hlist.handler is not None:
 
             try:
-                # Cache the server configuration for the
-                # current request so that it will be
-                # available from within 'import_module()'.
-
                 cache = None
 
                 directory = hlist.directory
                 handler = hlist.handler
 
+                # If directory for handler is not set,
+                # then search back through parents and
+                # inherit value from parent if found.
+
+                if directory is None:
+                    parent = hlist.parent
+                    while parent is not None:
+                        if parent.directory is not None:
+                            directory = parent.directory
+                            break
+                        parent = parent.parent
+
+                # Expand relative addressing shortcuts.
+
                 if type(handler) == types.StringType:
 
                     if handler[:2] == './':
@@ -1304,6 +1328,10 @@
                     elif handler[:3] == '../':
                         if directory is not None:
                             handler = os.path.join(directory, handler)
+
+                # Cache the server configuration for the
+                # current request so that it will be
+                # available from within 'import_module()'.
 
                 cache = _setup_config_cache(config, directory)
 

Modified: httpd/mod_python/trunk/src/filterobject.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/filterobject.c?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/filterobject.c (original)
+++ httpd/mod_python/trunk/src/filterobject.c Sun Jul 30 03:27:00 2006
@@ -75,7 +75,8 @@
 
 PyObject *MpFilter_FromFilter(ap_filter_t *f, apr_bucket_brigade *bb, int is_input,
                               ap_input_mode_t mode, apr_size_t readbytes,
-                              char *handler, PyObject *callable, char *dir)
+                              char *handler, PyObject *callable, char *dir,
+                              hl_entry *parent)
 {
     filterobject *result;
 
@@ -107,6 +108,7 @@
     result->handler = handler;
     result->callable = callable;
     result->dir = dir;
+    result->parent = parent;
 
     result->request_obj = NULL; 
 
@@ -554,7 +556,17 @@
             return self->callable;
         } else if (self->handler) {
             return PyString_FromString(self->handler);
-        } else {
+        }
+        else {
+            Py_INCREF(Py_None);
+            return Py_None;
+        }
+    }
+    else if (strcmp(name, "parent") == 0) {
+        if (self->parent) {
+            return MpHList_FromHLEntry(self->parent);
+        }
+        else {
             Py_INCREF(Py_None);
             return Py_None;
         }

Modified: httpd/mod_python/trunk/src/hlist.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/hlist.c?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/hlist.c (original)
+++ httpd/mod_python/trunk/src/hlist.c Sun Jul 30 03:27:00 2006
@@ -34,7 +34,8 @@
  */
 
 hl_entry *hlist_new(apr_pool_t *p, const char *h, PyObject *o, const char *d, 
-                    int d_is_fnmatch, ap_regex_t *regex, const int s)
+                    int d_is_fnmatch, ap_regex_t *regex, const int s,
+                    hl_entry* parent)
 {
     hl_entry *hle;
 
@@ -46,6 +47,7 @@
     hle->d_is_fnmatch = d_is_fnmatch;
     hle->regex = regex;
     hle->silent = s;
+    hle->parent = parent;
 
     return hle;
 }
@@ -61,7 +63,7 @@
 
 hl_entry *hlist_append(apr_pool_t *p, hl_entry *hle, const char * h,
                        PyObject *o, const char *d, int d_is_fnmatch,
-                       ap_regex_t *regex, const int s)
+                       ap_regex_t *regex, const int s, hl_entry *parent)
 {
     hl_entry *nhle;
 
@@ -77,6 +79,7 @@
     nhle->d_is_fnmatch = d_is_fnmatch;
     nhle->regex = regex;
     nhle->silent = s;
+    nhle->parent = parent;
 
     if (hle)
         hle->next = nhle;
@@ -101,6 +104,7 @@
     head->d_is_fnmatch = hle->d_is_fnmatch;
     head->regex = hle->regex;
     head->silent = hle->silent;
+    head->parent = hle->parent;
 
     hle = hle->next;
     nhle = head;
@@ -112,6 +116,8 @@
         nhle->directory = apr_pstrdup(p, hle->directory);
         nhle->d_is_fnmatch = hle->d_is_fnmatch;
         nhle->regex = hle->regex;
+        nhle->silent = hle->silent;
+        nhle->parent = hle->parent;
         hle = hle->next;
     }
 

Modified: httpd/mod_python/trunk/src/hlistobject.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/hlistobject.c?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/hlistobject.c (original)
+++ httpd/mod_python/trunk/src/hlistobject.c Sun Jul 30 03:27:00 2006
@@ -138,6 +138,14 @@
             return Py_None;
         }
     }
+    else if (strcmp(name, "parent") == 0) {
+        if (self->head->parent) {
+            return MpHList_FromHLEntry(self->head->parent);
+        } else {
+            Py_INCREF(Py_None);
+            return Py_None;
+        }
+    }
 
     return PyMember_Get((char *)self->head, hlist_memberlist, name);
 
@@ -152,9 +160,14 @@
 static PyObject *hlist_repr(hlistobject *self)
 {
     PyObject *s = PyString_FromString("{");
+    PyObject *repr = NULL;
     if (self->head->handler) {
         PyString_ConcatAndDel(&s, PyString_FromString("'handler:'"));
         PyString_ConcatAndDel(&s, PyString_FromString(self->head->handler));
+        PyString_ConcatAndDel(&s, PyString_FromString("'"));
+    } else if (self->head->callable) {
+        PyString_ConcatAndDel(&s, PyString_FromString("'handler:'"));
+        PyString_ConcatAndDel(&s, PyObject_Repr(self->head->callable));
         PyString_ConcatAndDel(&s, PyString_FromString("'"));
     }
     if (self->head->directory) {

Modified: httpd/mod_python/trunk/src/include/filterobject.h
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/filterobject.h?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/filterobject.h (original)
+++ httpd/mod_python/trunk/src/include/filterobject.h Sun Jul 30 03:27:00 2006
@@ -50,6 +50,7 @@
         char *handler;
         PyObject *callable;
         char *dir;
+        hl_entry *parent;
 
         requestobject *request_obj;
 
@@ -63,7 +64,8 @@
         MpFilter_FromFilter Py_PROTO((ap_filter_t *f, apr_bucket_brigade *bb_in, 
                                       int is_input, ap_input_mode_t mode, 
                                       apr_size_t readbytes, char *handler,
-                                      PyObject *callable, char *dir));
+                                      PyObject *callable, char *dir,
+                                      hl_entry *parent));
 
 #ifdef __cplusplus
 }

Modified: httpd/mod_python/trunk/src/include/hlist.h
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/hlist.h?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/hlist.h (original)
+++ httpd/mod_python/trunk/src/include/hlist.h Sun Jul 30 03:27:00 2006
@@ -42,14 +42,15 @@
                         if a handler is not found in a module,
                         no error should be reported */
         struct hl_entry *next;
+        struct hl_entry *parent;
     } hl_entry;
     
     hl_entry *hlist_new(apr_pool_t *p, const char *h, PyObject* o,
                         const char *d, int d_is_fnmatch, ap_regex_t *regex,
-                        const int s);
+                        const int s, hl_entry* parent);
     hl_entry *hlist_append(apr_pool_t *p, hl_entry *hle, const char * h,
                            PyObject* o, const char *d, int d_is_fnmatch,
-                           ap_regex_t *regex, const int s);
+                           ap_regex_t *regex, const int s, hl_entry* parent);
     hl_entry *hlist_copy(apr_pool_t *p, const hl_entry *hle);
 
 #ifdef __cplusplus

Modified: httpd/mod_python/trunk/src/include/mod_python.h
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/mod_python.h?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h Sun Jul 30 03:27:00 2006
@@ -199,6 +199,7 @@
     char *directory;
     int d_is_fnmatch;
     ap_regex_t *regex;
+    hl_entry *parent;
 } py_handler;
 
 apr_status_t python_cleanup(void *data);

Modified: httpd/mod_python/trunk/src/include/mod_python.h.in
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/include/mod_python.h.in?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h.in (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h.in Sun Jul 30 03:27:00 2006
@@ -199,6 +199,7 @@
     char *directory;
     int d_is_fnmatch;
     ap_regex_t *regex;
+    hl_entry *parent;
 } py_handler;
 
 apr_status_t python_cleanup(void *data);

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/mod_python.c?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sun Jul 30 03:27:00 2006
@@ -1038,11 +1038,11 @@
 
     while (*(h = ap_getword_white(p, &handler)) != '\0') {
         if (!head) {
-            head = hlist_new(p, h, 0, directory, d_is_fnmatch, regex, silent);
+            head = hlist_new(p, h, 0, directory, d_is_fnmatch, regex, silent, 0);
             apr_hash_set(hlists, phase, APR_HASH_KEY_STRING, head);
         }
         else {
-            hlist_append(p, head, h, 0, directory, d_is_fnmatch, regex, silent);
+            hlist_append(p, head, h, 0, directory, d_is_fnmatch, regex, silent, 0);
         }
     }
 }
@@ -1691,7 +1691,7 @@
     /* create filter */
     filter = (filterobject *)MpFilter_FromFilter(f, bb, is_input, mode, readbytes,
                                                  fh->handler, fh->callable,
-                                                 fh->directory);
+                                                 fh->directory, fh->parent);
 
     Py_INCREF(request_obj);
     filter->request_obj = request_obj;
@@ -1867,7 +1867,7 @@
     request_obj = python_get_request_object(req, 0);
 
     /* create filter */
-    filter = (filterobject *)MpFilter_FromFilter(f, bb, 0, 0, 0, 0, 0, 0);
+    filter = (filterobject *)MpFilter_FromFilter(f, bb, 0, 0, 0, 0, 0, 0, 0);
 
     Py_INCREF(request_obj);
     filter->request_obj = request_obj;
@@ -2008,7 +2008,7 @@
     request_obj = python_get_request_object(req, 0);
 
     /* create filter */
-    filter = (filterobject *)MpFilter_FromFilter(f, *bb, 0, 0, 0, 0, 0, 0);
+    filter = (filterobject *)MpFilter_FromFilter(f, *bb, 0, 0, 0, 0, 0, 0, 0);
 
     Py_INCREF(request_obj);
     filter->request_obj = request_obj;

Modified: httpd/mod_python/trunk/src/requestobject.c
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/requestobject.c?rev=426882&r1=426881&r2=426882&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/requestobject.c (original)
+++ httpd/mod_python/trunk/src/requestobject.c Sun Jul 30 03:27:00 2006
@@ -204,7 +204,8 @@
 
         /* then just append to hlist */
         hlist_append(self->request_rec->pool, self->hlo->head,
-                     handler, callable, dir, 0, NULL, NOTSILENT);
+                     handler, callable, dir, 0, NULL, NOTSILENT,
+                     self->hlo->head);
     }
     else {
         /* this is a phase that we're not in */
@@ -220,11 +221,13 @@
         hle = apr_hash_get(req_config->dynhls, phase, APR_HASH_KEY_STRING);
 
         if (! hle) {
-            hle = hlist_new(self->request_rec->pool, handler, callable, dir, 0, NULL, NOTSILENT);
+            hle = hlist_new(self->request_rec->pool, handler, callable, dir,
+                            0, NULL, NOTSILENT, self->hlo->head);
             apr_hash_set(req_config->dynhls, phase, APR_HASH_KEY_STRING, hle);
         }
         else {
-            hlist_append(self->request_rec->pool, hle, handler, callable, dir, 0, NULL, NOTSILENT);
+            hlist_append(self->request_rec->pool, hle, handler, callable, dir,
+                         0, NULL, NOTSILENT, self->hlo->head);
         }
     }
     
@@ -339,6 +342,7 @@
                                     sizeof(py_handler));
     fh->handler = apr_pstrdup(self->request_rec->pool, handler);
     fh->callable = callable;
+    fh->parent = self->hlo->head;
 
     /* Canonicalize path and add trailing slash at
      * this point if directory was provided. */
@@ -413,6 +417,7 @@
                                     sizeof(py_handler));
     fh->handler = apr_pstrdup(self->request_rec->pool, handler);
     fh->callable = callable;
+    fh->parent = self->hlo->head;
 
     /* Canonicalize path and add trailing slash at
      * this point if directory was provided. */