Permalink
Browse files

Add a ++unique++ resource traverser for resource directories to cache as

  'plone.stableResource'.

svn path=/plone.resource/trunk/; revision=51793
  • Loading branch information...
1 parent 73fc924 commit 6ea4e07dca48733d30f8f8754962fb6338426596 @lrowe lrowe committed Aug 25, 2011
View
@@ -4,6 +4,10 @@ Changelog
1.0b6 (unreleased)
------------------
+- Add a ++unique++ resource traverser for resource directories to cache as
+ 'plone.stableResource'.
+ [elro]
+
1.0b5 (2011-06-08)
------------------
@@ -10,4 +10,12 @@
class=".download.DownloadView"
/>
+ <!-- Unique traverser -->
+ <adapter
+ name="unique"
+ for=".interfaces.IResourceDirectory zope.publisher.interfaces.IRequest"
+ provides="zope.traversing.interfaces.ITraversable"
+ factory=".traversal.UniqueResourceTraverser"
+ />
+
</configure>
View
@@ -0,0 +1,21 @@
+from zope.interface import Interface
+from zope.interface import implements
+from zope.component import adapts
+from plone.caching.interfaces import IRulesetLookup
+from plone.resource.interfaces import IUniqueResourceRequest
+
+class UniqueResourceLookup(object):
+ """Unique resource ruleset lookup.
+
+ Returns 'plone.stableResource' for requests marked with
+ IUniqueResourceRequest.
+ """
+
+ implements(IRulesetLookup)
+ adapts(Interface, IUniqueResourceRequest)
+
+ def __init__(self, published, request):
+ pass
+
+ def __call__(self):
+ return 'plone.stableResource'
@@ -10,5 +10,8 @@
for=".file.FilesystemFile"
ruleset="plone.resource"
/>
-
+
+ <!-- Unique resource ruleset lookup -->
+ <adapter factory=".caching.UniqueResourceLookup" />
+
</configure>
@@ -1,4 +1,5 @@
from zope.interface import Attribute
+from zope.interface import Interface
from zope.publisher.interfaces import IPublishTraverse
@@ -78,3 +79,7 @@ def importZip(file):
def __delitem__(name):
"""Delete a file or directory inside this directory
"""
+
+
+class IUniqueResourceRequest(Interface):
+ """Marker interface for requests to ++unique++<id>"""
@@ -7,6 +7,7 @@
from zope.component import provideUtility
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from plone.resource.interfaces import IResourceDirectory
+from plone.resource.interfaces import IUniqueResourceRequest
from plone.resource.directory import PersistentResourceDirectory
from plone.resource.directory import FilesystemResourceDirectory
from plone.resource.file import FilesystemFile
@@ -40,7 +41,6 @@ def test_traverse_packaged_type_specific_file(self):
res = self.app.restrictedTraverse('++demo++foo/test.html')
self.assertTrue(isinstance(res, FilesystemFile))
-
def test_traverse_global_directory(self):
dir = FilesystemResourceDirectory(test_dir_path)
@@ -74,3 +74,20 @@ def test_publish_resource(self):
browser.open(self.app.absolute_url() + '/++demo++foo/test.html')
self.assertEqual('asdf', browser.contents)
+
+ def test_traverse_unique_resource_marks_request(self):
+ dir = FilesystemResourceDirectory(test_dir_path)
+ provideUtility(dir, provides=IResourceDirectory, name=u'')
+
+ res = self.app.restrictedTraverse('++demo++foo/++unique++bar/test.html')
+ self.assertTrue(IUniqueResourceRequest.providedBy(self.app.REQUEST))
+
+ def test_publish_unique_resource(self):
+ dir = FilesystemResourceDirectory(test_dir_path)
+ provideUtility(dir, provides=IResourceDirectory, name=u'')
+
+ browser = z2.Browser(self.app)
+ browser.handleErrors = False
+
+ browser.open(self.app.absolute_url() + '/++demo++foo/++unique++bar/test.html')
+ self.assertEqual('asdf', browser.contents)
@@ -1,6 +1,8 @@
import urllib
+from zope.interface import alsoProvides
from zope.traversing.namespace import SimpleHandler
+from plone.resource.interfaces import IUniqueResourceRequest
from plone.resource.utils import queryResourceDirectory
from zExceptions import NotFound
@@ -23,3 +25,15 @@ def traverse(self, name, remaining):
return res
raise NotFound
+
+
+class UniqueResourceTraverser(SimpleHandler):
+ """A traverser to allow unique URLs for caching"""
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def traverse(self, name, remaining):
+ alsoProvides(self.request, IUniqueResourceRequest)
+ return self.context

0 comments on commit 6ea4e07

Please sign in to comment.