[Zope] Problem Understanding URL

Tres Seaver tseaver at palladion.com
Mon Jul 23 19:43:33 UTC 2012

Hash: SHA1

On 07/23/2012 03:01 PM, Jared Hall wrote:
> Ok I'd read about those functions a little bit in the Zope 2 book or 
> the Developer's Guide, but they seemed like advanced techniques that I
> probably wouldn't need to understand.
> Back on topic; I ran this awesome command in the terminal:
> grep getitem x=$(find . *.*)
> and turned up some random references to getitem in some dtml code, 
> which I judge to be insignificant. There was also one very interesting
> usage of __getitem__ in the python code itself, and I have to
> investigate the code further to understand what's going on. The
> function definition looks suspiciously like what I would expect to
> find for this 'hijacking' of control:
> def __getitem__(self, key): v=self._getOb(key, None) if v is not None:
> return v if hasattr(self, 'REQUEST'): request=self.REQUEST 
> method=request.get('REQUEST_METHOD', 'GET') if
> request.maybe_webdav_client and not method in ('GET', 'POST'): return
> NullResource(self, key, request).__of__(self) raise KeyError, key
> I read this as: look up the object in the current context and return 
> it. The only problem with this is that I don't see when the object
> gets placed into the proper context for the TAL statements like
> here/FirstName, etc.

There isn't any "hijacking" going on here:  Zope2 uses '__getitem__' by
preference for fetching items from a container (falling back to
'__getattr__').  The "context" for your template (aliased as "here") is
going to be the object found by the publishing traversal:  in this case,
the 'v' returned from that '__getitem__'.

- -- 
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


More information about the Zope mailing list