summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorroberto@oneiric64 <roberto@oneiric64>2011-12-13 06:40:10 +0100
committerroberto@oneiric64 <roberto@oneiric64>2011-12-13 06:40:10 +0100
commit5ee106170b0fab08e6d859ae251ab09e96fd1f6e (patch)
tree2d37e3783f5510baf133380d8976fda05de249ac /contrib
parentd62f04a5a6644261e9d7b73ffb14ad896083859d (diff)
downloaduwsgi-5ee106170b0fab08e6d859ae251ab09e96fd1f6e.tar.gz
added contrib/cgi_python.c
Diffstat (limited to 'contrib')
-rw-r--r--contrib/cgi_python.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/contrib/cgi_python.c b/contrib/cgi_python.c
new file mode 100644
index 00000000..b2debbaf
--- /dev/null
+++ b/contrib/cgi_python.c
@@ -0,0 +1,53 @@
+#include <Python.h>
+
+void uwsgi_cgi_load_python() {
+
+ Py_Initialize();
+}
+
+void uwsgi_cgi_run_python(char *filename) {
+
+ char **e, *p;
+ PyObject *k, *env_value;
+
+ FILE *fp = fopen(filename, "r");
+
+ PySys_SetArgv(1, &filename);
+
+ PyObject *os_module = PyImport_ImportModule("os");
+ if (os_module) {
+ PyObject *os_module_dict = PyModule_GetDict(os_module);
+ PyObject *py_environ = PyDict_GetItemString(os_module_dict, "environ");
+ if (py_environ) {
+ for (e = environ; *e != NULL; e++) {
+ p = strchr(*e, '=');
+ if (p == NULL) continue;
+
+ k = PyString_FromStringAndSize(*e, (int)(p-*e));
+ if (k == NULL) {
+ PyErr_Print();
+ continue;
+ }
+
+ env_value = PyString_FromString(p+1);
+ if (env_value == NULL) {
+ PyErr_Print();
+ Py_DECREF(k);
+ continue;
+ }
+
+ if (PyObject_SetItem(py_environ, k, env_value)) {
+ PyErr_Print();
+ }
+
+ Py_DECREF(k);
+ Py_DECREF(env_value);
+
+ }
+
+ }
+ }
+
+
+ PyRun_AnyFileEx(fp, filename, 1);
+}