[Zope-dev] Re: ZCallable

Steve Alexander steve@cat-box.net
Sat, 15 Jul 2000 09:03:51 +0100


Chris Withers wrote:
> 
> Yup,
> 
> This looks good, as did your earlier post. However, it raises a question
> :(
> 
> Something like a ZCatalog or a Squishdot Site (which I have a passing
> interest in ;-) are both folderish. However, their __call__ method does
> something quite different: it returns the results of searching the catalog
> (I think this is the ZSearchable Interface, correct me if I'm wrong ;-)
> 
> I guess what's bothering me is why __call__ has this dual role and how the
> rendering process manages to correctly render index_html even on a
> Squishdot object which is actually callable?

I just looked over the source to ZCatalog. I'm pretty sure that __call__
has nothing to do with any index_html you might add to a catalog.

The __call__ method is what gets invoked when you call the method,
either through the magic of <dtml-var Catalog> or with <dtml-var
"Catalog(client, namespace, args*)">.

If Catalog has an index_html, or acquires one, then that is what gets
rendered when you go to the URL http://mysite.tld/foo/Catalog --
actually, it seems that the effective URL is
http://mysite.tld/foo/Catalog/index_html. Therefore, if you don't have
an index_html, it gets acquired.

This behaviour is set in lib/python/ZPublisher/BaseRequest.py, method
traverse(), line 257. (I'm using 2.2 final).


        # Set the default method
        if method=='GET' or method=='POST':
            method='index_html'
        else: baseflag=1

and later on, at line 300.

                elif (method and hasattr(object,method)
                      and entry_name != method
                      and getattr(object, method) is not None):
                    request._hacked_path=1
                    entry_name = method


So, if you're getting or posting, you effectively get "index_html"
appended to your URL.

This way of doing things allows individual classes to define protocol
handlers for other protocols they wish to support -- such as the PUT()
method in DTMLMethod.py. Thus, index_html() is the protocol handler for
GET and POST.

This mechanism is pretty much separate from the __call__ mechanism.

In conclusion, I can't see any disadvantage to making Folder callable as
I suggested in a previous message. It doesn't appear to break anything
:-)


> Hmm... I guess the implication of this is that a normal folder will never
> render itself to avoid confusion over the ZSearch interface and so if I
> want this behaviour I'll have to roll-my-own folder which inherits from
> ZCallable.

I'm not sure your paragraph above makes sense in light of what I've said
above.


> PS: Shane: what's the difference between ZCallable and the ZRenderable
> base class that Maik Roeder mentioned on zope@zope.org a few days back?

IIRC, ZRenderable lets you choose what method you want __call__ to
forward to, whereas ZCallable always chooses the method index_html, if
it exists.


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net