From: Jack Jansen Date: Sun, 24 Feb 2002 22:51:26 +0000 (+0000) Subject: backport of 1.13: X-Git-Tag: v2.2.1c1~178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad48e32cbcab0459e9a07b5ed54b350519f27dc7;p=thirdparty%2FPython%2Fcpython.git backport of 1.13: Fixed to work under MachoPython, doing the expected unpacking for applesingle files. --- diff --git a/Mac/Lib/macresource.py b/Mac/Lib/macresource.py index 001e6cc7bb69..1cd14332a8be 100644 --- a/Mac/Lib/macresource.py +++ b/Mac/Lib/macresource.py @@ -61,11 +61,33 @@ def need(restype, resid, filename=None, modname=None): else: raise ResourceFileNotFoundError, filename - refno = Res.FSpOpenResFile(pathname, 1) + try: + refno = Res.FSpOpenResFile(pathname, 1) + except Res.Error, arg: + if arg[0] in (-37, -39): + # No resource fork. We may be on OSX, try to decode + # the applesingle file. + pathname = _decode(pathname) + if pathname: + refno = Res.FSOpenResourceFile(pathname, u'', 1) + else: + raise + # And check that the resource exists now if type(resid) is type(1): h = Res.GetResource(restype, resid) else: h = Res.GetNamedResource(restype, resid) - return refno \ No newline at end of file + return refno + +def _decode(pathname): + # Decode an AppleSingle resource file, return the new pathname. + newpathname = pathname + '.df.rsrc' + if os.path.exists(newpathname): + return newpathname + import applesingle + applesingle.decode(pathname, newpathname, resonly=1) + return newpathname + + \ No newline at end of file