summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/python
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/python/client-test.py12
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp4
-rw-r--r--sca-cpp/trunk/modules/python/mod-python.cpp31
-rw-r--r--sca-cpp/trunk/modules/python/mod-python.hpp10
-rw-r--r--sca-cpp/trunk/modules/python/server-test.py30
5 files changed, 32 insertions, 55 deletions
diff --git a/sca-cpp/trunk/modules/python/client-test.py b/sca-cpp/trunk/modules/python/client-test.py
index 6e3723302a..47e6cf4bda 100644
--- a/sca-cpp/trunk/modules/python/client-test.py
+++ b/sca-cpp/trunk/modules/python/client-test.py
@@ -22,18 +22,14 @@ def echo(x, ref):
# ATOMPub test case
-def getall(ref):
- return ref("getall")
-
def get(id, ref):
return ref("get", id)
-def post(entry, ref):
- return ref("post", entry)
+def post(collection, item, ref):
+ return ref("post", collection, item)
-def put(id, entry, ref):
- return ref("put", id, entry)
+def put(id, item, ref):
+ return ref("put", id, item)
def delete(id, ref):
return ref("delete", id)
-
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index 5231b0ef60..136ecf6499 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -241,9 +241,9 @@ const failable<value> evalScript(const value& expr, PyObject* script) {
// The start, stop, and restart functions are optional
const value fn = car<value>(expr);
- if (fn == "start" || fn == "stop" || fn == "restart") {
+ if (fn == "start" || fn == "restart" || fn == "stop") {
PyErr_Clear();
- return value(false);
+ return value(lambda<value(const list<value>&)>());
}
return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError());
diff --git a/sca-cpp/trunk/modules/python/mod-python.cpp b/sca-cpp/trunk/modules/python/mod-python.cpp
index df94f2e8a1..8561a1fbf4 100644
--- a/sca-cpp/trunk/modules/python/mod-python.cpp
+++ b/sca-cpp/trunk/modules/python/mod-python.cpp
@@ -37,40 +37,27 @@ namespace server {
namespace modeval {
/**
- * Start the module.
+ * Apply a lifecycle start or restart event.
*/
-const failable<bool> start(unused ServerConf& sc) {
- // Start a Python runtime
- sc.moduleConf = new (gc_new<python::PythonRuntime>()) python::PythonRuntime();
- return true;
-}
+const value applyLifecycle(unused const list<value>& params) {
-/**
- * Stop the module.
- */
-const failable<bool> stop(unused ServerConf& sc) {
- return true;
-}
+ // Create a Python runtime
+ new (gc_new<python::PythonRuntime>()) python::PythonRuntime();
-/**
- * Restart the module.
- */
-const failable<bool> restart(unused ServerConf& sc) {
- // Start a Python runtime
- sc.moduleConf = new (gc_new<python::PythonRuntime>()) python::PythonRuntime();
- return true;
+ // Return a nil function as we don't need to handle the stop event
+ return failable<value>(lambda<value(const list<value>&)>());
}
/**
* Evaluate a Python component implementation and convert it to an applicable
* lambda function.
*/
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, modeval::ServerConf& sc) {
+const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, unused const lambda<value(const list<value>&)>& lifecycle) {
const string itype(elementName(impl));
if (contains(itype, ".python"))
- return modpython::evalImplementation(path, impl, px, sc);
+ return modpython::evalImplementation(path, impl, px);
if (contains(itype, ".cpp"))
- return modcpp::evalImplementation(path, impl, px, sc);
+ return modcpp::evalImplementation(path, impl, px);
return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype);
}
diff --git a/sca-cpp/trunk/modules/python/mod-python.hpp b/sca-cpp/trunk/modules/python/mod-python.hpp
index cbe2b6b97c..d13f2227ab 100644
--- a/sca-cpp/trunk/modules/python/mod-python.hpp
+++ b/sca-cpp/trunk/modules/python/mod-python.hpp
@@ -34,7 +34,6 @@
#include "value.hpp"
#include "monad.hpp"
#include "eval.hpp"
-#include "../server/mod-eval.hpp"
namespace tuscany {
namespace server {
@@ -51,11 +50,10 @@ struct applyImplementation {
const value operator()(const list<value>& params) const {
const value expr = append<value>(params, px);
debug(expr, "modeval::python::applyImplementation::input");
- const failable<value> val = python::evalScript(expr, impl);
+ const failable<value> res = python::evalScript(expr, impl);
+ const value val = !hasContent(res)? mklist<value>(value(), reason(res)) : mklist<value>(content(res));
debug(val, "modeval::python::applyImplementation::result");
- if (!hasContent(val))
- return mklist<value>(value(), reason(val));
- return mklist<value>(content(val));
+ return val;
}
};
@@ -63,7 +61,7 @@ struct applyImplementation {
* Evaluate a Python component implementation and convert it to an applicable
* lambda function.
*/
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, unused modeval::ServerConf& sc) {
+const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px) {
const string fpath(path + attributeValue("script", impl));
ifstream is(fpath);
if (fail(is))
diff --git a/sca-cpp/trunk/modules/python/server-test.py b/sca-cpp/trunk/modules/python/server-test.py
index ac2b6829c9..61e177d0aa 100644
--- a/sca-cpp/trunk/modules/python/server-test.py
+++ b/sca-cpp/trunk/modules/python/server-test.py
@@ -22,25 +22,21 @@ def echo(x):
# ATOMPub test case
-def getall():
- return ("Sample Feed", "123456789",
- ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))),
- ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))),
- ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55))))
-
def get(id):
- entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))
- return ("Item", id, entry)
-
-def post(entry):
- return "123456789"
-
-def put(id, entry):
- return true
-
-def deleteall():
+ if id == ():
+ return ("Sample Feed", "123456789",
+ ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))),
+ ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))),
+ ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55))))
+
+ entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))
+ return ("Item", id, entry)
+
+def post(collection, item):
+ return ("123456789",)
+
+def put(id, item):
return true
def delete(id):
return true
-