[Python-Dev] Multiple dicts for string interpolation?

Ken Manheimer klm@digicool.com
Wed, 26 Jan 2000 00:01:36 -0500 (EST)


On Tue, 25 Jan 2000, Skip Montanaro wrote:

>     Guido> Skip:
>     >> I'd like to propose a third alternative.  How about if the string
>     >> interpolation function accepted a tuple of dictionaries directly:
>     >> 
>     >> s = format % (d1, d2)
> [...]
>     Guido> I think it depends on to what extent this is a common, useful
>     Guido> idiom.  Do you have evidence of that?  Examples?
> 
> Well, the first place I ran into it was in DocumentTemplates a few years
> ago.  They used an idiom heavily which may have now been replaced by
> acquisition where you'd effectively push and pop value dicts onto a stack as
> you entered and exited nested blocks of DTML code.  Their solution was a
> special dict-like object.

Implementation of acquisition basically uses a MultiDict underneath.
Consider acquisition as a cumulative context composed from the containers
of the target of a web request.  (Actually, a distinction is made between
the object containment hierarchy of the target and the successive
components of the path along which the target is reached by the request,
with the containment contexts taking precedence - but that's probably not
important here:-)  Add in incidental things like the server environment
(from which you can get HTTP_REFERER and cookies and so forth).  Each of
the components can be a dictionary or a MultiDict (or a sequence of pairs,
i think), and they're ultimately composed in a MultiDict.

I think another place in zope where multidicts play prominently is in the
security mechanism, where any object can have local roles, and the
ultimate role of a user within a context is composed from the union across
the containment hierarchy.  There probably are lots of other places where
multidicts are used.

Suffice to say that there's a lot of composing of contexts that goes on in
Zope in general, acquistion being a prime example but not the only one,
and multidicts play heavily in many.  I would be surprised if this need to
combine contexts is peculiar to web server, or general server
applications.

> [...]
> It's not a big deal.  If it seems too obscure the other obvious solutions
> are not gruesome.

I suppose we'd be pretty happy to have something like MultiDict as part of
python...

Ken
klm@digicool.com

(Who's the only one left in fredericksburg to speak up, at the moment:-)