From: Rich S. <rs...@zo...> - 2001-09-11 18:05:38
|
Last week, Paul asked to be able to do this: #! /usr/bin/env python2.1 import zsiserver ...various functions... zsiserver.serve_forever() This was analogous to the CGI-oriented dispatching we talked about the previous week. I added it, and it's in ZSI1.1 which will be released by the end of the week. I think I already mentioned the scripting-like client code. So here's a script that can be either CGI or a stand-alone server: #! /usr/bin/env python2.1 from ZSI import dispatch def hello(*args): return 'hello world' def auth(): # cb = dispatch.GetClientBinding() if not cb: return 'No binding avail' return cb.GetAuth() def echo(*args): args = list(args) args.append("It would be my pleasure to connect you.") return args def incr(*args): return [ k + 1 for k in args ] def average(*args): sum = 0 for i in args: sum += i return sum / len(args) if __name__ == '__main__': dispatch.AsCGI() #dispatch.AsServer(port=8000) Here's client use: from ZSI.client import Binding, AUTH a = Binding(url="/cgi-bin/x") a.echo(1,2,3) a.SetAuth(AUTH.httpbasic, 'name', 'password') a.auth() You can also use typecodes by invoking Send and RPC, e.g., with params that describe the data. |