[Checkins] SVN: z3c.caching/trunk/ We don't need ILastModified to know about the request, so make it a simple adapter.
Martin Aspeli
optilude at gmx.net
Mon Jan 4 10:02:41 EST 2010
Log message for revision 107630:
We don't need ILastModified to know about the request, so make it a simple adapter.
Changed:
U z3c.caching/trunk/README.txt
U z3c.caching/trunk/src/z3c/caching/interfaces.py
U z3c.caching/trunk/src/z3c/caching/lastmodified.py
U z3c.caching/trunk/src/z3c/caching/tests/test_lastmodified.py
-=-
Modified: z3c.caching/trunk/README.txt
===================================================================
--- z3c.caching/trunk/README.txt 2010-01-04 14:14:45 UTC (rev 107629)
+++ z3c.caching/trunk/README.txt 2010-01-04 15:02:41 UTC (rev 107630)
@@ -118,8 +118,8 @@
"""An abstraction to help obtain a last-modified date for a published
resource.
- Should be registered as an unnamed multi-adapter from a published object
- (e.g. a view) and the request.
+ Should be registered as an unnamed adapter from a published object
+ (e.g. a view).
"""
def __call__():
Modified: z3c.caching/trunk/src/z3c/caching/interfaces.py
===================================================================
--- z3c.caching/trunk/src/z3c/caching/interfaces.py 2010-01-04 14:14:45 UTC (rev 107629)
+++ z3c.caching/trunk/src/z3c/caching/interfaces.py 2010-01-04 15:02:41 UTC (rev 107630)
@@ -57,10 +57,12 @@
"""An abstraction to help obtain a last-modified date for a published
resource.
- Should be registered as an unnamed multi-adapter from a published object
- (e.g. a view) and the request.
+ Should be registered as an unnamed adapter from a published object
+ (e.g. a view).
"""
def __call__():
"""Return the last-modified date, as a Python datetime object.
+
+ May return None if the last modified date cannot be determined.
"""
Modified: z3c.caching/trunk/src/z3c/caching/lastmodified.py
===================================================================
--- z3c.caching/trunk/src/z3c/caching/lastmodified.py 2010-01-04 14:14:45 UTC (rev 107629)
+++ z3c.caching/trunk/src/z3c/caching/lastmodified.py 2010-01-04 15:02:41 UTC (rev 107630)
@@ -1,13 +1,13 @@
-from zope.interface import implementer, Interface
-from zope.component import adapter, queryMultiAdapter
+from zope.interface import implementer
+from zope.component import adapter
from zope.browser.interfaces import IView
from z3c.caching.interfaces import ILastModified
@implementer(ILastModified)
- at adapter(IView, Interface)
-def viewDelegateLastModified(view, request):
+ at adapter(IView)
+def viewDelegateLastModified(view):
"""When looking up an ILastModified for a view, look up an ILastModified
for its context. May return None, in which case adaptation will fail.
"""
- return queryMultiAdapter((view.context, request), ILastModified)
+ return ILastModified(view.context, None)
Modified: z3c.caching/trunk/src/z3c/caching/tests/test_lastmodified.py
===================================================================
--- z3c.caching/trunk/src/z3c/caching/tests/test_lastmodified.py 2010-01-04 14:14:45 UTC (rev 107629)
+++ z3c.caching/trunk/src/z3c/caching/tests/test_lastmodified.py 2010-01-04 15:02:41 UTC (rev 107630)
@@ -2,7 +2,7 @@
import zope.component.testing
from zope.interface import implements
-from zope.component import adapts, provideAdapter, queryMultiAdapter
+from zope.component import adapts, provideAdapter
from zope.browser.interfaces import IView
from z3c.caching.interfaces import ILastModified
@@ -34,7 +34,9 @@
context = DummyContext()
request = DummyRequest()
- lastModified = queryMultiAdapter((context, request,), ILastModified)
+ view = DummyView(context, request)
+
+ lastModified = ILastModified(view, None)
self.assertEquals(None, lastModified)
def test_with_adapter(self):
@@ -54,9 +56,9 @@
class DummyLastModified(object):
implements(ILastModified)
- adapts(DummyContext, DummyRequest)
+ adapts(DummyContext)
- def __init__(self, context, request):
+ def __init__(self, context):
self.context = context
self.request = request
@@ -65,7 +67,9 @@
context = DummyContext()
request = DummyRequest()
- lastModified = queryMultiAdapter((context, request,), ILastModified)
+ view = DummyView(context, request)
+
+ lastModified = ILastModified(view)
self.failUnless(isinstance(lastModified, DummyLastModified,))
self.assertEquals(context, lastModified.context)
More information about the checkins
mailing list