summaryrefslogtreecommitdiffstats
path: root/Mac/Lib
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1998-08-18 12:23:11 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1998-08-18 12:23:11 (GMT)
commitb93f52158b57707cf94a51d5d66735d666be06d8 (patch)
treef474c02f0dc8d9ab7bae32e0838c265e10534f3d /Mac/Lib
parent201f46de2c0ce193209ba24d68ce4ae711cac571 (diff)
downloadcpython-b93f52158b57707cf94a51d5d66735d666be06d8.zip
cpython-b93f52158b57707cf94a51d5d66735d666be06d8.tar.gz
cpython-b93f52158b57707cf94a51d5d66735d666be06d8.tar.bz2
Support for freezing packages (Just).
Diffstat (limited to 'Mac/Lib')
-rw-r--r--Mac/Lib/py_resource.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/Mac/Lib/py_resource.py b/Mac/Lib/py_resource.py
index 3c1343e..85d67e5 100644
--- a/Mac/Lib/py_resource.py
+++ b/Mac/Lib/py_resource.py
@@ -28,9 +28,18 @@ def open(dst):
Res.UseResFile(output)
return output
-def writemodule(name, id, data, type='PYC ', preload=0):
+def writemodule(name, id, data, type='PYC ', preload=0, ispackage=0):
"""Write pyc code to a PYC resource with given name and id."""
# XXXX Check that it doesn't exist
+
+ # Normally, byte 4-7 are the time stamp, but that is not used
+ # for 'PYC ' resources. We abuse byte 4 as a flag to indicate
+ # that it is a package rather than an ordinary module.
+ # See also macimport.c. (jvr)
+ if ispackage:
+ data = data[:4] + '\377\0\0\0' + data[8:] # flag resource as package
+ else:
+ data = data[:4] + '\0\0\0\0' + data[8:] # clear mod date field, used as package flag
res = Res.Resource(data)
res.AddResource(type, id, name)
if preload:
@@ -40,22 +49,23 @@ def writemodule(name, id, data, type='PYC ', preload=0):
res.WriteResource()
res.ReleaseResource()
-def frompycfile(file, name=None, preload=0):
+def frompycfile(file, name=None, preload=0, ispackage=0):
"""Copy one pyc file to the open resource file"""
if name == None:
d, name = os.path.split(file)
name = name[:-4]
id = findfreeid()
- writemodule(name, id, __builtin__.open(file, 'rb').read(), preload=preload)
+ data = __builtin__.open(file, 'rb').read()
+ writemodule(name, id, data, preload=preload, ispackage=ispackage)
return id, name
-def frompyfile(file, name=None, preload=0):
+def frompyfile(file, name=None, preload=0, ispackage=0):
"""Compile python source file to pyc file and add to resource file"""
import py_compile
py_compile.compile(file)
file = file +'c'
- return frompycfile(file, name, preload=preload)
+ return frompycfile(file, name, preload=preload, ispackage=ispackage)
# XXXX Note this is incorrect, it only handles one type and one file....