Is there a recommended way or example code somewhere for removing a  
utility registration from a persistent component registry, when that  
utility's module no longer exists?

The use case is in Plone, which has a local utility.  Now that Hanno has factored out  
the RAM cache into zope.ramcache, we'd like the persistent utility to  
reference zope.ramcache, so that we can remove our  

I've been trying to make this work using a temporary module alias  
(code below), but something strange is going on.  In particular,  
unghosting the persistent utilities registry is affecting things  
somehow...before that happens, doing a repr of IRAMCache gives:
<InterfaceClass zope.ramcache.interfaces.ram.IRAMCache>
...(what I'd expect, I guess, given my module alias)...but after the  
registry is unghosted, it gives:
...(which is what I'm actually hoping for, in order to unregister the  
old utility)...but then I also get:
(Pdb) zope.ramcache.interfaces.ram.IRAMCache
...(e.g., now accessing it via the new module gives a class that  
thinks its in the old module)

Sorry for the rather muddled description, but I haven't been able to  
really understand what's going on there yet.

So what am I missing or doing wrong?  Is there a better way to go  
about this?

def relocateRamCacheUtility(portal):

     # temporary module alias
         old_zope_app_cache =
     except ImportError:
         old_zope_app_cache = None
     import zope.ramcache = sys.modules[''] = zope.ramcache

     sm = getSiteManager(context=portal)
     # make sure the persistent utilities registry is unghosted before  
     # reference the old interface name, as it seems to make a  
difference in
     # whether it can be unregistered (WTF?)

     component = sm.getUtility(
     import zope.ramcache
     import pdb; pdb.set_trace( )
         provided=zope.ramcache.interfaces.ram.IRAMCache)'Updated the import location of the local IRAMCache  

     # reset the module alias = sys.modules[''] = old_zope_app_cache


David Glick
Web Developer

New tools and strategies for engaging people in protecting the  
work: (206) 286-1235 x32
mobile: (206) 679-3833

Subscribe to ONEList, our email newsletter!
Practical advice for effective online engagement

Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to