Closed GoogleCodeExporter closed 9 years ago
Looks like the file.write method doesn't accept a flushing parameter
http://docs.python.org/library/stdtypes.html#file.write so I'm wondering
(educated guess!) if the fix should actually be something more like:
ret = self.wrapped_file.write(string)
if flushing:
self.flush()
return ret
Original comment by gc...@loowis.durge.org
on 24 Aug 2012 at 10:41
Yes, this could be a better way!
So the new function should look like:
def _write(self,string,flushing=False):
ret = self.wrapped_file.write(string)
if flushing:
self.flush()
return ret
right?
I'll test it :-), THX.
Original comment by mkhom...@googlemail.com
on 24 Aug 2012 at 12:04
Doesn't help, I Attaced an exable script where you can see my Problem.
Is there a Bug in my implementation?????
##Code##
from fs.base import *
from fs.errors import *
from fs.filelike import *
class TestFS(FS):
def open(self ,path ,mode='r'):
myfileobj = TestFile()
file_obj = FileWrapper(myfileobj,mode)
return file_obj
#That is a testfile
#I Use the buffer of this file like described in filelike base:
#~ def _write(self,string,flushing=False):
#~ """Write the given string to the file-like object.
#~
#~ This method must be implemented by subclasses wishing to be writable.
#~ It must attempt to write as much of the given data as possible to the
#~ file, but need not guarantee that it is all written. It may return
#~ None to indicate that all data was written, or return as a string any
#~ data that could not be written.
#~
#~ If the keyword argument 'flushing' is true, it indicates that the
#~ internal write buffers are being flushed, and *all* the given data
#~ is expected to be written to the file. If unwritten data is returned
#~ when 'flushing' is true, an IOError will be raised.
#~ """
class TestFile(file):
def __init__(self):
self.offset = 0
def read(self, size):
return None
def seek(self, seek, whence=0):
if whence == 0:
if seek != self.offset:
self.flush()
if whence == 0:
self.offset = seek
if whence == 1:
self.offset = self.offset + seek
if whence == 2:
self.offset = self.size - seek
def tell(self):
return self.offset
def write(self, data, flushing=False):
print 'write',len(data),flushing
#I'm working with 1MB Blocks!!!
if len(data) < 1024*1024 and flushing == False:
return data
else:
print 'write: take 1 MB and write it, if no flushing: return the rest else write all'
def flush(self):
#Flush doesnt help, because the Data is not in my buffer
print 'flush'
fso = TestFS()
file = fso.open(file,'w+')
file.write(100*'x')
file.flush()
file.close()
Original comment by mkhom...@googlemail.com
on 25 Aug 2012 at 2:28
Attachments:
I think you're muddling up the write() method on file objects (which doesn't
have a flushing parameter) and the _write() method on FileWrapper objects
(which does have a flushing parameter).
I can't quite tell what it is you're trying to do, but I think you might want
to add a subclass of FileWrapper that does the write-buffering for you?
Original comment by gc...@loowis.durge.org
on 25 Aug 2012 at 4:14
Not sure what the resolution is on this one, if it's a bug at all. Closing it
for now. If there is still an issue, feel free to re-open with more details...
Original comment by willmcgugan
on 10 Sep 2013 at 9:14
Original issue reported on code.google.com by
mkhom...@googlemail.com
on 24 Aug 2012 at 10:11