Fix PyObject reference counting bugs causing memory violations in the Python component implementation. Build Python runtime from source with pydebug to diagnose memory issues.

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-cpp/trunk@1343550 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/INSTALL b/INSTALL
index 50ae0f3..f4f3d3d 100644
--- a/INSTALL
+++ b/INSTALL
@@ -238,7 +238,7 @@
 --enable-libcloud \
 --with-libcloud=$build/libcloud-0.3.1-bin \
 --enable-threads \
---enable-python --with-python=/usr \
+--enable-python --with-python=$build/python-2.6.6-bin \
 --enable-opencl --with-opencl-include=/usr/include --with-opencl-lib=/usr/lib \
 --enable-gae --with-gae=$build/google_appengine \
 --enable-java --with-java=/usr/lib/jvm/default-java \
diff --git a/etc/memgrind b/etc/memgrind
index 079adca..312058c 100755
--- a/etc/memgrind
+++ b/etc/memgrind
@@ -18,6 +18,7 @@
 #  under the License.
 
 # Run valgrind to analyze memory usage and track memory leaks
+here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here`
 
-valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=40 --track-fds=yes --trace-children=yes $* 2>&1 | tee memgrind.log
+valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=50 --track-fds=yes --trace-children=yes --suppressions=$here/../../Python-2.6.6/Misc/valgrind-python.supp --suppressions=$here/valgrind-apr.supp $* 2>&1 | tee memgrind.log
 
diff --git a/etc/valgrind-apr.supp b/etc/valgrind-apr.supp
new file mode 100644
index 0000000..9a58600
--- /dev/null
+++ b/etc/valgrind-apr.supp
@@ -0,0 +1,27 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#  
+#    http://www.apache.org/licenses/LICENSE-2.0
+#    
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+# This is a valgrind suppression file.
+
+{
+   Suppress APR pool cleanup registrations.
+   Memcheck:Leak
+   fun:malloc
+   fun:apr_palloc
+   fun:apr_pool_cleanup_register
+}
+
diff --git a/macos/macos-install b/macos/macos-install
index e8332ed..82c802a 100755
--- a/macos/macos-install
+++ b/macos/macos-install
@@ -299,6 +299,18 @@
 fi
 cd $build
 
+# Build Python
+curl -OL http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
+tar xzf Python-2.6.6.tgz
+cd Python-2.6.6
+./configure --prefix=$build/python-2.6.6-bin --enable-shared
+make
+make install
+if [ "$?" != "0" ]; then
+    exit $?
+fi
+cd $build
+
 # Build Apache Libcloud
 curl -OL http://archive.apache.org/dist/incubator/libcloud/apache-libcloud-incubating-0.4.2.tar.bz2
 tar xjf apache-libcloud-incubating-0.4.2.tar.bz2
@@ -321,7 +333,7 @@
 git clone git://git.apache.org/tuscany-sca-cpp.git
 cd tuscany-sca-cpp
 ./bootstrap
-./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-bin --with-leveldb=$build/leveldb --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --enable-opencl --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
+./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-bin --with-leveldb=$build/leveldb --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-python=$build/python-2.6.6-bin --enable-opencl --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
 make
 make install
 if [ "$?" != "0" ]; then
@@ -330,8 +342,8 @@
 cd $build
 
 # Create src archive
-tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin autoconf-2.13 autoconf-2.13-bin autoconf-2.13.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin libevent-2.0.13-stable libevent-2.0.13-stable-bin libevent-2.0.13-stable.tar.gz liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.0-bin modsecurity-apache_2.6.0.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem pcre-8.12 pcre-8.12-bin pcre-8.12.zip pkg-config-0.25 pkg-config-0.25-bin pkg-config-0.25.tar.gz pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz tidy tinycdb tinycdb-bin leveldb tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin autoconf-2.13 autoconf-2.13-bin autoconf-2.13.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin libevent-2.0.13-stable libevent-2.0.13-stable-bin libevent-2.0.13-stable.tar.gz liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.0-bin modsecurity-apache_2.6.0.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem pcre-8.12 pcre-8.12-bin pcre-8.12.zip pkg-config-0.25 pkg-config-0.25-bin pkg-config-0.25.tar.gz pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz Python-2.6.6 python-2.6.6-bin Python-2.6.6.tgz tidy tinycdb tinycdb-bin leveldb tuscany-sca-cpp tuscany-sca-cpp-bin
 
 # Create bin archive
-tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin libevent-2.0.13-stable-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel pcre-8.12-bin pgbouncer-1.5-bin postgresql-9.1.2-bin tinycdb-bin leveldb tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin libevent-2.0.13-stable-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel pcre-8.12-bin pgbouncer-1.5-bin postgresql-9.1.2-bin python-2.6.6-bin tinycdb-bin leveldb tuscany-sca-cpp tuscany-sca-cpp-bin
 
diff --git a/modules/python/eval.hpp b/modules/python/eval.hpp
index 41f45ac..da5d226 100644
--- a/modules/python/eval.hpp
+++ b/modules/python/eval.hpp
@@ -27,8 +27,14 @@
  */
 #if PYTHON_VERSION == 27
 #include <python2.7/Python.h>
+#include <python2.7/frameobject.h>
+#include <python2.7/traceback.h>
 #else
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
 #include <python2.6/Python.h>
+#include <python2.6/frameobject.h>
+#include <python2.6/traceback.h>
 #endif
 
 #include "list.hpp"
@@ -40,6 +46,21 @@
 class PythonThreadIn;
 class PythonThreadOut;
 class PythonRuntimeLock;
+class PythonRuntime;
+
+/**
+ * Maintain a garbage collected reference to a Python object.
+ */
+const bool pyIncRef(PyObject* o);
+const bool pyDecRef(PyObject* o, PythonRuntime* py);
+
+/**
+ * Write to debug log from Python.
+ */
+const value pyDebug(const list<value>& args) {
+    debug(args, "python::debug");
+    return true;
+}
 
 /**
  * Represent a Python runtime.
@@ -63,10 +84,12 @@
         // Initialize the Python interpreter
 #ifdef IS_DARWIN
         debug("python::pythonruntime::initialize");
+        Py_SetPythonHome(const_cast<char*>(PYTHON_PREFIX));
         Py_InitializeEx(0);
 #else
         if (!Py_IsInitialized()) {
             debug("python::pythonruntime::initialize");
+            Py_SetPythonHome(const_cast<char*>(PYTHON_PREFIX));
             Py_InitializeEx(0);
         }
 #endif
@@ -84,12 +107,22 @@
 #endif
 #endif
 
-        // Set default interpreter args
 #ifdef WANT_THREADS
         PyGILState_STATE gstate = PyGILState_Ensure();
 #endif
+
+        // Set default interpreter args
         const char* arg0 = "";
         PySys_SetArgv(0, const_cast<char**>(&arg0));
+
+        // Install debug log function
+        PyObject* mkPyLambda(const lambda<value(const list<value>&)>& l, PythonRuntime* py);
+        PyObject* pyd= mkPyLambda(pyDebug, this);
+        PyObject* sys = PyImport_ImportModule("sys");
+        PyObject_SetAttrString(sys, "debug", pyd);
+        pyDecRef(pyd, this);
+        pyDecRef(sys, this);
+
 #ifdef WANT_THREADS
         PyGILState_Release(gstate);
 #endif
@@ -115,24 +148,46 @@
 /**
  * Return the last python error.
  */
-const string lastError() {
+const string lastErrorTrace(PyObject *trace) {
+    if (trace == NULL)
+        return "";
+    PyTracebackObject* tb = (PyTracebackObject*)trace;
+    const int limit = 16;
+    int depth = 0;
+    PyTracebackObject *tb1 = tb;
+    while (tb1 != NULL) {
+        depth++;
+        tb1 = tb1->tb_next;
+    }
+    ostringstream os;
+    while (tb != NULL) {
+        if (depth <= limit)
+            os << ", File " << PyString_AsString(tb->tb_frame->f_code->co_filename) <<
+                " line " << tb->tb_lineno << " in " << PyString_AsString(tb->tb_frame->f_code->co_name);
+        depth--;
+        tb = tb->tb_next;
+    }
+    return str(os);
+}
+
+const string lastError(PythonRuntime* py) {
     if(PyErr_Occurred()) {
-        PyObject* type;
-        PyObject* val;
-        PyObject* trace;
+        PyObject* type = NULL;
+        PyObject* val = NULL;
+        PyObject* trace = NULL;
         PyErr_Fetch(&type, &val, &trace);
         if (type != NULL && val != NULL) {
             PyObject* stype = PyObject_Str(type);    
             PyObject* sval = PyObject_Str(val);    
-            string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval);
-            Py_DECREF(stype);
-            Py_DECREF(sval);
+            string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval) + lastErrorTrace(trace);
+            pyDecRef(stype, py);
+            pyDecRef(sval, py);
             PyErr_Restore(type, val, trace);
-            PyErr_Print();
+            PyErr_Clear();
             return msg;
         }
         PyErr_Restore(type, val, trace);
-        PyErr_Print();
+        PyErr_Clear();
         return "Unknown Python error";
     }
     return "";
@@ -235,6 +290,44 @@
 };
 
 /**
+ * A gargabe collected Python object reference.
+ */
+class PyGCRef {
+public:
+    PyGCRef(PyObject* o, PythonRuntime* py) : o(o), py(py) {
+    }
+
+    ~PyGCRef() {
+        if (o == NULL)
+            return;
+        PythonThreadIn pyin(py);
+        Py_DECREF(o);
+    }
+
+private:
+    PyObject* o;
+    PythonRuntime* py;
+};
+
+/**
+ * Maintain a garbage collected reference to a Python object.
+ */
+const bool pyIncRef(PyObject* o) {
+    if (o == NULL)
+        return true;
+    Py_INCREF(o);
+    return true;
+}
+
+const bool pyDecRef(unused PyObject* o, unused PythonRuntime* py) {
+    if (o == NULL)
+        return true;
+    //new (gc_new<PyGCRef>()) PyGCRef(o, py);
+    Py_DECREF(o);
+    return true;
+}
+
+/**
  * Declare conversion functions.
  */
 PyObject* valueToPyObject(const value& v, PythonRuntime* py);
@@ -254,14 +347,14 @@
 PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l, PythonRuntime* py);
 
 void pyLambda_dealloc(PyObject* self) {
-    debug(self, "python::pylambda_dealloc");
+    //debug(self, "python::pylambda_dealloc");
     PyObject_Del(self);
 }
 
-const string pyRepr(PyObject* o) {
+const string pyRepr(PyObject* o, PythonRuntime* py) {
     PyObject* r = PyObject_Repr(o);
     const string s = PyString_AsString(r);
-    Py_DECREF(r);
+    pyDecRef(r, py);
     return s;
 }
 
@@ -300,7 +393,7 @@
         return PyObject_GenericGetAttr(self, attrname);
 
     if (name == "eval") {
-        Py_INCREF(self);
+        pyIncRef(self);
         return self;
     }
 
@@ -371,7 +464,7 @@
         pyl->func = new (gc_new<lambda<value(const list<value>&)> >()) lambda<value(const list<value>&)>(l);
         pyl->py = py;
     }
-    debug(pyl, "python::mkpylambda");
+    //debug(pyl, "python::mkpylambda");
     return (PyObject*)pyl;
 }
 
@@ -383,14 +476,14 @@
         return l;
     PyObject* pyv = valueToPyObject(car(v), py);
     PyList_Append(l, pyv);
-    Py_DECREF(pyv);
+    pyDecRef(pyv, py);
     return valuesToPyListHelper(l, cdr(v), py);
 }
 
 PyObject* valuesToPyTuple(const list<value>& v, PythonRuntime* py) {
     PyObject* pyl = valuesToPyListHelper(PyList_New(0), v, py);
     PyObject* pyt = PyList_AsTuple(pyl);
-    Py_DECREF(pyl);
+    pyDecRef(pyl, py);
     return pyt;
 }
 
@@ -411,10 +504,16 @@
     }
     case value::Number:
         return PyFloat_FromDouble((double)v);
-    case value::Bool:
-        return (bool)v? Py_True : Py_False;
-    default:
-        return Py_None;
+    case value::Bool: {
+        PyObject* b = (bool)v? Py_True : Py_False;
+        pyIncRef(b);
+        return b;
+    }
+    default: {
+        PyObject* n = Py_None;
+        pyIncRef(n);
+        return n;
+    }
     }
 }
 
@@ -438,22 +537,46 @@
 struct pyCallable {
     PyObject* func;
     PythonRuntime* py;
+    bool owner;
 
-    pyCallable(PyObject* func, PythonRuntime* py) : func(func), py(py) {
-        Py_INCREF(func);
+    pyCallable(PyObject* func, PythonRuntime* py) : func(func), py(py), owner(true) {
+        pyIncRef(func);
+    }
+
+    pyCallable(const pyCallable& c) : func(c.func), py(c.py), owner(false) {
     }
 
     ~pyCallable() {
-        Py_DECREF(func);
+        if (!owner)
+            return;
+        pyDecRef(func, py);
     }
 
     const value operator()(const list<value>& args) const {
         PythonThreadIn pyin(py);
+        {
+            // Temp
+            PyObject* rfunc = PyObject_Repr(func);
+            char* s = NULL;
+            Py_ssize_t l = 0;
+            PyString_AsStringAndSize(rfunc, &s, &l);
+            debug(string(s, l), "python::operator()::func");
+            pyDecRef(rfunc, py);
+        }
         PyObject* pyargs = valuesToPyTuple(args, py);
+        {
+            // Temp
+            PyObject* rargs = PyObject_Repr(pyargs);
+            char* s = NULL;
+            Py_ssize_t l = 0;
+            PyString_AsStringAndSize(rargs, &s, &l);
+            debug(string(s, l), "python::operator()::args");
+            pyDecRef(rargs, py);
+        }
         PyObject* result = PyObject_CallObject(func, pyargs);
         const value v = pyObjectToValue(result, py);
-        Py_DECREF(pyargs);
-        Py_DECREF(result);
+        pyDecRef(pyargs, py);
+        pyDecRef(result, py);
         return v;
     }
 };
@@ -462,6 +585,8 @@
  * Convert a python object to a value.
  */
 const value pyObjectToValue(PyObject *o, PythonRuntime* py) {
+    if (o == NULL)
+        return value();
     if (PyString_Check(o)) {
         char* s = NULL;
         Py_ssize_t l = 0;
@@ -509,10 +634,10 @@
             return value(lambda<value(const list<value>&)>());
         }
 
-        return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError());
+        return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError(&py));
     }
     if (!PyCallable_Check(func)) {
-        Py_DECREF(func);
+        pyDecRef(func, &py);
         return mkfailure<value>(string("Couldn't find callable function: ") + car<value>(expr));
     }
 
@@ -521,14 +646,14 @@
 
     // Call the function
     PyObject* result = PyObject_CallObject(func, args);
-    Py_DECREF(func);
-    Py_DECREF(args);
+    pyDecRef(func, &py);
+    pyDecRef(args, &py);
     if (result == NULL)
-        return mkfailure<value>(string("Function call failed: ") + car<value>(expr) + " : " + lastError());
+        return mkfailure<value>(string("Function call failed: ") + car<value>(expr) + " : " + lastError(&py));
 
     // Convert python result to a value
     const value v = pyObjectToValue(result, &py);
-    Py_DECREF(result);
+    pyDecRef(result, &py);
     return v;
 }
 
@@ -538,27 +663,35 @@
 const failable<PyObject*> readScript(const string& name, const string& path, istream& is, PythonRuntime& py) {
     PythonThreadIn pyin(&py);
 
+    // Lookup already loaded module
+    PyObject *mods = PyImport_GetModuleDict();
+    PyObject *emod = PyDict_GetItemString(mods, const_cast<char*>(c_str(name)));
+    if (emod != NULL)
+        return emod;
+
+    // Compile and import new module
+    debug(name, "python::readScript::compile::name");
+    debug(path, "python::readScript::compile::path");
     const list<string> ls = streamList(is);
     ostringstream os;
     write(ls, os);
     PyObject* code = Py_CompileStringFlags(c_str(str(os)), c_str(path), Py_file_input, NULL);
     if (code == NULL)
-        return mkfailure<PyObject*>(string("Couldn't compile script: ") + path + " : " + lastError());
+        return mkfailure<PyObject*>(string("Couldn't compile script: ") + path + " : " + lastError(&py));
     PyObject* mod = PyImport_ExecCodeModuleEx(const_cast<char*>(c_str(name)), code, const_cast<char*>(c_str(path)));
     if (mod == NULL) {
-        Py_DECREF(code);
-        return mkfailure<PyObject*>(string("Couldn't import module: ") + path + " : " + lastError());
+        pyDecRef(code, &py);
+        return mkfailure<PyObject*>(string("Couldn't import module: ") + path + " : " + lastError(&py));
     }
-    Py_DECREF(code);
     return mod;
 }
 
 /**
  * Release a python script.
  */
-const failable<bool> releaseScript(PyObject* script, PythonRuntime& py) {
+const failable<bool> releaseScript(unused PyObject* script, PythonRuntime& py) {
     PythonThreadIn pyin(&py);
-    Py_DECREF(script);
+    // No need to decref the script here, as it's referenced only once from sys.modules
     return true;
 }
 
@@ -566,9 +699,10 @@
  * Evaluate an expression against a script provided as an input stream.
  */
 const failable<value> evalScript(const value& expr, istream& is, PythonRuntime& py) {
-    failable<PyObject*> script = readScript("script", "script.py", is, py);
+    const value uuid = mkuuid();
+    failable<PyObject*> script = readScript(string("script") + string(uuid), string("script") + string(uuid) + string(".py"), is, py);
     if (!hasContent(script))
-        return mkfailure<value>(reason(script));
+        return mkfailure<value>(script);
     return evalScript(expr, content(script), py);
 }
 
diff --git a/modules/wsgi/wsgi-start b/modules/wsgi/wsgi-start
index 685dab3..1bda4f3 100755
--- a/modules/wsgi/wsgi-start
+++ b/modules/wsgi/wsgi-start
@@ -24,5 +24,6 @@
 
 python_prefix=`cat $here/../python/python.prefix`
 cd $root
+export LD_LIBRARY_PATH=$python_prefix/lib:$LD_LIBRARY_PATH
 $python_prefix/bin/python composite.py $port &
 
diff --git a/ubuntu/ubuntu-backup b/ubuntu/ubuntu-backup
index 62e0bc5..ac20e6c 100755
--- a/ubuntu/ubuntu-backup
+++ b/ubuntu/ubuntu-backup
@@ -23,8 +23,8 @@
 set -x
 
 # Create src archive
-tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz Python-2.6.6 python-2.6.6-bin Python-2.6.6.tgz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin
 
 # Create bin archive
-tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin python-2.6.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin
 
diff --git a/ubuntu/ubuntu-backup-all b/ubuntu/ubuntu-backup-all
index 609a570..80dccda 100755
--- a/ubuntu/ubuntu-backup-all
+++ b/ubuntu/ubuntu-backup-all
@@ -23,8 +23,8 @@
 set -x
 
 # Create src archive
-tar czf tuscany-sca-cpp-all-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin axis2c-1.6.0-bin axis2c-src-1.6.0 axis2c-src-1.6.0.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz google_appengine google_appengine_1.4.0.zip htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz qpidc-0.6 qpidc-0.6-bin qpid-cpp-0.6.tar.gz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6 vysper-0.6-bin.tar.gz
+tar czf tuscany-sca-cpp-all-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin axis2c-1.6.0-bin axis2c-src-1.6.0 axis2c-src-1.6.0.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz google_appengine google_appengine_1.4.0.zip htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz Python-2.6.6 python-2.6.6-bin Python-2.6.6.tgz qpidc-0.6 qpidc-0.6-bin qpid-cpp-0.6.tar.gz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6 vysper-0.6-bin.tar.gz
 
 # Create bin archive
-tar czf tuscany-sca-cpp-all-1.0.tar.gz apr-1.4.x-bin axis2c-1.6.0-bin curl-7.24.0-bin expat-2.0.1-bin google_appengine htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin qpidc-0.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6
+tar czf tuscany-sca-cpp-all-1.0.tar.gz apr-1.4.x-bin axis2c-1.6.0-bin curl-7.24.0-bin expat-2.0.1-bin google_appengine htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin python-2.6.6-bin qpidc-0.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6
 
diff --git a/ubuntu/ubuntu-bin-all-image b/ubuntu/ubuntu-bin-all-image
index c76af43..b230d75 100755
--- a/ubuntu/ubuntu-bin-all-image
+++ b/ubuntu/ubuntu-bin-all-image
@@ -74,7 +74,7 @@
     exit $?
 fi
 # Required by Apache Thrift
-sudo apt-get -y install bison flex python-dev
+sudo apt-get -y install bison flex
 if [ "$?" != "0" ]; then
     exit $?
 fi
diff --git a/ubuntu/ubuntu-bin-image b/ubuntu/ubuntu-bin-image
index 032c4e4..6c1082a 100755
--- a/ubuntu/ubuntu-bin-image
+++ b/ubuntu/ubuntu-bin-image
@@ -59,7 +59,7 @@
     exit $?
 fi
 # Required by Apache Thrift
-sudo apt-get -y install bison flex python-dev libboost-dev libboost-filesystem-dev
+sudo apt-get -y install bison flex libboost-dev libboost-filesystem-dev
 if [ "$?" != "0" ]; then
     exit $?
 fi
diff --git a/ubuntu/ubuntu-install b/ubuntu/ubuntu-install
index 71fd6d7..ef22091 100755
--- a/ubuntu/ubuntu-install
+++ b/ubuntu/ubuntu-install
@@ -285,7 +285,7 @@
 tar xzf thrift-0.2.0-incubating.tar.gz
 cd thrift-0.2.0
 ./bootstrap.sh
-./configure --prefix=$build/thrift-0.2.0-bin --with-java=no --with-erlang=no --with-perl=no --with-ruby=no --with-csharp=no --disable-static
+./configure --prefix=$build/thrift-0.2.0-bin --with-java=no --with-erlang=no --with-py=no --with-perl=no --with-ruby=no --with-csharp=no --disable-static
 make
 make install
 if [ "$?" != "0" ]; then
@@ -324,6 +324,18 @@
 cp src/lib/libscribe.so $build/scribe-2.2-bin/lib
 cd $build
 
+# Build Python
+curl -OL http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
+tar xzf Python-2.6.6.tgz
+cd Python-2.6.6
+./configure --prefix=$build/python-2.6.6-bin --enable-shared
+make
+make install
+if [ "$?" != "0" ]; then
+    exit $?
+fi
+cd $build
+
 # Build Apache Libcloud
 curl -OL http://archive.apache.org/dist/incubator/libcloud/apache-libcloud-incubating-0.4.2.tar.bz2
 tar xjf apache-libcloud-incubating-0.4.2.tar.bz2
@@ -356,7 +368,7 @@
 git clone git://git.apache.org/tuscany-sca-cpp.git
 cd tuscany-sca-cpp
 ./bootstrap
-./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-0.77-bin --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-pagespeed --with-pagespeed=$build/page-speed-1.9-bin --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-log --with-thrift=$build/thrift-0.2.0-bin --with-scribe=$build/scribe-2.2-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
+./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-0.77-bin --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-pagespeed --with-pagespeed=$build/page-speed-1.9-bin --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-python=$build/python-2.6.6-bin --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-log --with-thrift=$build/thrift-0.2.0-bin --with-scribe=$build/scribe-2.2-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
 make
 make install
 if [ "$?" != "0" ]; then
@@ -365,8 +377,8 @@
 cd $build
 
 # Create src archive
-tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz Python-2.6.6 python-2.6.6-bin Python-2.6.6.tgz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin
 
 # Create bin archive
-tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin
+tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.24.0-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin pgbouncer-1.5-bin postgresql-9.1.2-bin python-2.6.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin
 
diff --git a/ubuntu/ubuntu-install-all b/ubuntu/ubuntu-install-all
index a3acbd3..4aaa117 100755
--- a/ubuntu/ubuntu-install-all
+++ b/ubuntu/ubuntu-install-all
@@ -339,7 +339,7 @@
 tar xzf thrift-0.2.0-incubating.tar.gz
 cd thrift-0.2.0
 ./bootstrap.sh
-./configure --prefix=$build/thrift-0.2.0-bin --with-java=no --with-erlang=no --with-perl=no --with-ruby=no --with-csharp=no --disable-static
+./configure --prefix=$build/thrift-0.2.0-bin --with-java=no --with-erlang=no --with-py=no --with-perl=no --with-ruby=no --with-csharp=no --disable-static
 make
 make install
 if [ "$?" != "0" ]; then
@@ -378,6 +378,18 @@
 cp src/lib/libscribe.so $build/scribe-2.2-bin/lib
 cd $build
 
+# Build Python
+curl -OL http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
+tar xzf Python-2.6.6.tgz
+cd Python-2.6.6
+./configure --prefix=$build/python-2.6.6-bin --enable-shared
+make
+make install
+if [ "$?" != "0" ]; then
+    exit $?
+fi
+cd $build
+
 # Build Apache Libcloud
 curl -OL http://archive.apache.org/dist/incubator/libcloud/apache-libcloud-incubating-0.4.2.tar.bz2
 tar xjf apache-libcloud-incubating-0.4.2.tar.bz2
@@ -410,7 +422,7 @@
 git clone git://git.apache.org/tuscany-sca-cpp.git
 cd tuscany-sca-cpp
 ./bootstrap
-./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-0.77-bin --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-pagespeed --with-pagespeed=$build/page-speed-1.9-bin --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --enable-gae --with-gae=$build/google_appengine --enable-java --with-java=/usr/lib/jvm/java-6-openjdk --enable-webservice --with-libxml2=$build/libxml2-2.7.7-bin --with-axis2c=$build/axis2c-1.6.0-bin --enable-queue --with-qpidc=$build/qpidc-0.6-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --with-vysper=$build/vysper-0.6 --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-log --with-thrift=$build/thrift-0.2.0-bin --with-scribe=$build/scribe-2.2-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
+./configure --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.24.0-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.15-bin --with-memcached=$build/memcached-1.4.7-bin --with-tinycdb=$build/tinycdb-0.77-bin --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --enable-pagespeed --with-pagespeed=$build/page-speed-1.9-bin --enable-libcloud --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-python=$build/python-2.6.6-bin --enable-gae --with-gae=$build/google_appengine --enable-java --with-java=/usr/lib/jvm/java-6-openjdk --enable-webservice --with-libxml2=$build/libxml2-2.7.7-bin --with-axis2c=$build/axis2c-1.6.0-bin --enable-queue --with-qpidc=$build/qpidc-0.6-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --with-vysper=$build/vysper-0.6 --enable-sqldb --with-pgsql=$build/postgresql-9.1.2-bin --with-pgbouncer=$build/pgbouncer-1.5-bin --enable-log --with-thrift=$build/thrift-0.2.0-bin --with-scribe=$build/scribe-2.2-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.1-bin
 make
 make install
 if [ "$?" != "0" ]; then
@@ -419,8 +431,8 @@
 cd $build
 
 # Create src archive
-tar czf tuscany-sca-cpp-all-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin axis2c-1.6.0-bin axis2c-src-1.6.0 axis2c-src-1.6.0.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz google_appengine google_appengine_1.4.0.zip htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz qpidc-0.6 qpidc-0.6-bin qpid-cpp-0.6.tar.gz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6 vysper-0.6-bin.tar.gz
+tar czf tuscany-sca-cpp-all-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin axis2c-1.6.0-bin axis2c-src-1.6.0 axis2c-src-1.6.0.tar.gz curl-7.24.0 curl-7.24.0-bin curl-7.24.0.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz google_appengine google_appengine_1.4.0.zip htmltidy-bin httpd-2.3.15-beta httpd-2.3.15-beta.tar.gz httpd-2.3.15-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.7 memcached-1.4.7-bin memcached-1.4.7.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.1 modsecurity-apache-2.6.1-bin modsecurity-apache_2.6.1.tar.gz modsecurity-crs_2.2.2 modsecurity-crs_2.2.2.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem page-speed-1.9 page-speed-1.9-bin page-speed-sdk.zip pgbouncer-1.5 pgbouncer-1.5-bin pgbouncer-1.5.tar.gz postgresql-9.1.2 postgresql-9.1.2-bin postgresql-9.1.2.tar.gz qpidc-0.6 qpidc-0.6-bin qpid-cpp-0.6.tar.gz Python-2.6.6 python-2.6.6-bin Python-2.6.6.tgz scribe scribe-2.2-bin scribe-2.2.tar.gz thrift-0.2.0 thrift-0.2.0-bin thrift-0.2.0-incubating.tar.gz tidy tinycdb-0.77 tinycdb-0.77-bin tinycdb_0.77.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6 vysper-0.6-bin.tar.gz
 
 # Create bin archive
-tar czf tuscany-sca-cpp-all-1.0.tar.gz apr-1.4.x-bin axis2c-1.6.0-bin curl-7.24.0-bin expat-2.0.1-bin google_appengine htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin postgresql-9.1.2-bin qpidc-0.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6
+tar czf tuscany-sca-cpp-all-1.0.tar.gz apr-1.4.x-bin axis2c-1.6.0-bin curl-7.24.0-bin expat-2.0.1-bin google_appengine htmltidy-bin httpd-2.3.15-bin js-1.8.5-bin libcloud-0.4.2-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.7-bin mod-auth-openid-bin modsecurity-apache-2.6.1-bin nspr-4.8.8-bin nuvem/nuvem-parallel page-speed-1.9-bin postgresql-9.1.2-bin python-2.6.6-bin qpidc-0.6-bin scribe-2.2-bin thrift-0.2.0-bin tinycdb-0.77-bin tuscany-sca-cpp tuscany-sca-cpp-bin vysper-0.6