diff --git a/attach.py b/attach.py new file mode 100644 index 00000000..246b649b --- /dev/null +++ b/attach.py @@ -0,0 +1,13 @@ +import struct +import sys +import os + +filename = sys.argv[1] + +size = os.path.getsize(filename) + +f = open(filename, 'r') +print(f.read()) +f.close() + +print(struct.pack("zip = PyInstance_New(zipfile_zipfile, zipfile_args, NULL); + if (!self->zip) { + return -1; + } + + Py_INCREF(self->zip); + + self->items = PyObject_CallMethod(self->zip, "namelist", NULL); + if (!self->items) { + return -1; + } + + Py_INCREF(self->items); + + self->prefix = NULL; + if (prefix) { + self->prefix = prefix+1; + prefix[0] = ':'; + } + + + return 0; +} + + + static int symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds) { @@ -439,19 +540,16 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds PyObject *stringio = PyImport_ImportModule("StringIO"); if (!stringio) { - PyErr_Print(); return -1; } PyObject *stringio_dict = PyModule_GetDict(stringio); if (!stringio_dict) { - PyErr_Print(); return -1; } PyObject *stringio_stringio = PyDict_GetItemString(stringio_dict, "StringIO"); if (!stringio_stringio) { - PyErr_Print(); return -1; } @@ -460,25 +558,21 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds PyObject *source_code = PyInstance_New(stringio_stringio, stringio_args, NULL); if (!source_code) { - PyErr_Print(); return -1; } PyObject *zipfile = PyImport_ImportModule("zipfile"); if (!zipfile) { - PyErr_Print(); return -1; } PyObject *zipfile_dict = PyModule_GetDict(zipfile); if (!zipfile_dict) { - PyErr_Print(); return -1; } PyObject *zipfile_zipfile = PyDict_GetItemString(zipfile_dict, "ZipFile"); if (!zipfile_zipfile) { - PyErr_Print(); return -1; } @@ -487,7 +581,6 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds self->zip = PyInstance_New(zipfile_zipfile, zipfile_args, NULL); if (!self->zip) { - PyErr_Print(); return -1; } @@ -495,7 +588,6 @@ symzipimporter_init(struct _symzipimporter *self, PyObject *args, PyObject *kwds self->items = PyObject_CallMethod(self->zip, "namelist", NULL); if (!self->items) { - PyErr_Print(); return -1; } @@ -553,6 +645,49 @@ static PyTypeObject SymZipImporter_Type = { PyObject_GC_Del, /* tp_free */ }; +static PyTypeObject ZipImporter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "uwsgi.ZipImporter", + sizeof(struct _symzipimporter), + 0, /* tp_itemsize */ + (destructor) uwsgi_symimporter_free, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, + "uwsgi zip importer", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + symzipimporter_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc) zipimporter_init, /* tp_init */ + PyType_GenericAlloc, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + PyObject_GC_Del, /* tp_free */ +}; + + int uwsgi_init_symbol_import() { @@ -563,6 +698,12 @@ int uwsgi_init_symbol_import() { exit(1); } + if (PyType_Ready(&ZipImporter_Type) < 0) { + PyErr_Print(); + uwsgi_log("unable to initialize zip importer module\n"); + exit(1); + } + if (PyType_Ready(&SymZipImporter_Type) < 0) { PyErr_Print(); uwsgi_log("unable to initialize symbols zip importer module\n"); @@ -583,6 +724,13 @@ int uwsgi_init_symbol_import() { exit(1); } + if (PyModule_AddObject(uwsgi_em, "ZipImporter", + (PyObject *)&ZipImporter_Type) < 0) { + PyErr_Print(); + uwsgi_log("unable to initialize zip importer object\n"); + exit(1); + } + if (PyModule_AddObject(uwsgi_em, "SymbolsZipImporter", (PyObject *)&SymZipImporter_Type) < 0) { PyErr_Print();