[Twisted-Python] rfc: pb filetransfers

Paul Boehm typo at soniq.net
Thu Aug 29 13:34:56 EDT 2002

My approach to doing pb filetransfers is attached,
Suggestions welcome!

this code should illustrate the basic idea:

# A Session is a chain of Jobs that are carried out in order,
# one after another.

# The server builds a custom Session from Mixins, to provide
# only the jobs he wants to accept. ServerSession is the base
# class (pb.Viewable).
# FileSSM is the ServerSessionMixin for Filetransfers.
class FileSession(session.ServerSession, session.FileSSM):

# Then that class is offered to clients via callRemote.
class FilePerspective(pb.Perspective):
    def perspective_getsession(self):
        return FileSession()

# That's all, the server now provides file transfer functionality
# to clients.

# Client builds a Custom Session too.
# FileCSM is the ClientSessionMixin for Filetransfers,
# CallableCSM provides session.call(func, args)
#   which is used to call a function after some other
#   job has completed (e.g. a file download)
class MySession(session.ClientSession, session.FileCSM, session.CallableCSM):

# Then a session is requested from the server, and the received
# deferred is wrapped by MySession. After that we can queue jobs
# on the session.
session = MySession(perspective.callRemote("getsession"))
session.sendfile("/etc/hosts", "remotecopy")
session.getfile("/etc/passwd", "localcopy")
session.getfile("/etc/hosts", "localcopy")
session.call(woot, "Done with Session.")

# Go!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SAM3.tgz
Type: application/x-gzip
Size: 2421 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20020829/5b40312e/attachment.bin 

More information about the Twisted-Python mailing list