summaryrefslogtreecommitdiffstats
path: root/Lib/plat-mac/applesingle.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-04-09 13:25:43 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-04-09 13:25:43 (GMT)
commit0ae3220736f9b71820b01aee1f540d0afcceb9a6 (patch)
tree6015b689b7555940e0c0822b1896fff3ee39cb23 /Lib/plat-mac/applesingle.py
parent058a84f36ae62dc69f4cb2a07d038e10a617fffc (diff)
downloadcpython-0ae3220736f9b71820b01aee1f540d0afcceb9a6.zip
cpython-0ae3220736f9b71820b01aee1f540d0afcceb9a6.tar.gz
cpython-0ae3220736f9b71820b01aee1f540d0afcceb9a6.tar.bz2
Detabbed.
Diffstat (limited to 'Lib/plat-mac/applesingle.py')
-rw-r--r--Lib/plat-mac/applesingle.py142
1 files changed, 71 insertions, 71 deletions
diff --git a/Lib/plat-mac/applesingle.py b/Lib/plat-mac/applesingle.py
index f8be3d2..5b9c2dd 100644
--- a/Lib/plat-mac/applesingle.py
+++ b/Lib/plat-mac/applesingle.py
@@ -24,77 +24,77 @@ AS_RESOURCEFORK=2
AS_IGNORE=(3,4,5,6,8,9,10,11,12,13,14,15)
def decode(input, output, resonly=0):
- if type(input) == type(''):
- input = open(input, 'rb')
- # Should we also test for FSSpecs or FSRefs?
- header = input.read(AS_HEADER_LENGTH)
- try:
- magic, version, dummy, nentry = struct.unpack(AS_HEADER_FORMAT, header)
- except ValueError, arg:
- raise Error, "Unpack header error: %s"%arg
- if verbose:
- print 'Magic: 0x%8.8x'%magic
- print 'Version: 0x%8.8x'%version
- print 'Entries: %d'%nentry
- if magic != AS_MAGIC:
- raise Error, 'Unknown AppleSingle magic number 0x%8.8x'%magic
- if version != AS_VERSION:
- raise Error, 'Unknown AppleSingle version number 0x%8.8x'%version
- if nentry <= 0:
- raise Error, "AppleSingle file contains no forks"
- headers = [input.read(AS_ENTRY_LENGTH) for i in range(nentry)]
- didwork = 0
- for hdr in headers:
- try:
- id, offset, length = struct.unpack(AS_ENTRY_FORMAT, hdr)
- except ValueError, arg:
- raise Error, "Unpack entry error: %s"%arg
- if verbose:
- print 'Fork %d, offset %d, length %d'%(id, offset, length)
- input.seek(offset)
- if length == 0:
- data = ''
- else:
- data = input.read(length)
- if len(data) != length:
- raise Error, 'Short read: expected %d bytes got %d'%(length, len(data))
- if id == AS_DATAFORK:
- if verbose:
- print ' (data fork)'
- if not resonly:
- didwork = 1
- fp = open(output, 'wb')
- fp.write(data)
- fp.close()
- elif id == AS_RESOURCEFORK:
- didwork = 1
- if verbose:
- print ' (resource fork)'
- if resonly:
- fp = open(output, 'wb')
- else:
- fp = MacOS.openrf(output, 'wb')
- fp.write(data)
- fp.close()
- elif id in AS_IGNORE:
- if verbose:
- print ' (ignored)'
- else:
- raise Error, 'Unknown fork type %d'%id
- if not didwork:
- raise Error, 'No useful forks found'
+ if type(input) == type(''):
+ input = open(input, 'rb')
+ # Should we also test for FSSpecs or FSRefs?
+ header = input.read(AS_HEADER_LENGTH)
+ try:
+ magic, version, dummy, nentry = struct.unpack(AS_HEADER_FORMAT, header)
+ except ValueError, arg:
+ raise Error, "Unpack header error: %s"%arg
+ if verbose:
+ print 'Magic: 0x%8.8x'%magic
+ print 'Version: 0x%8.8x'%version
+ print 'Entries: %d'%nentry
+ if magic != AS_MAGIC:
+ raise Error, 'Unknown AppleSingle magic number 0x%8.8x'%magic
+ if version != AS_VERSION:
+ raise Error, 'Unknown AppleSingle version number 0x%8.8x'%version
+ if nentry <= 0:
+ raise Error, "AppleSingle file contains no forks"
+ headers = [input.read(AS_ENTRY_LENGTH) for i in range(nentry)]
+ didwork = 0
+ for hdr in headers:
+ try:
+ id, offset, length = struct.unpack(AS_ENTRY_FORMAT, hdr)
+ except ValueError, arg:
+ raise Error, "Unpack entry error: %s"%arg
+ if verbose:
+ print 'Fork %d, offset %d, length %d'%(id, offset, length)
+ input.seek(offset)
+ if length == 0:
+ data = ''
+ else:
+ data = input.read(length)
+ if len(data) != length:
+ raise Error, 'Short read: expected %d bytes got %d'%(length, len(data))
+ if id == AS_DATAFORK:
+ if verbose:
+ print ' (data fork)'
+ if not resonly:
+ didwork = 1
+ fp = open(output, 'wb')
+ fp.write(data)
+ fp.close()
+ elif id == AS_RESOURCEFORK:
+ didwork = 1
+ if verbose:
+ print ' (resource fork)'
+ if resonly:
+ fp = open(output, 'wb')
+ else:
+ fp = MacOS.openrf(output, 'wb')
+ fp.write(data)
+ fp.close()
+ elif id in AS_IGNORE:
+ if verbose:
+ print ' (ignored)'
+ else:
+ raise Error, 'Unknown fork type %d'%id
+ if not didwork:
+ raise Error, 'No useful forks found'
def _test():
- if len(sys.argv) < 3 or sys.argv[1] == '-r' and len(sys.argv) != 4:
- print 'Usage: applesingle.py [-r] applesinglefile decodedfile'
- sys.exit(1)
- if sys.argv[1] == '-r':
- resonly = 1
- del sys.argv[1]
- else:
- resonly = 0
- decode(sys.argv[1], sys.argv[2], resonly=resonly)
-
+ if len(sys.argv) < 3 or sys.argv[1] == '-r' and len(sys.argv) != 4:
+ print 'Usage: applesingle.py [-r] applesinglefile decodedfile'
+ sys.exit(1)
+ if sys.argv[1] == '-r':
+ resonly = 1
+ del sys.argv[1]
+ else:
+ resonly = 0
+ decode(sys.argv[1], sys.argv[2], resonly=resonly)
+
if __name__ == '__main__':
- _test()
- \ No newline at end of file
+ _test()
+ \ No newline at end of file