summaryrefslogtreecommitdiff
path: root/repoze/bfg/zcml.py
diff options
context:
space:
mode:
Diffstat (limited to 'repoze/bfg/zcml.py')
-rw-r--r--repoze/bfg/zcml.py90
1 files changed, 3 insertions, 87 deletions
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 16e6d7012..7ea6eae8d 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -1,7 +1,3 @@
-import cPickle
-import os
-from os.path import realpath
-import time
import types
from zope.configuration import xmlconfig
@@ -28,8 +24,6 @@ from repoze.bfg.interfaces import IRoutesContext
from repoze.bfg.interfaces import IViewPermission
from repoze.bfg.interfaces import IView
-from repoze.bfg.path import package_path
-
from repoze.bfg.security import ViewPermissionFactory
import martian
@@ -132,93 +126,15 @@ class IViewDirective(Interface):
PVERSION = 1
-def pickle_name(name, package):
- path = package_path(package)
- basename = os.path.join(path, name)
- return os.path.join(path, basename + '.cache')
-
-def zcml_configure(name, package, load=cPickle.load):
- """ Execute pickled zcml actions or fall back to parsing from file
- """
- pckname = pickle_name(name, package)
-
- if not (os.path.isfile(pckname) or os.path.islink(pckname)):
- return file_configure(name, package)
-
- try:
- vers, ptime, actions = load(open(pckname, 'rb'))
- except (IOError, cPickle.UnpicklingError, EOFError, TypeError, ValueError,
- AttributeError, NameError, ImportError):
- return file_configure(name, package)
-
- if vers != PVERSION:
- return file_configure(name, package)
-
- try:
- ptime = int(ptime)
- except:
- return file_configure(name, package)
-
- if not hasattr(actions, '__iter__'):
- return file_configure(name, package)
-
- files = set()
- for action in actions:
- try:
- fileset = action[4]
- files.update(fileset)
- except (TypeError, IndexError):
- return file_configure(name, package)
-
- for file in files:
- if not(os.path.isfile(file) or os.path.islink(file)):
- return file_configure(name, package)
-
- mtime = os.stat(realpath(file)).st_mtime
-
- if mtime >= ptime:
- return file_configure(name, package)
-
- context = zope.configuration.config.ConfigurationMachine()
- xmlconfig.registerCommonDirectives(context)
- context.actions = actions
- context.cached_execution = True
- context.execute_actions()
- return True
-
-def remove(name, os=os): # os parameterized for unit tests
- try:
- os.remove(name)
- return True
- except:
- pass
- return False
-
-def file_configure(name, package, dump=cPickle.dump):
+def zcml_configure(name, package):
context = zope.configuration.config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
context.package = package
-
xmlconfig.include(context, name, package)
context.execute_actions(clear=False)
+ return context.actions
- actions = context.actions
- pckname = pickle_name(name, package)
-
- for action in actions:
-
- discriminator = action[0]
- if discriminator and Uncacheable in discriminator:
- remove(pckname)
- return False
-
- try:
- data = (PVERSION, time.time(), actions)
- dump(data, open(pckname, 'wb'), -1)
- except (OSError, IOError, TypeError, cPickle.PickleError):
- remove(pckname)
-
- return False
+file_configure = zcml_configure # backwards compat (>0.8.1)
def exclude(name):
if name.startswith('.'):