[Zope-dev] zope.filerepresentation

Martin Aspeli optilude+lists at gmail.com
Thu Oct 1 09:51:14 EDT 2009


Hanno Schlichting wrote:
> On Thu, Oct 1, 2009 at 2:13 AM, Martin Aspeli <optilude+lists at gmail.com> wrote:
>> Hanno Schlichting wrote:
>>
>>> Is there any reason to invent a new API and not just use Python's file API?
>> I don't know. IReadFile and IWriteFile have been around for ever and are
>> used by a number of things in Zope. They have read(), write() and
>> size(). The first two are on file, the last one isn't. I'd like to be
>> able to use this API as a base, since it's used for things like
>> z3c.blobfile already, and is documented as the way to do this kind of
>> thing in Philipp's book.
> 
> Ok. I have a feeling that Zope3 at various times invented a new
> Java-ish API instead of using standard Python protocols. I'd just like
> to avoid going down that way even more.
> 
>> class IReadFile(Interface):
>>     """Provide read access to file data
>>     """
>>
>>     def read():
>>         """Return the file data as a str
>>         """
>>
>>     def size():
>>         """Return the data length
>>         """
> 
> This needs a clarification on what kind of length this is. Is it the
> length of the binary data? Since these interfaces also know about
> encoding, it's otherwise not clear if the size for textual data might
> be its Unicode length.

I assume so. Note that this interface already exists, so I'm not 
proposing to change it. ;-)

>> 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 or undefined.
>>         """
>>
>>     name = schema.TextLine(title=u"Filename", readonly=True)
>>     encoding = schema.ASCIILine(title=u"Encoding", readonly=True)
> 
> encoding only makes sense for text/*, so maybe some small hint at that?

Sure, yeah.

>>     def __iter__():
>>         """Get an iterator"""
>>
>>     def next():
>>         """See file"""
>>
>>     def seek():
>>         """See file"""
>>
>>     def tell():
>>         """See file"""
>>
>> class IWriteFile(Interface):
>>
>>     def write(data):
>>         """Update the file data
>>         """
>>
>> class ILargeWriteFile(IWriteFile):
>>
>>     def write(data):
>>         """Write a chunk of data
>>         """
>>
>>     name = schema.TextLine(title=u"Filename", readonly=False)
>>     encoding = schema.ASCIILine(title=u"Encoding", readonly=False)
>>
>>     def tell():
>>         """See file"""
>>
>>     def close():
>>         """See file""
>>
>> I've still got the content type as a method (maybe make it a read-only
>> property?) that may return None. That could be in a separate adapter,
>> but that feels like overkill to me. :)
> 
> There's no standard way to spell "content type", so I don't really
> care. On the pure file level it's even called mime type and only
> internet data handling uses "content type". So you have to look things
> up anyways. Compared to the other attributes/methods "getContentType"
> looks like a Java-intruder in otherwise Python naming conventions,
> though.

Haha. Maybe I'll have a property mimeType instead? That looks better, I 
guess.

But we *are* in a Zope package, so Zope naming conventions probably apply.

Ok, I'm going to do this shortly, unless anyone objects.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book



More information about the Zope-Dev mailing list