[Checkins] SVN: z3c.jbot/trunk/ Fixed issue where multiple registrations that match the same request would fail in the sense that only one manager (picked randomly) would be allowed to check for an override.
Malthe Borch
mborch at gmail.com
Mon Jan 9 13:40:02 UTC 2012
Log message for revision 123999:
Fixed issue where multiple registrations that match the same request would fail in the sense that only one manager (picked randomly) would be allowed to check for an override.
Changed:
U z3c.jbot/trunk/CHANGES.txt
U z3c.jbot/trunk/z3c/jbot/README.txt
U z3c.jbot/trunk/z3c/jbot/manager.py
U z3c.jbot/trunk/z3c/jbot/patches.py
U z3c.jbot/trunk/z3c/jbot/tests/common.py
U z3c.jbot/trunk/z3c/jbot/tests/test_doctests.py
U z3c.jbot/trunk/z3c/jbot/utility.py
-=-
Modified: z3c.jbot/trunk/CHANGES.txt
===================================================================
--- z3c.jbot/trunk/CHANGES.txt 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/CHANGES.txt 2012-01-09 13:40:01 UTC (rev 123999)
@@ -1,6 +1,15 @@
Changes
=======
+In next release ...
+
+- Fixed an issue where multiple registrations against the same layer
+ would cause only one registration (decided randomly) to have effect.
+
+ The lookup code now uses the specification resolution order to query
+ for override registrations in order of specialization.
+ [malthe]
+
0.7 (2012-01-05)
----------------
Modified: z3c.jbot/trunk/z3c/jbot/README.txt
===================================================================
--- z3c.jbot/trunk/z3c/jbot/README.txt 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/README.txt 2012-01-09 13:40:01 UTC (rev 123999)
@@ -36,6 +36,13 @@
>>> from z3c.jbot.metaconfigure import handler
>>> manager = handler("%s/overrides/interface" % directory, interface.Interface)
+We make sure that the presence of an additional, trivial manager, does
+not affect the result. We register the system temporary directory:
+
+ >>> import tempfile
+ >>> handler(tempfile.tempdir, interface.Interface)
+ <z3c.jbot.manager.TemplateManager object at ...>
+
We should now see that the new filename will be used for rendering:
>>> view.template()
@@ -194,7 +201,7 @@
Unregister overrides.
- >>> for manager in z3c.jbot.utility.getManagers():
+ >>> for manager in z3c.jbot.utility.getManagers(IHTTPRequest):
... manager.unregisterAllDirectories()
>>> view.template()
Modified: z3c.jbot/trunk/z3c/jbot/manager.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/manager.py 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/manager.py 2012-01-09 13:40:01 UTC (rev 123999)
@@ -131,7 +131,7 @@
filename = path.replace(os.path.sep, '.')
if filename not in paths:
self.templates[token] = IGNORE
- return True
+ return
path = paths[filename]
Modified: z3c.jbot/trunk/z3c/jbot/patches.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/patches.py 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/patches.py 2012-01-09 13:40:01 UTC (rev 123999)
@@ -31,7 +31,7 @@
inst = registry[key] = cls.__new__(cls)
inst.__dict__ = template.__dict__.copy()
- for manager in utility.getManagers():
+ for manager in utility.getManagers(layer):
# register template; this call returns ``True`` if the
# template was invalidated (changed filename)
if manager.registerTemplate(inst, template):
@@ -109,7 +109,7 @@
inst = registry[key] = cls.__new__(cls)
inst.__dict__ = obj.__dict__.copy()
- for manager in utility.getManagers():
+ for manager in utility.getManagers(layer):
# register template; this call returns ``True`` if the
# template was invalidated (changed filename)
if manager.registerTemplate(inst, obj):
Modified: z3c.jbot/trunk/z3c/jbot/tests/common.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/tests/common.py 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/tests/common.py 2012-01-09 13:40:01 UTC (rev 123999)
@@ -1,3 +1,6 @@
+import shutil
+import tempfile
+
import zope.component.testing
import zope.configuration.xmlconfig
@@ -15,3 +18,20 @@
pass
else:
zope.configuration.xmlconfig.XMLConfig('configure.zcml', five.pt)()
+
+ test.tempdir = tempfile.tempdir
+ tempfile.tempdir = tempfile.mkdtemp()
+
+
+def tearDown(test):
+ zope.component.testing.tearDown(test)
+
+ try:
+ tempdir = test.tempdir
+ except AttributeError:
+ pass
+ else:
+ try:
+ shutil.rmtree(tempfile.tempdir)
+ finally:
+ tempfile.tempdir = tempdir
Modified: z3c.jbot/trunk/z3c/jbot/tests/test_doctests.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/tests/test_doctests.py 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/tests/test_doctests.py 2012-01-09 13:40:01 UTC (rev 123999)
@@ -7,6 +7,7 @@
zope.testing.doctest.NORMALIZE_WHITESPACE)
from common import setUp
+from common import tearDown
def test_suite():
@@ -19,7 +20,7 @@
'README.txt',
optionflags=OPTIONFLAGS,
setUp=setUp,
- tearDown=zope.component.testing.tearDown,
+ tearDown=tearDown,
globs=globs,
package="z3c.jbot"),
))
Modified: z3c.jbot/trunk/z3c/jbot/utility.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/utility.py 2012-01-09 11:29:32 UTC (rev 123998)
+++ z3c.jbot/trunk/z3c/jbot/utility.py 2012-01-09 13:40:01 UTC (rev 123999)
@@ -1,5 +1,6 @@
-from zope import interface
-from zope import component
+from zope.interface import Interface
+from zope.interface import providedBy
+from zope.component import getGlobalSiteManager
try:
from zope.site.hooks import getSite
@@ -11,14 +12,16 @@
import zope.security.management
import zope.security.interfaces
-import interfaces
+from z3c.jbot.interfaces import ITemplateManager
+
try:
import Acquisition
ZOPE_2 = True
except:
ZOPE_2 = False
+
def getRequest():
if ZOPE_2:
# get request by acquisition
@@ -38,18 +41,32 @@
if IRequest.providedBy(p):
return p
+
def getLayer():
request = getRequest()
if request is not None:
- return interface.providedBy(request)
+ return providedBy(request)
- return interface.Interface
+ return Interface
-def getManagers():
- layer = getLayer()
- gsm = component.getGlobalSiteManager()
- for name, factory in reversed(
- gsm.adapters.lookupAll((layer,), interfaces.ITemplateManager)):
- yield factory(layer)
+def getManagers(layer):
+ try:
+ adapters = getGlobalSiteManager().adapters._adapters[1]
+ except IndexError:
+ return
+
+ for iface in layer.__sro__:
+ by_interface = adapters.get(iface)
+
+ if by_interface is not None:
+ managers = by_interface.get(ITemplateManager)
+
+ if managers is not None:
+ items = managers.items()
+ if len(items) > 1:
+ items = sorted(items)
+
+ for name, factory in items:
+ yield factory(layer)
More information about the checkins
mailing list