This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
/
five.py
71 lines (60 loc) · 1.72 KB
/
five.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Component architecture support
#
# $Id$
from __future__ import nested_scopes
from zope.testing.cleanup import cleanUp as _cleanUp
def cleanUp():
'''Cleans up the component architecture.'''
_cleanUp()
try:
from Zope2.App import zcml
zcml._initialized = 0
except ImportError:
pass
try:
from Products.Five import zcml
zcml._initialized = 0
except ImportError:
pass
def setDebugMode(mode):
'''Allows manual setting of Five's inspection of debug mode
to allow for ZCML to fail meaningfully.
'''
try:
from OFS import metaconfigure
except ImportError:
from Products.Five import fiveconfigure as metaconfigure
metaconfigure.debug_mode = mode
def safe_load_site():
'''Loads entire component architecture (w/ debug mode on).'''
cleanUp()
setDebugMode(1)
try:
from Zope2.App import zcml
except ImportError:
from Products.Five import zcml
zcml.load_site()
try:
from Zope2.App.schema import configure_vocabulary_registry
except ImportError:
try:
from zope.schema.vocabulary import setVocabularyRegistry
from Products.Five.schema import Zope2VocabularyRegistry
except ImportError:
pass
else:
setVocabularyRegistry(Zope2VocabularyRegistry())
else:
configure_vocabulary_registry()
setDebugMode(0)
def safe_load_site_wrapper(func):
'''Wraps func with a temporary loading of entire component
architecture. Used as a decorator.
'''
def wrapped_func(*args, **kw):
safe_load_site()
value = func(*args, **kw)
cleanUp()
return value
return wrapped_func