[Zope3-dev] Important IFile bug!
Jim Fulton
jim at zope.com
Mon Jan 17 10:53:10 EST 2005
Jim Fulton wrote:
> Roger Ineichen wrote:
>
>> Ok I see...
>>
>>
>>> -----Original Message-----
>>> From: Jim Fulton [mailto:jim at zope.com] Sent: Monday, January 17, 2005
>>> 12:58 PM
>>> To: dev at projekt01.ch
>>> Cc: zope3-dev at zope.org
>>> Subject: Re: [Zope3-dev] Important IFile bug!
>>>
>>> Roger Ineichen wrote:
>>>
>>>> Hi jim
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Jim Fulton [mailto:jim at zope.com] Sent: Friday, January 14,
>>>>> 2005 5:30 PM
>>>>> To: dev at projekt01.ch
>>>>> Cc: zope3-dev at zope.org
>>>>> Subject: Re: [Zope3-dev] Important IFile bug!
>>>>>
>>>>> Roger Ineichen wrote:
>>>>>
>>>>> ...
>>>>>
>>>>>
>>>>>
>>>>>> Ok, what can I do?
>>>>>>
>>>>>> Should I implement a IData field and enhance this field?
>>>>>
>>>>>
>>>>> I think you should define an IMime schema that defines methods
>>>>> to get and set the data. I suggest that this should be a
>>>>> file-like interface, with, at least, read and write.
>>>>> It should have a mime-type attribute and an encoding
>>>>> attribute, for use with text.
>>>>>
>>>>> Then you should define a mine field (IMImeField/MimeField)
>>>>> for data with this interface.
>>>>
>>>>
>>>>
>>>> This whould mean we change the IFile implementation?
>>>
>>>
>>> IFile should be changes to use a mime field.
>>>
>>>
>>>> Or can we Implement IMime with the attribute
>>>> contentType?
>>>
>>>
>>> We should define a mime data type and provide a field
>>> and widget to support it.
>>>
>>>
>>>> like:
>>>>
>>>> class IMime(Interface):
>>>>
>>>> contentType = BytesLine(
>>>> title = _(u'Content Type'),
>>>> description=_(u'[...].'),
>>>> default='',
>>>> required=False,
>>>> missing_value=''
>>>> )
>>>>
>>>> class IFile(IIMime):
>>>>
>>>> data = FileData(*) (
>>>> title=_(u'Data'),
>>>> description=_(u'[...]'),
>>>> default='',
>>>> missing_value='',
>>>> required=False,
>>>> )
>>>>
>>>> (*)The field FileData will replace the Bytes field and validate
>>>> Bytes and FileChunk.
>>>
>>>
>>> No
>>>
>>> class IMime(Interface):
>>>
>>> data = ...
>>>
>>> contentType = ...
>>>
>>> encoding = ...
>>>
>>> class IFile(Interface):
>>>
>>> def open(mode='r'):
>>> # return a file-like object for reading or updating the
>>> # file value
>>>
>>> # For backward compatibility, a deprecated data attr
>>> data = ... # as is now
>
>
> Waaaaaaa, I got that wrong! Waaaaa waaaa waaaaa.
> (I edited the wrong interface.)
>
> Sorry, This should have been:
>
> class IMime(Interface):
>
> def open(mode='r'):
> # return a file-like object for reading or updating the
> # file value
>
> contentType = ...
>
> encoding = ...
>
> class IFile(Interface):
>
> contents = Mime(...)
>
> # For backward compatibility, a deprecated data attr
> data = ... # as is now
>
>
>
>>
>>
>> And the class File looks like:
>>
>> Class File(Persistent):
>>
>> implements(IFile, IMime)
>>
>> def __init__(self, data='', contentType='', encoding=''):
>> self.data = data
>> self.contentType = contentType
>> self.encoding = encoding
>
>
>
> No:
>
> implements(IFile)
>
> def __init__(self, contents):
> self.contents = contents
>
> def _getData(self):
> return self.contents.open().read()
>
> def _setData(self, v):
> self.contents.open('w').write(v)
Oops, I left out:
data = property(_getData, _setData)
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list