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

Skip to content

Commit 32d1a3b

Browse files
committed
Fixed to work under MachoPython, doing the expected unpacking for applesingle files. The IDE still doesn't work, though, because it uses :-style pathnames.
1 parent d48b106 commit 32d1a3b

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

Mac/Lib/macresource.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,33 @@ def need(restype, resid, filename=None, modname=None):
6161
else:
6262
raise ResourceFileNotFoundError, filename
6363

64-
refno = Res.FSpOpenResFile(pathname, 1)
64+
try:
65+
refno = Res.FSpOpenResFile(pathname, 1)
66+
except Res.Error, arg:
67+
if arg[0] in (-37, -39):
68+
# No resource fork. We may be on OSX, try to decode
69+
# the applesingle file.
70+
pathname = _decode(pathname)
71+
if pathname:
72+
refno = Res.FSOpenResourceFile(pathname, u'', 1)
73+
else:
74+
raise
75+
6576

6677
# And check that the resource exists now
6778
if type(resid) is type(1):
6879
h = Res.GetResource(restype, resid)
6980
else:
7081
h = Res.GetNamedResource(restype, resid)
71-
return refno
82+
return refno
83+
84+
def _decode(pathname):
85+
# Decode an AppleSingle resource file, return the new pathname.
86+
newpathname = pathname + '.df.rsrc'
87+
if os.path.exists(newpathname):
88+
return newpathname
89+
import applesingle
90+
applesingle.decode(pathname, newpathname, resonly=1)
91+
return newpathname
92+
93+

0 commit comments

Comments
 (0)