diff options
Diffstat (limited to 'sca-cpp/trunk')
-rwxr-xr-x | sca-cpp/trunk/modules/wsgi/composite.py | 19 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/jsonutil.py | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/scdl.py | 10 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain-frontend.composite | 1 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain-single.composite | 1 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain.composite | 1 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/htdocs/index.html | 11 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/shopping-cart.py | 14 |
8 files changed, 53 insertions, 10 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/composite.py b/sca-cpp/trunk/modules/wsgi/composite.py index 4be44c3101..453718e556 100755 --- a/sca-cpp/trunk/modules/wsgi/composite.py +++ b/sca-cpp/trunk/modules/wsgi/composite.py @@ -86,6 +86,9 @@ def result(e, r, st, h = (), b = None): r("200 OK", list(h + (("Etag", md), ("Expires", "Tue, 01 Jan 1980 00:00:00 GMT")))) return b + if st == 301: + r("301 Moved Permanently", list(h)) + return failure(e, r, 500) # Return an HTTP failure result @@ -115,6 +118,14 @@ def postArgs(a): l = car(a); return cons(l, postArgs(cdr(a))) +# Return the URL of the logout page +def logout(ruri): + try: + from google.appengine.api import users + return users.create_logout_url(ruri) + except: + return None + # WSGI application function def application(e, r): m = requestMethod(e) @@ -132,6 +143,14 @@ def application(e, r): return fileresult(e, r, "application/x-javascript", fpath) if fpath.endswith(".png"): return fileresult(e, r, "image/png", fpath) + if fpath == "/": + return result(e, r, 301, (("Location", "/index.html"),)) + + # Logout + if fpath == "/logout": + redir = logout("/") + if redir: + return result(e, r, 301, (("Location", redir),)) # Find the requested component path = tokens(fpath) diff --git a/sca-cpp/trunk/modules/wsgi/jsonutil.py b/sca-cpp/trunk/modules/wsgi/jsonutil.py index ae7839df57..f69559de54 100644 --- a/sca-cpp/trunk/modules/wsgi/jsonutil.py +++ b/sca-cpp/trunk/modules/wsgi/jsonutil.py @@ -132,9 +132,11 @@ def jsonResultValue(s): # Return a portable function name from a JSON-RPC function name def funcName(f): - if len(f) > 7 and f.find("system.") == 0: + if f.startswith("."): + return f[1:] + if f.startswith("system."): return f[7:] - if len(f) > 8 and f.find("Service.") == 0: + if f.startswith("Service."): return f[8:] return f diff --git a/sca-cpp/trunk/modules/wsgi/scdl.py b/sca-cpp/trunk/modules/wsgi/scdl.py index a50bba3b7a..309f7f91f8 100644 --- a/sca-cpp/trunk/modules/wsgi/scdl.py +++ b/sca-cpp/trunk/modules/wsgi/scdl.py @@ -19,6 +19,7 @@ from xml.etree.cElementTree import iterparse from sys import stderr +from os import environ from util import * from httputil import * @@ -186,9 +187,11 @@ def evalReference(r, comps): return nameToComponent(t, comps) # Evaluate a property, return a lambda function returning the property -# value. The user and email properties are configured with the values -# from the HTTP request, if any +# 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) if car(p) == "user": return lambda: userProperty(cadr(p)) if car(p) == "email": @@ -206,6 +209,9 @@ def userProperty(v): user = currentUser() return user.user_id() if user else v +def hostProperty(v, e): + return e.get("HTTP_HOST", e.get("SERVER_NAME", v)).split(":")[0] + def emailProperty(v): user = currentUser() return user.email() if user else v diff --git a/sca-cpp/trunk/samples/store-gae/domain-frontend.composite b/sca-cpp/trunk/samples/store-gae/domain-frontend.composite index f84b9ba500..e7e10e2de1 100644 --- a/sca-cpp/trunk/samples/store-gae/domain-frontend.composite +++ b/sca-cpp/trunk/samples/store-gae/domain-frontend.composite @@ -52,6 +52,7 @@ <reference name="cache"> <t:binding.http uri="https://sca-store-backend.appspot.com/cache"/> </reference> + <property name="host">localhost</property> <property name="email">anonymous@example.com</property> </component> diff --git a/sca-cpp/trunk/samples/store-gae/domain-single.composite b/sca-cpp/trunk/samples/store-gae/domain-single.composite index 2863838e18..4a5d53e695 100644 --- a/sca-cpp/trunk/samples/store-gae/domain-single.composite +++ b/sca-cpp/trunk/samples/store-gae/domain-single.composite @@ -50,6 +50,7 @@ <t:binding.jsonrpc uri="total"/> </service> <reference name="cache" target="Cache"/> + <property name="host">localhost</property> <property name="email">anonymous@example.com</property> </component> diff --git a/sca-cpp/trunk/samples/store-gae/domain.composite b/sca-cpp/trunk/samples/store-gae/domain.composite index 2863838e18..4a5d53e695 100644 --- a/sca-cpp/trunk/samples/store-gae/domain.composite +++ b/sca-cpp/trunk/samples/store-gae/domain.composite @@ -50,6 +50,7 @@ <t:binding.jsonrpc uri="total"/> </service> <reference name="cache" target="Cache"/> + <property name="host">localhost</property> <property name="email">anonymous@example.com</property> </component> diff --git a/sca-cpp/trunk/samples/store-gae/htdocs/index.html b/sca-cpp/trunk/samples/store-gae/htdocs/index.html index e880285f23..2f61b1f946 100644 --- a/sca-cpp/trunk/samples/store-gae/htdocs/index.html +++ b/sca-cpp/trunk/samples/store-gae/htdocs/index.html @@ -51,6 +51,14 @@ function catalog_getcatalogResponse(items, exception) { catalogItems = items;
}
+function shoppingCart_gethostResponse(host, exception) {
+ if (exception) {
+ alert(exception.message);
+ return;
+ }
+ document.getElementById('host').innerHTML = host;
+}
+
function shoppingCart_getemailResponse(email, exception) {
if (exception) {
alert(exception.message);
@@ -131,6 +139,7 @@ function init() { try {
catalog.apply("getcatalog", catalog_getcatalogResponse);
shoppingCart.apply("getemail", shoppingCart_getemailResponse);
+ shoppingCart.apply("gethost", shoppingCart_gethostResponse);
shoppingCart.get("", shoppingCart_getResponse);
} catch(e){
alert(e);
@@ -141,7 +150,7 @@ function init() { <body onload="init()">
<h1>Store</h1>
-<p>You're signed in as: <span id="email"></span><br/><a href="/_ah/login?continue=/store.html&action=Logout">Sign out</a></p>
+<p>Welcome to: <span id="host"></span>, you're signed in as: <span id="email"></span><br/><a href="/logout">Sign out</a></p>
<div id="store">
<h2>Catalog</h2>
<form name="catalogForm">
diff --git a/sca-cpp/trunk/samples/store-gae/shopping-cart.py b/sca-cpp/trunk/samples/store-gae/shopping-cart.py index 04ad729585..8d369e3315 100644 --- a/sca-cpp/trunk/samples/store-gae/shopping-cart.py +++ b/sca-cpp/trunk/samples/store-gae/shopping-cart.py @@ -30,7 +30,7 @@ def getcart(id, cache): return cart # Post a new item to the cart, create a new cart if necessary -def post(collection, item, cache, email): +def post(collection, item, cache, host, email): id = str(uuid.uuid1()) cart = ((item[0], id, item[2]),) + getcart(cartId, cache) cache("put", (cartId,), cart) @@ -46,13 +46,13 @@ def find(id, cart): return find(id, cart[1:]) # Get items from the cart -def get(id, cache, email): +def get(id, cache, host, email): if id == (): return ("Your Cart", cartId) + getcart(cartId, cache) return find(id[0], getcart(cartId, cache)) # Delete items from the cart -def delete(id, cache, email): +def delete(id, cache, host, email): if id == (): return cache("delete", (cartId,)) return True @@ -68,11 +68,15 @@ def sum(items): return price(items[0]) + sum(items[1:]) # Return the total price of the items in the cart -def gettotal(cache, email): +def gettotal(cache, host, email): cart = getcart(cartId, cache) return sum(cart) # Return the email of the cart owner -def getemail(cache, email): +def getemail(cache, host, email): return email() +# Return the host that the app is running on +def gethost(cache, host, email): + return host() + |