[Zope-Coders] Re: [Zope-Checkins] CVS: Zope/lib/python/AccessControl - ZopeGuards.py:1.13

Shane Hathaway shane@zope.com
Wed, 18 Dec 2002 11:19:53 -0500


Chris Withers wrote:
> Shane Hathaway wrote:
> 
>>> How so? The idea I was suggesting should let you hot-replace the bits 
>>> that you would otherwise have to put into the core...
>>
>>
>> I don't see what you mean.  The name "TransparentFolder" should not 
>> appear anywhere in Zope, so what would I do?
> 
> 
> Why would it? The code which would do the hotpatchign would only reside 
> in your product. Then again, maybe I'm misunderstanding how the 
> PluginIndexes shenanigans works, and I certainyl don't know anything 
> about what TransparentFolder needs to alter.

Description of nasty hack follows. :-)

TransparentFolders has to patch OFS.ObjectManager before any class 
derives from it.  Any subclass created before the __getattr__ hook gets 
installed will not behave properly in the TransparentFolders world.  So 
the patch has to get installed very, very early.  The trick I used was 
to change OFS/__init__.py, which otherwise has no Python code.  So I 
could slip in the special OFS/__init__.py to make it easier to install 
TransparentFolders, but I'd be setting a terrible precedent that would 
lead to bloat. ("Put in my hook too!")

>>>> imp.find_module() doesn't seem to do enough: it can't deal with 
>>>> hierarchical names until you load_module().
>>>
>>>
>>> Well, you wouldn't use find_module, just load_module. And I'm 
>>> counting on that not to do anything with heirarchical names so that 
>>> we don't import anything we're not planning on importing...
>>
>>
>> load_module executes the module, just like __import__.  Maybe I don't 
>> understand what you're saying.
> 
> 
> Use load_module to _only_ import the zope_security module IFF it can be 
> found by find_module. Sicne we know where we're starting from, would it 
> matter that the dotted name isn't used?

Say you have a package called "shadyhacks" and you put a 
zope_security.py inside it.  Zope can't use find_module to find out 
whether zope_security.py exists until it has already loaded and executed 
the "shadyhacks" package.

> I dunno, maybe the manual searching thing is easier :-(

It might be the only reliable way.

Shane