vendor/Five/1.2b-r20590

view zcml.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2004, 2005 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """ZCML machinery
16 $Id: zcml.py 20007 2005-11-18 13:03:48Z efge $
17 """
18 import os
19 from zope.configuration import xmlconfig
21 _initialized = False
22 _context = None
25 def load_site():
26 """Load a Five/Zope site by finding and loading the appropriate site
27 configuration file."""
28 global _initialized
29 if _initialized:
30 return
31 _initialized = True
33 # load instance site configuration file
34 site_zcml = os.path.join(INSTANCE_HOME, "etc", "site.zcml")
35 if os.path.exists(site_zcml):
36 file = site_zcml
37 else:
38 file = os.path.join(os.path.dirname(__file__), "skel", "site.zcml")
40 global _context
41 _context = xmlconfig.file(file)
44 def load_config(file, package=None, execute=True):
45 """Load an additional ZCML file into the context.
47 Use with extreme care.
48 """
49 global _context
50 _context = xmlconfig.file(file, package, _context, execute=execute)
52 def load_string(s):
53 """Load a snipped of ZCML into the context.
55 Use with extreme care.
56 """
57 global _context
58 _context = xmlconfig.string(s, _context)
60 # clean up code
62 def cleanUp():
63 global _context
64 _context = None
66 from zope.testing.cleanup import addCleanUp
67 addCleanUp(cleanUp)
68 del addCleanUp