diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-08-04 08:12:36 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-08-04 08:12:36 (GMT) |
commit | c1731373914622dcaa4de259b96ec44d490b5e2c (patch) | |
tree | e6fc3dc8c57669055ce2f43b56ac02f4b3534796 /Python/import.c | |
parent | 289898cdbb1d4526ce45e600ed2843a14d1feb0d (diff) | |
download | cpython-c1731373914622dcaa4de259b96ec44d490b5e2c.zip cpython-c1731373914622dcaa4de259b96ec44d490b5e2c.tar.gz cpython-c1731373914622dcaa4de259b96ec44d490b5e2c.tar.bz2 |
Derived from SF patch #446899 Permit import of .pyw under Windows, from
David Bolen.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c index a2106de..8e08164 100644 --- a/Python/import.c +++ b/Python/import.c @@ -70,6 +70,9 @@ static const struct filedescr _PyImport_StandardFiletab[] = { #else static const struct filedescr _PyImport_StandardFiletab[] = { {".py", "r", PY_SOURCE}, +#ifdef MS_WIN32 + {".pyw", "r", PY_SOURCE}, +#endif {".pyc", "rb", PY_COMPILED}, {0, 0} }; @@ -513,13 +516,19 @@ PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) static char * make_compiled_pathname(char *pathname, char *buf, size_t buflen) { - size_t len; - - len = strlen(pathname); + size_t len = strlen(pathname); if (len+2 > buflen) return NULL; - strcpy(buf, pathname); - strcpy(buf+len, Py_OptimizeFlag ? "o" : "c"); + +#ifdef MS_WIN32 + /* Treat .pyw as if it were .py. The case of ".pyw" must match + that used in _PyImport_StandardFiletab. */ + if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0) + --len; /* pretend 'w' isn't there */ +#endif + memcpy(buf, pathname, len); + buf[len] = Py_OptimizeFlag ? 'o' : 'c'; + buf[len+1] = '\0'; return buf; } |