/* Given a path to a .pyc file in the archive, return the modification time of the matching .py file, or 0 if no source is available. */ static time_t get_mtime_of_source(ZipImporter *self, PyObject *path) { PyObject *toc_entry, *stripped; time_t mtime; /* strip 'c' or 'o' from *.py[co] */ if (PyUnicode_READY(path) == -1) return (time_t)-1; stripped = PyUnicode_FromKindAndData(PyUnicode_KIND(path), PyUnicode_DATA(path), PyUnicode_GET_LENGTH(path) - 1); if (stripped == NULL) return (time_t)-1; toc_entry = PyDict_GetItem(self->files, stripped); Py_DECREF(stripped); if (toc_entry != NULL && PyTuple_Check(toc_entry) && PyTuple_Size(toc_entry) == 8) { /* fetch the time stamp of the .py file for comparison with an embedded pyc time stamp */ int time, date; time = PyLong_AsLong(PyTuple_GetItem(toc_entry, 5)); date = PyLong_AsLong(PyTuple_GetItem(toc_entry, 6)); mtime = parse_dostime(time, date); } else mtime = 0; return mtime; }
/* Given a path to a .pyc or .pyo file in the archive, return the modifictaion time of the matching .py file, or 0 if no source is available. */ static time_t get_mtime_of_source(ZipImporter *self, char *path) { PyObject *toc_entry; time_t mtime = 0; Py_ssize_t lastchar = strlen(path) - 1; char savechar = path[lastchar]; path[lastchar] = '\0'; /* strip 'c' or 'o' from *.py[co] */ toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry != NULL && PyTuple_Check(toc_entry) && PyTuple_Size(toc_entry) == 8) { /* fetch the time stamp of the .py file for comparison with an embedded pyc time stamp */ int time, date; time = PyInt_AsLong(PyTuple_GetItem(toc_entry, 5)); date = PyInt_AsLong(PyTuple_GetItem(toc_entry, 6)); mtime = parse_dostime(time, date); } path[lastchar] = savechar; return mtime; }