durusmail: quixote-users: Proposed change to _traverse
Proposed change to _traverse
2000-11-09
2000-11-09
2000-11-10
2000-11-10
Proposed change to _traverse
Andrew Kuchling
2000-11-10
On Fri, Nov 10, 2000 at 08:52:16AM -0500, Greg Ward wrote:
>This suggests a very simple rule: after the main traversal loop, do this:

That certainly simplifies things, since it collapses the very similar
logic for modules and instances into a single code path.  I then wind
up with the patch below that deletes a bunch of redundant code.

I'll test the changes on my machine for today, and then check it in if
no problems show up.

--amk

Index: publish.py
===================================================================
RCS file: /projects/cvsroot/mems/quixote/publish.py,v
retrieving revision 1.43
diff -u -r1.43 publish.py
--- publish.py  2000/10/27 15:31:20     1.43
+++ publish.py  2000/11/10 17:03:43
@@ -163,14 +163,10 @@
     (script_name, path_info, object) = \
         _traverse(original_path, path, request, response)

-    # ExtensionClass-proof test for "this is a class instance"
-    is_instance = (hasattr(object, '__class__') and
-                   not hasattr(object, '__bases__'))
-    is_module = type(object) == types.ModuleType
-
-    if is_module:
-        # It's a module, which isn't callable.  First, make sure URL has
-        # trailing slash
+    if not callable(object):
+        # It's something which isn't callable, like a module or an
+        # instance without a __call__ method.
+        # Therefore we'll first ensure that the URL has a trailing slash.
         if original_path[-1] != '/':
             # repair path and redirect
             path = "%s/%s/" % (config.URL_PREFIX, string.join(path, '/'))
@@ -183,22 +179,6 @@
         if (hasattr(object, 'index') and
             callable(object.index) and
             'index' in object.__exports__):
-            object = object.index
-        else:
-            raise errors.TraversalError(
-                "module %s has no function index (or it's not in __exports__)"
-                % object.__name__,
-                original_path)
-
-    # Instances get a similar treatment to modules, except they may be
-    # callable already (in which case we leave them be, and just call
-    # them).
-    elif is_instance:
-        if callable(object):
-            pass                        # object is just fine as-is
-        elif (hasattr(object, 'index') and
-              callable(object.index) and
-              'index' in object.__exports__):
             object = object.index
         else:
             raise errors.TraversalError(



reply