[Zope-Checkins] CVS: Zope/lib/python/ZPublisher/FTP - __init__.py:1.1.2.1 ftp.py:1.1.2.1

Jim Fulton jim@zope.com
Thu, 25 Oct 2001 12:34:47 -0400


Update of /cvs-repository/Zope/lib/python/ZPublisher/FTP
In directory cvs.zope.org:/tmp/cvs-serv28851/lib/python/ZPublisher/FTP

Added Files:
      Tag: ComponentArchitecture-branch
	__init__.py ftp.py 
Log Message:
Various changes (in progress) to reflect tutorial.
Checking in to sync with Shane.



=== Added File Zope/lib/python/ZPublisher/FTP/__init__.py ===
from ftp import FTPPublish, BaseLeafFTPPublish


=== Added File Zope/lib/python/ZPublisher/FTP/ftp.py ===


import Interface


class FTPPublish (Interface.Base):

    def _ftp_traverse(request, name):
        """
        """

    def manage_FTPlist():
        """
        """

    def manage_FTPstat():
        """
        """

    def manage_FTPget():
        """
        """

    def manage_delObjects(ids):
        """
        """

    def manage_addFolder(id):
        """
        """

    def manage_renameObject(id, new_id):
        """
        """

    def PUT():
        """
        """

class BaseLeafFTPPublish:

    __implements__ = FTPPublish

    def _ftp_traverse(self, request, name):
        """
        This is called with the name of a method such as 'manage_FTPget'.
        """
        return getattr(self, name)

    def manage_FTPlist(self):
        """
        """
        import marshal
        stat=marshal.loads(self.manage_FTPstat(REQUEST))
        id = self.getId()
        return marshal.dumps((id,stat))

    def manage_FTPstat(self, REQUEST):
        "psuedo stat, used by FTP for directory listings"
        from AccessControl.User import nobody
        from Acquisition import aq_base
        from AccessControl import getSecurityManager
        import time
        import marshal

        mode=0100000
        
        # check read permissions
        if (hasattr(aq_base(self),'manage_FTPget') and 
            hasattr(self.manage_FTPget, '__roles__')):
            try:
                if getSecurityManager().validateValue(self.manage_FTPget):
                    mode=mode | 0440
            except: pass
            if nobody.allowed(self.manage_FTPget,
                              self.manage_FTPget.__roles__):
                mode=mode | 0004
                
        # check write permissions
        if hasattr(aq_base(self),'PUT') and hasattr(self.PUT, '__roles__'):
            try:
                if getSecurityManager().validateValue(self.PUT):
                    mode=mode | 0220
            except: pass
            
            if nobody.allowed(self.PUT, self.PUT.__roles__):
                mode=mode | 0002
                
        # get size
        if hasattr(aq_base(self), 'get_size'):
            size=self.get_size()
        elif hasattr(aq_base(self),'manage_FTPget'):
            size=len(self.manage_FTPget())
        else:
            size=0
        # get modification time
        if hasattr(aq_base(self), 'bobobase_modification_time'):
            mtime=self.bobobase_modification_time().timeTime()
        else:
            mtime=time.time()
        # get owner and group
        owner=group='Zope'
        if hasattr(aq_base(self), 'get_local_roles'):
            for user, roles in self.get_local_roles():
                if 'Owner' in roles:
                    owner=user
                    break
        return marshal.dumps((mode,0,0,1,owner,group,size,mtime,mtime,mtime))

    def manage_FTPget(self):
        """
        """
        print 'cp4'
        raise NotImplemented

    def manage_delObjects(self, ids):
        """
        """
        print 'cp5'
        raise 'NotSupported'

    def manage_addFolder(self, id):
        """
        """
        print 'cp6'
        raise 'NotSupported'

    def manage_renameObject(self, id, new_id):
        """
        """
        print 'cp7'
        raise 'NotSupported'

    def PUT(self, BODY):
        """
        """
        print 'cp8'
        raise NotImplemented

    def get_size(self):
        return len(self.manage_FTPget())