[Zope3-checkins] CVS: Zope3/lib/python/Zope/Publisher/VFS - VFSFileView.py:1.1

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


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/VFS
In directory cvs.zope.org:/tmp/cvs-serv7739/Zope/Publisher/VFS

Added Files:
	VFSFileView.py 
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/Publisher/VFS/VFSFileView.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.
#
##############################################################################
"""VFS-View for IFile

VFS-view implementation for a generic file. 

$Id: VFSFileView.py,v 1.1 2002/12/20 10:31:49 srichter Exp $
"""
import datetime
zerotime = datetime.datetime.fromtimestamp(0)

from Zope.ComponentArchitecture import queryAdapter

from Zope.Publisher.VFS.VFSView import VFSView
from Zope.Publisher.VFS.IVFSFilePublisher import IVFSFilePublisher

from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore


class VFSFileView(VFSView):
    """Abstract class providing the infrastructure for a basic VFS view
    for basic file-like content object."""

    __implements__ = IVFSFilePublisher, VFSView.__implements__


    # These methods need to be implmented by the real view class

    def _setData(self, data):
        raise NotImplemented

    def _getData(self):
        raise NotImplemented

    def _getSize(self):
        return len(self._getData())

    ############################################################
    # Implementation methods for interface
    # Zope.Publisher.VFS.IVFSFilePublisher.

    def read(self, mode, outstream, start = 0, end = -1):
        """See Zope.Publisher.VFS.IVFSFilePublisher.IVFSFilePublisher"""
        
        data = self._getData()
        try:
            if start != 0: data = data[start:]
            if end != -1: data = data[:end]
        except TypeError:
            pass
        outstream.write(data)


    def write(self, mode, instream, start = 0):
        """See Zope.Publisher.VFS.IVFSFilePublisher.IVFSFilePublisher"""
        try:
            instream.seek(start)
        except:
            pass
        self._setData(instream.read())


    def check_writable(self, mode):
        """See Zope.Publisher.VFS.IVFSFilePublisher.IVFSFilePublisher"""
        return 1

    ######################################
    # from: Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher

    def isdir(self):
        """See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher"""
        return 0


    def isfile(self):
        """See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher"""
        return 1


    def stat(self):
        """See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher"""
        dc = queryAdapter(self, IZopeDublinCore)
        if dc is not None:
            modified = dc.modified
            created = dc.created
        else:
            created = zerotime
            modified = zerotime
        if modified is None:
            modified = created

        size = self._getSize()
        uid = "nouser"
        gid = "nogroup"
        return (504, 0, 0, 0, uid, gid, size, modified, modified, created)


    ######################################
    # from: Zope.Publisher.VFS.IVFSPublisher.IVFSPublisher

    def publishTraverse(self, request, name):
        """See Zope.Publisher.VFS.IVFSPublisher.IVFSPublisher"""
        # Traversing always stops here.
        return None

    #
    ############################################################