2 # okay, this demo is more advanced. here we'll learn about:
\r
3 # * redirecting standard files
\r
4 # * synchronous callbacks
\r
5 # * the ulitities module
\r
9 from Rpyc.Factories import SocketConnection
\r
10 from Rpyc.Utils import hasattr, getattr, reload, upload, remote_interpreter
\r
12 c = SocketConnection("localhost", 22222)
\r
15 # redirect our stdout to the server
\r
17 sys.stdout = c.modules.sys.stdout
\r
18 print "this time we focus on `the seatle music`"
\r
21 # and the other way round
\r
23 sys.stdout = sys.__stdout__
\r
24 c.modules.sys.stdout = sys.stdout
\r
25 c.modules.sys.stdout.write("alice in chains\n")
\r
28 # but you dont believe me, so
\r
30 c.modules.Rpyc.Demo.testmodule.printer("tool")
\r
35 c.modules.sys.stdout = c.modules.sys.__stdout__
\r
38 # now let's play with callbacks
\r
43 c.modules.Rpyc.Demo.testmodule.caller(f, "nirvana")
\r
49 c.modules.Rpyc.Demo.testmodule.caller(func, text)
\r
51 c.modules.Rpyc.Demo.testmodule.caller(g, f, "soundgarden")
\r
54 # now for the utilities module. it gives us the following cool functions:
\r
55 # * dir, getattr, hasattr, help, reload -- overriding builtins
\r
56 # * upload, download -- transfering files/directories to/from the client/server (all the permutations)
\r
57 # * remote_shell, remote_interpreter -- running remote processess and debugging
\r
59 print hasattr(sys, "path")
\r
60 print hasattr(c.modules.sys, "path")
\r
62 print getattr(sys, "maxint")
\r
63 print getattr(c.modules.sys, "maxint")
\r
66 print reload(c.modules.sys)
\r
68 f=open("lala.txt", "w")
\r
69 f.write("king crimson")
\r
71 upload(c, "lala.txt", "../lala.txt")
\r
72 os.remove("lala.txt")
\r
73 c.modules.os.remove("../lala.txt")
\r
75 remote_interpreter(c)
\r