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): pass
# 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): pass
# 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! reactor.run()