ported symimporter/symzipimporter to python3

This commit is contained in:
roberto@debian32
2011-10-24 16:35:59 +02:00
parent 3a8db4a97a
commit 07fd84f89f
5 changed files with 53 additions and 12 deletions
+1
View File
@@ -1,4 +1,5 @@
import sys
import uwsgi
print("i am the bootstrap for uwsgi.SymbolsImporter")
sys.meta_path.insert(0, uwsgi.SymbolsImporter())
+3 -1
View File
@@ -915,9 +915,11 @@ void uwsgi_python_init_apps() {
#ifdef __linux__
#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
#ifndef UWSGI_PYPY
#ifdef UWSGI_EMBEDDED
uwsgi_init_symbol_import();
#endif
#endif
#endif
if (up.test_module != NULL) {
+43 -3
View File
@@ -1,6 +1,6 @@
#include "uwsgi_python.h"
#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
#ifndef UWSGI_PYPY
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
@@ -201,9 +201,14 @@ static PyObject* symzipimporter_load_module(PyObject *self, PyObject *args) {
PyObject *source = PyObject_CallMethod(this->zip, "read", "(s)", filename);
free(filename);
PyObject *code = Py_CompileString(PyString_AsString(source), modname, Py_file_input);
if (!code) {
PyErr_Print();
goto shit;
}
mod = PyImport_ExecCodeModuleEx(fullname, code, modname);
Py_DECREF(code);
shit:
Py_DECREF(source);
free(modname);
return mod;
@@ -231,9 +236,14 @@ static PyObject* symzipimporter_load_module(PyObject *self, PyObject *args) {
PyObject *source = PyObject_CallMethod(this->zip, "read", "(s)", filename);
free(filename);
PyObject *code = Py_CompileString(PyString_AsString(source), modname, Py_file_input);
if (!code) {
PyErr_Print();
goto shit2;
}
mod = PyImport_ExecCodeModuleEx(fullname, code, modname);
Py_DECREF(code);
shit2:
Py_DECREF(source);
free(modname);
return mod;
@@ -306,9 +316,14 @@ static PyObject* symimporter_load_module(PyObject *self, PyObject *args) {
modname = uwsgi_concat3("sym://", fullname2, "_py");
code = Py_CompileString(source, modname, Py_file_input);
if (!code) {
PyErr_Print();
goto shit;
}
mod = PyImport_ExecCodeModuleEx(fullname, code, modname);
Py_DECREF(code);
shit:
free(source);
free(modname);
free(fullname2);
@@ -334,9 +349,14 @@ static PyObject* symimporter_load_module(PyObject *self, PyObject *args) {
PyDict_SetItemString(dict, "__loader__", self);
code = Py_CompileString(source, modname, Py_file_input);
if (!code) {
PyErr_Print();
goto shit2;
}
mod = PyImport_ExecCodeModuleEx(fullname, code, modname);
Py_DECREF(code);
shit2:
free(source);
free(modname);
free(fullname2);
@@ -450,7 +470,10 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds)
}
PyObject *stringio_dict = PyModule_GetDict(stringio);
#ifdef PYTHREE
PyObject *source_code = PyObject_CallMethodObjArgs(stringio, PyString_FromString("StringIO"), PyString_FromStringAndSize(body, len));
#else
PyObject *stringio_dict = PyModule_GetDict(stringio);
if (!stringio_dict) {
return -1;
}
@@ -466,7 +489,9 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds)
PyTuple_SetItem(stringio_args, 0, PyString_FromStringAndSize(body, len));
PyObject *source_code = PyInstance_New(stringio_stringio, stringio_args, NULL);
#endif
if (!source_code) {
return -1;
}
@@ -480,7 +505,10 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds)
}
PyObject *zipfile_dict = PyModule_GetDict(zipfile);
#ifdef PYTHREE
self->zip = PyObject_CallMethodObjArgs(zipfile, PyString_FromString("ZipFile"), source_code);
#else
PyObject *zipfile_dict = PyModule_GetDict(zipfile);
if (!zipfile_dict) {
return -1;
}
@@ -494,7 +522,9 @@ zipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds)
PyObject *zipfile_args = PyTuple_New(1);
PyTuple_SetItem(zipfile_args, 0, source_code);
self->zip = PyInstance_New(zipfile_zipfile, zipfile_args, NULL);
#endif
if (!self->zip) {
return -1;
}
@@ -556,6 +586,9 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds
return -1;
}
#ifdef PYTHREE
PyObject *source_code = PyObject_CallMethodObjArgs(stringio, PyString_FromString("StringIO"), PyString_FromStringAndSize(code_start, code_end-code_start));
#else
PyObject *stringio_dict = PyModule_GetDict(stringio);
if (!stringio_dict) {
return -1;
@@ -569,7 +602,9 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds
PyObject *stringio_args = PyTuple_New(1);
PyTuple_SetItem(stringio_args, 0, PyString_FromStringAndSize(code_start, code_end-code_start));
PyObject *source_code = PyInstance_New(stringio_stringio, stringio_args, NULL);
#endif
if (!source_code) {
return -1;
}
@@ -579,6 +614,9 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds
return -1;
}
#ifdef PYTHREE
self->zip = PyObject_CallMethodObjArgs(zipfile, PyString_FromString("ZipFile"), source_code);
#else
PyObject *zipfile_dict = PyModule_GetDict(zipfile);
if (!zipfile_dict) {
return -1;
@@ -592,7 +630,9 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds
PyObject *zipfile_args = PyTuple_New(1);
PyTuple_SetItem(zipfile_args, 0, source_code);
self->zip = PyInstance_New(zipfile_zipfile, zipfile_args, NULL);
#endif
if (!self->zip) {
return -1;
}
-2
View File
@@ -275,7 +275,5 @@ char *uwsgi_pythonize(char *);
#define uwsgi_pyexit {PyErr_Print();exit(1);}
#ifdef __linux__
#ifndef PYTHREE
int uwsgi_init_symbol_import(void);
#endif
#endif
+6 -6
View File
@@ -5,9 +5,9 @@ import sys
from uwsgidecorators import *
gc.set_debug(gc.DEBUG_SAVEALL)
print os.environ
print sys.modules
print sys.argv
print(os.environ)
print(sys.modules)
print(sys.argv)
try:
if sys.argv[1] == 'debug':
@@ -58,7 +58,7 @@ def application(env, start_response):
gc.collect(2)
if DEBUG:
print env['wsgi.input'].fileno()
print(env['wsgi.input'].fileno())
if routes.has_key(env['PATH_INFO']):
return routes[env['PATH_INFO']](env, start_response)
@@ -66,12 +66,12 @@ def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
if DEBUG:
print env['wsgi.input'].fileno()
print(env['wsgi.input'].fileno())
gc.collect(2)
if DEBUG:
print len(gc.get_objects())
print(len(gc.get_objects()))
workers = ''
for w in uwsgi.workers():