[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/VFS - Adding.py:1.1 ContainerTraverser.py:1.1 configure.zcml:1.1

Stephan Richter srichter@cbu.edu
Fri, 20 Dec 2002 05:31:46 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Views/VFS
In directory cvs.zope.org:/tmp/cvs-serv7739/Zope/App/OFS/Container/Views/VFS

Added Files:
	Adding.py ContainerTraverser.py configure.zcml 
Log Message:
Big oops. I fogot to checkin the added files. This is the rest of the VFS/FTP fix and revamp checkin.


=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/Adding.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Adding View for IContentContainer

This 

$Id: Adding.py,v 1.1 2002/12/20 10:31:45 srichter Exp $
"""
from Zope.ComponentArchitecture import getAdapter

from Zope.Event import publish
from Zope.Event.ObjectEvent import ObjectAddedEvent

from Zope.Publisher.IPublishTraverse import IPublishTraverse
from Zope.Publisher.VFS.VFSView import VFSView

from Zope.App.OFS.Container.IAdding import IAdding
from Zope.App.OFS.Container.IContainer import IContainerNamesContainer
from Zope.App.OFS.Container.IZopeContainer import IZopeContainer


class Adding(VFSView):

    __implements__ =  IAdding, VFSView.__implements__

    ############################################################
    # Implementation methods for interface
    # IAdding.py

    def add(self, content):
        'See Zope.App.OFS.Container.IAdding.IAdding'
        container = self.context
        container = getAdapter(container, IZopeContainer)
        name = container.setObject(self.contentName, content)
        publish(self.context, ObjectAddedEvent(container[name]))
        return container[name]

    def setContentName(self, name):
        self.contentName = name
        
    # See Zope.App.OFS.Container.Views.Browser.IAdding.IAdding
    contentName = None # usually set by setContentName

    ######################################
    # from: Zope.ComponentArchitecture.IPresentation.IPresentation

    # See Zope.ComponentArchitecture.IPresentation.IPresentation
    request = None # set in VFSView.__init__

    ######################################
    # from: Zope.ComponentArchitecture.IContextDependent.IContextDependent

    # See Zope.ComponentArchitecture.IContextDependent.IContextDependent
    context = None # set in VFSView.__init__





=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/ContainerTraverser.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""Define VFS View Traverser for folder contents.

$Id: ContainerTraverser.py,v 1.1 2002/12/20 10:31:45 srichter Exp $
"""

from Zope.Publisher.VFS.IVFSPublisher import IVFSPublisher
from Zope.Publisher.Exceptions import NotFound
from Zope.App.OFS.Container.IContainer import \
     ISimpleReadContainer, IItemContainer
from Zope.ComponentArchitecture import queryView


class ContainerTraverser:

    __implements__ = IVFSPublisher
    __used_for__ = ISimpleReadContainer

    def __init__(self, container, request):
        """Initialize Traverser."""
        self.context = container
        self.request = request

    def _splitExtension(self, name):
        """Split the possible extension from the name"""
        ext_start = name.rfind(".")
        if ext_start > 0:
            return name[:ext_start], name[ext_start:]
        return name, ""

    def publishTraverse(self, request, name):
        """See Zope.Publisher.IPublishTraverse."""
        context = self.context

        # First, try to resolve the name as we get it.
        subob = context.get(name, None)

        if subob is None:
            # It did not work the first time, so let's try without the
            # extension.
            name, ext = self._splitExtension(name)
            subob = context.get(name, None)

        if subob is None:
            view = queryView(context, name, request)
            if view is not None:
                return view

            raise NotFound(context, name, request)

        return subob


class ItemTraverser(ContainerTraverser):

    __used_for__ = IItemContainer

    def publishTraverse(self, request, name):
        """See Zope.Publisher.IPublishTraverse."""
        context = self.context

        # First, try to resolve the name as we get it.
        try:            
            return context[name]
        except KeyError:
            pass

        # It did not work the first time, so let's try without the extension.
        name, ext = self._splitExtension(name)
        try:            
            return context[name]
        except KeyError:
            view = queryView(context, name, request)
            if view is not None:
                return view

        raise NotFound(context, name, request)



=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/configure.zcml ===
<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:vfs="http://namespaces.zope.org/vfs">

  <vfs:view 
      name="_traverse" 
      for="Zope.App.OFS.Container.IContainer.IItemContainer."
      factory=".ContainerTraverser.ItemTraverser" />

  <vfs:view 
      name="_traverse" 
      for="Zope.App.OFS.Container.IContainer.IReadContainer"
      factory=".ContainerTraverser." />


   <vfs:view
       for="Zope.App.OFS.Container.IContentContainer."
       name="+"  
       factory=".Adding."
       allowed_attributes="setContentName add"
       permission="Zope.ManageContent" />
 
  <!-- Generic VFS Container View -->
  <vfs:view
      name="vfs"
      for="Zope.App.OFS.Container.IContainer."
      permission="Zope.ManageContent" 
      allowed_interface="Zope.Publisher.VFS.IVFSDirectoryPublisher." 
      factory="Zope.App.OFS.Container.Views.VFS.VFSContainerView." 
      />

</zopeConfigure>