Author: victor.stinner Date: Wed Jul 14 22:38:21 2010 New Revision: 82905 Log: use an object to access zipimport cache Modified: python/branches/import_unicode/Modules/zipimport.c Modified: python/branches/import_unicode/Modules/zipimport.c ============================================================================== --- python/branches/import_unicode/Modules/zipimport.c (original) +++ python/branches/import_unicode/Modules/zipimport.c Wed Jul 14 22:38:21 2010 @@ -64,11 +64,14 @@ PyObject *pathbytes; char *path, *p, *prefix, buf[MAXPATHLEN+2]; size_t len; + PyObject *files; + PyObject *pathobj; if (!_PyArg_NoKeywords("zipimporter()", kwds)) return -1; - if (!PyArg_ParseTuple(args, "O&:zipimporter", PyUnicode_FSConverter, &pathbytes)) + if (!PyArg_ParseTuple(args, "O&:zipimporter", + PyUnicode_FSConverter, &pathbytes)) return -1; len = PyBytes_GET_SIZE(pathbytes); @@ -117,31 +120,38 @@ *p = '\0'; prefix = p; } - if (path != NULL) { - PyObject *files; - files = PyDict_GetItemString(zip_directory_cache, path); - if (files == NULL) { - PyObject *bufobj; - bufobj = PyUnicode_DecodeFSDefault(buf); - if (bufobj == NULL) - return -1; - files = read_directory(bufobj); - Py_DECREF(bufobj); - if (files == NULL) - return -1; - if (PyDict_SetItemString(zip_directory_cache, path, - files) != 0) - return -1; - } - else - Py_INCREF(files); - self->files = files; - } - else { + if (path == NULL) PyErr_SetString(ZipImportError, "not a Zip file"); return -1; } + pathobj = PyUnicode_DecodeFSDefault(path); + if (pathobj == NULL) + return -1; + files = PyDict_GetItem(zip_directory_cache, pathobj); + if (files == NULL) { + PyObject *bufobj; + bufobj = PyUnicode_DecodeFSDefault(buf); + if (bufobj == NULL) { + Py_DECREF(pathobj); + return -1; + } + files = read_directory(bufobj); + Py_DECREF(bufobj); + if (files == NULL) { + Py_DECREF(pathobj); + return -1; + } + if (PyDict_SetItem(zip_directory_cache, pathobj, files) != 0) { + Py_DECREF(pathobj); + return -1; + } + } + else + Py_INCREF(files); + Py_DECREF(pathobj); + self->files = files; + if (prefix == NULL) prefix = ""; else {
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4