Support python method invocation style on references, ref.func(...) in addition to ref('func', ...). Minor cleanup of the various samples, renamed gettotal to total and getcatalog to items, for consistency with the python sample.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1026939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jsdelfino 2010-10-25 03:18:16 +00:00
commit a2a2cb76e9
62 changed files with 307 additions and 218 deletions

View file

@ -15,21 +15,26 @@
# specific language governing permissions and limitations
# under the License.
import unittest
# JSON-RPC test case
def echo(x, ref):
return ref("echo", x)
e1 = ref("echo", x)
e2 = ref.echo(x)
assert e1 == e2
return e1
# ATOMPub test case
def get(id, ref):
return ref("get", id)
return ref.get(id)
def post(collection, item, ref):
return ref("post", collection, item)
return ref.post(collection, item)
def put(id, item, ref):
return ref("put", id, item)
return ref.put(id, item)
def delete(id, ref):
return ref("delete", id)
return ref.delete(id)

View file

@ -22,7 +22,7 @@ from httputil import *
def testClient():
c = mkclient("http://localhost:8090/wsgi")
assert c("echo", "Hey") == "Hey"
assert c.echo("Hey") == "Hey"
return True
if __name__ == "__main__":

View file

@ -56,6 +56,15 @@ class client:
return None
return jsonResultValue((res.read(),))
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError()
if name == "eval":
return self
l = lambda *args: self.__call__(name, *args)
self.__dict__[name] = l
return l
def __repr__(self):
return repr((self.url,))

View file

@ -56,6 +56,15 @@ class component:
def __call__(self, func, *args):
return self.mod.__getattribute__(func)(*(args + self.proxies))
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError()
if name == "eval":
return self
l = lambda *args: self.__call__(name, *args)
self.__dict__[name] = l
return l
def __repr__(self):
return repr((self.name, self.impl, self.mod, self.svcs, self.refs, self.props, self.proxies))
@ -186,19 +195,39 @@ def evalReference(r, comps):
return mkclient(t)
return nameToComponent(t, comps)
# Make a callable property
class property:
def __init__(self, name, l):
self.name = name
self.l = l
def __call__(self, *args):
return self.l(*args)
def __getattr__(self, name):
if name == "eval":
return self
raise AttributeError()
def __repr__(self):
return repr((self.name, self.l()))
def mkproperty(name, l):
return property(name, l)
# Evaluate a property, return a lambda function returning the property
# value. The host, user and email properties are configured with the
# values from the HTTP request, if any
def evalProperty(p):
if car(p) == "host":
return lambda: hostProperty(cadr(p), environ)
return mkproperty(car(p), lambda: hostProperty(cadr(p), environ))
if car(p) == "user":
return lambda: userProperty(cadr(p))
return mkproperty(car(p), lambda: userProperty(cadr(p)))
if car(p) == "nickname":
return lambda: nicknameProperty(cadr(p))
return mkproperty(car(p), lambda: nicknameProperty(cadr(p)))
if car(p) == "email":
return lambda: emailProperty(cadr(p))
return lambda: cadr(p)
return mkproperty(car(p), lambda: emailProperty(cadr(p)))
return mkproperty(car(p), lambda: cadr(p))
def currentUser():
try: