[CMF-checkins] CVS: CMF/CMFWorkspaces - References.py:1.5 Workspace.py:1.4

Casey Duncan casey@zope.com
Fri, 19 Jul 2002 17:01:29 -0400


Update of /cvs-repository/CMF/CMFWorkspaces
In directory cvs.zope.org:/tmp/cvs-serv21763

Modified Files:
	References.py Workspace.py 
Log Message:
First crack at direct FTP traversal of workspaces
The biggest change is that the ids of references are no longer a numeric sequence. They are uniquified versions of the ids of the objects being referred. Most of the time the workspace id is the same as the referenced object.
This is minimal support. It supports only traversal and not arbitrary PUT handling directly in the workspace. PUTs into referenced subobjects are possible.


=== CMF/CMFWorkspaces/References.py 1.4 => 1.5 ===
     security = ClassSecurityInfo()
 
     _reference_factory = PortalRelativeReference
-    _next_id = 1
     _ignore_dups = 1
 
     def __init__(self):
         self._refs = {}
 
-    def _new_id(self):
-        """Produce a new, unique string id."""
-        id = str(self._next_id)
-        self._next_id += 1
+    def _new_id(self, object):
+        """Produce a new, locally unique string id for an object."""
+        id = object.getId()
+        i = 0
+        while self._refs.has_key(id):
+            i += 1
+            id = '%s~%d' % (object.getId(), i)
         return id
 
     security.declarePrivate('addReference')
@@ -132,7 +134,7 @@
                 if other == r:
                     # We already have a reference to this object.
                     return
-        self._refs[self._new_id()] = r
+        self._refs[self._new_id(object)] = r
         self._p_changed = 1
 
     security.declarePrivate('removeReference')
@@ -148,6 +150,11 @@
     def keys(self):
         """Return all reference ids."""
         return self._refs.keys()
+        
+    security.declarePrivate('has_key')
+    def has_key(self, key):
+        """Check for existence of key"""
+        return self._refs.has_key(key)
 
     security.declarePrivate('values')
     def values(self):


=== CMF/CMFWorkspaces/Workspace.py 1.3 => 1.4 ===
 """
 
 from types import StringType
+import marshal
 
 import Globals
 from DateTime import DateTime
-from AccessControl import ClassSecurityInfo
+from AccessControl import ClassSecurityInfo, User, getSecurityManager
 from Products.CMFCore import CMFCorePermissions, PortalContent
 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
 
@@ -151,7 +152,66 @@
             seq.reverse()
 
         return map(lambda item: item[1:], seq)
-
+        
+    ## Basic FTP Support ##
+    
+    # The main thing we are punting on right now is generic PUT support into
+    # the workspace. Subobjects can implement there own PUT factories to deal
+    # with it down below.
+    
+    def manage_FTPlist(self, REQUEST):
+        """ FTP dir list """
+        # Things currently missing: recursion and globbing support
+        # Hey, I said it was basic ;^)
+        out = []
+        for id, ob in self.listReferencedItems():
+            try:
+                stat = marshal.loads(ob.manage_FTPstat(REQUEST))
+            except:
+                pass # Skip broken objects
+            else:
+                out.append((id, stat))
+        
+        return marshal.dumps(out)
+        
+    def manage_FTPstat(self, REQUEST):
+        """ FTP stat for listings """
+        mode = 0040000
+        
+        try:
+            if getSecurityManager().validateValue(self.manage_FTPlist):
+                mode=mode | 0770
+        except: 
+            pass
+        
+        # Check for anonymous access
+        if User.nobody.allowed(
+                    self.manage_FTPlist,
+                    self.manage_FTPlist.__roles__):
+            mode=mode | 0007
+            
+        mtime=self.bobobase_modification_time().timeTime()
+        
+        # get owner and group
+        owner=group='Zope'
+        for user, roles in self.get_local_roles():
+            if 'Owner' in roles:
+                owner=user
+                break
+                
+        return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
+        
+    ## Basic traversal support ##        
+
+    def __getitem__(self, key):
+        """ Returns an object based on its unique workspace key """
+        # Return the referenced object wrapped in our context
+        return self._refs[key].dereference(self)
+        
+    def has_key(self, key):
+        """ read-only mapping interface """
+        return self._refs.has_key(key)
+        
 Globals.InitializeClass(Workspace)