[Zope-Checkins] SVN: Products.Five/branches/1.3/ Port code from Zope 3 making resource directories recursive. Thanks to Richard Waid.

Brian Sutherland jinty at web.de
Fri Oct 27 04:29:02 EDT 2006


Log message for revision 70924:
  Port code from Zope 3 making resource directories recursive. Thanks to Richard Waid.

Changed:
  U   Products.Five/branches/1.3/CHANGES.txt
  U   Products.Five/branches/1.3/browser/resource.py
  U   Products.Five/branches/1.3/browser/tests/resource_ftest.txt
  A   Products.Five/branches/1.3/browser/tests/resource_subdir/
  A   Products.Five/branches/1.3/browser/tests/resource_subdir/resource.txt

-=-
Modified: Products.Five/branches/1.3/CHANGES.txt
===================================================================
--- Products.Five/branches/1.3/CHANGES.txt	2006-10-27 06:00:43 UTC (rev 70923)
+++ Products.Five/branches/1.3/CHANGES.txt	2006-10-27 08:28:58 UTC (rev 70924)
@@ -2,6 +2,16 @@
 Five Changes
 ============
 
+Five 1.3.8 (unreleased)
+=======================
+
+Bugfixes
+--------
+
+* Port code from Zope 3 making resource directories recursive.
+  Thanks to Richard Waid.
+
+
 Five 1.3.7 (2006-08-13)
 =======================
 

Modified: Products.Five/branches/1.3/browser/resource.py
===================================================================
--- Products.Five/branches/1.3/browser/resource.py	2006-10-27 06:00:43 UTC (rev 70923)
+++ Products.Five/branches/1.3/browser/resource.py	2006-10-27 08:28:58 UTC (rev 70924)
@@ -213,12 +213,20 @@
     def get(self, name, default=_marker):
         path = self.context.path
         filename = os.path.join(path, name)
-        if not os.path.isfile(filename):
+        isfile = os.path.isfile(filename)
+        isdir = os.path.isdir(filename)
+
+        if not (isfile or isdir):
             if default is _marker:
                 raise KeyError(name)
             return default
-        ext = name.split('.')[-1]
-        factory = self.resource_factories.get(ext, self.default_factory)
+
+        if isfile:
+            ext = name.split('.')[-1]
+            factory = self.resource_factories.get(ext, self.default_factory)
+        else:
+            factory = DirectoryResourceFactory
+
         resource = factory(name, filename)(self.request)
         resource.__name__ = name
         resource.__parent__ = self

Modified: Products.Five/branches/1.3/browser/tests/resource_ftest.txt
===================================================================
--- Products.Five/branches/1.3/browser/tests/resource_ftest.txt	2006-10-27 06:00:43 UTC (rev 70923)
+++ Products.Five/branches/1.3/browser/tests/resource_ftest.txt	2006-10-27 08:28:58 UTC (rev 70924)
@@ -66,6 +66,18 @@
   ...     self.assertEquals(200, response.getStatus())
 
 
+We also can traverse into sub-directories:
+
+  >>> print http(r'''
+  ... GET /test_folder_1_/testoid/++resource++fivetest_resources/resource_subdir/resource.txt HTTP/1.1
+  ... Authorization: Basic manager:r00t
+  ... ''')
+  HTTP/1.1 200 OK
+  ...
+  This is a resource in a subdirectory of a normal resource to test traversal.
+  <BLANKLINE>
+
+
 Clean up
 --------
 

Added: Products.Five/branches/1.3/browser/tests/resource_subdir/resource.txt
===================================================================
--- Products.Five/branches/1.3/browser/tests/resource_subdir/resource.txt	2006-10-27 06:00:43 UTC (rev 70923)
+++ Products.Five/branches/1.3/browser/tests/resource_subdir/resource.txt	2006-10-27 08:28:58 UTC (rev 70924)
@@ -0,0 +1 @@
+This is a resource in a subdirectory of a normal resource to test traversal.


Property changes on: Products.Five/branches/1.3/browser/tests/resource_subdir/resource.txt
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope-Checkins mailing list