summaryrefslogtreecommitdiffstats
path: root/Mac/Lib/py_resource.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-11-19 14:34:18 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-11-19 14:34:18 (GMT)
commit28ecf70db57828db2ca279643bf9aeca7662f35c (patch)
tree09b7767bbc411f85313b58d6fe7e5e67d9392973 /Mac/Lib/py_resource.py
parent6045b9c93511c767f6cfa2d2fa299c76181acd9b (diff)
downloadcpython-28ecf70db57828db2ca279643bf9aeca7662f35c.zip
cpython-28ecf70db57828db2ca279643bf9aeca7662f35c.tar.gz
cpython-28ecf70db57828db2ca279643bf9aeca7662f35c.tar.bz2
Getting rid of support for MacOS9 and earlier. This is the first step,
and the biggest in size, but probably the easiest. Hunting through the source code comes next.
Diffstat (limited to 'Mac/Lib/py_resource.py')
-rw-r--r--Mac/Lib/py_resource.py90
1 files changed, 0 insertions, 90 deletions
diff --git a/Mac/Lib/py_resource.py b/Mac/Lib/py_resource.py
deleted file mode 100644
index 0faf1f1..0000000
--- a/Mac/Lib/py_resource.py
+++ /dev/null
@@ -1,90 +0,0 @@
-"""Creation of PYC resources"""
-import os
-from Carbon import Res
-import __builtin__
-
-READ = 1
-WRITE = 2
-smAllScripts = -3
-
-def Pstring(str):
- """Return a pascal-style string from a python-style string"""
- if len(str) > 255:
- raise ValueError, 'String too large'
- return chr(len(str))+str
-
-def create(dst, creator='Pyth'):
- """Create output file. Return handle and first id to use."""
-
- try:
- os.unlink(dst)
- except os.error:
- pass
- Res.FSpCreateResFile(dst, creator, 'rsrc', smAllScripts)
- return open(dst)
-
-def open(dst):
- output = Res.FSpOpenResFile(dst, WRITE)
- Res.UseResFile(output)
- return output
-
-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:
- attrs = res.GetResAttrs()
- attrs = attrs | 0x04
- res.SetResAttrs(attrs)
- res.WriteResource()
- res.ReleaseResource()
-
-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()
- data = __builtin__.open(file, 'rb').read()
- writemodule(name, id, data, preload=preload, ispackage=ispackage)
- return id, name
-
-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, ispackage=ispackage)
-
-# XXXX Note this is incorrect, it only handles one type and one file....
-
-_firstfreeid = None
-
-def findfreeid(type='PYC '):
- """Find next free id-number for given resource type"""
- global _firstfreeid
-
- if _firstfreeid == None:
- Res.SetResLoad(0)
- highest = 511
- num = Res.Count1Resources(type)
- for i in range(1, num+1):
- r = Res.Get1IndResource(type, i)
- id, d1, d2 = r.GetResInfo()
- highest = max(highest, id)
- Res.SetResLoad(1)
- _firstfreeid = highest+1
- id = _firstfreeid
- _firstfreeid = _firstfreeid+1
- return id