[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS - NaiveFile.py:1.1.2.1 NaiveFileEdit.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Sat, 19 Jan 2002 15:05:21 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS
In directory cvs.zope.org:/tmp/cvs-serv7462

Added Files:
      Tag: Zope-3x-branch
	NaiveFile.py NaiveFileEdit.py 
Log Message:
- Added Support for simple File saved in the ZODB
- Provided a Web-based view

Note: You should not use this object to save large pieces of data.


=== Added File Zope3/lib/python/Zope/App/OFS/NaiveFile.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.

import Persistence
from Interface import Interface
from Zope.App.Security.IAttributeRolePermissionManageable \
     import IAttributeRolePermissionManageable


class INaiveFile(Interface):
    """This is a simple implementation of a File in Zope.

    Warning: You should not use this interface to implement large data
             files.
    """


    def edit(data, contentType):
        """Sets the data and the content type for the object."""


    def setData(data):
        """Sets ONLY the data without changing the content type."""
    

    def getData():
        """Returns the bits (data) of the File itself."""


    def setContentType(contentType):
        """Sets the content type of the file."""


    def getContentType():
        """Returns the content type of the file using mime-types syntax."""



_RAISE_KEYERROR = []


class NaiveFile(Persistence.Persistent):
    """ """

    __implements__ = INaiveFile


    def __init__(self, data=None, contentType=None):
        """ """

        self._data = data

        if contentType is None:
            self._contentType = ''
        else:
            self._contentType = contentType
        

    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.NaiveFile.INaiveFile

    def setContentType(self, contentType):
        '''See interface INaiveFile'''
        self._contentType = contentType

        
    def getContentType(self):
        '''See interface INaiveFile'''
        return self._contentType

        
    def edit(self, data, contentType):
        '''See interface INaiveFile'''
        self._data = data
        self._contentType = contentType

    def getData(self):
        '''See interface INaiveFile'''
        return self._data


    def setData(self, data):
        '''See interface INaiveFile'''
        self._data = data
        
    #
    ############################################################
                                                                                



=== Added File Zope3/lib/python/Zope/App/OFS/NaiveFileEdit.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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 view component for naive file editing.
"""

import os

from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
from Zope.PageTemplate.PageTemplateFile import PageTemplateFile

class NaiveFileEdit( AttributePublisher ):

    __implements__ = AttributePublisher.__implements__
    
    def __init__( self, naiveFile ):
        self._naiveFile = naiveFile


    def edit(self, data, contentType, REQUEST=None):

        file = self.getContext()
        file.edit(data, contentType)

        if REQUEST is not None:
            return self.index(REQUEST, msg='File Edited.')


    #
    #   Make it possible for 'index' to find the naiveFile.
    #
    def getContext( self ):
        return self._naiveFile

    index = PageTemplateFile('www/naiveFile_edit.pt')