-----BEGIN PGP SIGNED MESSAGE-----
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.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlANqV4ACgkQ+gerLs4ltQ7egQCeOdxitDMAxAMD9YBHf5S/aNau
GHwAn0mraihjntJorXFBQ0/dPNs4CWEp
=0ejr
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to