diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-25 03:18:16 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-25 03:18:16 +0000 |
commit | a2a2cb76e9582af32b6803be7fa99af074dc04ae (patch) | |
tree | d0ef504321e72fe16afd23f385f20386530f5dfc /sca-cpp/trunk/modules/wsgi/scdl.py | |
parent | 0dd33c3859618f3a385583d7344230f0e1eb1004 (diff) |
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
Diffstat (limited to 'sca-cpp/trunk/modules/wsgi/scdl.py')
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/scdl.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/scdl.py b/sca-cpp/trunk/modules/wsgi/scdl.py index 6b22e92823..447dd985c2 100644 --- a/sca-cpp/trunk/modules/wsgi/scdl.py +++ b/sca-cpp/trunk/modules/wsgi/scdl.py @@ -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: |