Back to index

plone3  3.1.7
five.py
Go to the documentation of this file.
00001 #
00002 # Component architecture support
00003 #
00004 
00005 # $Id: five.py 37194 2007-02-13 15:40:24Z shh42 $
00006 
00007 from __future__ import nested_scopes
00008 
00009 try:
00010     from zope.testing.cleanup import cleanUp as _cleanUp
00011 except ImportError:
00012     try:
00013         from zope.app.testing.placelesssetup import tearDown as _cleanUp
00014     except ImportError:
00015         # Zope < 2.8
00016         def _cleanUp(): pass
00017 
00018 
00019 def cleanUp():
00020     '''Cleans up the component architecture.'''
00021     _cleanUp()
00022     import Products.Five.zcml as zcml
00023     zcml._initialized = 0
00024 
00025 
00026 def setDebugMode(mode):
00027     '''Allows manual setting of Five's inspection of debug mode
00028        to allow for ZCML to fail meaningfully.
00029     '''
00030     import Products.Five.fiveconfigure as fc
00031     fc.debug_mode = mode
00032 
00033 
00034 def safe_load_site():
00035     '''Loads entire component architecture (w/ debug mode on).'''
00036     cleanUp()
00037     setDebugMode(1)
00038     import Products.Five.zcml as zcml
00039     zcml.load_site()
00040     setDebugMode(0)
00041 
00042 
00043 def safe_load_site_wrapper(func):
00044     '''Wraps func with a temporary loading of entire component
00045        architecture. Used as a decorator.
00046     '''
00047     def wrapped_func(*args, **kw):
00048         safe_load_site()
00049         value = func(*args, **kw)
00050         cleanUp()
00051         return value
00052     return wrapped_func
00053