diff options
| -rw-r--r-- | CHANGES.txt | 7 | ||||
| -rw-r--r-- | repoze/bfg/zcml.py | 26 |
2 files changed, 31 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 5426da283..83126b062 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,12 @@ Next release + - The component registration handler for views (functions or class + instances) now observes component adaptation annotations (see + ``zope.component.adaptedBy``) and uses them before the fallback + values for ``for_`` and ``request_type``. This change does not + affect existing code insomuch as the code does not rely on these + defaults when an annotation is set on the view (unlikely). + - Strip all slashes from end and beginning of path in clean_path within traversal machinery. diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index 960be33bc..aba5847d2 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -2,10 +2,12 @@ import cPickle import os from os.path import realpath import time +import types from zope.configuration import xmlconfig from zope.component import getSiteManager +from zope.component import adaptedBy import zope.configuration.config from zope.component.interface import provideInterface @@ -36,7 +38,7 @@ def view(_context, for_=None, view=None, name="", - request_type=IRequest, + request_type=None, cacheable=True, ): @@ -50,6 +52,26 @@ def view(_context, args = ('', for_) ) + # views may be either functions or class instances + if isinstance(view, types.FunctionType): + adapted_by = adaptedBy(view) + else: + adapted_by = adaptedBy(type(view)) + + if adapted_by is not None: + try: + if for_ is None: + for_, _ = adapted_by + if request_type is None: + _, request_type = adapted_by + except ValueError: + # the component adaptation annotation does not conform to + # the view specification; we ignore it. + pass + + if request_type is None: + request_type = IRequest + if permission: pfactory = ViewPermissionFactory(permission) _context.action( @@ -150,7 +172,7 @@ def zcml_configure(name, package, load=cPickle.load): return file_configure(name, package) mtime = os.stat(realpath(file)).st_mtime - + if mtime >= ptime: return file_configure(name, package) |
