[Zope-dev] zope.filerepresentation

Hanno Schlichting hanno at hannosch.eu
Wed Sep 30 11:50:13 EDT 2009


On Wed, Sep 30, 2009 at 5:00 PM, Martin Aspeli <optilude+lists at gmail.com> wrote:
> Here's an initial take on the interfaces:
>
> class IReadFile(Interface):
>     """Provide read access to file data
>     """
>
>     def read():
>         """Return the file data as a str
>         """
>
>     def size():
>         """Return the data length
>         """
>
> class ILargeReadFile(IReadFile):
>     """Provide efficient read access to file data
>     """
>
>     def getContentType():
>         """Get the content/MIME type of the file as a string in the form
>         'major/minor'. Return None if this is not known.
>         """
>
>     def getFilename():
>         """Get the intended file name for this file. Return None if this
>         is not known.
>         """
>
>
>     def getIterator():
>         """Return an iterable of the file data
>         """
>
> class IWriteFile(Interface):
>
>     def write(data):
>         """Update the file data
>         """
>
> class ILargeWriteFile(IWriteFile):
>
>     def writeFile(data, contentType=None, encoding=None):
>         """Update the file data.
>
>         data is a file-like object containing input data
>
>         contentType is the content/MIME type of the data as a string in
>         the form 'major/minor'. It may be None if unknown.
>
>         encoding is the encoding of the string. It may be None
>         if unknown.
>         """

Is there any reason to invent a new API and not just use Python's file API?

So .name instead of getFilename, iterator per __iter__ and next?

I'm not sure about the different read/write methods on file-objects,
but I think the standard ones do cover all the same use-cases.

The standard file implementation has no knowledge of its size, as this
is sometimes impossible to get, when dealing with stream based
file-like objects. Do we really need to have files to know their size?

Hanno


More information about the Zope-Dev mailing list