[Zope-Coders] GlobalRequestPatch into Zope Core

Jim Fulton jim@zope.com
Sun, 28 Oct 2001 15:14:28 -0500


Stephan Richter wrote:
> 
> Hello everyone,
> 
> as you may know there was quiet some discussion a while ago about adding the GlobalRequestPatch into the Zope core. You can find the patch at http://www.zope.org/Members/tmclaugh/GlobalRequestPatch. It was turned down, since ZC feels very uneasy about adding another method to Globals.

It's not a question of adding things to Globals, it's a question of
using global thread state. Doing so means that you can only have one active
request per thread. This is very much worth avoiding, if possible.
Sometimes, it's a necessary evil, as with security and transactions 
(although I hope to allow some other approaches with transactions).

> What does the GlobalRequestPatch do? It adds a method called get_request() to Globals that allows you to access the REQUEST variable everywhere in your Python code, without having to pass it as an argument or call it via self.REQUEST. It is especially needed in __getattr__, since there the self.REQUEST variable is not available.
> Why do we need it? Well, three internationalization products now use the Patch: Tim McLaughlin's recent product, Localizer and ZBabel. All of these projects overwrite __getattr__ but need to know the language before they can return the appropriate attribute. The language is usually found in the REQUEST itself or in 'HTTP_ACCEPT_LANGUAGE', which is the standard HTTP language string.

I am very concerned about making a __getattr__ a cornerstone of something as 
important as internationalization.  I regret that I haven't had time to look 
at these systems, but hearing that they rely on __getattr__ worries me a lot.

The __getattr__ hook interacts very badly with implicit acquisition. Using the 
__getattr__ hook in combination pretty much guarentees poor performance.

Jim

--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org