[Zope3-checkins] SVN: Zope3/branches/3.3/ - Backport for fix of #728

Christian Theune ct at gocept.com
Mon Dec 18 04:14:13 EST 2006


Log message for revision 71583:
   - Backport for fix of #728
  

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/app/folder/filerepresentation.py
  A   Zope3/branches/3.3/src/zope/app/folder/filerepresentation.txt
  U   Zope3/branches/3.3/src/zope/app/folder/tests.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-12-18 09:13:47 UTC (rev 71582)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-12-18 09:14:12 UTC (rev 71583)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed bug #728:  Able to change-dir into non-existant directories
+        using FTP
+
       - Fixed bug #717: formlib raised FormError when schema fields were
         missing from a request although not required.
 

Modified: Zope3/branches/3.3/src/zope/app/folder/filerepresentation.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/folder/filerepresentation.py	2006-12-18 09:13:47 UTC (rev 71582)
+++ Zope3/branches/3.3/src/zope/app/folder/filerepresentation.py	2006-12-18 09:14:12 UTC (rev 71583)
@@ -19,7 +19,9 @@
 
 from zope.app.component.interfaces import ISite
 
+MARKER = object()
 
+
 class RootDirectoryFactory(object):
 
     def __init__(self, context):
@@ -30,8 +32,7 @@
 
 
 class ReadDirectory(object):
-    """Adapter to provide a file-system rendition of folders
-    """
+    """Adapter to provide a file-system rendition of folders."""
 
     def __init__(self, context):
         self.context = context
@@ -45,15 +46,14 @@
     def get(self, key, default=None):
         if key == '++etc++site' and ISite.providedBy(self.context):
             return self.context.getSiteManager()
-
         return self.context.get(key, default)
 
     def __iter__(self):
         return iter(self.keys())
 
     def __getitem__(self, key):
-        v = self.get(key, self)
-        if v is self:
+        v = self.get(key, MARKER)
+        if v is MARKER:
             raise KeyError(key)
         return v
 

Added: Zope3/branches/3.3/src/zope/app/folder/filerepresentation.txt
===================================================================
--- Zope3/branches/3.3/src/zope/app/folder/filerepresentation.txt	2006-12-18 09:13:47 UTC (rev 71582)
+++ Zope3/branches/3.3/src/zope/app/folder/filerepresentation.txt	2006-12-18 09:14:12 UTC (rev 71583)
@@ -0,0 +1,87 @@
+===============================
+File representation for folders
+===============================
+
+Folders can be represented in file-system-like protocols (e.g. FTP). An
+adapter abstracts some internals away and adds support for accessing the
+'++etc++site' folder from those protocols.
+
+  >>> folder = getRootFolder()
+  >>> from zope.app.folder.filerepresentation import ReadDirectory
+  >>> fs_folder = ReadDirectory(folder)
+
+As the root folder is a site, the ++etc++site object appears:
+
+  >>> fs_folder.keys()
+  ['++etc++site']
+  >>> fs_folder.get('++etc++site')
+  <LocalSiteManager ++etc++site>
+  >>> fs_folder['++etc++site']
+  <LocalSiteManager ++etc++site>
+  >>> list(fs_folder.__iter__())
+  ['++etc++site']
+  >>> fs_folder.values()
+  [<LocalSiteManager ++etc++site>]
+  >>> len(fs_folder)
+  1
+  >>> fs_folder.items()
+  [('++etc++site', <LocalSiteManager ++etc++site>)]
+  >>> '++etc++site' in fs_folder
+  True
+
+Let's add another folder to see how a non-site folder behaves:
+
+  >>> from zope.app.folder.folder import Folder
+  >>> folder['test'] = Folder()
+
+The site folder now contains the new folder:
+
+  >>> fs_folder.keys()
+  [u'test', '++etc++site']
+  >>> fs_folder.get('test')
+  <zope.app.folder.folder.Folder object at 0x...>
+  >>> fs_folder['test']
+  <zope.app.folder.folder.Folder object at 0x...>
+  >>> list(fs_folder.__iter__())
+  [u'test', '++etc++site']
+  >>> fs_folder.values()
+  [<zope.app.folder.folder.Folder object at 0x...>, <LocalSiteManager ++etc++site>]
+  >>> len(fs_folder)
+  2
+  >>> fs_folder.items()
+  [(u'test', <zope.app.folder.folder.Folder object at 0x...>),
+   ('++etc++site', <LocalSiteManager ++etc++site>)]
+  >>> 'test' in fs_folder
+  True
+
+The new folder isn't a site manager and doesn't have any entries:
+
+  >>> fs_folder2 = ReadDirectory(folder['test'])
+  >>> list(fs_folder2.keys())
+  []
+  >>> fs_folder2.get('test', )
+  >>> fs_folder2['test']
+  Traceback (most recent call last):
+  KeyError: 'test'
+  >>> list(fs_folder2.__iter__())
+  []
+  >>> fs_folder2.values()
+  []
+  >>> len(fs_folder2)
+  0
+  >>> fs_folder2.items()
+  []
+  >>> 'test' in fs_folder2
+  False
+
+This is a short regression test for #728: we get a KeyError when trying to
+access non-existing entries:
+
+  >>> from zope.security.proxy import ProxyFactory
+  >>> from zope.security.checker import NamesChecker
+  >>> proxied_folder = ProxyFactory(fs_folder, NamesChecker(('get',)))
+  >>> proxied_fs_folder = ReadDirectory(proxied_folder)
+  >>> print proxied_fs_folder['i dont exist']
+  Traceback (most recent call last):
+  KeyError: 'i dont exist'
+


Property changes on: Zope3/branches/3.3/src/zope/app/folder/filerepresentation.txt
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/src/zope/app/folder/tests.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/folder/tests.py	2006-12-18 09:13:47 UTC (rev 71582)
+++ Zope3/branches/3.3/src/zope/app/folder/tests.py	2006-12-18 09:14:12 UTC (rev 71583)
@@ -20,9 +20,11 @@
 
 import zope.component
 from zope.testing.doctestunit import DocTestSuite
+from zope.testing import doctest
 from zope.dublincore.interfaces import IZopeDublinCore
 from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
 
+from zope.app.testing.functional import FunctionalDocFileSuite
 from zope.app.folder.interfaces import IFolder
 from zope.app.component.testing import PlacefulSetup
 from zope.app.component.tests.test_site import BaseTestSiteManagerContainer
@@ -60,9 +62,11 @@
     return TestSuite((
         makeSuite(Test),
         makeSuite(FolderMetaDataTest),
+        FunctionalDocFileSuite("filerepresentation.txt",
+                               optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE),
         DocTestSuite('zope.app.folder.folder',
                      setUp=setUp, tearDown=tearDown),
-        ))    
+        ))
 
 if __name__=='__main__':
     main(defaultTest='test_suite')



More information about the Zope3-Checkins mailing list