convert ftp.retrbinary to file object? - Python language lacks expression?

Robert k.robert at gmx.de
Thu Feb 3 05:08:23 EST 2005


I just tried to convert a (hugh size) ftp.retrbinary run into a
pseudo-file object with .read(bytes) method in order to not consume
500MB on a copy operation.

First I thought, its easy as usual with python using something like
'yield' or so.

Yet I didn't manage to do (without using threads or rewriting
'retrbinary')? Any ideas?

#### I tried a pattern like:
    .... 
    def open(self,ftppath,mode='rb'):
        class FTPFile: #TODO
            ...
            def iter_retr()
                ...
                def callback(blk):
                    how-to-yield-from-here-to-iter_retr blk???
                ftp.retrbinary("RETR %s" % relpath,callback)
            def read(self, bytes=-1):
                ... 
                self.buf+=self.iter.next()
            ...
        ....



More information about the Python-list mailing list