Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cef721

Browse files
committed
Allow .pyc files as applets as well as .py files. .py files have
priority, for safety reasons.
1 parent 5053b70 commit 3cef721

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Mac/Python/macmain.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ PyMac_Initialize(void)
476476
#if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
477477

478478
static int
479-
locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
479+
locateResourcePy(CFStringRef resourceType, char *resourceName, char *resourceURLCStr, int length)
480+
{
480481
CFBundleRef mainBundle = NULL;
481482
CFURLRef URL, absoluteURL;
482483
CFStringRef filenameString, filepathString, rsrcString;
@@ -500,7 +501,7 @@ locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
500501

501502
/* Look for py files in the main bundle by type */
502503
arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
503-
CFSTR("py"),
504+
resourceType,
504505
NULL );
505506

506507
/* See if there are any filename matches */
@@ -541,18 +542,22 @@ main(int argc, char **argv)
541542
/* First we see whether we have __rawmain__.py and run that if it
542543
** is there
543544
*/
544-
if (locateResourcePy("__rawmain__.py", scriptpath, 1024)) {
545+
if (locateResourcePy(CFSTR("py"), "__rawmain__.py", scriptpath, 1024)) {
545546
/* If we have a raw main we don't do AppleEvent processing.
546547
** Notice that this also means we keep the -psn.... argv[1]
547548
** value intact. Not sure whether that is important to someone,
548549
** but you never know...
549550
*/
550551
script = scriptpath;
552+
} else if (locateResourcePy(CFSTR("pyc"), "__rawmain__.pyc", scriptpath, 1024)) {
553+
script = scriptpath;
551554
} else {
552555
/* Otherwise we look for __main__.py. Whether that is
553556
** found or not we also process AppleEvent arguments.
554557
*/
555-
if (locateResourcePy("__main__.py", scriptpath, 1024))
558+
if (locateResourcePy(CFSTR("py"), "__main__.py", scriptpath, 1024))
559+
script = scriptpath;
560+
else if (locateResourcePy(CFSTR("pyc"), "__main__.pyc", scriptpath, 1024))
556561
script = scriptpath;
557562

558563
init_common(&argc, &argv, 0);

0 commit comments

Comments
 (0)