[Python-checkins] python/dist/src/Lib/plat-mac Audio_mac.py,1.2,1.3 PixMapWrapper.py,1.2,1.3 aepack.py,1.5,1.6 aetools.py,1.6,1.7 aetypes.py,1.4,1.5 applesingle.py,1.1,1.2 appletrawmain.py,1.1,1.2 appletrunner.py,1.1,1.2 bgenlocations.py,1.3,1.4 buildtools.py,1.8,1.9 bundlebuilder.py,1.24,1.25 cfmfile.py,1.2,1.3 findertools.py,1.3,1.4 gensuitemodule.py,1.5,1.6 ic.py,1.4,1.5 macerrors.py,1.1,1.2 macfs.py,1.9,1.10 macresource.py,1.4,1.5 pimp.py,1.14,1.15 plistlib.py,1.1,1.2 videoreader.py,1.2,1.3
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Wed, 09 Apr 2003 06:25:50 -0700
Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1:/tmp/cvs-serv29131
Modified Files:
Audio_mac.py PixMapWrapper.py aepack.py aetools.py aetypes.py
applesingle.py appletrawmain.py appletrunner.py
bgenlocations.py buildtools.py bundlebuilder.py cfmfile.py
findertools.py gensuitemodule.py ic.py macerrors.py macfs.py
macresource.py pimp.py plistlib.py videoreader.py
Log Message:
Detabbed.
Index: Audio_mac.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/Audio_mac.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Audio_mac.py 6 Feb 2003 23:12:23 -0000 1.2
--- Audio_mac.py 9 Apr 2003 13:25:42 -0000 1.3
***************
*** 4,121 ****
class Play_Audio_mac:
! def __init__(self, qsize=QSIZE):
! self._chan = None
! self._qsize = qsize
! self._outrate = 22254
! self._sampwidth = 1
! self._nchannels = 1
! self._gc = []
! self._usercallback = None
! def __del__(self):
! self.stop()
! self._usercallback = None
! def wait(self):
! import time
! while self.getfilled():
! time.sleep(0.1)
! self._chan = None
! self._gc = []
! def stop(self, quietNow = 1):
! ##chan = self._chan
! self._chan = None
! ##chan.SndDisposeChannel(1)
! self._gc = []
! def setoutrate(self, outrate):
! self._outrate = outrate
! def setsampwidth(self, sampwidth):
! self._sampwidth = sampwidth
! def setnchannels(self, nchannels):
! self._nchannels = nchannels
! def writeframes(self, data):
! import time
! from Carbon.Sound import bufferCmd, callBackCmd, extSH
! import struct
! import MacOS
! if not self._chan:
! from Carbon import Snd
! self._chan = Snd.SndNewChannel(5, 0, self._callback)
! nframes = len(data) / self._nchannels / self._sampwidth
! if len(data) != nframes * self._nchannels * self._sampwidth:
! raise error, 'data is not a whole number of frames'
! while self._gc and \
! self.getfilled() + nframes > \
! self._qsize / self._nchannels / self._sampwidth:
! time.sleep(0.1)
! if self._sampwidth == 1:
! import audioop
! data = audioop.add(data, '\x80'*len(data), 1)
! h1 = struct.pack('llHhllbbl',
! id(data)+MacOS.string_id_to_buffer,
! self._nchannels,
! self._outrate, 0,
! 0,
! 0,
! extSH,
! 60,
! nframes)
! h2 = 22*'\0'
! h3 = struct.pack('hhlll',
! self._sampwidth*8,
! 0,
! 0,
! 0,
! 0)
! header = h1+h2+h3
! self._gc.append((header, data))
! self._chan.SndDoCommand((bufferCmd, 0, header), 0)
! self._chan.SndDoCommand((callBackCmd, 0, 0), 0)
! def _callback(self, *args):
! del self._gc[0]
! if self._usercallback:
! self._usercallback()
!
! def setcallback(self, callback):
! self._usercallback = callback
! def getfilled(self):
! filled = 0
! for header, data in self._gc:
! filled = filled + len(data)
! return filled / self._nchannels / self._sampwidth
! def getfillable(self):
! return (self._qsize / self._nchannels / self._sampwidth) - self.getfilled()
! def ulaw2lin(self, data):
! import audioop
! return audioop.ulaw2lin(data, 2)
def test():
! import aifc
! import EasyDialogs
! fn = EasyDialogs.AskFileForOpen(message="Select an AIFF soundfile", typeList=("AIFF",))
! if not fn: return
! af = aifc.open(fn, 'r')
! print af.getparams()
! p = Play_Audio_mac()
! p.setoutrate(af.getframerate())
! p.setsampwidth(af.getsampwidth())
! p.setnchannels(af.getnchannels())
! BUFSIZ = 10000
! while 1:
! data = af.readframes(BUFSIZ)
! if not data: break
! p.writeframes(data)
! print 'wrote', len(data), 'space', p.getfillable()
! p.wait()
if __name__ == '__main__':
! test()
--- 4,121 ----
class Play_Audio_mac:
! def __init__(self, qsize=QSIZE):
! self._chan = None
! self._qsize = qsize
! self._outrate = 22254
! self._sampwidth = 1
! self._nchannels = 1
! self._gc = []
! self._usercallback = None
! def __del__(self):
! self.stop()
! self._usercallback = None
! def wait(self):
! import time
! while self.getfilled():
! time.sleep(0.1)
! self._chan = None
! self._gc = []
! def stop(self, quietNow = 1):
! ##chan = self._chan
! self._chan = None
! ##chan.SndDisposeChannel(1)
! self._gc = []
! def setoutrate(self, outrate):
! self._outrate = outrate
! def setsampwidth(self, sampwidth):
! self._sampwidth = sampwidth
! def setnchannels(self, nchannels):
! self._nchannels = nchannels
! def writeframes(self, data):
! import time
! from Carbon.Sound import bufferCmd, callBackCmd, extSH
! import struct
! import MacOS
! if not self._chan:
! from Carbon import Snd
! self._chan = Snd.SndNewChannel(5, 0, self._callback)
! nframes = len(data) / self._nchannels / self._sampwidth
! if len(data) != nframes * self._nchannels * self._sampwidth:
! raise error, 'data is not a whole number of frames'
! while self._gc and \
! self.getfilled() + nframes > \
! self._qsize / self._nchannels / self._sampwidth:
! time.sleep(0.1)
! if self._sampwidth == 1:
! import audioop
! data = audioop.add(data, '\x80'*len(data), 1)
! h1 = struct.pack('llHhllbbl',
! id(data)+MacOS.string_id_to_buffer,
! self._nchannels,
! self._outrate, 0,
! 0,
! 0,
! extSH,
! 60,
! nframes)
! h2 = 22*'\0'
! h3 = struct.pack('hhlll',
! self._sampwidth*8,
! 0,
! 0,
! 0,
! 0)
! header = h1+h2+h3
! self._gc.append((header, data))
! self._chan.SndDoCommand((bufferCmd, 0, header), 0)
! self._chan.SndDoCommand((callBackCmd, 0, 0), 0)
! def _callback(self, *args):
! del self._gc[0]
! if self._usercallback:
! self._usercallback()
!
! def setcallback(self, callback):
! self._usercallback = callback
! def getfilled(self):
! filled = 0
! for header, data in self._gc:
! filled = filled + len(data)
! return filled / self._nchannels / self._sampwidth
! def getfillable(self):
! return (self._qsize / self._nchannels / self._sampwidth) - self.getfilled()
! def ulaw2lin(self, data):
! import audioop
! return audioop.ulaw2lin(data, 2)
def test():
! import aifc
! import EasyDialogs
! fn = EasyDialogs.AskFileForOpen(message="Select an AIFF soundfile", typeList=("AIFF",))
! if not fn: return
! af = aifc.open(fn, 'r')
! print af.getparams()
! p = Play_Audio_mac()
! p.setoutrate(af.getframerate())
! p.setsampwidth(af.getsampwidth())
! p.setnchannels(af.getnchannels())
! BUFSIZ = 10000
! while 1:
! data = af.readframes(BUFSIZ)
! if not data: break
! p.writeframes(data)
! print 'wrote', len(data), 'space', p.getfillable()
! p.wait()
if __name__ == '__main__':
! test()
Index: PixMapWrapper.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/PixMapWrapper.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PixMapWrapper.py 21 Feb 2003 23:18:48 -0000 1.2
--- PixMapWrapper.py 9 Apr 2003 13:25:42 -0000 1.3
***************
*** 15,215 ****
# PixMap data structure element format (as used with struct)
_pmElemFormat = {
! 'baseAddr':'l', # address of pixel data
! 'rowBytes':'H', # bytes per row, plus 0x8000
! 'bounds':'hhhh', # coordinates imposed over pixel data
! 'top':'h',
! 'left':'h',
! 'bottom':'h',
! 'right':'h',
! 'pmVersion':'h', # flags for Color QuickDraw
! 'packType':'h', # format of compression algorithm
! 'packSize':'l', # size after compression
! 'hRes':'l', # horizontal pixels per inch
! 'vRes':'l', # vertical pixels per inch
! 'pixelType':'h', # pixel format
! 'pixelSize':'h', # bits per pixel
! 'cmpCount':'h', # color components per pixel
! 'cmpSize':'h', # bits per component
! 'planeBytes':'l', # offset in bytes to next plane
! 'pmTable':'l', # handle to color table
! 'pmReserved':'l' # reserved for future use
}
# PixMap data structure element offset
_pmElemOffset = {
! 'baseAddr':0,
! 'rowBytes':4,
! 'bounds':6,
! 'top':6,
! 'left':8,
! 'bottom':10,
! 'right':12,
! 'pmVersion':14,
! 'packType':16,
! 'packSize':18,
! 'hRes':22,
! 'vRes':26,
! 'pixelType':30,
! 'pixelSize':32,
! 'cmpCount':34,
! 'cmpSize':36,
! 'planeBytes':38,
! 'pmTable':42,
! 'pmReserved':46
}
class PixMapWrapper:
! """PixMapWrapper -- wraps the QD PixMap object in a Python class,
! with methods to easily get/set various pixmap fields. Note: Use the
! PixMap() method when passing to QD calls."""
! def __init__(self):
! self.__dict__['data'] = ''
! self._header = struct.pack("lhhhhhhhlllhhhhlll",
! id(self.data)+MacOS.string_id_to_buffer,
! 0, # rowBytes
! 0, 0, 0, 0, # bounds
! 0, # pmVersion
! 0, 0, # packType, packSize
! 72<<16, 72<<16, # hRes, vRes
! QuickDraw.RGBDirect, # pixelType
! 16, # pixelSize
! 2, 5, # cmpCount, cmpSize,
! 0, 0, 0) # planeBytes, pmTable, pmReserved
! self.__dict__['_pm'] = Qd.RawBitMap(self._header)
!
! def _stuff(self, element, bytes):
! offset = _pmElemOffset[element]
! fmt = _pmElemFormat[element]
! self._header = self._header[:offset] \
! + struct.pack(fmt, bytes) \
! + self._header[offset + struct.calcsize(fmt):]
! self.__dict__['_pm'] = None
!
! def _unstuff(self, element):
! offset = _pmElemOffset[element]
! fmt = _pmElemFormat[element]
! return struct.unpack(fmt, self._header[offset:offset+struct.calcsize(fmt)])[0]
! def __setattr__(self, attr, val):
! if attr == 'baseAddr':
! raise 'UseErr', "don't assign to .baseAddr -- assign to .data instead"
! elif attr == 'data':
! self.__dict__['data'] = val
! self._stuff('baseAddr', id(self.data) + MacOS.string_id_to_buffer)
! elif attr == 'rowBytes':
! # high bit is always set for some odd reason
! self._stuff('rowBytes', val | 0x8000)
! elif attr == 'bounds':
! # assume val is in official Left, Top, Right, Bottom order!
! self._stuff('left',val[0])
! self._stuff('top',val[1])
! self._stuff('right',val[2])
! self._stuff('bottom',val[3])
! elif attr == 'hRes' or attr == 'vRes':
! # 16.16 fixed format, so just shift 16 bits
! self._stuff(attr, int(val) << 16)
! elif attr in _pmElemFormat.keys():
! # any other pm attribute -- just stuff
! self._stuff(attr, val)
! else:
! self.__dict__[attr] = val
! def __getattr__(self, attr):
! if attr == 'rowBytes':
! # high bit is always set for some odd reason
! return self._unstuff('rowBytes') & 0x7FFF
! elif attr == 'bounds':
! # return bounds in official Left, Top, Right, Bottom order!
! return ( \
! self._unstuff('left'),
! self._unstuff('top'),
! self._unstuff('right'),
! self._unstuff('bottom') )
! elif attr == 'hRes' or attr == 'vRes':
! # 16.16 fixed format, so just shift 16 bits
! return self._unstuff(attr) >> 16
! elif attr in _pmElemFormat.keys():
! # any other pm attribute -- just unstuff
! return self._unstuff(attr)
! else:
! return self.__dict__[attr]
!
! def PixMap(self):
! "Return a QuickDraw PixMap corresponding to this data."
! if not self.__dict__['_pm']:
! self.__dict__['_pm'] = Qd.RawBitMap(self._header)
! return self.__dict__['_pm']
! def blit(self, x1=0,y1=0,x2=None,y2=None, port=None):
! """Draw this pixmap into the given (default current) grafport."""
! src = self.bounds
! dest = [x1,y1,x2,y2]
! if x2 == None:
! dest[2] = x1 + src[2]-src[0]
! if y2 == None:
! dest[3] = y1 + src[3]-src[1]
! if not port: port = Qd.GetPort()
! Qd.CopyBits(self.PixMap(), port.GetPortBitMapForCopyBits(), src, tuple(dest),
! QuickDraw.srcCopy, None)
!
! def fromstring(self,s,width,height,format=imgformat.macrgb):
! """Stuff this pixmap with raw pixel data from a string.
! Supply width, height, and one of the imgformat specifiers."""
! # we only support 16- and 32-bit mac rgb...
! # so convert if necessary
! if format != imgformat.macrgb and format != imgformat.macrgb16:
! # (LATER!)
! raise "NotImplementedError", "conversion to macrgb or macrgb16"
! self.data = s
! self.bounds = (0,0,width,height)
! self.cmpCount = 3
! self.pixelType = QuickDraw.RGBDirect
! if format == imgformat.macrgb:
! self.pixelSize = 32
! self.cmpSize = 8
! else:
! self.pixelSize = 16
! self.cmpSize = 5
! self.rowBytes = width*self.pixelSize/8
! def tostring(self, format=imgformat.macrgb):
! """Return raw data as a string in the specified format."""
! # is the native format requested? if so, just return data
! if (format == imgformat.macrgb and self.pixelSize == 32) or \
! (format == imgformat.macrgb16 and self.pixelsize == 16):
! return self.data
! # otherwise, convert to the requested format
! # (LATER!)
! raise "NotImplementedError", "data format conversion"
! def fromImage(self,im):
! """Initialize this PixMap from a PIL Image object."""
! # We need data in ARGB format; PIL can't currently do that,
! # but it can do RGBA, which we can use by inserting one null
! # up frontpm =
! if im.mode != 'RGBA': im = im.convert('RGBA')
! data = chr(0) + im.tostring()
! self.fromstring(data, im.size[0], im.size[1])
! def toImage(self):
! """Return the contents of this PixMap as a PIL Image object."""
! import Image
! # our tostring() method returns data in ARGB format,
! # whereas Image uses RGBA; a bit of slicing fixes this...
! data = self.tostring()[1:] + chr(0)
! bounds = self.bounds
! return Image.fromstring('RGBA',(bounds[2]-bounds[0],bounds[3]-bounds[1]),data)
def test():
! import MacOS
! import EasyDialogs
! import Image
! path = EasyDialogs.AskFileForOpen("Image File:")
! if not path: return
! pm = PixMapWrapper()
! pm.fromImage( Image.open(path) )
! pm.blit(20,20)
! return pm
--- 15,215 ----
# PixMap data structure element format (as used with struct)
_pmElemFormat = {
! 'baseAddr':'l', # address of pixel data
! 'rowBytes':'H', # bytes per row, plus 0x8000
! 'bounds':'hhhh', # coordinates imposed over pixel data
! 'top':'h',
! 'left':'h',
! 'bottom':'h',
! 'right':'h',
! 'pmVersion':'h', # flags for Color QuickDraw
! 'packType':'h', # format of compression algorithm
! 'packSize':'l', # size after compression
! 'hRes':'l', # horizontal pixels per inch
! 'vRes':'l', # vertical pixels per inch
! 'pixelType':'h', # pixel format
! 'pixelSize':'h', # bits per pixel
! 'cmpCount':'h', # color components per pixel
! 'cmpSize':'h', # bits per component
! 'planeBytes':'l', # offset in bytes to next plane
! 'pmTable':'l', # handle to color table
! 'pmReserved':'l' # reserved for future use
}
# PixMap data structure element offset
_pmElemOffset = {
! 'baseAddr':0,
! 'rowBytes':4,
! 'bounds':6,
! 'top':6,
! 'left':8,
! 'bottom':10,
! 'right':12,
! 'pmVersion':14,
! 'packType':16,
! 'packSize':18,
! 'hRes':22,
! 'vRes':26,
! 'pixelType':30,
! 'pixelSize':32,
! 'cmpCount':34,
! 'cmpSize':36,
! 'planeBytes':38,
! 'pmTable':42,
! 'pmReserved':46
}
class PixMapWrapper:
! """PixMapWrapper -- wraps the QD PixMap object in a Python class,
! with methods to easily get/set various pixmap fields. Note: Use the
! PixMap() method when passing to QD calls."""
! def __init__(self):
! self.__dict__['data'] = ''
! self._header = struct.pack("lhhhhhhhlllhhhhlll",
! id(self.data)+MacOS.string_id_to_buffer,
! 0, # rowBytes
! 0, 0, 0, 0, # bounds
! 0, # pmVersion
! 0, 0, # packType, packSize
! 72<<16, 72<<16, # hRes, vRes
! QuickDraw.RGBDirect, # pixelType
! 16, # pixelSize
! 2, 5, # cmpCount, cmpSize,
! 0, 0, 0) # planeBytes, pmTable, pmReserved
! self.__dict__['_pm'] = Qd.RawBitMap(self._header)
!
! def _stuff(self, element, bytes):
! offset = _pmElemOffset[element]
! fmt = _pmElemFormat[element]
! self._header = self._header[:offset] \
! + struct.pack(fmt, bytes) \
! + self._header[offset + struct.calcsize(fmt):]
! self.__dict__['_pm'] = None
!
! def _unstuff(self, element):
! offset = _pmElemOffset[element]
! fmt = _pmElemFormat[element]
! return struct.unpack(fmt, self._header[offset:offset+struct.calcsize(fmt)])[0]
! def __setattr__(self, attr, val):
! if attr == 'baseAddr':
! raise 'UseErr', "don't assign to .baseAddr -- assign to .data instead"
! elif attr == 'data':
! self.__dict__['data'] = val
! self._stuff('baseAddr', id(self.data) + MacOS.string_id_to_buffer)
! elif attr == 'rowBytes':
! # high bit is always set for some odd reason
! self._stuff('rowBytes', val | 0x8000)
! elif attr == 'bounds':
! # assume val is in official Left, Top, Right, Bottom order!
! self._stuff('left',val[0])
! self._stuff('top',val[1])
! self._stuff('right',val[2])
! self._stuff('bottom',val[3])
! elif attr == 'hRes' or attr == 'vRes':
! # 16.16 fixed format, so just shift 16 bits
! self._stuff(attr, int(val) << 16)
! elif attr in _pmElemFormat.keys():
! # any other pm attribute -- just stuff
! self._stuff(attr, val)
! else:
! self.__dict__[attr] = val
! def __getattr__(self, attr):
! if attr == 'rowBytes':
! # high bit is always set for some odd reason
! return self._unstuff('rowBytes') & 0x7FFF
! elif attr == 'bounds':
! # return bounds in official Left, Top, Right, Bottom order!
! return ( \
! self._unstuff('left'),
! self._unstuff('top'),
! self._unstuff('right'),
! self._unstuff('bottom') )
! elif attr == 'hRes' or attr == 'vRes':
! # 16.16 fixed format, so just shift 16 bits
! return self._unstuff(attr) >> 16
! elif attr in _pmElemFormat.keys():
! # any other pm attribute -- just unstuff
! return self._unstuff(attr)
! else:
! return self.__dict__[attr]
!
! def PixMap(self):
! "Return a QuickDraw PixMap corresponding to this data."
! if not self.__dict__['_pm']:
! self.__dict__['_pm'] = Qd.RawBitMap(self._header)
! return self.__dict__['_pm']
! def blit(self, x1=0,y1=0,x2=None,y2=None, port=None):
! """Draw this pixmap into the given (default current) grafport."""
! src = self.bounds
! dest = [x1,y1,x2,y2]
! if x2 == None:
! dest[2] = x1 + src[2]-src[0]
! if y2 == None:
! dest[3] = y1 + src[3]-src[1]
! if not port: port = Qd.GetPort()
! Qd.CopyBits(self.PixMap(), port.GetPortBitMapForCopyBits(), src, tuple(dest),
! QuickDraw.srcCopy, None)
!
! def fromstring(self,s,width,height,format=imgformat.macrgb):
! """Stuff this pixmap with raw pixel data from a string.
! Supply width, height, and one of the imgformat specifiers."""
! # we only support 16- and 32-bit mac rgb...
! # so convert if necessary
! if format != imgformat.macrgb and format != imgformat.macrgb16:
! # (LATER!)
! raise "NotImplementedError", "conversion to macrgb or macrgb16"
! self.data = s
! self.bounds = (0,0,width,height)
! self.cmpCount = 3
! self.pixelType = QuickDraw.RGBDirect
! if format == imgformat.macrgb:
! self.pixelSize = 32
! self.cmpSize = 8
! else:
! self.pixelSize = 16
! self.cmpSize = 5
! self.rowBytes = width*self.pixelSize/8
! def tostring(self, format=imgformat.macrgb):
! """Return raw data as a string in the specified format."""
! # is the native format requested? if so, just return data
! if (format == imgformat.macrgb and self.pixelSize == 32) or \
! (format == imgformat.macrgb16 and self.pixelsize == 16):
! return self.data
! # otherwise, convert to the requested format
! # (LATER!)
! raise "NotImplementedError", "data format conversion"
! def fromImage(self,im):
! """Initialize this PixMap from a PIL Image object."""
! # We need data in ARGB format; PIL can't currently do that,
! # but it can do RGBA, which we can use by inserting one null
! # up frontpm =
! if im.mode != 'RGBA': im = im.convert('RGBA')
! data = chr(0) + im.tostring()
! self.fromstring(data, im.size[0], im.size[1])
! def toImage(self):
! """Return the contents of this PixMap as a PIL Image object."""
! import Image
! # our tostring() method returns data in ARGB format,
! # whereas Image uses RGBA; a bit of slicing fixes this...
! data = self.tostring()[1:] + chr(0)
! bounds = self.bounds
! return Image.fromstring('RGBA',(bounds[2]-bounds[0],bounds[3]-bounds[1]),data)
def test():
! import MacOS
! import EasyDialogs
! import Image
! path = EasyDialogs.AskFileForOpen("Image File:")
! if not path: return
! pm = PixMapWrapper()
! pm.fromImage( Image.open(path) )
! pm.blit(20,20)
! return pm
Index: aepack.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aepack.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** aepack.py 31 Mar 2003 13:32:59 -0000 1.5
--- aepack.py 9 Apr 2003 13:25:42 -0000 1.6
***************
*** 45,57 ****
#
unpacker_coercions = {
! typeComp : typeFloat,
! typeColorTable : typeAEList,
! typeDrawingArea : typeAERecord,
! typeFixed : typeFloat,
! typeExtended : typeFloat,
! typePixelMap : typeAERecord,
! typeRotation : typeAERecord,
! typeStyledText : typeAERecord,
! typeTextStyles : typeAERecord,
};
--- 45,57 ----
#
unpacker_coercions = {
! typeComp : typeFloat,
! typeColorTable : typeAEList,
! typeDrawingArea : typeAERecord,
! typeFixed : typeFloat,
! typeExtended : typeFloat,
! typePixelMap : typeAERecord,
! typeRotation : typeAERecord,
! typeStyledText : typeAERecord,
! typeTextStyles : typeAERecord,
};
***************
*** 65,259 ****
def packkey(ae, key, value):
! if hasattr(key, 'which'):
! keystr = key.which
! elif hasattr(key, 'want'):
! keystr = key.want
! else:
! keystr = key
! ae.AEPutParamDesc(keystr, pack(value))
def pack(x, forcetype = None):
! """Pack a python object into an AE descriptor"""
!
! if forcetype:
! if type(x) is StringType:
! return AE.AECreateDesc(forcetype, x)
! else:
! return pack(x).AECoerceDesc(forcetype)
!
! if x == None:
! return AE.AECreateDesc('null', '')
!
! if isinstance(x, AEDescType):
! return x
! if isinstance(x, FSSType):
! return AE.AECreateDesc('fss ', x.data)
! if isinstance(x, FSRefType):
! return AE.AECreateDesc('fsrf', x.data)
! if isinstance(x, AliasType):
! return AE.AECreateDesc('alis', x.data)
! if isinstance(x, IntType):
! return AE.AECreateDesc('long', struct.pack('l', x))
! if isinstance(x, FloatType):
! return AE.AECreateDesc('doub', struct.pack('d', x))
! if isinstance(x, StringType):
! return AE.AECreateDesc('TEXT', x)
! if isinstance(x, UnicodeType):
! data = x.encode('utf16')
! if data[:2] == '\xfe\xff':
! data = data[2:]
! return AE.AECreateDesc('utxt', data)
! if isinstance(x, ListType):
! list = AE.AECreateList('', 0)
! for item in x:
! list.AEPutDesc(0, pack(item))
! return list
! if isinstance(x, DictionaryType):
! record = AE.AECreateList('', 1)
! for key, value in x.items():
! packkey(record, key, value)
! #record.AEPutParamDesc(key, pack(value))
! return record
! if type(x) == types.ClassType and issubclass(x, ObjectSpecifier):
! # Note: we are getting a class object here, not an instance
! return AE.AECreateDesc('type', x.want)
! if hasattr(x, '__aepack__'):
! return x.__aepack__()
! if hasattr(x, 'which'):
! return AE.AECreateDesc('TEXT', x.which)
! if hasattr(x, 'want'):
! return AE.AECreateDesc('TEXT', x.want)
! return AE.AECreateDesc('TEXT', repr(x)) # Copout
def unpack(desc, formodulename=""):
! """Unpack an AE descriptor to a python object"""
! t = desc.type
!
! if unpacker_coercions.has_key(t):
! desc = desc.AECoerceDesc(unpacker_coercions[t])
! t = desc.type # This is a guess by Jack....
!
! if t == typeAEList:
! l = []
! for i in range(desc.AECountItems()):
! keyword, item = desc.AEGetNthDesc(i+1, '****')
! l.append(unpack(item, formodulename))
! return l
! if t == typeAERecord:
! d = {}
! for i in range(desc.AECountItems()):
! keyword, item = desc.AEGetNthDesc(i+1, '****')
! d[keyword] = unpack(item, formodulename)
! return d
! if t == typeAEText:
! record = desc.AECoerceDesc('reco')
! return mkaetext(unpack(record, formodulename))
! if t == typeAlias:
! return Carbon.File.Alias(rawdata=desc.data)
! # typeAppleEvent returned as unknown
! if t == typeBoolean:
! return struct.unpack('b', desc.data)[0]
! if t == typeChar:
! return desc.data
! if t == typeUnicodeText:
! return unicode(desc.data, 'utf16')
! # typeColorTable coerced to typeAEList
! # typeComp coerced to extended
! # typeData returned as unknown
! # typeDrawingArea coerced to typeAERecord
! if t == typeEnumeration:
! return mkenum(desc.data)
! # typeEPS returned as unknown
! if t == typeFalse:
! return 0
! if t == typeFloat:
! data = desc.data
! return struct.unpack('d', data)[0]
! if t == typeFSS:
! return Carbon.File.FSSpec(rawdata=desc.data)
! if t == typeFSRef:
! return Carbon.File.FSRef(rawdata=desc.data)
! if t == typeInsertionLoc:
! record = desc.AECoerceDesc('reco')
! return mkinsertionloc(unpack(record, formodulename))
! # typeInteger equal to typeLongInteger
! if t == typeIntlText:
! script, language = struct.unpack('hh', desc.data[:4])
! return aetypes.IntlText(script, language, desc.data[4:])
! if t == typeIntlWritingCode:
! script, language = struct.unpack('hh', desc.data)
! return aetypes.IntlWritingCode(script, language)
! if t == typeKeyword:
! return mkkeyword(desc.data)
! if t == typeLongInteger:
! return struct.unpack('l', desc.data)[0]
! if t == typeLongDateTime:
! a, b = struct.unpack('lL', desc.data)
! return (long(a) << 32) + b
! if t == typeNull:
! return None
! if t == typeMagnitude:
! v = struct.unpack('l', desc.data)
! if v < 0:
! v = 0x100000000L + v
! return v
! if t == typeObjectSpecifier:
! record = desc.AECoerceDesc('reco')
! # If we have been told the name of the module we are unpacking aedescs for,
! # we can attempt to create the right type of python object from that module.
! if formodulename:
! return mkobjectfrommodule(unpack(record, formodulename), formodulename)
! return mkobject(unpack(record, formodulename))
! # typePict returned as unknown
! # typePixelMap coerced to typeAERecord
! # typePixelMapMinus returned as unknown
! # typeProcessSerialNumber returned as unknown
! if t == typeQDPoint:
! v, h = struct.unpack('hh', desc.data)
! return aetypes.QDPoint(v, h)
! if t == typeQDRectangle:
! v0, h0, v1, h1 = struct.unpack('hhhh', desc.data)
! return aetypes.QDRectangle(v0, h0, v1, h1)
! if t == typeRGBColor:
! r, g, b = struct.unpack('hhh', desc.data)
! return aetypes.RGBColor(r, g, b)
! # typeRotation coerced to typeAERecord
! # typeScrapStyles returned as unknown
! # typeSessionID returned as unknown
! if t == typeShortFloat:
! return struct.unpack('f', desc.data)[0]
! if t == typeShortInteger:
! return struct.unpack('h', desc.data)[0]
! # typeSMFloat identical to typeShortFloat
! # typeSMInt indetical to typeShortInt
! # typeStyledText coerced to typeAERecord
! if t == typeTargetID:
! return mktargetid(desc.data)
! # typeTextStyles coerced to typeAERecord
! # typeTIFF returned as unknown
! if t == typeTrue:
! return 1
! if t == typeType:
! return mktype(desc.data, formodulename)
! #
! # The following are special
! #
! if t == 'rang':
! record = desc.AECoerceDesc('reco')
! return mkrange(unpack(record, formodulename))
! if t == 'cmpd':
! record = desc.AECoerceDesc('reco')
! return mkcomparison(unpack(record, formodulename))
! if t == 'logi':
! record = desc.AECoerceDesc('reco')
! return mklogical(unpack(record, formodulename))
! return mkunknown(desc.type, desc.data)
!
def coerce(data, egdata):
! """Coerce a python object to another type using the AE coercers"""
! pdata = pack(data)
! pegdata = pack(egdata)
! pdata = pdata.AECoerceDesc(pegdata.type)
! return unpack(pdata)
#
--- 65,259 ----
def packkey(ae, key, value):
! if hasattr(key, 'which'):
! keystr = key.which
! elif hasattr(key, 'want'):
! keystr = key.want
! else:
! keystr = key
! ae.AEPutParamDesc(keystr, pack(value))
def pack(x, forcetype = None):
! """Pack a python object into an AE descriptor"""
!
! if forcetype:
! if type(x) is StringType:
! return AE.AECreateDesc(forcetype, x)
! else:
! return pack(x).AECoerceDesc(forcetype)
!
! if x == None:
! return AE.AECreateDesc('null', '')
!
! if isinstance(x, AEDescType):
! return x
! if isinstance(x, FSSType):
! return AE.AECreateDesc('fss ', x.data)
! if isinstance(x, FSRefType):
! return AE.AECreateDesc('fsrf', x.data)
! if isinstance(x, AliasType):
! return AE.AECreateDesc('alis', x.data)
! if isinstance(x, IntType):
! return AE.AECreateDesc('long', struct.pack('l', x))
! if isinstance(x, FloatType):
! return AE.AECreateDesc('doub', struct.pack('d', x))
! if isinstance(x, StringType):
! return AE.AECreateDesc('TEXT', x)
! if isinstance(x, UnicodeType):
! data = x.encode('utf16')
! if data[:2] == '\xfe\xff':
! data = data[2:]
! return AE.AECreateDesc('utxt', data)
! if isinstance(x, ListType):
! list = AE.AECreateList('', 0)
! for item in x:
! list.AEPutDesc(0, pack(item))
! return list
! if isinstance(x, DictionaryType):
! record = AE.AECreateList('', 1)
! for key, value in x.items():
! packkey(record, key, value)
! #record.AEPutParamDesc(key, pack(value))
! return record
! if type(x) == types.ClassType and issubclass(x, ObjectSpecifier):
! # Note: we are getting a class object here, not an instance
! return AE.AECreateDesc('type', x.want)
! if hasattr(x, '__aepack__'):
! return x.__aepack__()
! if hasattr(x, 'which'):
! return AE.AECreateDesc('TEXT', x.which)
! if hasattr(x, 'want'):
! return AE.AECreateDesc('TEXT', x.want)
! return AE.AECreateDesc('TEXT', repr(x)) # Copout
def unpack(desc, formodulename=""):
! """Unpack an AE descriptor to a python object"""
! t = desc.type
!
! if unpacker_coercions.has_key(t):
! desc = desc.AECoerceDesc(unpacker_coercions[t])
! t = desc.type # This is a guess by Jack....
!
! if t == typeAEList:
! l = []
! for i in range(desc.AECountItems()):
! keyword, item = desc.AEGetNthDesc(i+1, '****')
! l.append(unpack(item, formodulename))
! return l
! if t == typeAERecord:
! d = {}
! for i in range(desc.AECountItems()):
! keyword, item = desc.AEGetNthDesc(i+1, '****')
! d[keyword] = unpack(item, formodulename)
! return d
! if t == typeAEText:
! record = desc.AECoerceDesc('reco')
! return mkaetext(unpack(record, formodulename))
! if t == typeAlias:
! return Carbon.File.Alias(rawdata=desc.data)
! # typeAppleEvent returned as unknown
! if t == typeBoolean:
! return struct.unpack('b', desc.data)[0]
! if t == typeChar:
! return desc.data
! if t == typeUnicodeText:
! return unicode(desc.data, 'utf16')
! # typeColorTable coerced to typeAEList
! # typeComp coerced to extended
! # typeData returned as unknown
! # typeDrawingArea coerced to typeAERecord
! if t == typeEnumeration:
! return mkenum(desc.data)
! # typeEPS returned as unknown
! if t == typeFalse:
! return 0
! if t == typeFloat:
! data = desc.data
! return struct.unpack('d', data)[0]
! if t == typeFSS:
! return Carbon.File.FSSpec(rawdata=desc.data)
! if t == typeFSRef:
! return Carbon.File.FSRef(rawdata=desc.data)
! if t == typeInsertionLoc:
! record = desc.AECoerceDesc('reco')
! return mkinsertionloc(unpack(record, formodulename))
! # typeInteger equal to typeLongInteger
! if t == typeIntlText:
! script, language = struct.unpack('hh', desc.data[:4])
! return aetypes.IntlText(script, language, desc.data[4:])
! if t == typeIntlWritingCode:
! script, language = struct.unpack('hh', desc.data)
! return aetypes.IntlWritingCode(script, language)
! if t == typeKeyword:
! return mkkeyword(desc.data)
! if t == typeLongInteger:
! return struct.unpack('l', desc.data)[0]
! if t == typeLongDateTime:
! a, b = struct.unpack('lL', desc.data)
! return (long(a) << 32) + b
! if t == typeNull:
! return None
! if t == typeMagnitude:
! v = struct.unpack('l', desc.data)
! if v < 0:
! v = 0x100000000L + v
! return v
! if t == typeObjectSpecifier:
! record = desc.AECoerceDesc('reco')
! # If we have been told the name of the module we are unpacking aedescs for,
! # we can attempt to create the right type of python object from that module.
! if formodulename:
! return mkobjectfrommodule(unpack(record, formodulename), formodulename)
! return mkobject(unpack(record, formodulename))
! # typePict returned as unknown
! # typePixelMap coerced to typeAERecord
! # typePixelMapMinus returned as unknown
! # typeProcessSerialNumber returned as unknown
! if t == typeQDPoint:
! v, h = struct.unpack('hh', desc.data)
! return aetypes.QDPoint(v, h)
! if t == typeQDRectangle:
! v0, h0, v1, h1 = struct.unpack('hhhh', desc.data)
! return aetypes.QDRectangle(v0, h0, v1, h1)
! if t == typeRGBColor:
! r, g, b = struct.unpack('hhh', desc.data)
! return aetypes.RGBColor(r, g, b)
! # typeRotation coerced to typeAERecord
! # typeScrapStyles returned as unknown
! # typeSessionID returned as unknown
! if t == typeShortFloat:
! return struct.unpack('f', desc.data)[0]
! if t == typeShortInteger:
! return struct.unpack('h', desc.data)[0]
! # typeSMFloat identical to typeShortFloat
! # typeSMInt indetical to typeShortInt
! # typeStyledText coerced to typeAERecord
! if t == typeTargetID:
! return mktargetid(desc.data)
! # typeTextStyles coerced to typeAERecord
! # typeTIFF returned as unknown
! if t == typeTrue:
! return 1
! if t == typeType:
! return mktype(desc.data, formodulename)
! #
! # The following are special
! #
! if t == 'rang':
! record = desc.AECoerceDesc('reco')
! return mkrange(unpack(record, formodulename))
! if t == 'cmpd':
! record = desc.AECoerceDesc('reco')
! return mkcomparison(unpack(record, formodulename))
! if t == 'logi':
! record = desc.AECoerceDesc('reco')
! return mklogical(unpack(record, formodulename))
! return mkunknown(desc.type, desc.data)
!
def coerce(data, egdata):
! """Coerce a python object to another type using the AE coercers"""
! pdata = pack(data)
! pegdata = pack(egdata)
! pdata = pdata.AECoerceDesc(pegdata.type)
! return unpack(pdata)
#
***************
*** 261,340 ****
#
def mktargetid(data):
! sessionID = getlong(data[:4])
! name = mkppcportrec(data[4:4+72])
! location = mklocationnamerec(data[76:76+36])
! rcvrName = mkppcportrec(data[112:112+72])
! return sessionID, name, location, rcvrName
def mkppcportrec(rec):
! namescript = getword(rec[:2])
! name = getpstr(rec[2:2+33])
! portkind = getword(rec[36:38])
! if portkind == 1:
! ctor = rec[38:42]
! type = rec[42:46]
! identity = (ctor, type)
! else:
! identity = getpstr(rec[38:38+33])
! return namescript, name, portkind, identity
def mklocationnamerec(rec):
! kind = getword(rec[:2])
! stuff = rec[2:]
! if kind == 0: stuff = None
! if kind == 2: stuff = getpstr(stuff)
! return kind, stuff
def mkunknown(type, data):
! return aetypes.Unknown(type, data)
def getpstr(s):
! return s[1:1+ord(s[0])]
def getlong(s):
! return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
def getword(s):
! return (ord(s[0])<<8) | (ord(s[1])<<0)
def mkkeyword(keyword):
! return aetypes.Keyword(keyword)
def mkrange(dict):
! return aetypes.Range(dict['star'], dict['stop'])
def mkcomparison(dict):
! return aetypes.Comparison(dict['obj1'], dict['relo'].enum, dict['obj2'])
def mklogical(dict):
! return aetypes.Logical(dict['logc'], dict['term'])
def mkstyledtext(dict):
! return aetypes.StyledText(dict['ksty'], dict['ktxt'])
!
def mkaetext(dict):
! return aetypes.AEText(dict[keyAEScriptTag], dict[keyAEStyles], dict[keyAEText])
!
def mkinsertionloc(dict):
! return aetypes.InsertionLoc(dict[keyAEObject], dict[keyAEPosition])
def mkobject(dict):
! want = dict['want'].type
! form = dict['form'].enum
! seld = dict['seld']
! fr = dict['from']
! if form in ('name', 'indx', 'rang', 'test'):
! if want == 'text': return aetypes.Text(seld, fr)
! if want == 'cha ': return aetypes.Character(seld, fr)
! if want == 'cwor': return aetypes.Word(seld, fr)
! if want == 'clin': return aetypes.Line(seld, fr)
! if want == 'cpar': return aetypes.Paragraph(seld, fr)
! if want == 'cwin': return aetypes.Window(seld, fr)
! if want == 'docu': return aetypes.Document(seld, fr)
! if want == 'file': return aetypes.File(seld, fr)
! if want == 'cins': return aetypes.InsertionPoint(seld, fr)
! if want == 'prop' and form == 'prop' and aetypes.IsType(seld):
! return aetypes.Property(seld.type, fr)
! return aetypes.ObjectSpecifier(want, form, seld, fr)
# Note by Jack: I'm not 100% sure of the following code. This was
--- 261,340 ----
#
def mktargetid(data):
! sessionID = getlong(data[:4])
! name = mkppcportrec(data[4:4+72])
! location = mklocationnamerec(data[76:76+36])
! rcvrName = mkppcportrec(data[112:112+72])
! return sessionID, name, location, rcvrName
def mkppcportrec(rec):
! namescript = getword(rec[:2])
! name = getpstr(rec[2:2+33])
! portkind = getword(rec[36:38])
! if portkind == 1:
! ctor = rec[38:42]
! type = rec[42:46]
! identity = (ctor, type)
! else:
! identity = getpstr(rec[38:38+33])
! return namescript, name, portkind, identity
def mklocationnamerec(rec):
! kind = getword(rec[:2])
! stuff = rec[2:]
! if kind == 0: stuff = None
! if kind == 2: stuff = getpstr(stuff)
! return kind, stuff
def mkunknown(type, data):
! return aetypes.Unknown(type, data)
def getpstr(s):
! return s[1:1+ord(s[0])]
def getlong(s):
! return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
def getword(s):
! return (ord(s[0])<<8) | (ord(s[1])<<0)
def mkkeyword(keyword):
! return aetypes.Keyword(keyword)
def mkrange(dict):
! return aetypes.Range(dict['star'], dict['stop'])
def mkcomparison(dict):
! return aetypes.Comparison(dict['obj1'], dict['relo'].enum, dict['obj2'])
def mklogical(dict):
! return aetypes.Logical(dict['logc'], dict['term'])
def mkstyledtext(dict):
! return aetypes.StyledText(dict['ksty'], dict['ktxt'])
!
def mkaetext(dict):
! return aetypes.AEText(dict[keyAEScriptTag], dict[keyAEStyles], dict[keyAEText])
!
def mkinsertionloc(dict):
! return aetypes.InsertionLoc(dict[keyAEObject], dict[keyAEPosition])
def mkobject(dict):
! want = dict['want'].type
! form = dict['form'].enum
! seld = dict['seld']
! fr = dict['from']
! if form in ('name', 'indx', 'rang', 'test'):
! if want == 'text': return aetypes.Text(seld, fr)
! if want == 'cha ': return aetypes.Character(seld, fr)
! if want == 'cwor': return aetypes.Word(seld, fr)
! if want == 'clin': return aetypes.Line(seld, fr)
! if want == 'cpar': return aetypes.Paragraph(seld, fr)
! if want == 'cwin': return aetypes.Window(seld, fr)
! if want == 'docu': return aetypes.Document(seld, fr)
! if want == 'file': return aetypes.File(seld, fr)
! if want == 'cins': return aetypes.InsertionPoint(seld, fr)
! if want == 'prop' and form == 'prop' and aetypes.IsType(seld):
! return aetypes.Property(seld.type, fr)
! return aetypes.ObjectSpecifier(want, form, seld, fr)
# Note by Jack: I'm not 100% sure of the following code. This was
***************
*** 343,366 ****
# initializer for the classes in the suites?
def mkobjectfrommodule(dict, modulename):
! if type(dict['want']) == types.ClassType and issubclass(dict['want'], ObjectSpecifier):
! # The type has already been converted to Python. Convert back:-(
! classtype = dict['want']
! dict['want'] = aetypes.mktype(classtype.want)
! want = dict['want'].type
! module = __import__(modulename)
! codenamemapper = module._classdeclarations
! classtype = codenamemapper.get(want, None)
! newobj = mkobject(dict)
! if classtype:
! assert issubclass(classtype, ObjectSpecifier)
! newobj.__class__ = classtype
! return newobj
!
def mktype(typecode, modulename=None):
! if modulename:
! module = __import__(modulename)
! codenamemapper = module._classdeclarations
! classtype = codenamemapper.get(typecode, None)
! if classtype:
! return classtype
! return aetypes.mktype(typecode)
--- 343,366 ----
# initializer for the classes in the suites?
def mkobjectfrommodule(dict, modulename):
! if type(dict['want']) == types.ClassType and issubclass(dict['want'], ObjectSpecifier):
! # The type has already been converted to Python. Convert back:-(
! classtype = dict['want']
! dict['want'] = aetypes.mktype(classtype.want)
! want = dict['want'].type
! module = __import__(modulename)
! codenamemapper = module._classdeclarations
! classtype = codenamemapper.get(want, None)
! newobj = mkobject(dict)
! if classtype:
! assert issubclass(classtype, ObjectSpecifier)
! newobj.__class__ = classtype
! return newobj
!
def mktype(typecode, modulename=None):
! if modulename:
! module = __import__(modulename)
! codenamemapper = module._classdeclarations
! classtype = codenamemapper.get(typecode, None)
! if classtype:
! return classtype
! return aetypes.mktype(typecode)
Index: aetools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aetools.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** aetools.py 1 Apr 2003 22:27:18 -0000 1.6
--- aetools.py 9 Apr 2003 13:25:42 -0000 1.7
***************
*** 10,18 ****
ranges, conditionals, logicals, etc., so you can write, e.g.:
! x = Character(1, Document("foobar"))
and pack(x) will create an AE object reference equivalent to AppleScript's
! character 1 of document "foobar"
Some of the stuff that appears to be exported from this module comes from other
--- 10,18 ----
ranges, conditionals, logicals, etc., so you can write, e.g.:
! x = Character(1, Document("foobar"))
and pack(x) will create an AE object reference equivalent to AppleScript's
! character 1 of document "foobar"
Some of the stuff that appears to be exported from this module comes from other
***************
*** 42,102 ****
aekeywords = [
! 'tran',
! 'rtid',
! 'evcl',
! 'evid',
! 'addr',
! 'optk',
! 'timo',
! 'inte', # this attribute is read only - will be set in AESend
! 'esrc', # this attribute is read only
! 'miss', # this attribute is read only
! 'from' # new in 1.0.1
]
def missed(ae):
! try:
! desc = ae.AEGetAttributeDesc('miss', 'keyw')
! except AE.Error, msg:
! return None
! return desc.data
def unpackevent(ae, formodulename=""):
! parameters = {}
! try:
! dirobj = ae.AEGetParamDesc('----', '****')
! except AE.Error:
! pass
! else:
! parameters['----'] = unpack(dirobj, formodulename)
! del dirobj
! # Workaround for what I feel is a bug in OSX 10.2: 'errn' won't show up in missed...
! try:
! dirobj = ae.AEGetParamDesc('errn', '****')
! except AE.Error:
! pass
! else:
! parameters['errn'] = unpack(dirobj, formodulename)
! del dirobj
! while 1:
! key = missed(ae)
! if not key: break
! parameters[key] = unpack(ae.AEGetParamDesc(key, '****'), formodulename)
! attributes = {}
! for key in aekeywords:
! try:
! desc = ae.AEGetAttributeDesc(key, '****')
! except (AE.Error, MacOS.Error), msg:
! if msg[0] != -1701 and msg[0] != -1704:
! raise
! continue
! attributes[key] = unpack(desc, formodulename)
! return parameters, attributes
def packevent(ae, parameters = {}, attributes = {}):
! for key, value in parameters.items():
! packkey(ae, key, value)
! for key, value in attributes.items():
! ae.AEPutAttributeDesc(key, pack(value))
#
--- 42,102 ----
aekeywords = [
! 'tran',
! 'rtid',
! 'evcl',
! 'evid',
! 'addr',
! 'optk',
! 'timo',
! 'inte', # this attribute is read only - will be set in AESend
! 'esrc', # this attribute is read only
! 'miss', # this attribute is read only
! 'from' # new in 1.0.1
]
def missed(ae):
! try:
! desc = ae.AEGetAttributeDesc('miss', 'keyw')
! except AE.Error, msg:
! return None
! return desc.data
def unpackevent(ae, formodulename=""):
! parameters = {}
! try:
! dirobj = ae.AEGetParamDesc('----', '****')
! except AE.Error:
! pass
! else:
! parameters['----'] = unpack(dirobj, formodulename)
! del dirobj
! # Workaround for what I feel is a bug in OSX 10.2: 'errn' won't show up in missed...
! try:
! dirobj = ae.AEGetParamDesc('errn', '****')
! except AE.Error:
! pass
! else:
! parameters['errn'] = unpack(dirobj, formodulename)
! del dirobj
! while 1:
! key = missed(ae)
! if not key: break
! parameters[key] = unpack(ae.AEGetParamDesc(key, '****'), formodulename)
! attributes = {}
! for key in aekeywords:
! try:
! desc = ae.AEGetAttributeDesc(key, '****')
! except (AE.Error, MacOS.Error), msg:
! if msg[0] != -1701 and msg[0] != -1704:
! raise
! continue
! attributes[key] = unpack(desc, formodulename)
! return parameters, attributes
def packevent(ae, parameters = {}, attributes = {}):
! for key, value in parameters.items():
! packkey(ae, key, value)
! for key, value in attributes.items():
! ae.AEPutAttributeDesc(key, pack(value))
#
***************
*** 105,346 ****
#
def keysubst(arguments, keydict):
! """Replace long name keys by their 4-char counterparts, and check"""
! ok = keydict.values()
! for k in arguments.keys():
! if keydict.has_key(k):
! v = arguments[k]
! del arguments[k]
! arguments[keydict[k]] = v
! elif k != '----' and k not in ok:
! raise TypeError, 'Unknown keyword argument: %s'%k
!
def enumsubst(arguments, key, edict):
! """Substitute a single enum keyword argument, if it occurs"""
! if not arguments.has_key(key) or edict is None:
! return
! v = arguments[key]
! ok = edict.values()
! if edict.has_key(v):
! arguments[key] = Enum(edict[v])
! elif not v in ok:
! raise TypeError, 'Unknown enumerator: %s'%v
!
def decodeerror(arguments):
! """Create the 'best' argument for a raise MacOS.Error"""
! errn = arguments['errn']
! err_a1 = errn
! if arguments.has_key('errs'):
! err_a2 = arguments['errs']
! else:
! err_a2 = MacOS.GetErrorString(errn)
! if arguments.has_key('erob'):
! err_a3 = arguments['erob']
! else:
! err_a3 = None
!
! return (err_a1, err_a2, err_a3)
class TalkTo:
! """An AE connection to an application"""
! _signature = None # Can be overridden by subclasses
! _moduleName = None # Can be overridden by subclasses
!
! __eventloop_initialized = 0
! def __ensure_WMAvailable(klass):
! if klass.__eventloop_initialized: return 1
! if not MacOS.WMAvailable(): return 0
! # Workaround for a but in MacOSX 10.2: we must have an event
! # loop before we can call AESend.
! Evt.WaitNextEvent(0,0)
! return 1
! __ensure_WMAvailable = classmethod(__ensure_WMAvailable)
! def __init__(self, signature=None, start=0, timeout=0):
! """Create a communication channel with a particular application.
!
! Addressing the application is done by specifying either a
! 4-byte signature, an AEDesc or an object that will __aepack__
! to an AEDesc.
! """
! self.target_signature = None
! if signature is None:
! signature = self._signature
! if type(signature) == AEDescType:
! self.target = signature
! elif type(signature) == InstanceType and hasattr(signature, '__aepack__'):
! self.target = signature.__aepack__()
! elif type(signature) == StringType and len(signature) == 4:
! self.target = AE.AECreateDesc(AppleEvents.typeApplSignature, signature)
! self.target_signature = signature
! else:
! raise TypeError, "signature should be 4-char string or AEDesc"
! self.send_flags = AppleEvents.kAEWaitReply
! self.send_priority = AppleEvents.kAENormalPriority
! if timeout:
! self.send_timeout = timeout
! else:
! self.send_timeout = AppleEvents.kAEDefaultTimeout
! if start:
! self._start()
!
! def _start(self):
! """Start the application, if it is not running yet"""
! try:
! self.send('ascr', 'noop')
! except AE.Error:
! _launch(self.target_signature)
! for i in range(LAUNCH_MAX_WAIT_TIME):
! try:
! self.send('ascr', 'noop')
! except AE.Error:
! pass
! else:
! break
! time.sleep(1)
!
! def start(self):
! """Deprecated, used _start()"""
! self._start()
!
! def newevent(self, code, subcode, parameters = {}, attributes = {}):
! """Create a complete structure for an apple event"""
!
! event = AE.AECreateAppleEvent(code, subcode, self.target,
! AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)
! packevent(event, parameters, attributes)
! return event
!
! def sendevent(self, event):
! """Send a pre-created appleevent, await the reply and unpack it"""
! if not self.__ensure_WMAvailable():
! raise RuntimeError, "No window manager access, cannot send AppleEvent"
! reply = event.AESend(self.send_flags, self.send_priority,
! self.send_timeout)
! parameters, attributes = unpackevent(reply, self._moduleName)
! return reply, parameters, attributes
!
! def send(self, code, subcode, parameters = {}, attributes = {}):
! """Send an appleevent given code/subcode/pars/attrs and unpack the reply"""
! return self.sendevent(self.newevent(code, subcode, parameters, attributes))
!
! #
! # The following events are somehow "standard" and don't seem to appear in any
! # suite...
! #
! def activate(self):
! """Send 'activate' command"""
! self.send('misc', 'actv')
! def _get(self, _object, as=None, _attributes={}):
! """_get: get data from an object
! Required argument: the object
! Keyword argument _attributes: AppleEvent attribute dictionary
! Returns: the data
! """
! _code = 'core'
! _subcode = 'getd'
! _arguments = {'----':_object}
! if as:
! _arguments['rtyp'] = mktype(as)
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.has_key('errn'):
! raise Error, decodeerror(_arguments)
! if _arguments.has_key('----'):
! return _arguments['----']
! if as:
! item.__class__ = as
! return item
!
! get = _get
!
! _argmap_set = {
! 'to' : 'data',
! }
! def _set(self, _object, _attributes={}, **_arguments):
! """set: Set an object's data.
! Required argument: the object for the command
! Keyword argument to: The new value.
! Keyword argument _attributes: AppleEvent attribute dictionary
! """
! _code = 'core'
! _subcode = 'setd'
! keysubst(_arguments, self._argmap_set)
! _arguments['----'] = _object
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.get('errn', 0):
! raise Error, decodeerror(_arguments)
! # XXXX Optionally decode result
! if _arguments.has_key('----'):
! return _arguments['----']
!
! set = _set
# Tiny Finder class, for local use only
class _miniFinder(TalkTo):
! def open(self, _object, _attributes={}, **_arguments):
! """open: Open the specified object(s)
! Required argument: list of objects to open
! Keyword argument _attributes: AppleEvent attribute dictionary
! """
! _code = 'aevt'
! _subcode = 'odoc'
! if _arguments: raise TypeError, 'No optional args expected'
! _arguments['----'] = _object
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.has_key('errn'):
! raise Error, decodeerror(_arguments)
! # XXXX Optionally decode result
! if _arguments.has_key('----'):
! return _arguments['----']
#pass
!
_finder = _miniFinder('MACS')
def _launch(appfile):
! """Open a file thru the finder. Specify file by name or fsspec"""
! _finder.open(_application_file(('ID ', appfile)))
class _application_file(ComponentItem):
! """application file - An application's file on disk"""
! want = 'appf'
!
_application_file._propdict = {
}
_application_file._elemdict = {
}
!
# Test program
# XXXX Should test more, really...
def test():
! target = AE.AECreateDesc('sign', 'quil')
! ae = AE.AECreateAppleEvent('aevt', 'oapp', target, -1, 0)
! print unpackevent(ae)
! raw_input(":")
! ae = AE.AECreateAppleEvent('core', 'getd', target, -1, 0)
! obj = Character(2, Word(1, Document(1)))
! print obj
! print repr(obj)
! packevent(ae, {'----': obj})
! params, attrs = unpackevent(ae)
! print params['----']
! raw_input(":")
if __name__ == '__main__':
! test()
! sys.exit(1)
--- 105,346 ----
#
def keysubst(arguments, keydict):
! """Replace long name keys by their 4-char counterparts, and check"""
! ok = keydict.values()
! for k in arguments.keys():
! if keydict.has_key(k):
! v = arguments[k]
! del arguments[k]
! arguments[keydict[k]] = v
! elif k != '----' and k not in ok:
! raise TypeError, 'Unknown keyword argument: %s'%k
!
def enumsubst(arguments, key, edict):
! """Substitute a single enum keyword argument, if it occurs"""
! if not arguments.has_key(key) or edict is None:
! return
! v = arguments[key]
! ok = edict.values()
! if edict.has_key(v):
! arguments[key] = Enum(edict[v])
! elif not v in ok:
! raise TypeError, 'Unknown enumerator: %s'%v
!
def decodeerror(arguments):
! """Create the 'best' argument for a raise MacOS.Error"""
! errn = arguments['errn']
! err_a1 = errn
! if arguments.has_key('errs'):
! err_a2 = arguments['errs']
! else:
! err_a2 = MacOS.GetErrorString(errn)
! if arguments.has_key('erob'):
! err_a3 = arguments['erob']
! else:
! err_a3 = None
!
! return (err_a1, err_a2, err_a3)
class TalkTo:
! """An AE connection to an application"""
! _signature = None # Can be overridden by subclasses
! _moduleName = None # Can be overridden by subclasses
!
! __eventloop_initialized = 0
! def __ensure_WMAvailable(klass):
! if klass.__eventloop_initialized: return 1
! if not MacOS.WMAvailable(): return 0
! # Workaround for a but in MacOSX 10.2: we must have an event
! # loop before we can call AESend.
! Evt.WaitNextEvent(0,0)
! return 1
! __ensure_WMAvailable = classmethod(__ensure_WMAvailable)
! def __init__(self, signature=None, start=0, timeout=0):
! """Create a communication channel with a particular application.
!
! Addressing the application is done by specifying either a
! 4-byte signature, an AEDesc or an object that will __aepack__
! to an AEDesc.
! """
! self.target_signature = None
! if signature is None:
! signature = self._signature
! if type(signature) == AEDescType:
! self.target = signature
! elif type(signature) == InstanceType and hasattr(signature, '__aepack__'):
! self.target = signature.__aepack__()
! elif type(signature) == StringType and len(signature) == 4:
! self.target = AE.AECreateDesc(AppleEvents.typeApplSignature, signature)
! self.target_signature = signature
! else:
! raise TypeError, "signature should be 4-char string or AEDesc"
! self.send_flags = AppleEvents.kAEWaitReply
! self.send_priority = AppleEvents.kAENormalPriority
! if timeout:
! self.send_timeout = timeout
! else:
! self.send_timeout = AppleEvents.kAEDefaultTimeout
! if start:
! self._start()
!
! def _start(self):
! """Start the application, if it is not running yet"""
! try:
! self.send('ascr', 'noop')
! except AE.Error:
! _launch(self.target_signature)
! for i in range(LAUNCH_MAX_WAIT_TIME):
! try:
! self.send('ascr', 'noop')
! except AE.Error:
! pass
! else:
! break
! time.sleep(1)
!
! def start(self):
! """Deprecated, used _start()"""
! self._start()
!
! def newevent(self, code, subcode, parameters = {}, attributes = {}):
! """Create a complete structure for an apple event"""
!
! event = AE.AECreateAppleEvent(code, subcode, self.target,
! AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)
! packevent(event, parameters, attributes)
! return event
!
! def sendevent(self, event):
! """Send a pre-created appleevent, await the reply and unpack it"""
! if not self.__ensure_WMAvailable():
! raise RuntimeError, "No window manager access, cannot send AppleEvent"
! reply = event.AESend(self.send_flags, self.send_priority,
! self.send_timeout)
! parameters, attributes = unpackevent(reply, self._moduleName)
! return reply, parameters, attributes
!
! def send(self, code, subcode, parameters = {}, attributes = {}):
! """Send an appleevent given code/subcode/pars/attrs and unpack the reply"""
! return self.sendevent(self.newevent(code, subcode, parameters, attributes))
!
! #
! # The following events are somehow "standard" and don't seem to appear in any
! # suite...
! #
! def activate(self):
! """Send 'activate' command"""
! self.send('misc', 'actv')
! def _get(self, _object, as=None, _attributes={}):
! """_get: get data from an object
! Required argument: the object
! Keyword argument _attributes: AppleEvent attribute dictionary
! Returns: the data
! """
! _code = 'core'
! _subcode = 'getd'
! _arguments = {'----':_object}
! if as:
! _arguments['rtyp'] = mktype(as)
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.has_key('errn'):
! raise Error, decodeerror(_arguments)
! if _arguments.has_key('----'):
! return _arguments['----']
! if as:
! item.__class__ = as
! return item
!
! get = _get
!
! _argmap_set = {
! 'to' : 'data',
! }
! def _set(self, _object, _attributes={}, **_arguments):
! """set: Set an object's data.
! Required argument: the object for the command
! Keyword argument to: The new value.
! Keyword argument _attributes: AppleEvent attribute dictionary
! """
! _code = 'core'
! _subcode = 'setd'
! keysubst(_arguments, self._argmap_set)
! _arguments['----'] = _object
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.get('errn', 0):
! raise Error, decodeerror(_arguments)
! # XXXX Optionally decode result
! if _arguments.has_key('----'):
! return _arguments['----']
!
! set = _set
# Tiny Finder class, for local use only
class _miniFinder(TalkTo):
! def open(self, _object, _attributes={}, **_arguments):
! """open: Open the specified object(s)
! Required argument: list of objects to open
! Keyword argument _attributes: AppleEvent attribute dictionary
! """
! _code = 'aevt'
! _subcode = 'odoc'
! if _arguments: raise TypeError, 'No optional args expected'
! _arguments['----'] = _object
! _reply, _arguments, _attributes = self.send(_code, _subcode,
! _arguments, _attributes)
! if _arguments.has_key('errn'):
! raise Error, decodeerror(_arguments)
! # XXXX Optionally decode result
! if _arguments.has_key('----'):
! return _arguments['----']
#pass
!
_finder = _miniFinder('MACS')
def _launch(appfile):
! """Open a file thru the finder. Specify file by name or fsspec"""
! _finder.open(_application_file(('ID ', appfile)))
class _application_file(ComponentItem):
! """application file - An application's file on disk"""
! want = 'appf'
!
_application_file._propdict = {
}
_application_file._elemdict = {
}
!
# Test program
# XXXX Should test more, really...
def test():
! target = AE.AECreateDesc('sign', 'quil')
! ae = AE.AECreateAppleEvent('aevt', 'oapp', target, -1, 0)
! print unpackevent(ae)
! raw_input(":")
! ae = AE.AECreateAppleEvent('core', 'getd', target, -1, 0)
! obj = Character(2, Word(1, Document(1)))
! print obj
! print repr(obj)
! packevent(ae, {'----': obj})
! params, attrs = unpackevent(ae)
! print params['----']
! raw_input(":")
if __name__ == '__main__':
! test()
! sys.exit(1)
Index: aetypes.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aetypes.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** aetypes.py 21 Mar 2003 12:04:18 -0000 1.4
--- aetypes.py 9 Apr 2003 13:25:42 -0000 1.5
***************
*** 11,433 ****
#
def pack(*args, **kwargs):
! from aepack import pack
! return pack( *args, **kwargs)
!
def nice(s):
! """'nice' representation of an object"""
! if type(s) is StringType: return repr(s)
! else: return str(s)
[...1066 lines suppressed...]
! cls = self._propdict[name]
! return cls(self)
! raise AttributeError, name
!
!
class DelayedComponentItem:
! def __init__(self, compclass, fr):
! self.compclass = compclass
! self.fr = fr
!
! def __call__(self, which):
! return self.compclass(which, self.fr)
!
! def __repr__(self):
! return "%s(???, %s)" % (self.__class__.__name__, `self.fr`)
!
! def __str__(self):
! return "selector for element %s of %s"%(self.__class__.__name__, str(self.fr))
template = """
Index: applesingle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/applesingle.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** applesingle.py 30 Dec 2002 22:04:20 -0000 1.1
--- applesingle.py 9 Apr 2003 13:25:42 -0000 1.2
***************
*** 25,100 ****
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'
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 __name__ == '__main__':
! _test()
!
\ No newline at end of file
--- 25,100 ----
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'
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 __name__ == '__main__':
! _test()
!
\ No newline at end of file
Index: appletrawmain.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/appletrawmain.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** appletrawmain.py 30 Dec 2002 22:04:20 -0000 1.1
--- appletrawmain.py 9 Apr 2003 13:25:42 -0000 1.2
***************
*** 15,25 ****
#
if not sys.argv or sys.argv[0][:1] == '-':
! # Insert our (guessed) name.
! _dir = os.path.split(sys.executable)[0] # removes "python"
! _dir = os.path.split(_dir)[0] # Removes "MacOS"
! _dir = os.path.join(_dir, 'Resources')
! sys.argv.insert(0, '__rawmain__')
else:
! _dir = os.path.split(sys.argv[0])[0]
#
# Add the Resources directory to the path. This is where files installed
--- 15,25 ----
#
if not sys.argv or sys.argv[0][:1] == '-':
! # Insert our (guessed) name.
! _dir = os.path.split(sys.executable)[0] # removes "python"
! _dir = os.path.split(_dir)[0] # Removes "MacOS"
! _dir = os.path.join(_dir, 'Resources')
! sys.argv.insert(0, '__rawmain__')
else:
! _dir = os.path.split(sys.argv[0])[0]
#
# Add the Resources directory to the path. This is where files installed
***************
*** 37,63 ****
__file__ = os.path.join(_dir, '__main__.py')
if os.path.exists(__file__):
! #
! # Setup something resembling a normal environment and go.
! #
! sys.argv[0] = __file__
! del argvemulator, os, sys, _dir
! execfile(__file__)
else:
! __file__ = os.path.join(_dir, '__main__.pyc')
! if os.path.exists(__file__):
! #
! # If we have only a .pyc file we read the code object from that
! #
! sys.argv[0] = __file__
! _fp = open(__file__, 'rb')
! _fp.read(8)
! __code__ = marshal.load(_fp)
! #
! # Again, we create an almost-normal environment (only __code__ is
! # funny) and go.
! #
! del argvemulator, os, sys, marshal, _dir, _fp
! exec __code__
! else:
! sys.stderr.write("%s: neither __main__.py nor __main__.pyc found\n"%sys.argv[0])
! sys.exit(1)
--- 37,63 ----
__file__ = os.path.join(_dir, '__main__.py')
if os.path.exists(__file__):
! #
! # Setup something resembling a normal environment and go.
! #
! sys.argv[0] = __file__
! del argvemulator, os, sys, _dir
! execfile(__file__)
else:
! __file__ = os.path.join(_dir, '__main__.pyc')
! if os.path.exists(__file__):
! #
! # If we have only a .pyc file we read the code object from that
! #
! sys.argv[0] = __file__
! _fp = open(__file__, 'rb')
! _fp.read(8)
! __code__ = marshal.load(_fp)
! #
! # Again, we create an almost-normal environment (only __code__ is
! # funny) and go.
! #
! del argvemulator, os, sys, marshal, _dir, _fp
! exec __code__
! else:
! sys.stderr.write("%s: neither __main__.py nor __main__.pyc found\n"%sys.argv[0])
! sys.exit(1)
Index: appletrunner.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/appletrunner.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** appletrunner.py 30 Dec 2002 22:04:20 -0000 1.1
--- appletrunner.py 9 Apr 2003 13:25:42 -0000 1.2
***************
*** 7,17 ****
import sys
for name in ["__rawmain__.py", "__rawmain__.pyc", "__main__.py", "__main__.pyc"]:
! realmain = os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])),
! "Resources", name)
! if os.path.exists(realmain):
! break
else:
! sys.stderr.write("%s: cannot find applet main program\n" % sys.argv[0])
! sys.exit(1)
sys.argv.insert(1, realmain)
os.execve(sys.executable, sys.argv, os.environ)
--- 7,17 ----
import sys
for name in ["__rawmain__.py", "__rawmain__.pyc", "__main__.py", "__main__.pyc"]:
! realmain = os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])),
! "Resources", name)
! if os.path.exists(realmain):
! break
else:
! sys.stderr.write("%s: cannot find applet main program\n" % sys.argv[0])
! sys.exit(1)
sys.argv.insert(1, realmain)
os.execve(sys.executable, sys.argv, os.environ)
Index: bgenlocations.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/bgenlocations.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** bgenlocations.py 12 Feb 2003 15:37:26 -0000 1.3
--- bgenlocations.py 9 Apr 2003 13:25:42 -0000 1.4
***************
*** 13,22 ****
# the source tree here.
if sys.platform == 'mac':
! # For MacPython we know where it is
! def _pardir(p): return os.path.split(p)[0]
! BGENDIR=os.path.join(sys.prefix, "Tools", "bgen", "bgen")
else:
! # for unix-Python we don't know, please set it yourself.
! BGENDIR="/Users/jack/src/python/Tools/bgen/bgen"
#
--- 13,22 ----
# the source tree here.
if sys.platform == 'mac':
! # For MacPython we know where it is
! def _pardir(p): return os.path.split(p)[0]
! BGENDIR=os.path.join(sys.prefix, "Tools", "bgen", "bgen")
else:
! # for unix-Python we don't know, please set it yourself.
! BGENDIR="/Users/jack/src/python/Tools/bgen/bgen"
#
***************
*** 27,33 ****
#
if sys.platform == 'mac':
! _MWERKSDIR="Sap:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
else:
! _MWERKSDIR="/Volumes/Sap/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
--- 27,33 ----
#
if sys.platform == 'mac':
! _MWERKSDIR="Sap:Applications (Mac OS 9):Metrowerks CodeWarrior 7.0:Metrowerks CodeWarrior"
else:
! _MWERKSDIR="/Volumes/Sap/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/"
INCLUDEDIR=os.path.join(_MWERKSDIR, "MacOS Support", "Universal", "Interfaces", "CIncludes")
***************
*** 38,44 ****
#
if sys.platform == 'mac':
! TOOLBOXDIR=os.path.join(sys.prefix, "Lib", "plat-mac", "Carbon")
else:
! TOOLBOXDIR="/Users/jack/src/python/Lib/plat-mac/Carbon"
# Creator for C files:
--- 38,44 ----
#
if sys.platform == 'mac':
! TOOLBOXDIR=os.path.join(sys.prefix, "Lib", "plat-mac", "Carbon")
else:
! TOOLBOXDIR="/Users/jack/src/python/Lib/plat-mac/Carbon"
# Creator for C files:
***************
*** 46,61 ****
if not os.path.exists(BGENDIR):
! raise Error, "Please fix bgenlocations.py, BGENDIR does not exist: %s" % BGENDIR
if not os.path.exists(INCLUDEDIR):
! raise Error, "Please fix bgenlocations.py, INCLUDEDIR does not exist: %s" % INCLUDEDIR
if not os.path.exists(TOOLBOXDIR):
! raise Error, "Please fix bgenlocations.py, TOOLBOXDIR does not exist: %s" % TOOLBOXDIR
!
# Sigh, due to the way these are used make sure they end with : or /.
if BGENDIR[-1] != os.sep:
! BGENDIR = BGENDIR + os.sep
if INCLUDEDIR[-1] != os.sep:
! INCLUDEDIR = INCLUDEDIR + os.sep
if TOOLBOXDIR[-1] != os.sep:
! TOOLBOXDIR = TOOLBOXDIR + os.sep
!
--- 46,61 ----
if not os.path.exists(BGENDIR):
! raise Error, "Please fix bgenlocations.py, BGENDIR does not exist: %s" % BGENDIR
if not os.path.exists(INCLUDEDIR):
! raise Error, "Please fix bgenlocations.py, INCLUDEDIR does not exist: %s" % INCLUDEDIR
if not os.path.exists(TOOLBOXDIR):
! raise Error, "Please fix bgenlocations.py, TOOLBOXDIR does not exist: %s" % TOOLBOXDIR
!
# Sigh, due to the way these are used make sure they end with : or /.
if BGENDIR[-1] != os.sep:
! BGENDIR = BGENDIR + os.sep
if INCLUDEDIR[-1] != os.sep:
! INCLUDEDIR = INCLUDEDIR + os.sep
if TOOLBOXDIR[-1] != os.sep:
! TOOLBOXDIR = TOOLBOXDIR + os.sep
!
Index: buildtools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/buildtools.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** buildtools.py 25 Feb 2003 23:02:03 -0000 1.8
--- buildtools.py 9 Apr 2003 13:25:42 -0000 1.9
***************
*** 43,325 ****
def findtemplate(template=None):
! """Locate the applet template along sys.path"""
! if MacOS.runtimemodel == 'macho':
! return None
! if not template:
! template=TEMPLATE
! for p in sys.path:
! file = os.path.join(p, template)
! try:
! file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1)
! break
! except (Carbon.File.Error, ValueError):
! continue
! else:
! raise BuildError, "Template %s not found on sys.path" % `template`
! file = file.as_pathname()
! return file
!
def process(template, filename, destname, copy_codefragment=0,
! rsrcname=None, others=[], raw=0, progress="default"):
!
! if progress == "default":
! progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
! progress.label("Compiling...")
! progress.inc(0)
! # check for the script name being longer than 32 chars. This may trigger a bug
! # on OSX that can destroy your sourcefile.
! if '#' in os.path.split(filename)[1]:
! raise BuildError, "BuildApplet could destroy your sourcefile on OSX, please rename: %s" % filename
! # Read the source and compile it
! # (there's no point overwriting the destination if it has a syntax error)
!
! fp = open(filename, 'rU')
! text = fp.read()
! fp.close()
! try:
! code = compile(text + '\n', filename, "exec")
! except SyntaxError, arg:
! raise BuildError, "Syntax error in script %s: %s" % (filename, arg)
! except EOFError:
! raise BuildError, "End-of-file in script %s" % (filename,)
!
! # Set the destination file name. Note that basename
! # does contain the whole filepath, only a .py is stripped.
!
! if string.lower(filename[-3:]) == ".py":
! basename = filename[:-3]
! if MacOS.runtimemodel != 'macho' and not destname:
! destname = basename
! else:
! basename = filename
!
! if not destname:
! if MacOS.runtimemodel == 'macho':
! destname = basename + '.app'
! else:
! destname = basename + '.applet'
! if not rsrcname:
! rsrcname = basename + '.rsrc'
!
! # Try removing the output file. This fails in MachO, but it should
! # do any harm.
! try:
! os.remove(destname)
! except os.error:
! pass
! process_common(template, progress, code, rsrcname, destname, 0,
! copy_codefragment, raw, others, filename)
!
def update(template, filename, output):
! if MacOS.runtimemodel == 'macho':
! raise BuildError, "No updating yet for MachO applets"
! if progress:
! progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
! else:
! progress = None
! if not output:
! output = filename + ' (updated)'
!
! # Try removing the output file
! try:
! os.remove(output)
! except os.error:
! pass
! process_common(template, progress, None, filename, output, 1, 1)
def process_common(template, progress, code, rsrcname, destname, is_update,
! copy_codefragment, raw=0, others=[], filename=None):
! if MacOS.runtimemodel == 'macho':
! return process_common_macho(template, progress, code, rsrcname, destname,
! is_update, raw, others, filename)
! if others:
! raise BuildError, "Extra files only allowed for MachoPython applets"
! # Create FSSpecs for the various files
! template_fsr, d1, d2 = Carbon.File.FSResolveAliasFile(template, 1)
! template = template_fsr.as_pathname()
!
! # Copy data (not resources, yet) from the template
! if progress:
! progress.label("Copy data fork...")
! progress.set(10)
!
! if copy_codefragment:
! tmpl = open(template, "rb")
! dest = open(destname, "wb")
! data = tmpl.read()
! if data:
! dest.write(data)
! dest.close()
! tmpl.close()
! del dest
! del tmpl
!
! # Open the output resource fork
!
! if progress:
! progress.label("Copy resources...")
! progress.set(20)
! try:
! output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)
! except MacOS.Error:
! destdir, destfile = os.path.split(destname)
! Res.FSCreateResourceFile(destdir, unicode(destfile), RESOURCE_FORK_NAME)
! output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)
!
! # Copy the resources from the target specific resource template, if any
! typesfound, ownertype = [], None
! try:
! input = Res.FSOpenResourceFile(rsrcname, RESOURCE_FORK_NAME, READ)
! except (MacOS.Error, ValueError):
! pass
! if progress:
! progress.inc(50)
! else:
! if is_update:
! skip_oldfile = ['cfrg']
! else:
! skip_oldfile = []
! typesfound, ownertype = copyres(input, output, skip_oldfile, 0, progress)
! Res.CloseResFile(input)
!
! # Check which resource-types we should not copy from the template
! skiptypes = []
! if 'vers' in typesfound: skiptypes.append('vers')
! if 'SIZE' in typesfound: skiptypes.append('SIZE')
! if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4',
! 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
! if not copy_codefragment:
! skiptypes.append('cfrg')
! ## skipowner = (ownertype <> None)
!
! # Copy the resources from the template
!
! input = Res.FSOpenResourceFile(template, RESOURCE_FORK_NAME, READ)
! dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
!
! Res.CloseResFile(input)
! ## if ownertype == None:
! ## raise BuildError, "No owner resource found in either resource file or template"
! # Make sure we're manipulating the output resource file now
!
! Res.UseResFile(output)
! if ownertype == None:
! # No owner resource in the template. We have skipped the
! # Python owner resource, so we have to add our own. The relevant
! # bundle stuff is already included in the interpret/applet template.
! newres = Res.Resource('\0')
! newres.AddResource(DEFAULT_APPLET_CREATOR, 0, "Owner resource")
! ownertype = DEFAULT_APPLET_CREATOR
!
! if code:
! # Delete any existing 'PYC ' resource named __main__
!
! try:
! res = Res.Get1NamedResource(RESTYPE, RESNAME)
! res.RemoveResource()
! except Res.Error:
! pass
!
! # Create the raw data for the resource from the code object
! if progress:
! progress.label("Write PYC resource...")
! progress.set(120)
!
! data = marshal.dumps(code)
! del code
! data = (MAGIC + '\0\0\0\0') + data
!
! # Create the resource and write it
!
! id = 0
! while id < 128:
! id = Res.Unique1ID(RESTYPE)
! res = Res.Resource(data)
! res.AddResource(RESTYPE, id, RESNAME)
! attrs = res.GetResAttrs()
! attrs = attrs | 0x04 # set preload
! res.SetResAttrs(attrs)
! res.WriteResource()
! res.ReleaseResource()
!
! # Close the output file
!
! Res.CloseResFile(output)
!
! # Now set the creator, type and bundle bit of the destination.
! # Done with FSSpec's, FSRef FInfo isn't good enough yet (2.3a1+)
! dest_fss = Carbon.File.FSSpec(destname)
! dest_finfo = dest_fss.FSpGetFInfo()
! dest_finfo.Creator = ownertype
! dest_finfo.Type = 'APPL'
! dest_finfo.Flags = dest_finfo.Flags | Carbon.Files.kHasBundle | Carbon.Files.kIsShared
! dest_finfo.Flags = dest_finfo.Flags & ~Carbon.Files.kHasBeenInited
! dest_fss.FSpSetFInfo(dest_finfo)
!
! macostools.touched(destname)
! if progress:
! progress.label("Done.")
! progress.inc(0)
def process_common_macho(template, progress, code, rsrcname, destname, is_update,
! raw=0, others=[], filename=None):
! # Check that we have a filename
! if filename is None:
! raise BuildError, "Need source filename on MacOSX"
! # First make sure the name ends in ".app"
! if destname[-4:] != '.app':
! destname = destname + '.app'
! # Now deduce the short name
! destdir, shortname = os.path.split(destname)
! if shortname[-4:] == '.app':
! # Strip the .app suffix
! shortname = shortname[:-4]
! # And deduce the .plist and .icns names
! plistname = None
! icnsname = None
! if rsrcname and rsrcname[-5:] == '.rsrc':
! tmp = rsrcname[:-5]
! plistname = tmp + '.plist'
! if os.path.exists(plistname):
! icnsname = tmp + '.icns'
! if not os.path.exists(icnsname):
! icnsname = None
! else:
! plistname = None
! if not os.path.exists(rsrcname):
! rsrcname = None
! if progress:
! progress.label('Creating bundle...')
! import bundlebuilder
! builder = bundlebuilder.AppBuilder(verbosity=0)
! builder.mainprogram = filename
! builder.builddir = destdir
! builder.name = shortname
! if rsrcname:
! realrsrcname = macresource.resource_pathname(rsrcname)
! builder.files.append((realrsrcname,
! os.path.join('Contents/Resources', os.path.basename(rsrcname))))
! for o in others:
! if type(o) == str:
! builder.resources.append(o)
! else:
! builder.files.append(o)
! if plistname:
! import plistlib
! builder.plist = plistlib.Plist.fromFile(plistname)
! if icnsname:
! builder.iconfile = icnsname
! if not raw:
! builder.argv_emulation = 1
! builder.setup()
! builder.build()
! if progress:
! progress.label('Done.')
! progress.inc(0)
!
! ## macostools.touched(dest_fss)
# Copy resources between two resource file descriptors.
--- 43,325 ----
def findtemplate(template=None):
! """Locate the applet template along sys.path"""
! if MacOS.runtimemodel == 'macho':
! return None
! if not template:
! template=TEMPLATE
! for p in sys.path:
! file = os.path.join(p, template)
! try:
! file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1)
! break
! except (Carbon.File.Error, ValueError):
! continue
! else:
! raise BuildError, "Template %s not found on sys.path" % `template`
! file = file.as_pathname()
! return file
!
def process(template, filename, destname, copy_codefragment=0,
! rsrcname=None, others=[], raw=0, progress="default"):
!
! if progress == "default":
! progress = EasyDialogs.ProgressBar("Processing %s..."%os.path.split(filename)[1], 120)
! progress.label("Compiling...")
! progress.inc(0)
! # check for the script name being longer than 32 chars. This may trigger a bug
! # on OSX that can destroy your sourcefile.
! if '#' in os.path.split(filename)[1]:
! raise BuildError, "BuildApplet could destroy your sourcefile on OSX, please rename: %s" % filename
! # Read the source and compile it
! # (there's no point overwriting the destination if it has a syntax error)
!
! fp = open(filename, 'rU')
! text = fp.read()
! fp.close()
! try:
! code = compile(text + '\n', filename, "exec")
! except SyntaxError, arg:
! raise BuildError, "Syntax error in script %s: %s" % (filename, arg)
! except EOFError:
! raise BuildError, "End-of-file in script %s" % (filename,)
!
! # Set the destination file name. Note that basename
! # does contain the whole filepath, only a .py is stripped.
!
! if string.lower(filename[-3:]) == ".py":
! basename = filename[:-3]
! if MacOS.runtimemodel != 'macho' and not destname:
! destname = basename
! else:
! basename = filename
!
! if not destname:
! if MacOS.runtimemodel == 'macho':
! destname = basename + '.app'
! else:
! destname = basename + '.applet'
! if not rsrcname:
! rsrcname = basename + '.rsrc'
!
! # Try removing the output file. This fails in MachO, but it should
! # do any harm.
! try:
! os.remove(destname)
! except os.error:
! pass
! process_common(template, progress, code, rsrcname, destname, 0,
! copy_codefragment, raw, others, filename)
!
def update(template, filename, output):
! if MacOS.runtimemodel == 'macho':
! raise BuildError, "No updating yet for MachO applets"
! if progress:
! progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
! else:
! progress = None
! if not output:
! output = filename + ' (updated)'
!
! # Try removing the output file
! try:
! os.remove(output)
! except os.error:
! pass
! process_common(template, progress, None, filename, output, 1, 1)
def process_common(template, progress, code, rsrcname, destname, is_update,
! copy_codefragment, raw=0, others=[], filename=None):
! if MacOS.runtimemodel == 'macho':
! return process_common_macho(template, progress, code, rsrcname, destname,
! is_update, raw, others, filename)
! if others:
! raise BuildError, "Extra files only allowed for MachoPython applets"
! # Create FSSpecs for the various files
! template_fsr, d1, d2 = Carbon.File.FSResolveAliasFile(template, 1)
! template = template_fsr.as_pathname()
!
! # Copy data (not resources, yet) from the template
! if progress:
! progress.label("Copy data fork...")
! progress.set(10)
!
! if copy_codefragment:
! tmpl = open(template, "rb")
! dest = open(destname, "wb")
! data = tmpl.read()
! if data:
! dest.write(data)
! dest.close()
! tmpl.close()
! del dest
! del tmpl
!
! # Open the output resource fork
!
! if progress:
! progress.label("Copy resources...")
! progress.set(20)
! try:
! output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)
! except MacOS.Error:
! destdir, destfile = os.path.split(destname)
! Res.FSCreateResourceFile(destdir, unicode(destfile), RESOURCE_FORK_NAME)
! output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)
!
! # Copy the resources from the target specific resource template, if any
! typesfound, ownertype = [], None
! try:
! input = Res.FSOpenResourceFile(rsrcname, RESOURCE_FORK_NAME, READ)
! except (MacOS.Error, ValueError):
! pass
! if progress:
! progress.inc(50)
! else:
! if is_update:
! skip_oldfile = ['cfrg']
! else:
! skip_oldfile = []
! typesfound, ownertype = copyres(input, output, skip_oldfile, 0, progress)
! Res.CloseResFile(input)
!
! # Check which resource-types we should not copy from the template
! skiptypes = []
! if 'vers' in typesfound: skiptypes.append('vers')
! if 'SIZE' in typesfound: skiptypes.append('SIZE')
! if 'BNDL' in typesfound: skiptypes = skiptypes + ['BNDL', 'FREF', 'icl4',
! 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#']
! if not copy_codefragment:
! skiptypes.append('cfrg')
! ## skipowner = (ownertype <> None)
!
! # Copy the resources from the template
!
! input = Res.FSOpenResourceFile(template, RESOURCE_FORK_NAME, READ)
! dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
!
! Res.CloseResFile(input)
! ## if ownertype == None:
! ## raise BuildError, "No owner resource found in either resource file or template"
! # Make sure we're manipulating the output resource file now
!
! Res.UseResFile(output)
! if ownertype == None:
! # No owner resource in the template. We have skipped the
! # Python owner resource, so we have to add our own. The relevant
! # bundle stuff is already included in the interpret/applet template.
! newres = Res.Resource('\0')
! newres.AddResource(DEFAULT_APPLET_CREATOR, 0, "Owner resource")
! ownertype = DEFAULT_APPLET_CREATOR
!
! if code:
! # Delete any existing 'PYC ' resource named __main__
!
! try:
! res = Res.Get1NamedResource(RESTYPE, RESNAME)
! res.RemoveResource()
! except Res.Error:
! pass
!
! # Create the raw data for the resource from the code object
! if progress:
! progress.label("Write PYC resource...")
! progress.set(120)
!
! data = marshal.dumps(code)
! del code
! data = (MAGIC + '\0\0\0\0') + data
!
! # Create the resource and write it
!
! id = 0
! while id < 128:
! id = Res.Unique1ID(RESTYPE)
! res = Res.Resource(data)
! res.AddResource(RESTYPE, id, RESNAME)
! attrs = res.GetResAttrs()
! attrs = attrs | 0x04 # set preload
! res.SetResAttrs(attrs)
! res.WriteResource()
! res.ReleaseResource()
!
! # Close the output file
!
! Res.CloseResFile(output)
!
! # Now set the creator, type and bundle bit of the destination.
! # Done with FSSpec's, FSRef FInfo isn't good enough yet (2.3a1+)
! dest_fss = Carbon.File.FSSpec(destname)
! dest_finfo = dest_fss.FSpGetFInfo()
! dest_finfo.Creator = ownertype
! dest_finfo.Type = 'APPL'
! dest_finfo.Flags = dest_finfo.Flags | Carbon.Files.kHasBundle | Carbon.Files.kIsShared
! dest_finfo.Flags = dest_finfo.Flags & ~Carbon.Files.kHasBeenInited
! dest_fss.FSpSetFInfo(dest_finfo)
!
! macostools.touched(destname)
! if progress:
! progress.label("Done.")
! progress.inc(0)
def process_common_macho(template, progress, code, rsrcname, destname, is_update,
! raw=0, others=[], filename=None):
! # Check that we have a filename
! if filename is None:
! raise BuildError, "Need source filename on MacOSX"
! # First make sure the name ends in ".app"
! if destname[-4:] != '.app':
! destname = destname + '.app'
! # Now deduce the short name
! destdir, shortname = os.path.split(destname)
! if shortname[-4:] == '.app':
! # Strip the .app suffix
! shortname = shortname[:-4]
! # And deduce the .plist and .icns names
! plistname = None
! icnsname = None
! if rsrcname and rsrcname[-5:] == '.rsrc':
! tmp = rsrcname[:-5]
! plistname = tmp + '.plist'
! if os.path.exists(plistname):
! icnsname = tmp + '.icns'
! if not os.path.exists(icnsname):
! icnsname = None
! else:
! plistname = None
! if not os.path.exists(rsrcname):
! rsrcname = None
! if progress:
! progress.label('Creating bundle...')
! import bundlebuilder
! builder = bundlebuilder.AppBuilder(verbosity=0)
! builder.mainprogram = filename
! builder.builddir = destdir
! builder.name = shortname
! if rsrcname:
! realrsrcname = macresource.resource_pathname(rsrcname)
! builder.files.append((realrsrcname,
! os.path.join('Contents/Resources', os.path.basename(rsrcname))))
! for o in others:
! if type(o) == str:
! builder.resources.append(o)
! else:
! builder.files.append(o)
! if plistname:
! import plistlib
! builder.plist = plistlib.Plist.fromFile(plistname)
! if icnsname:
! builder.iconfile = icnsname
! if not raw:
! builder.argv_emulation = 1
! builder.setup()
! builder.build()
! if progress:
! progress.label('Done.')
! progress.inc(0)
!
! ## macostools.touched(dest_fss)
# Copy resources between two resource file descriptors.
***************
*** 328,416 ****
#
def copyres(input, output, skiptypes, skipowner, progress=None):
! ctor = None
! alltypes = []
! Res.UseResFile(input)
! ntypes = Res.Count1Types()
! progress_type_inc = 50/ntypes
! for itype in range(1, 1+ntypes):
! type = Res.Get1IndType(itype)
! if type in skiptypes:
! continue
! alltypes.append(type)
! nresources = Res.Count1Resources(type)
! progress_cur_inc = progress_type_inc/nresources
! for ires in range(1, 1+nresources):
! res = Res.Get1IndResource(type, ires)
! id, type, name = res.GetResInfo()
! lcname = string.lower(name)
! if lcname == OWNERNAME and id == 0:
! if skipowner:
! continue # Skip this one
! else:
! ctor = type
! size = res.size
! attrs = res.GetResAttrs()
! if progress:
! progress.label("Copy %s %d %s"%(type, id, name))
! progress.inc(progress_cur_inc)
! res.LoadResource()
! res.DetachResource()
! Res.UseResFile(output)
! try:
! res2 = Res.Get1Resource(type, id)
! except MacOS.Error:
! res2 = None
! if res2:
! if progress:
! progress.label("Overwrite %s %d %s"%(type, id, name))
! progress.inc(0)
! res2.RemoveResource()
! res.AddResource(type, id, name)
! res.WriteResource()
! attrs = attrs | res.GetResAttrs()
! res.SetResAttrs(attrs)
! Res.UseResFile(input)
! return alltypes, ctor
def copyapptree(srctree, dsttree, exceptlist=[], progress=None):
! names = []
! if os.path.exists(dsttree):
! shutil.rmtree(dsttree)
! os.mkdir(dsttree)
! todo = os.listdir(srctree)
! while todo:
! this, todo = todo[0], todo[1:]
! if this in exceptlist:
! continue
! thispath = os.path.join(srctree, this)
! if os.path.isdir(thispath):
! thiscontent = os.listdir(thispath)
! for t in thiscontent:
! todo.append(os.path.join(this, t))
! names.append(this)
! for this in names:
! srcpath = os.path.join(srctree, this)
! dstpath = os.path.join(dsttree, this)
! if os.path.isdir(srcpath):
! os.mkdir(dstpath)
! elif os.path.islink(srcpath):
! endpoint = os.readlink(srcpath)
! os.symlink(endpoint, dstpath)
! else:
! if progress:
! progress.label('Copy '+this)
! progress.inc(0)
! shutil.copy2(srcpath, dstpath)
!
def writepycfile(codeobject, cfile):
! import marshal
! fc = open(cfile, 'wb')
! fc.write('\0\0\0\0') # MAGIC placeholder, written later
! fc.write('\0\0\0\0') # Timestap placeholder, not needed
! marshal.dump(codeobject, fc)
! fc.flush()
! fc.seek(0, 0)
! fc.write(MAGIC)
! fc.close()
--- 328,416 ----
#
def copyres(input, output, skiptypes, skipowner, progress=None):
! ctor = None
! alltypes = []
! Res.UseResFile(input)
! ntypes = Res.Count1Types()
! progress_type_inc = 50/ntypes
! for itype in range(1, 1+ntypes):
! type = Res.Get1IndType(itype)
! if type in skiptypes:
! continue
! alltypes.append(type)
! nresources = Res.Count1Resources(type)
! progress_cur_inc = progress_type_inc/nresources
! for ires in range(1, 1+nresources):
! res = Res.Get1IndResource(type, ires)
! id, type, name = res.GetResInfo()
! lcname = string.lower(name)
! if lcname == OWNERNAME and id == 0:
! if skipowner:
! continue # Skip this one
! else:
! ctor = type
! size = res.size
! attrs = res.GetResAttrs()
! if progress:
! progress.label("Copy %s %d %s"%(type, id, name))
! progress.inc(progress_cur_inc)
! res.LoadResource()
! res.DetachResource()
! Res.UseResFile(output)
! try:
! res2 = Res.Get1Resource(type, id)
! except MacOS.Error:
! res2 = None
! if res2:
! if progress:
! progress.label("Overwrite %s %d %s"%(type, id, name))
! progress.inc(0)
! res2.RemoveResource()
! res.AddResource(type, id, name)
! res.WriteResource()
! attrs = attrs | res.GetResAttrs()
! res.SetResAttrs(attrs)
! Res.UseResFile(input)
! return alltypes, ctor
def copyapptree(srctree, dsttree, exceptlist=[], progress=None):
! names = []
! if os.path.exists(dsttree):
! shutil.rmtree(dsttree)
! os.mkdir(dsttree)
! todo = os.listdir(srctree)
! while todo:
! this, todo = todo[0], todo[1:]
! if this in exceptlist:
! continue
! thispath = os.path.join(srctree, this)
! if os.path.isdir(thispath):
! thiscontent = os.listdir(thispath)
! for t in thiscontent:
! todo.append(os.path.join(this, t))
! names.append(this)
! for this in names:
! srcpath = os.path.join(srctree, this)
! dstpath = os.path.join(dsttree, this)
! if os.path.isdir(srcpath):
! os.mkdir(dstpath)
! elif os.path.islink(srcpath):
! endpoint = os.readlink(srcpath)
! os.symlink(endpoint, dstpath)
! else:
! if progress:
! progress.label('Copy '+this)
! progress.inc(0)
! shutil.copy2(srcpath, dstpath)
!
def writepycfile(codeobject, cfile):
! import marshal
! fc = open(cfile, 'wb')
! fc.write('\0\0\0\0') # MAGIC placeholder, written later
! fc.write('\0\0\0\0') # Timestap placeholder, not needed
! marshal.dump(codeobject, fc)
! fc.flush()
! fc.seek(0, 0)
! fc.write(MAGIC)
! fc.close()
Index: bundlebuilder.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/bundlebuilder.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** bundlebuilder.py 21 Mar 2003 22:22:19 -0000 1.24
--- bundlebuilder.py 9 Apr 2003 13:25:42 -0000 1.25
***************
*** 43,213 ****
class Defaults:
! """Class attributes that don't start with an underscore and are
! not functions or classmethods are (deep)copied to self.__dict__.
! This allows for mutable default values.
! """
! def __init__(self, **kwargs):
! defaults = self._getDefaults()
! defaults.update(kwargs)
[...1344 lines suppressed...]
! if command == "build":
! builder.setup()
! builder.build()
! elif command == "report":
! builder.setup()
! builder.report()
! elif command == "help":
! usage()
! else:
! usage("Unknown command '%s'" % command)
def buildapp(**kwargs):
! builder = AppBuilder(**kwargs)
! main(builder)
if __name__ == "__main__":
! main()
Index: cfmfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/cfmfile.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** cfmfile.py 5 Feb 2003 15:44:03 -0000 1.2
--- cfmfile.py 9 Apr 2003 13:25:42 -0000 1.3
***************
*** 19,184 ****
def mergecfmfiles(srclist, dst, architecture = 'fat'):
! """Merge all files in srclist into a new file dst.
!
! If architecture is given, only code fragments of that type will be used:
! "pwpc" for PPC, "m68k" for cfm68k. This does not work for "classic"
! 68k code, since it does not use code fragments to begin with.
! If architecture is None, all fragments will be used, enabling FAT binaries.
! """
!
! srclist = list(srclist)
! for i in range(len(srclist)):
! srclist[i] = Carbon.File.pathname(srclist[i])
! dst = Carbon.File.pathname(dst)
!
! dstfile = open(dst, "wb")
! rf = Res.FSpOpenResFile(dst, 3)
! try:
! dstcfrg = CfrgResource()
! for src in srclist:
! srccfrg = CfrgResource(src)
! for frag in srccfrg.fragments:
! if frag.architecture == 'pwpc' and architecture == 'm68k':
! continue
! if frag.architecture == 'm68k' and architecture == 'pwpc':
! continue
! dstcfrg.append(frag)
!
! frag.copydata(dstfile)
!
! cfrgres = Res.Resource(dstcfrg.build())
! Res.UseResFile(rf)
! cfrgres.AddResource('cfrg', 0, "")
! finally:
! dstfile.close()
! rf = Res.CloseResFile(rf)
class CfrgResource:
!
! def __init__(self, path = None):
! self.version = 1
! self.fragments = []
! self.path = path
! if path is not None and os.path.exists(path):
! currentresref = Res.CurResFile()
! resref = Res.FSpOpenResFile(path, 1)
! Res.UseResFile(resref)
! try:
! try:
! data = Res.Get1Resource('cfrg', 0).data
! except Res.Error:
! raise Res.Error, "no 'cfrg' resource found", sys.exc_traceback
! finally:
! Res.CloseResFile(resref)
! Res.UseResFile(currentresref)
! self.parse(data)
! if self.version <> 1:
! raise error, "unknown 'cfrg' resource format"
!
! def parse(self, data):
! (res1, res2, self.version,
! res3, res4, res5, res6,
! self.memberCount) = struct.unpack("8l", data[:32])
! data = data[32:]
! while data:
! frag = FragmentDescriptor(self.path, data)
! data = data[frag.memberSize:]
! self.fragments.append(frag)
!
! def build(self):
! self.memberCount = len(self.fragments)
! data = struct.pack("8l", 0, 0, self.version, 0, 0, 0, 0, self.memberCount)
! for frag in self.fragments:
! data = data + frag.build()
! return data
!
! def append(self, frag):
! self.fragments.append(frag)
class FragmentDescriptor:
!
! def __init__(self, path, data = None):
! self.path = path
! if data is not None:
! self.parse(data)
!
! def parse(self, data):
! self.architecture = data[:4]
! ( self.updatelevel,
! self.currentVersion,
! self.oldDefVersion,
! self.stacksize,
! self.applibdir,
! self.fragtype,
! self.where,
! self.offset,
! self.length,
! self.res1, self.res2,
! self.memberSize,) = struct.unpack("4lhBB4lh", data[4:42])
! pname = data[42:self.memberSize]
! self.name = pname[1:1+ord(pname[0])]
!
! def build(self):
! data = self.architecture
! data = data + struct.pack("4lhBB4l",
! self.updatelevel,
! self.currentVersion,
! self.oldDefVersion,
! self.stacksize,
! self.applibdir,
! self.fragtype,
! self.where,
! self.offset,
! self.length,
! self.res1, self.res2)
! self.memberSize = len(data) + 2 + 1 + len(self.name)
! # pad to 4 byte boundaries
! if self.memberSize % 4:
! self.memberSize = self.memberSize + 4 - (self.memberSize % 4)
! data = data + struct.pack("hb", self.memberSize, len(self.name))
! data = data + self.name
! data = data + '\000' * (self.memberSize - len(data))
! return data
!
! def getfragment(self):
! if self.where <> 1:
! raise error, "can't read fragment, unsupported location"
! f = open(self.path, "rb")
! f.seek(self.offset)
! if self.length:
! frag = f.read(self.length)
! else:
! frag = f.read()
! f.close()
! return frag
!
! def copydata(self, outfile):
! if self.where <> 1:
! raise error, "can't read fragment, unsupported location"
! infile = open(self.path, "rb")
! if self.length == 0:
! infile.seek(0, 2)
! self.length = infile.tell()
!
! # Position input file and record new offset from output file
! infile.seek(self.offset)
!
! # pad to 16 byte boundaries
! offset = outfile.tell()
! if offset % 16:
! offset = offset + 16 - (offset % 16)
! outfile.seek(offset)
! self.offset = offset
!
! l = self.length
! while l:
! if l > BUFSIZE:
! outfile.write(infile.read(BUFSIZE))
! l = l - BUFSIZE
! else:
! outfile.write(infile.read(l))
! l = 0
! infile.close()
--- 19,184 ----
def mergecfmfiles(srclist, dst, architecture = 'fat'):
! """Merge all files in srclist into a new file dst.
!
! If architecture is given, only code fragments of that type will be used:
! "pwpc" for PPC, "m68k" for cfm68k. This does not work for "classic"
! 68k code, since it does not use code fragments to begin with.
! If architecture is None, all fragments will be used, enabling FAT binaries.
! """
!
! srclist = list(srclist)
! for i in range(len(srclist)):
! srclist[i] = Carbon.File.pathname(srclist[i])
! dst = Carbon.File.pathname(dst)
!
! dstfile = open(dst, "wb")
! rf = Res.FSpOpenResFile(dst, 3)
! try:
! dstcfrg = CfrgResource()
! for src in srclist:
! srccfrg = CfrgResource(src)
! for frag in srccfrg.fragments:
! if frag.architecture == 'pwpc' and architecture == 'm68k':
! continue
! if frag.architecture == 'm68k' and architecture == 'pwpc':
! continue
! dstcfrg.append(frag)
!
! frag.copydata(dstfile)
!
! cfrgres = Res.Resource(dstcfrg.build())
! Res.UseResFile(rf)
! cfrgres.AddResource('cfrg', 0, "")
! finally:
! dstfile.close()
! rf = Res.CloseResFile(rf)
class CfrgResource:
!
! def __init__(self, path = None):
! self.version = 1
! self.fragments = []
! self.path = path
! if path is not None and os.path.exists(path):
! currentresref = Res.CurResFile()
! resref = Res.FSpOpenResFile(path, 1)
! Res.UseResFile(resref)
! try:
! try:
! data = Res.Get1Resource('cfrg', 0).data
! except Res.Error:
! raise Res.Error, "no 'cfrg' resource found", sys.exc_traceback
! finally:
! Res.CloseResFile(resref)
! Res.UseResFile(currentresref)
! self.parse(data)
! if self.version <> 1:
! raise error, "unknown 'cfrg' resource format"
!
! def parse(self, data):
! (res1, res2, self.version,
! res3, res4, res5, res6,
! self.memberCount) = struct.unpack("8l", data[:32])
! data = data[32:]
! while data:
! frag = FragmentDescriptor(self.path, data)
! data = data[frag.memberSize:]
! self.fragments.append(frag)
!
! def build(self):
! self.memberCount = len(self.fragments)
! data = struct.pack("8l", 0, 0, self.version, 0, 0, 0, 0, self.memberCount)
! for frag in self.fragments:
! data = data + frag.build()
! return data
!
! def append(self, frag):
! self.fragments.append(frag)
class FragmentDescriptor:
!
! def __init__(self, path, data = None):
! self.path = path
! if data is not None:
! self.parse(data)
!
! def parse(self, data):
! self.architecture = data[:4]
! ( self.updatelevel,
! self.currentVersion,
! self.oldDefVersion,
! self.stacksize,
! self.applibdir,
! self.fragtype,
! self.where,
! self.offset,
! self.length,
! self.res1, self.res2,
! self.memberSize,) = struct.unpack("4lhBB4lh", data[4:42])
! pname = data[42:self.memberSize]
! self.name = pname[1:1+ord(pname[0])]
!
! def build(self):
! data = self.architecture
! data = data + struct.pack("4lhBB4l",
! self.updatelevel,
! self.currentVersion,
! self.oldDefVersion,
! self.stacksize,
! self.applibdir,
! self.fragtype,
! self.where,
! self.offset,
! self.length,
! self.res1, self.res2)
! self.memberSize = len(data) + 2 + 1 + len(self.name)
! # pad to 4 byte boundaries
! if self.memberSize % 4:
! self.memberSize = self.memberSize + 4 - (self.memberSize % 4)
! data = data + struct.pack("hb", self.memberSize, len(self.name))
! data = data + self.name
! data = data + '\000' * (self.memberSize - len(data))
! return data
!
! def getfragment(self):
! if self.where <> 1:
! raise error, "can't read fragment, unsupported location"
! f = open(self.path, "rb")
! f.seek(self.offset)
! if self.length:
! frag = f.read(self.length)
! else:
! frag = f.read()
! f.close()
! return frag
!
! def copydata(self, outfile):
! if self.where <> 1:
! raise error, "can't read fragment, unsupported location"
! infile = open(self.path, "rb")
! if self.length == 0:
! infile.seek(0, 2)
! self.length = infile.tell()
!
! # Position input file and record new offset from output file
! infile.seek(self.offset)
!
! # pad to 16 byte boundaries
! offset = outfile.tell()
! if offset % 16:
! offset = offset + 16 - (offset % 16)
! outfile.seek(offset)
! self.offset = offset
!
! l = self.length
! while l:
! if l > BUFSIZE:
! outfile.write(infile.read(BUFSIZE))
! l = l - BUFSIZE
! else:
! outfile.write(infile.read(l))
! l = 0
! infile.close()
Index: findertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/findertools.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** findertools.py 21 Feb 2003 23:14:30 -0000 1.3
--- findertools.py 9 Apr 2003 13:25:42 -0000 1.4
***************
*** 31,832 ****
def _getfinder():
! """returns basic (recyclable) Finder AE interface object"""
! global _finder_talker
! if not _finder_talker:
! _finder_talker = Finder.Finder()
! _finder_talker.send_flags = ( _finder_talker.send_flags |
! AppleEvents.kAECanInteract | AppleEvents.kAECanSwitchLayer)
! return _finder_talker
!
[...1575 lines suppressed...]
! print 'Return a list of current active processes:'
! for p in pr:
! print '\t', p
!
! # get attributes of the first process in the list
! print 'Attributes of the first process in the list:'
! pinfo = processinfo(pr[0][0])
! print '\t', pr[0][0]
! print '\t\tmemory partition', pinfo.partition # the memory allocated to this process
! print '\t\tmemory used', pinfo.used # the memory actuall used by this process
! print '\t\tis visible', pinfo.visible # is the process visible to the user
! print '\t\tis frontmost', pinfo.frontmost # is the process the front most one?
! print '\t\thas scripting', pinfo.hasscripting # is the process scriptable?
! print '\t\taccepts high level events', pinfo.accepthighlevel # does the process accept high level appleevents?
if __name__ == '__main__':
! _test()
! _test2()
! _test3()
!
Index: gensuitemodule.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/gensuitemodule.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** gensuitemodule.py 1 Apr 2003 22:01:58 -0000 1.5
--- gensuitemodule.py 9 Apr 2003 13:25:42 -0000 1.6
***************
*** 30,35 ****
def usage():
! sys.stderr.write("Usage: %s [opts] application-or-resource-file\n" % sys.argv[0])
! sys.stderr.write("""Options:
--output pkgdir Pathname of the output package (short: -o)
--resource Parse resource file in stead of launching application (-r)
--- 30,35 ----
def usage():
! sys.stderr.write("Usage: %s [opts] application-or-resource-file\n" % sys.argv[0])
[...2296 lines suppressed...]
! rv = ''
! ok = string.ascii_letters + '_'
! ok2 = ok + string.digits
! for c in str:
! if c in ok:
! rv = rv + c
! elif c == ' ':
! rv = rv + '_'
! else:
! rv = rv + '_%02.2x_'%ord(c)
! ok = ok2
! if keyword.iskeyword(rv):
! rv = rv + '_'
! return rv
# Call the main program
if __name__ == '__main__':
! main()
! sys.exit(1)
Index: ic.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/ic.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ic.py 25 Feb 2003 13:34:22 -0000 1.4
--- ic.py 9 Apr 2003 13:25:43 -0000 1.5
***************
*** 12,25 ****
# From ictypes.h:
! icPrefNotFoundErr = -666 # preference not found (duh!)
! icPermErr = -667 # cannot set preference
! icPrefDataErr = -668 # problem with preference data
! icInternalErr = -669 # hmm, this is not good
! icTruncatedErr = -670 # more data was present than was returned
! icNoMoreWritersErr = -671 # you cannot begin a write session because someone else is already doing it */
! icNothingToOverrideErr = -672 # no component for the override component to capture
! icNoURLErr = -673 # no URL found
! icConfigNotFoundErr = -674 # no configuration was found
! icConfigInappropriateErr = -675 # incorrect manufacturer code
ICattr_no_change = -1
--- 12,25 ----
# From ictypes.h:
! icPrefNotFoundErr = -666 # preference not found (duh!)
! icPermErr = -667 # cannot set preference
! icPrefDataErr = -668 # problem with preference data
! icInternalErr = -669 # hmm, this is not good
! icTruncatedErr = -670 # more data was present than was returned
! icNoMoreWritersErr = -671 # you cannot begin a write session because someone else is already doing it */
! icNothingToOverrideErr = -672 # no component for the override component to capture
! icNoURLErr = -673 # no URL found
! icConfigNotFoundErr = -674 # no configuration was found
! icConfigInappropriateErr = -675 # incorrect manufacturer code
ICattr_no_change = -1
***************
*** 31,269 ****
class ICOpaqueData:
! """An unparseable IC entry"""
! def __init__(self, data):
! self.data = data
! def __repr__(self):
! return "ICOpaqueData(%s)"%`self.data`
_ICOpaqueDataType=type(ICOpaqueData(''))
!
def _decode_default(data, key):
! if len(data) == 0:
! return data
! if ord(data[0]) == len(data)-1:
! # Assume Pstring
! return data[1:]
! return ICOpaqueData(data)
!
!
def _decode_multistr(data, key):
! numstr = ord(data[0]) << 8 | ord(data[1])
! rv = []
! ptr = 2
! for i in range(numstr):
! strlen = ord(data[ptr])
! str = data[ptr+1:ptr+strlen+1]
! rv.append(str)
! ptr = ptr + strlen + 1
! return rv
!
def _decode_fontrecord(data, key):
! size = ord(data[0]) << 8 | ord(data[1])
! face = ord(data[2])
! namelen = ord(data[4])
! return size, face, data[5:5+namelen]
!
def _decode_boolean(data, key):
! return ord(data[0])
!
def _decode_text(data, key):
! return data
!
def _decode_charset(data, key):
! return data[:256], data[256:]
!
def _decode_appspec(data, key):
! namelen = ord(data[4])
! return data[0:4], data[5:5+namelen]
def _code_default(data, key):
! return chr(len(data)) + data
!
def _code_multistr(data, key):
! numstr = len(data)
! rv = chr((numstr>>8) & 0xff) + chr(numstr & 0xff)
! for i in data:
! rv = rv + _code_default(i)
! return rv
!
def _code_fontrecord(data, key):
! size, face, name = data
! return chr((size>>8) & 0xff) + chr(size & 0xff) + chr(face & 0xff) + \
! chr(0) + _code_default(name)
!
def _code_boolean(data, key):
! print 'XXXX boolean:', `data`
! return chr(data)
!
def _code_text(data, key):
! return data
!
def _code_charset(data, key):
! return data[0] + data[1]
!
def _code_appspec(data, key):
! return data[0] + _code_default(data[1])
!
_decoder_table = {
! "ArchieAll" : (_decode_multistr , _code_multistr),
! "UMichAll" : (_decode_multistr , _code_multistr),
! "InfoMacAll" : (_decode_multistr , _code_multistr),
! "ListFont" : (_decode_fontrecord , _code_fontrecord),
! "ScreenFont" : (_decode_fontrecord , _code_fontrecord),
! "PrinterFont" : (_decode_fontrecord , _code_fontrecord),
! # "DownloadFolder" : (_decode_filespec , _code_filespec),
! "Signature": (_decode_text , _code_text),
! "Plan" : (_decode_text , _code_text),
! "MailHeaders" : (_decode_text , _code_text),
! "NewsHeaders" : (_decode_text , _code_text),
! # "Mapping"
! "CharacterSet" : (_decode_charset , _code_charset),
! "Helper\245" : (_decode_appspec , _code_appspec),
! # "Services" : (_decode_services, ????),
! "NewMailFlashIcon" : (_decode_boolean , _code_boolean),
! "NewMailDialog" : (_decode_boolean , _code_boolean),
! "NewMailPlaySound" : (_decode_boolean , _code_boolean),
! # "WebBackgroundColor" : _decode_color,
! "NoProxyDomains" : (_decode_multistr , _code_multistr),
! "UseHTTPProxy" : (_decode_boolean , _code_boolean),
! "UseGopherProxy": (_decode_boolean , _code_boolean),
! "UseFTPProxy" : (_decode_boolean , _code_boolean),
! "UsePassiveFTP" : (_decode_boolean , _code_boolean),
}
def _decode(data, key):
! if '\245' in key:
! key2 = key[:string.index(key, '\245')+1]
! else:
! key2 = key
! if _decoder_table.has_key(key2):
! decoder = _decoder_table[key2][0]
! else:
! decoder = _decode_default
! return decoder(data, key)
def _code(data, key):
! if type(data) == _ICOpaqueDataType:
! return data.data
! if '\245' in key:
! key2 = key[:string.index(key, '\245')+1]
! else:
! key2 = key
! if _decoder_table.has_key(key2):
! coder = _decoder_table[key2][1]
! else:
! coder = _code_default
! return coder(data, key)
!
class IC:
! def __init__(self, signature='Pyth', ic=None):
! if ic:
! self.ic = ic
! else:
! self.ic = icglue.ICStart(signature)
! if hasattr(self.ic, 'ICFindConfigFile'):
! self.ic.ICFindConfigFile()
! self.h = Res.Resource('')
!
! def keys(self):
! rv = []
! self.ic.ICBegin(icReadOnlyPerm)
! num = self.ic.ICCountPref()
! for i in range(num):
! rv.append(self.ic.ICGetIndPref(i+1))
! self.ic.ICEnd()
! return rv
!
! def has_key(self, key):
! return self.__contains__(key)
!
! def __contains__(self, key):
! try:
! dummy = self.ic.ICFindPrefHandle(key, self.h)
! except icglue.error:
! return 0
! return 1
!
! def __getitem__(self, key):
! attr = self.ic.ICFindPrefHandle(key, self.h)
! return _decode(self.h.data, key)
!
! def __setitem__(self, key, value):
! value = _code(value, key)
! self.ic.ICSetPref(key, ICattr_no_change, value)
!
! def launchurl(self, url, hint=""):
! # Work around a bug in ICLaunchURL: file:/foo does
! # not work but file:///foo does.
! if url[:6] == 'file:/' and url[6] != '/':
! url = 'file:///' + url[6:]
! self.ic.ICLaunchURL(hint, url, 0, len(url))
!
! def parseurl(self, data, start=None, end=None, hint=""):
! if start == None:
! selStart = 0
! selEnd = len(data)
! else:
! selStart = selEnd = start
! if end != None:
! selEnd = end
! selStart, selEnd = self.ic.ICParseURL(hint, data, selStart, selEnd, self.h)
! return self.h.data, selStart, selEnd
!
! def mapfile(self, file):
! if type(file) != type(''):
! file = file.as_tuple()[2]
! return self.ic.ICMapFilename(file)
!
! def maptypecreator(self, type, creator, filename=""):
! return self.ic.ICMapTypeCreator(type, creator, filename)
!
! def settypecreator(self, file):
! file = Carbon.File.pathname(file)
! record = self.mapfile(os.path.split(file)[1])
! MacOS.SetCreatorAndType(file, record[2], record[1])
! macostools.touched(fss)
!
# Convenience routines
_dft_ic = None
def launchurl(url, hint=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.launchurl(url, hint)
!
def parseurl(data, start=None, end=None, hint=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.parseurl(data, start, end, hint)
!
def mapfile(filename):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.mapfile(filename)
!
def maptypecreator(type, creator, filename=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.maptypecreator(type, creator, filename)
!
def settypecreator(file):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.settypecreator(file)
!
def _test():
! ic = IC()
! for k in ic.keys():
! try:
! v = ic[k]
! except error:
! v = '????'
! print k, '\t', v
! sys.exit(1)
!
if __name__ == '__main__':
! _test()
!
--- 31,269 ----
class ICOpaqueData:
! """An unparseable IC entry"""
! def __init__(self, data):
! self.data = data
! def __repr__(self):
! return "ICOpaqueData(%s)"%`self.data`
_ICOpaqueDataType=type(ICOpaqueData(''))
!
def _decode_default(data, key):
! if len(data) == 0:
! return data
! if ord(data[0]) == len(data)-1:
! # Assume Pstring
! return data[1:]
! return ICOpaqueData(data)
!
!
def _decode_multistr(data, key):
! numstr = ord(data[0]) << 8 | ord(data[1])
! rv = []
! ptr = 2
! for i in range(numstr):
! strlen = ord(data[ptr])
! str = data[ptr+1:ptr+strlen+1]
! rv.append(str)
! ptr = ptr + strlen + 1
! return rv
!
def _decode_fontrecord(data, key):
! size = ord(data[0]) << 8 | ord(data[1])
! face = ord(data[2])
! namelen = ord(data[4])
! return size, face, data[5:5+namelen]
!
def _decode_boolean(data, key):
! return ord(data[0])
!
def _decode_text(data, key):
! return data
!
def _decode_charset(data, key):
! return data[:256], data[256:]
!
def _decode_appspec(data, key):
! namelen = ord(data[4])
! return data[0:4], data[5:5+namelen]
def _code_default(data, key):
! return chr(len(data)) + data
!
def _code_multistr(data, key):
! numstr = len(data)
! rv = chr((numstr>>8) & 0xff) + chr(numstr & 0xff)
! for i in data:
! rv = rv + _code_default(i)
! return rv
!
def _code_fontrecord(data, key):
! size, face, name = data
! return chr((size>>8) & 0xff) + chr(size & 0xff) + chr(face & 0xff) + \
! chr(0) + _code_default(name)
!
def _code_boolean(data, key):
! print 'XXXX boolean:', `data`
! return chr(data)
!
def _code_text(data, key):
! return data
!
def _code_charset(data, key):
! return data[0] + data[1]
!
def _code_appspec(data, key):
! return data[0] + _code_default(data[1])
!
_decoder_table = {
! "ArchieAll" : (_decode_multistr , _code_multistr),
! "UMichAll" : (_decode_multistr , _code_multistr),
! "InfoMacAll" : (_decode_multistr , _code_multistr),
! "ListFont" : (_decode_fontrecord , _code_fontrecord),
! "ScreenFont" : (_decode_fontrecord , _code_fontrecord),
! "PrinterFont" : (_decode_fontrecord , _code_fontrecord),
! # "DownloadFolder" : (_decode_filespec , _code_filespec),
! "Signature": (_decode_text , _code_text),
! "Plan" : (_decode_text , _code_text),
! "MailHeaders" : (_decode_text , _code_text),
! "NewsHeaders" : (_decode_text , _code_text),
! # "Mapping"
! "CharacterSet" : (_decode_charset , _code_charset),
! "Helper\245" : (_decode_appspec , _code_appspec),
! # "Services" : (_decode_services, ????),
! "NewMailFlashIcon" : (_decode_boolean , _code_boolean),
! "NewMailDialog" : (_decode_boolean , _code_boolean),
! "NewMailPlaySound" : (_decode_boolean , _code_boolean),
! # "WebBackgroundColor" : _decode_color,
! "NoProxyDomains" : (_decode_multistr , _code_multistr),
! "UseHTTPProxy" : (_decode_boolean , _code_boolean),
! "UseGopherProxy": (_decode_boolean , _code_boolean),
! "UseFTPProxy" : (_decode_boolean , _code_boolean),
! "UsePassiveFTP" : (_decode_boolean , _code_boolean),
}
def _decode(data, key):
! if '\245' in key:
! key2 = key[:string.index(key, '\245')+1]
! else:
! key2 = key
! if _decoder_table.has_key(key2):
! decoder = _decoder_table[key2][0]
! else:
! decoder = _decode_default
! return decoder(data, key)
def _code(data, key):
! if type(data) == _ICOpaqueDataType:
! return data.data
! if '\245' in key:
! key2 = key[:string.index(key, '\245')+1]
! else:
! key2 = key
! if _decoder_table.has_key(key2):
! coder = _decoder_table[key2][1]
! else:
! coder = _code_default
! return coder(data, key)
!
class IC:
! def __init__(self, signature='Pyth', ic=None):
! if ic:
! self.ic = ic
! else:
! self.ic = icglue.ICStart(signature)
! if hasattr(self.ic, 'ICFindConfigFile'):
! self.ic.ICFindConfigFile()
! self.h = Res.Resource('')
!
! def keys(self):
! rv = []
! self.ic.ICBegin(icReadOnlyPerm)
! num = self.ic.ICCountPref()
! for i in range(num):
! rv.append(self.ic.ICGetIndPref(i+1))
! self.ic.ICEnd()
! return rv
!
! def has_key(self, key):
! return self.__contains__(key)
!
! def __contains__(self, key):
! try:
! dummy = self.ic.ICFindPrefHandle(key, self.h)
! except icglue.error:
! return 0
! return 1
!
! def __getitem__(self, key):
! attr = self.ic.ICFindPrefHandle(key, self.h)
! return _decode(self.h.data, key)
!
! def __setitem__(self, key, value):
! value = _code(value, key)
! self.ic.ICSetPref(key, ICattr_no_change, value)
!
! def launchurl(self, url, hint=""):
! # Work around a bug in ICLaunchURL: file:/foo does
! # not work but file:///foo does.
! if url[:6] == 'file:/' and url[6] != '/':
! url = 'file:///' + url[6:]
! self.ic.ICLaunchURL(hint, url, 0, len(url))
!
! def parseurl(self, data, start=None, end=None, hint=""):
! if start == None:
! selStart = 0
! selEnd = len(data)
! else:
! selStart = selEnd = start
! if end != None:
! selEnd = end
! selStart, selEnd = self.ic.ICParseURL(hint, data, selStart, selEnd, self.h)
! return self.h.data, selStart, selEnd
!
! def mapfile(self, file):
! if type(file) != type(''):
! file = file.as_tuple()[2]
! return self.ic.ICMapFilename(file)
!
! def maptypecreator(self, type, creator, filename=""):
! return self.ic.ICMapTypeCreator(type, creator, filename)
!
! def settypecreator(self, file):
! file = Carbon.File.pathname(file)
! record = self.mapfile(os.path.split(file)[1])
! MacOS.SetCreatorAndType(file, record[2], record[1])
! macostools.touched(fss)
!
# Convenience routines
_dft_ic = None
def launchurl(url, hint=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.launchurl(url, hint)
!
def parseurl(data, start=None, end=None, hint=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.parseurl(data, start, end, hint)
!
def mapfile(filename):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.mapfile(filename)
!
def maptypecreator(type, creator, filename=""):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.maptypecreator(type, creator, filename)
!
def settypecreator(file):
! global _dft_ic
! if _dft_ic == None: _dft_ic = IC()
! return _dft_ic.settypecreator(file)
!
def _test():
! ic = IC()
! for k in ic.keys():
! try:
! v = ic[k]
! except error:
! v = '????'
! print k, '\t', v
! sys.exit(1)
!
if __name__ == '__main__':
! _test()
!
Index: macerrors.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/macerrors.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** macerrors.py 30 Dec 2002 22:04:20 -0000 1.1
--- macerrors.py 9 Apr 2003 13:25:43 -0000 1.2
***************
*** 1,1852 ****
! svTempDisable = -32768 #svTempDisable
! svDisabled = -32640 #Reserve range -32640 to -32768 for Apple temp disables.
! fontNotOutlineErr = -32615 #bitmap font passed to routine that does outlines only
! kURL68kNotSupportedError = -30788 #kURL68kNotSupportedError
! kURLAccessNotAvailableError = -30787 #kURLAccessNotAvailableError
! kURLInvalidConfigurationError = -30786 #kURLInvalidConfigurationError
! kURLExtensionFailureError = -30785 #kURLExtensionFailureError
! kURLFileEmptyError = -30783 #kURLFileEmptyError
! kURLInvalidCallError = -30781 #kURLInvalidCallError
! kURLUnsettablePropertyError = -30780 #kURLUnsettablePropertyError
[...3675 lines suppressed...]
! ENETRESET = 52 #Network dropped connection on reset
! ECONNABORTED = 53 #Software caused connection abort
! ECONNRESET = 54 #Connection reset by peer
! ENOBUFS = 55 #No buffer space available
! EISCONN = 56 #Socket is already connected
! ENOTCONN = 57 #Socket is not connected
! ESHUTDOWN = 58 #Can't send after socket shutdown
! ETOOMANYREFS = 59 #Too many references: can't splice
! ETIMEDOUT = 60 #Operation timed out
! ECONNREFUSED = 61 #Connection refused
! ELOOP = 62 #Too many levels of symbolic links
! ENAMETOOLONG = 63 #File name too long
! EHOSTDOWN = 64 #Host is down
! EHOSTUNREACH = 65 #No route to host
! ENOTEMPTY = 66 #Directory not empty
! ELOOK = 67 #Internal mapping for kOTLookErr, don't return to client
! ENOLCK = 77 #No locks available
! ENOSYS = 78 #Function not implemented
! EILSEQ = 88 #Wide character encoding error
! EUNKNOWN = 99 #Unknown error
Index: macfs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/macfs.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** macfs.py 27 Feb 2003 23:17:59 -0000 1.9
--- macfs.py 9 Apr 2003 13:25:43 -0000 1.10
***************
*** 29,51 ****
import time
if time.gmtime(0)[0] == 1970:
! _EPOCHCONVERT = -((1970-1904)*365 + 17) * (24*60*60) + 0x100000000L
! def _utc2time(utc):
! t = utc[1] + _EPOCHCONVERT
! return int(t)
! def _time2utc(t):
! t = int(t) - _EPOCHCONVERT
! if t < -0x7fffffff:
! t = t + 0x10000000L
! return (0, int(t), 0)
else:
! def _utc2time(utc):
! t = utc[1]
! if t < 0:
! t = t + 0x100000000L
! return t
! def _time2utc(t):
! if t > 0x7fffffff:
! t = t - 0x100000000L
! return (0, int(t), 0)
# The old name of the error object:
--- 29,51 ----
import time
if time.gmtime(0)[0] == 1970:
! _EPOCHCONVERT = -((1970-1904)*365 + 17) * (24*60*60) + 0x100000000L
! def _utc2time(utc):
! t = utc[1] + _EPOCHCONVERT
! return int(t)
! def _time2utc(t):
! t = int(t) - _EPOCHCONVERT
! if t < -0x7fffffff:
! t = t + 0x10000000L
! return (0, int(t), 0)
else:
! def _utc2time(utc):
! t = utc[1]
! if t < 0:
! t = t + 0x100000000L
! return t
! def _time2utc(t):
! if t > 0x7fffffff:
! t = t - 0x100000000L
! return (0, int(t), 0)
# The old name of the error object:
***************
*** 57,114 ****
#
class FSSpec(Carbon.File.FSSpec):
! def as_fsref(self):
! return FSRef(self)
!
! def NewAlias(self, src=None):
! return Alias(Carbon.File.NewAlias(src, self))
!
! def GetCreatorType(self):
! finfo = self.FSpGetFInfo()
! return finfo.Creator, finfo.Type
!
! def SetCreatorType(self, ctor, tp):
! finfo = self.FSpGetFInfo()
! finfo.Creator = ctor
! finfo.Type = tp
! self.FSpSetFInfo(finfo)
!
! def GetFInfo(self):
! return self.FSpGetFInfo()
!
! def SetFInfo(self, info):
! return self.FSpSetFInfo(info)
!
! def GetDates(self):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo, d1, d2, d3 = FSRef(self).FSGetCatalogInfo(catInfoFlags)
! cdate = catinfo.createDate
! mdate = catinfo.contentModDate
! bdate = catinfo.backupDate
! return _utc2time(cdate), _utc2time(mdate), _utc2time(bdate)
!
! def SetDates(self, cdate, mdate, bdate):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo = Carbon.File.FSCatalogInfo(
! createDate = _time2utc(cdate),
! contentModDate = _time2utc(mdate),
! backupDate = _time2utc(bdate))
! FSRef(self).FSSetCatalogInfo(catInfoFlags, catinfo)
!
class FSRef(Carbon.File.FSRef):
! def as_fsspec(self):
! return FSSpec(self)
!
class Alias(Carbon.File.Alias):
! def GetInfo(self, index):
! return self.GetAliasInfo(index)
!
! def Update(self, *args):
! pass # print "Alias.Update not yet implemented"
!
! def Resolve(self, src=None):
! fss, changed = self.ResolveAlias(src)
! return FSSpec(fss), changed
!
from Carbon.File import FInfo
--- 57,114 ----
#
class FSSpec(Carbon.File.FSSpec):
! def as_fsref(self):
! return FSRef(self)
!
! def NewAlias(self, src=None):
! return Alias(Carbon.File.NewAlias(src, self))
!
! def GetCreatorType(self):
! finfo = self.FSpGetFInfo()
! return finfo.Creator, finfo.Type
!
! def SetCreatorType(self, ctor, tp):
! finfo = self.FSpGetFInfo()
! finfo.Creator = ctor
! finfo.Type = tp
! self.FSpSetFInfo(finfo)
!
! def GetFInfo(self):
! return self.FSpGetFInfo()
!
! def SetFInfo(self, info):
! return self.FSpSetFInfo(info)
!
! def GetDates(self):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo, d1, d2, d3 = FSRef(self).FSGetCatalogInfo(catInfoFlags)
! cdate = catinfo.createDate
! mdate = catinfo.contentModDate
! bdate = catinfo.backupDate
! return _utc2time(cdate), _utc2time(mdate), _utc2time(bdate)
!
! def SetDates(self, cdate, mdate, bdate):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo = Carbon.File.FSCatalogInfo(
! createDate = _time2utc(cdate),
! contentModDate = _time2utc(mdate),
! backupDate = _time2utc(bdate))
! FSRef(self).FSSetCatalogInfo(catInfoFlags, catinfo)
!
class FSRef(Carbon.File.FSRef):
! def as_fsspec(self):
! return FSSpec(self)
!
class Alias(Carbon.File.Alias):
! def GetInfo(self, index):
! return self.GetAliasInfo(index)
!
! def Update(self, *args):
! pass # print "Alias.Update not yet implemented"
!
! def Resolve(self, src=None):
! fss, changed = self.ResolveAlias(src)
! return FSSpec(fss), changed
!
from Carbon.File import FInfo
***************
*** 121,139 ****
# Global functions:
def ResolveAliasFile(fss, chain=1):
! fss, isdir, isalias = Carbon.File.ResolveAliasFile(fss, chain)
! return FSSpec(fss), isdir, isalias
!
def RawFSSpec(data):
! return FSSpec(rawdata=data)
!
def RawAlias(data):
! return Alias(rawdata=data)
!
def FindApplication(*args):
! raise NotImplementedError, "FindApplication no longer implemented"
!
def NewAliasMinimalFromFullPath(path):
! return Alias(Carbon.File.NewAliasMinimalFromFullPath(path, '', ''))
!
# Another global function:
from Carbon.Folder import FindFolder
--- 121,139 ----
# Global functions:
def ResolveAliasFile(fss, chain=1):
! fss, isdir, isalias = Carbon.File.ResolveAliasFile(fss, chain)
! return FSSpec(fss), isdir, isalias
!
def RawFSSpec(data):
! return FSSpec(rawdata=data)
!
def RawAlias(data):
! return Alias(rawdata=data)
!
def FindApplication(*args):
! raise NotImplementedError, "FindApplication no longer implemented"
!
def NewAliasMinimalFromFullPath(path):
! return Alias(Carbon.File.NewAliasMinimalFromFullPath(path, '', ''))
!
# Another global function:
from Carbon.Folder import FindFolder
***************
*** 146,198 ****
def StandardGetFile(*typelist):
! """Ask for an input file, optionally specifying 4-char file types that are
! allowable"""
! return PromptGetFile('', *typelist)
!
def PromptGetFile(prompt, *typelist):
! """Ask for an input file giving the user a prompt message. Optionally you can
! specifying 4-char file types that are allowable"""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! if not typelist:
! typelist = None
! fss = EasyDialogs.AskFileForOpen(message=prompt, wanted=FSSpec,
! typeList=typelist, defaultLocation=_handleSetFolder())
! return fss, not fss is None
def StandardPutFile(prompt, default=None):
! """Ask the user for an output file, with a prompt. Optionally you cn supply a
! default output filename"""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! fss = EasyDialogs.AskFileForSave(wanted=FSSpec, message=prompt,
! savedFileName=default, defaultLocation=_handleSetFolder())
! return fss, not fss is None
!
def SetFolder(folder):
! global _curfolder
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! if _curfolder:
! rv = FSSpec(_curfolder)
! else:
! rv = None
! _curfolder = folder
! return rv
!
def _handleSetFolder():
! global _curfolder
! rv = _curfolder
! _curfolder = None
! return rv
!
def GetDirectory(prompt=None):
! """Ask the user to select a folder. Optionally you can give a prompt."""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! fss = EasyDialogs.AskFolder(message=prompt, wanted=FSSpec,
! defaultLocation=_handleSetFolder())
! return fss, not fss is None
--- 146,198 ----
def StandardGetFile(*typelist):
! """Ask for an input file, optionally specifying 4-char file types that are
! allowable"""
! return PromptGetFile('', *typelist)
!
def PromptGetFile(prompt, *typelist):
! """Ask for an input file giving the user a prompt message. Optionally you can
! specifying 4-char file types that are allowable"""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! if not typelist:
! typelist = None
! fss = EasyDialogs.AskFileForOpen(message=prompt, wanted=FSSpec,
! typeList=typelist, defaultLocation=_handleSetFolder())
! return fss, not fss is None
def StandardPutFile(prompt, default=None):
! """Ask the user for an output file, with a prompt. Optionally you cn supply a
! default output filename"""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! fss = EasyDialogs.AskFileForSave(wanted=FSSpec, message=prompt,
! savedFileName=default, defaultLocation=_handleSetFolder())
! return fss, not fss is None
!
def SetFolder(folder):
! global _curfolder
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! if _curfolder:
! rv = FSSpec(_curfolder)
! else:
! rv = None
! _curfolder = folder
! return rv
!
def _handleSetFolder():
! global _curfolder
! rv = _curfolder
! _curfolder = None
! return rv
!
def GetDirectory(prompt=None):
! """Ask the user to select a folder. Optionally you can give a prompt."""
! import EasyDialogs
! warnings.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
DeprecationWarning, stacklevel=2)
! fss = EasyDialogs.AskFolder(message=prompt, wanted=FSSpec,
! defaultLocation=_handleSetFolder())
! return fss, not fss is None
Index: macresource.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/macresource.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** macresource.py 25 Feb 2003 23:02:03 -0000 1.4
--- macresource.py 9 Apr 2003 13:25:43 -0000 1.5
***************
*** 11,146 ****
def need(restype, resid, filename=None, modname=None):
! """Open a resource file, if needed. restype and resid
! are required parameters, and identify the resource for which to test. If it
! is available we are done. If it is not available we look for a file filename
! (default: modname with .rsrc appended) either in the same folder as
! where modname was loaded from, or otherwise across sys.path.
!
! Returns the refno of the resource file opened (or None)"""
! if modname is None and filename is None:
! raise ArgumentError, "Either filename or modname argument (or both) must be given"
!
! if type(resid) is type(1):
! try:
! h = Res.GetResource(restype, resid)
! except Res.Error:
! pass
! else:
! return None
! else:
! try:
! h = Res.GetNamedResource(restype, resid)
! except Res.Error:
! pass
! else:
! return None
!
! # Construct a filename if we don't have one
! if not filename:
! if '.' in modname:
! filename = modname.split('.')[-1] + '.rsrc'
! else:
! filename = modname + '.rsrc'
!
! # Now create a list of folders to search
! searchdirs = []
! if modname == '__main__':
! # If we're main we look in the current directory
! searchdirs = [os.curdir]
! if sys.modules.has_key(modname):
! mod = sys.modules[modname]
! if hasattr(mod, '__file__'):
! searchdirs = [os.path.dirname(mod.__file__)]
! searchdirs.extend(sys.path)
!
! # And look for the file
! for dir in searchdirs:
! pathname = os.path.join(dir, filename)
! if os.path.exists(pathname):
! break
! else:
! raise ResourceFileNotFoundError, filename
!
! refno = open_pathname(pathname)
!
! # 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
!
def open_pathname(pathname, verbose=0):
! """Open a resource file given by pathname, possibly decoding an
! AppleSingle file"""
! try:
! refno = Res.FSpOpenResFile(pathname, 1)
! except Res.Error, arg:
! if arg[0] in (-37, -39):
! # No resource fork. We may be on OSX, and this may be either
! # a data-fork based resource file or a AppleSingle file
! # from the CVS repository.
! try:
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! except Res.Error, arg:
! if arg[0] != -199:
! # -199 is "bad resource map"
! raise
! else:
! return refno
! # Finally try decoding an AppleSingle file
! pathname = _decode(pathname, verbose=verbose)
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! else:
! raise
! return refno
!
def resource_pathname(pathname, verbose=0):
! """Return the pathname for a resource file (either DF or RF based).
! If the pathname given already refers to such a file simply return it,
! otherwise first decode it."""
! try:
! refno = Res.FSpOpenResFile(pathname, 1)
! Res.CloseResFile(refno)
! except Res.Error, arg:
! if arg[0] in (-37, -39):
! # No resource fork. We may be on OSX, and this may be either
! # a data-fork based resource file or a AppleSingle file
! # from the CVS repository.
! try:
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! except Res.Error, arg:
! if arg[0] != -199:
! # -199 is "bad resource map"
! raise
! else:
! return refno
! # Finally try decoding an AppleSingle file
! pathname = _decode(pathname, verbose=verbose)
! else:
! raise
! return pathname
!
def open_error_resource():
! """Open the resource file containing the error code to error message
! mapping."""
! need('Estr', 1, filename="errors.rsrc", modname=__name__)
!
def _decode(pathname, verbose=0):
! # Decode an AppleSingle resource file, return the new pathname.
! newpathname = pathname + '.df.rsrc'
! if os.path.exists(newpathname) and \
! os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime:
! return newpathname
! if hasattr(os, 'access') and not \
! os.access(os.path.dirname(pathname), os.W_OK|os.X_OK):
! # The destination directory isn't writeable. Create the file in
! # a temporary directory
! import tempfile
! fd, newpathname = tempfile.mkstemp(".rsrc")
! if verbose:
! print 'Decoding', pathname, 'to', newpathname
! import applesingle
! applesingle.decode(pathname, newpathname, resonly=1)
! return newpathname
--- 11,146 ----
def need(restype, resid, filename=None, modname=None):
! """Open a resource file, if needed. restype and resid
! are required parameters, and identify the resource for which to test. If it
! is available we are done. If it is not available we look for a file filename
! (default: modname with .rsrc appended) either in the same folder as
! where modname was loaded from, or otherwise across sys.path.
!
! Returns the refno of the resource file opened (or None)"""
! if modname is None and filename is None:
! raise ArgumentError, "Either filename or modname argument (or both) must be given"
!
! if type(resid) is type(1):
! try:
! h = Res.GetResource(restype, resid)
! except Res.Error:
! pass
! else:
! return None
! else:
! try:
! h = Res.GetNamedResource(restype, resid)
! except Res.Error:
! pass
! else:
! return None
!
! # Construct a filename if we don't have one
! if not filename:
! if '.' in modname:
! filename = modname.split('.')[-1] + '.rsrc'
! else:
! filename = modname + '.rsrc'
!
! # Now create a list of folders to search
! searchdirs = []
! if modname == '__main__':
! # If we're main we look in the current directory
! searchdirs = [os.curdir]
! if sys.modules.has_key(modname):
! mod = sys.modules[modname]
! if hasattr(mod, '__file__'):
! searchdirs = [os.path.dirname(mod.__file__)]
! searchdirs.extend(sys.path)
!
! # And look for the file
! for dir in searchdirs:
! pathname = os.path.join(dir, filename)
! if os.path.exists(pathname):
! break
! else:
! raise ResourceFileNotFoundError, filename
!
! refno = open_pathname(pathname)
!
! # 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
!
def open_pathname(pathname, verbose=0):
! """Open a resource file given by pathname, possibly decoding an
! AppleSingle file"""
! try:
! refno = Res.FSpOpenResFile(pathname, 1)
! except Res.Error, arg:
! if arg[0] in (-37, -39):
! # No resource fork. We may be on OSX, and this may be either
! # a data-fork based resource file or a AppleSingle file
! # from the CVS repository.
! try:
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! except Res.Error, arg:
! if arg[0] != -199:
! # -199 is "bad resource map"
! raise
! else:
! return refno
! # Finally try decoding an AppleSingle file
! pathname = _decode(pathname, verbose=verbose)
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! else:
! raise
! return refno
!
def resource_pathname(pathname, verbose=0):
! """Return the pathname for a resource file (either DF or RF based).
! If the pathname given already refers to such a file simply return it,
! otherwise first decode it."""
! try:
! refno = Res.FSpOpenResFile(pathname, 1)
! Res.CloseResFile(refno)
! except Res.Error, arg:
! if arg[0] in (-37, -39):
! # No resource fork. We may be on OSX, and this may be either
! # a data-fork based resource file or a AppleSingle file
! # from the CVS repository.
! try:
! refno = Res.FSOpenResourceFile(pathname, u'', 1)
! except Res.Error, arg:
! if arg[0] != -199:
! # -199 is "bad resource map"
! raise
! else:
! return refno
! # Finally try decoding an AppleSingle file
! pathname = _decode(pathname, verbose=verbose)
! else:
! raise
! return pathname
!
def open_error_resource():
! """Open the resource file containing the error code to error message
! mapping."""
! need('Estr', 1, filename="errors.rsrc", modname=__name__)
!
def _decode(pathname, verbose=0):
! # Decode an AppleSingle resource file, return the new pathname.
! newpathname = pathname + '.df.rsrc'
! if os.path.exists(newpathname) and \
! os.stat(newpathname).st_mtime >= os.stat(pathname).st_mtime:
! return newpathname
! if hasattr(os, 'access') and not \
! os.access(os.path.dirname(pathname), os.W_OK|os.X_OK):
! # The destination directory isn't writeable. Create the file in
! # a temporary directory
! import tempfile
! fd, newpathname = tempfile.mkstemp(".rsrc")
! if verbose:
! print 'Decoding', pathname, 'to', newpathname
! import applesingle
! applesingle.decode(pathname, newpathname, resonly=1)
! return newpathname
Index: pimp.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/pimp.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** pimp.py 17 Mar 2003 10:54:41 -0000 1.14
--- pimp.py 9 Apr 2003 13:25:43 -0000 1.15
***************
*** 44,798 ****
ARCHIVE_FORMATS = [
! (".tar.Z", "zcat \"%s\" | tar -xf -"),
! (".taz", "zcat \"%s\" | tar -xf -"),
! (".tar.gz", "zcat \"%s\" | tar -xf -"),
! (".tgz", "zcat \"%s\" | tar -xf -"),
! (".tar.bz", "bzcat \"%s\" | tar -xf -"),
! (".zip", "unzip \"%s\""),
]
[...1481 lines suppressed...]
! _help()
! mode = 'list'
! if o == '-d':
! if mode:
! _help()
! mode = 'dump'
! if o == '-i':
! mode = 'install'
! if o == '-f':
! force = 1
! if o == '-v':
! verbose = 1
! if not mode:
! _help()
! _run(mode, verbose, force, args)
!
if __name__ == '__main__':
! main()
!
!
Index: plistlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/plistlib.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** plistlib.py 30 Dec 2002 22:04:20 -0000 1.1
--- plistlib.py 9 Apr 2003 13:25:43 -0000 1.2
***************
*** 34,60 ****
Generate Plist example:
! pl = Plist(
! aString="Doodah",
! aList=["A", "B", 12, 32.1, [1, 2, 3]],
! aFloat = 0.1,
! anInt = 728,
! aDict=Dict(
! anotherString="<hello & hi there!>",
! aUnicodeValue=u'M\xe4ssig, Ma\xdf',
! aTrueValue=True,
! aFalseValue=False,
! ),
! someData = Data("<binary gunk>"),
! someMoreData = Data("<lots of binary gunk>" * 10),
! aDate = Date(time.mktime(time.gmtime())),
! )
! # unicode keys are possible, but a little awkward to use:
! pl[u'\xc5benraa'] = "That was a unicode key."
! pl.write(fileName)
Parse Plist example:
! pl = Plist.fromFile(pathOrFile)
! print pl.aKey
--- 34,60 ----
Generate Plist example:
! pl = Plist(
! aString="Doodah",
! aList=["A", "B", 12, 32.1, [1, 2, 3]],
! aFloat = 0.1,
! anInt = 728,
! aDict=Dict(
! anotherString="<hello & hi there!>",
! aUnicodeValue=u'M\xe4ssig, Ma\xdf',
! aTrueValue=True,
! aFalseValue=False,
! ),
! someData = Data("<binary gunk>"),
! someMoreData = Data("<lots of binary gunk>" * 10),
! aDate = Date(time.mktime(time.gmtime())),
! )
! # unicode keys are possible, but a little awkward to use:
! pl[u'\xc5benraa'] = "That was a unicode key."
! pl.write(fileName)
Parse Plist example:
! pl = Plist.fromFile(pathOrFile)
! print pl.aKey
***************
*** 72,109 ****
class DumbXMLWriter:
! def __init__(self, file):
! self.file = file
! self.stack = []
! self.indentLevel = 0
! def beginElement(self, element):
! self.stack.append(element)
! self.writeln("<%s>" % element)
! self.indentLevel += 1
! def endElement(self, element):
! assert self.indentLevel > 0
! assert self.stack.pop() == element
! self.indentLevel -= 1
! self.writeln("</%s>" % element)
! def simpleElement(self, element, value=None):
! if value:
! value = _encode(value)
! self.writeln("<%s>%s</%s>" % (element, value, element))
! else:
! self.writeln("<%s/>" % element)
! def writeln(self, line):
! if line:
! self.file.write(self.indentLevel * INDENT + line + "\n")
! else:
! self.file.write("\n")
def _encode(text):
! text = text.replace("&", "&")
! text = text.replace("<", "<")
! return text.encode("utf-8")
--- 72,109 ----
class DumbXMLWriter:
! def __init__(self, file):
! self.file = file
! self.stack = []
! self.indentLevel = 0
! def beginElement(self, element):
! self.stack.append(element)
! self.writeln("<%s>" % element)
! self.indentLevel += 1
! def endElement(self, element):
! assert self.indentLevel > 0
! assert self.stack.pop() == element
! self.indentLevel -= 1
! self.writeln("</%s>" % element)
! def simpleElement(self, element, value=None):
! if value:
! value = _encode(value)
! self.writeln("<%s>%s</%s>" % (element, value, element))
! else:
! self.writeln("<%s/>" % element)
! def writeln(self, line):
! if line:
! self.file.write(self.indentLevel * INDENT + line + "\n")
! else:
! self.file.write("\n")
def _encode(text):
! text = text.replace("&", "&")
! text = text.replace("<", "<")
! return text.encode("utf-8")
***************
*** 115,375 ****
class PlistWriter(DumbXMLWriter):
! def __init__(self, file):
! file.write(PLISTHEADER)
! DumbXMLWriter.__init__(self, file)
! def writeValue(self, value):
! if isinstance(value, (str, unicode)):
! self.simpleElement("string", value)
! elif isinstance(value, bool):
! # must switch for bool before int, as bool is a
! # subclass of int...
! if value:
! self.simpleElement("true")
! else:
! self.simpleElement("false")
! elif isinstance(value, int):
! self.simpleElement("integer", str(value))
! elif isinstance(value, float):
! # should perhaps use repr() for better precision?
! self.simpleElement("real", str(value))
! elif isinstance(value, (dict, Dict)):
! self.writeDict(value)
! elif isinstance(value, Data):
! self.writeData(value)
! elif isinstance(value, Date):
! self.simpleElement("date", value.toString())
! elif isinstance(value, (tuple, list)):
! self.writeArray(value)
! else:
! assert 0, "unsuported type: %s" % type(value)
! def writeData(self, data):
! self.beginElement("data")
! for line in data.asBase64().split("\n"):
! if line:
! self.writeln(line)
! self.endElement("data")
! def writeDict(self, d):
! self.beginElement("dict")
! items = d.items()
! items.sort()
! for key, value in items:
! assert isinstance(key, (str, unicode)), "keys must be strings"
! self.simpleElement("key", key)
! self.writeValue(value)
! self.endElement("dict")
! def writeArray(self, array):
! self.beginElement("array")
! for value in array:
! self.writeValue(value)
! self.endElement("array")
class Dict:
! """Dict wrapper for convenient access of values through attributes."""
! def __init__(self, **kwargs):
! self.__dict__.update(kwargs)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.__dict__, other.__dict__)
! elif isinstance(other, dict):
! return cmp(self.__dict__, other)
! else:
! return cmp(id(self), id(other))
! def __str__(self):
! return "%s(**%s)" % (self.__class__.__name__, self.__dict__)
! __repr__ = __str__
! def copy(self):
! return self.__class__(**self.__dict__)
! def __getattr__(self, attr):
! """Delegate everything else to the dict object."""
! return getattr(self.__dict__, attr)
class Plist(Dict):
! """The main Plist object. Basically a dict (the toplevel object
! of a plist is a dict) with two additional methods to read from
! and write to files.
! """
! def fromFile(cls, pathOrFile):
! didOpen = 0
! if not hasattr(pathOrFile, "write"):
! pathOrFile = open(pathOrFile)
! didOpen = 1
! p = PlistParser()
! plist = p.parse(pathOrFile)
! if didOpen:
! pathOrFile.close()
! return plist
! fromFile = classmethod(fromFile)
! def write(self, pathOrFile):
! if not hasattr(pathOrFile, "write"):
! pathOrFile = open(pathOrFile, "w")
! didOpen = 1
! else:
! didOpen = 0
! writer = PlistWriter(pathOrFile)
! writer.writeln("<plist version=\"1.0\">")
! writer.writeDict(self.__dict__)
! writer.writeln("</plist>")
! if didOpen:
! pathOrFile.close()
class Data:
! """Wrapper for binary data."""
! def __init__(self, data):
! self.data = data
! def fromBase64(cls, data):
! import base64
! return cls(base64.decodestring(data))
! fromBase64 = classmethod(fromBase64)
! def asBase64(self):
! import base64
! return base64.encodestring(self.data)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.data, other.data)
! elif isinstance(other, str):
! return cmp(self.data, other)
! else:
! return cmp(id(self), id(other))
! def __repr__(self):
! return "%s(%s)" % (self.__class__.__name__, repr(self.data))
class Date:
! """Primitive date wrapper, uses time floats internally, is agnostic
! about time zones.
! """
! def __init__(self, date):
! if isinstance(date, str):
! from xml.utils.iso8601 import parse
! date = parse(date)
! self.date = date
! def toString(self):
! from xml.utils.iso8601 import tostring
! return tostring(self.date)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.date, other.date)
! elif isinstance(other, (int, float)):
! return cmp(self.date, other)
! else:
! return cmp(id(self), id(other))
! def __repr__(self):
! return "%s(%s)" % (self.__class__.__name__, repr(self.toString()))
class PlistParser:
! def __init__(self):
! self.stack = []
! self.currentKey = None
! self.root = None
! def parse(self, file):
! from xml.parsers.expat import ParserCreate
! parser = ParserCreate()
! parser.StartElementHandler = self.handleBeginElement
! parser.EndElementHandler = self.handleEndElement
! parser.CharacterDataHandler = self.handleData
! parser.ParseFile(file)
! return self.root
! def handleBeginElement(self, element, attrs):
! self.data = []
! handler = getattr(self, "begin_" + element, None)
! if handler is not None:
! handler(attrs)
! def handleEndElement(self, element):
! handler = getattr(self, "end_" + element, None)
! if handler is not None:
! handler()
! def handleData(self, data):
! self.data.append(data)
! def addObject(self, value):
! if self.currentKey is not None:
! self.stack[-1][self.currentKey] = value
! self.currentKey = None
! elif not self.stack:
! # this is the root object
! assert self.root is value
! else:
! self.stack[-1].append(value)
! def getData(self):
! data = "".join(self.data)
! try:
! data = data.encode("ascii")
! except UnicodeError:
! pass
! self.data = []
! return data
! # element handlers
! def begin_dict(self, attrs):
! if self.root is None:
! self.root = d = Plist()
! else:
! d = Dict()
! self.addObject(d)
! self.stack.append(d)
! def end_dict(self):
! self.stack.pop()
! def end_key(self):
! self.currentKey = self.getData()
! def begin_array(self, attrs):
! a = []
! self.addObject(a)
! self.stack.append(a)
! def end_array(self):
! self.stack.pop()
! def end_true(self):
! self.addObject(True)
! def end_false(self):
! self.addObject(False)
! def end_integer(self):
! self.addObject(int(self.getData()))
! def end_real(self):
! self.addObject(float(self.getData()))
! def end_string(self):
! self.addObject(self.getData())
! def end_data(self):
! self.addObject(Data.fromBase64(self.getData()))
! def end_date(self):
! self.addObject(Date(self.getData()))
--- 115,375 ----
class PlistWriter(DumbXMLWriter):
! def __init__(self, file):
! file.write(PLISTHEADER)
! DumbXMLWriter.__init__(self, file)
! def writeValue(self, value):
! if isinstance(value, (str, unicode)):
! self.simpleElement("string", value)
! elif isinstance(value, bool):
! # must switch for bool before int, as bool is a
! # subclass of int...
! if value:
! self.simpleElement("true")
! else:
! self.simpleElement("false")
! elif isinstance(value, int):
! self.simpleElement("integer", str(value))
! elif isinstance(value, float):
! # should perhaps use repr() for better precision?
! self.simpleElement("real", str(value))
! elif isinstance(value, (dict, Dict)):
! self.writeDict(value)
! elif isinstance(value, Data):
! self.writeData(value)
! elif isinstance(value, Date):
! self.simpleElement("date", value.toString())
! elif isinstance(value, (tuple, list)):
! self.writeArray(value)
! else:
! assert 0, "unsuported type: %s" % type(value)
! def writeData(self, data):
! self.beginElement("data")
! for line in data.asBase64().split("\n"):
! if line:
! self.writeln(line)
! self.endElement("data")
! def writeDict(self, d):
! self.beginElement("dict")
! items = d.items()
! items.sort()
! for key, value in items:
! assert isinstance(key, (str, unicode)), "keys must be strings"
! self.simpleElement("key", key)
! self.writeValue(value)
! self.endElement("dict")
! def writeArray(self, array):
! self.beginElement("array")
! for value in array:
! self.writeValue(value)
! self.endElement("array")
class Dict:
! """Dict wrapper for convenient access of values through attributes."""
! def __init__(self, **kwargs):
! self.__dict__.update(kwargs)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.__dict__, other.__dict__)
! elif isinstance(other, dict):
! return cmp(self.__dict__, other)
! else:
! return cmp(id(self), id(other))
! def __str__(self):
! return "%s(**%s)" % (self.__class__.__name__, self.__dict__)
! __repr__ = __str__
! def copy(self):
! return self.__class__(**self.__dict__)
! def __getattr__(self, attr):
! """Delegate everything else to the dict object."""
! return getattr(self.__dict__, attr)
class Plist(Dict):
! """The main Plist object. Basically a dict (the toplevel object
! of a plist is a dict) with two additional methods to read from
! and write to files.
! """
! def fromFile(cls, pathOrFile):
! didOpen = 0
! if not hasattr(pathOrFile, "write"):
! pathOrFile = open(pathOrFile)
! didOpen = 1
! p = PlistParser()
! plist = p.parse(pathOrFile)
! if didOpen:
! pathOrFile.close()
! return plist
! fromFile = classmethod(fromFile)
! def write(self, pathOrFile):
! if not hasattr(pathOrFile, "write"):
! pathOrFile = open(pathOrFile, "w")
! didOpen = 1
! else:
! didOpen = 0
! writer = PlistWriter(pathOrFile)
! writer.writeln("<plist version=\"1.0\">")
! writer.writeDict(self.__dict__)
! writer.writeln("</plist>")
! if didOpen:
! pathOrFile.close()
class Data:
! """Wrapper for binary data."""
! def __init__(self, data):
! self.data = data
! def fromBase64(cls, data):
! import base64
! return cls(base64.decodestring(data))
! fromBase64 = classmethod(fromBase64)
! def asBase64(self):
! import base64
! return base64.encodestring(self.data)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.data, other.data)
! elif isinstance(other, str):
! return cmp(self.data, other)
! else:
! return cmp(id(self), id(other))
! def __repr__(self):
! return "%s(%s)" % (self.__class__.__name__, repr(self.data))
class Date:
! """Primitive date wrapper, uses time floats internally, is agnostic
! about time zones.
! """
! def __init__(self, date):
! if isinstance(date, str):
! from xml.utils.iso8601 import parse
! date = parse(date)
! self.date = date
! def toString(self):
! from xml.utils.iso8601 import tostring
! return tostring(self.date)
! def __cmp__(self, other):
! if isinstance(other, self.__class__):
! return cmp(self.date, other.date)
! elif isinstance(other, (int, float)):
! return cmp(self.date, other)
! else:
! return cmp(id(self), id(other))
! def __repr__(self):
! return "%s(%s)" % (self.__class__.__name__, repr(self.toString()))
class PlistParser:
! def __init__(self):
! self.stack = []
! self.currentKey = None
! self.root = None
! def parse(self, file):
! from xml.parsers.expat import ParserCreate
! parser = ParserCreate()
! parser.StartElementHandler = self.handleBeginElement
! parser.EndElementHandler = self.handleEndElement
! parser.CharacterDataHandler = self.handleData
! parser.ParseFile(file)
! return self.root
! def handleBeginElement(self, element, attrs):
! self.data = []
! handler = getattr(self, "begin_" + element, None)
! if handler is not None:
! handler(attrs)
! def handleEndElement(self, element):
! handler = getattr(self, "end_" + element, None)
! if handler is not None:
! handler()
! def handleData(self, data):
! self.data.append(data)
! def addObject(self, value):
! if self.currentKey is not None:
! self.stack[-1][self.currentKey] = value
! self.currentKey = None
! elif not self.stack:
! # this is the root object
! assert self.root is value
! else:
! self.stack[-1].append(value)
! def getData(self):
! data = "".join(self.data)
! try:
! data = data.encode("ascii")
! except UnicodeError:
! pass
! self.data = []
! return data
! # element handlers
! def begin_dict(self, attrs):
! if self.root is None:
! self.root = d = Plist()
! else:
! d = Dict()
! self.addObject(d)
! self.stack.append(d)
! def end_dict(self):
! self.stack.pop()
! def end_key(self):
! self.currentKey = self.getData()
! def begin_array(self, attrs):
! a = []
! self.addObject(a)
! self.stack.append(a)
! def end_array(self):
! self.stack.pop()
! def end_true(self):
! self.addObject(True)
! def end_false(self):
! self.addObject(False)
! def end_integer(self):
! self.addObject(int(self.getData()))
! def end_real(self):
! self.addObject(float(self.getData()))
! def end_string(self):
! self.addObject(self.getData())
! def end_data(self):
! self.addObject(Data.fromBase64(self.getData()))
! def end_date(self):
! self.addObject(Date(self.getData()))
***************
*** 377,436 ****
import sys
if sys.version_info[:2] < (2, 3):
! # Python 2.2 and earlier: no booleans
! # Python 2.2.x: booleans are ints
! class bool(int):
! """Imitation of the Python 2.3 bool object."""
! def __new__(cls, value):
! return int.__new__(cls, not not value)
! def __repr__(self):
! if self:
! return "True"
! else:
! return "False"
! True = bool(1)
! False = bool(0)
else:
! # Bind the boolean builtins to local names
! True = True
! False = False
! bool = bool
if __name__ == "__main__":
! from StringIO import StringIO
! import time
! if len(sys.argv) == 1:
! pl = Plist(
! aString="Doodah",
! aList=["A", "B", 12, 32.1, [1, 2, 3]],
! aFloat = 0.1,
! anInt = 728,
! aDict=Dict(
! anotherString="<hello & hi there!>",
! aUnicodeValue=u'M\xe4ssig, Ma\xdf',
! aTrueValue=True,
! aFalseValue=False,
! ),
! someData = Data("<binary gunk>"),
! someMoreData = Data("<lots of binary gunk>" * 10),
! aDate = Date(time.mktime(time.gmtime())),
! )
! elif len(sys.argv) == 2:
! pl = Plist.fromFile(sys.argv[1])
! else:
! print "Too many arguments: at most 1 plist file can be given."
! sys.exit(1)
! # unicode keys are possible, but a little awkward to use:
! pl[u'\xc5benraa'] = "That was a unicode key."
! f = StringIO()
! pl.write(f)
! xml = f.getvalue()
! print xml
! f.seek(0)
! pl2 = Plist.fromFile(f)
! assert pl == pl2
! f = StringIO()
! pl2.write(f)
! assert xml == f.getvalue()
! #print repr(pl2)
--- 377,436 ----
import sys
if sys.version_info[:2] < (2, 3):
! # Python 2.2 and earlier: no booleans
! # Python 2.2.x: booleans are ints
! class bool(int):
! """Imitation of the Python 2.3 bool object."""
! def __new__(cls, value):
! return int.__new__(cls, not not value)
! def __repr__(self):
! if self:
! return "True"
! else:
! return "False"
! True = bool(1)
! False = bool(0)
else:
! # Bind the boolean builtins to local names
! True = True
! False = False
! bool = bool
if __name__ == "__main__":
! from StringIO import StringIO
! import time
! if len(sys.argv) == 1:
! pl = Plist(
! aString="Doodah",
! aList=["A", "B", 12, 32.1, [1, 2, 3]],
! aFloat = 0.1,
! anInt = 728,
! aDict=Dict(
! anotherString="<hello & hi there!>",
! aUnicodeValue=u'M\xe4ssig, Ma\xdf',
! aTrueValue=True,
! aFalseValue=False,
! ),
! someData = Data("<binary gunk>"),
! someMoreData = Data("<lots of binary gunk>" * 10),
! aDate = Date(time.mktime(time.gmtime())),
! )
! elif len(sys.argv) == 2:
! pl = Plist.fromFile(sys.argv[1])
! else:
! print "Too many arguments: at most 1 plist file can be given."
! sys.exit(1)
! # unicode keys are possible, but a little awkward to use:
! pl[u'\xc5benraa'] = "That was a unicode key."
! f = StringIO()
! pl.write(f)
! xml = f.getvalue()
! print xml
! f.seek(0)
! pl2 = Plist.fromFile(f)
! assert pl == pl2
! f = StringIO()
! pl2.write(f)
! assert xml == f.getvalue()
! #print repr(pl2)
Index: videoreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/videoreader.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** videoreader.py 4 Feb 2003 15:36:42 -0000 1.2
--- videoreader.py 9 Apr 2003 13:25:43 -0000 1.3
***************
*** 14,292 ****
from Carbon import Res
try:
! import MediaDescr
except ImportError:
! def _audiodescr(data):
! return None
else:
! def _audiodescr(data):
! return MediaDescr.SoundDescription.decode(data)
try:
! from imgformat import macrgb
except ImportError:
! macrgb = "Macintosh RGB format"
import os
# import audio.format
class VideoFormat:
! def __init__(self, name, descr, width, height, format):
! self.__name = name
! self.__descr = descr
! self.__width = width
! self.__height = height
! self.__format = format
!
! def getname(self):
! return self.__name
!
! def getdescr(self):
! return self.__descr
!
! def getsize(self):
! return self.__width, self.__height
!
! def getformat(self):
! return self.__format
!
class _Reader:
! def __init__(self, path):
! fd = Qt.OpenMovieFile(path, 0)
! self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0)
! self.movietimescale = self.movie.GetMovieTimeScale()
! try:
! self.audiotrack = self.movie.GetMovieIndTrackType(1,
! QuickTime.AudioMediaCharacteristic, QuickTime.movieTrackCharacteristic)
! self.audiomedia = self.audiotrack.GetTrackMedia()
! except Qt.Error:
! self.audiotrack = self.audiomedia = None
! self.audiodescr = {}
! else:
! handle = Res.Handle('')
! n = self.audiomedia.GetMediaSampleDescriptionCount()
! self.audiomedia.GetMediaSampleDescription(1, handle)
! self.audiodescr = _audiodescr(handle.data)
! self.audiotimescale = self.audiomedia.GetMediaTimeScale()
! del handle
!
! try:
! self.videotrack = self.movie.GetMovieIndTrackType(1,
! QuickTime.VisualMediaCharacteristic, QuickTime.movieTrackCharacteristic)
! self.videomedia = self.videotrack.GetTrackMedia()
! except Qt.Error:
! self.videotrack = self.videomedia = self.videotimescale = None
! if self.videotrack:
! self.videotimescale = self.videomedia.GetMediaTimeScale()
! x0, y0, x1, y1 = self.movie.GetMovieBox()
! self.videodescr = {'width':(x1-x0), 'height':(y1-y0)}
! self._initgworld()
! self.videocurtime = None
! self.audiocurtime = None
!
! def __del__(self):
! self.audiomedia = None
! self.audiotrack = None
! self.videomedia = None
! self.videotrack = None
! self.movie = None
!
! def _initgworld(self):
! old_port, old_dev = Qdoffs.GetGWorld()
! try:
! movie_w = self.videodescr['width']
! movie_h = self.videodescr['height']
! movie_rect = (0, 0, movie_w, movie_h)
! self.gworld = Qdoffs.NewGWorld(32, movie_rect, None, None, QDOffscreen.keepLocal)
! self.pixmap = self.gworld.GetGWorldPixMap()
! Qdoffs.LockPixels(self.pixmap)
! Qdoffs.SetGWorld(self.gworld.as_GrafPtr(), None)
! Qd.EraseRect(movie_rect)
! self.movie.SetMovieGWorld(self.gworld.as_GrafPtr(), None)
! self.movie.SetMovieBox(movie_rect)
! self.movie.SetMovieActive(1)
! self.movie.MoviesTask(0)
! self.movie.SetMoviePlayHints(QuickTime.hintsHighQuality, QuickTime.hintsHighQuality)
! # XXXX framerate
! finally:
! Qdoffs.SetGWorld(old_port, old_dev)
!
! def _gettrackduration_ms(self, track):
! tracktime = track.GetTrackDuration()
! return self._movietime_to_ms(tracktime)
!
! def _movietime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.movietimescale, None), 1000)
! return value
!
! def _videotime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.videotimescale, None), 1000)
! return value
!
! def _audiotime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.audiotimescale, None), 1000)
! return value
!
! def _videotime_to_movietime(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.videotimescale, None),
! self.movietimescale)
! return value
!
! def HasAudio(self):
! return not self.audiotrack is None
!
! def HasVideo(self):
! return not self.videotrack is None
!
! def GetAudioDuration(self):
! if not self.audiotrack:
! return 0
! return self._gettrackduration_ms(self.audiotrack)
! def GetVideoDuration(self):
! if not self.videotrack:
! return 0
! return self._gettrackduration_ms(self.videotrack)
!
! def GetAudioFormat(self):
! if not self.audiodescr:
! return None, None, None, None, None
! bps = self.audiodescr['sampleSize']
! nch = self.audiodescr['numChannels']
! if nch == 1:
! channels = ['mono']
! elif nch == 2:
! channels = ['left', 'right']
! else:
! channels = map(lambda x: str(x+1), range(nch))
! if bps % 8:
! # Funny bits-per sample. We pretend not to understand
! blocksize = 0
! fpb = 0
! else:
! # QuickTime is easy (for as far as we support it): samples are always a whole
! # number of bytes, so frames are nchannels*samplesize, and there's one frame per block.
! blocksize = (bps/8)*nch
! fpb = 1
! if self.audiodescr['dataFormat'] == 'raw ':
! encoding = 'linear-excess'
! elif self.audiodescr['dataFormat'] == 'twos':
! encoding = 'linear-signed'
! else:
! encoding = 'quicktime-coding-%s'%self.audiodescr['dataFormat']
! ## return audio.format.AudioFormatLinear('quicktime_audio', 'QuickTime Audio Format',
! ## channels, encoding, blocksize=blocksize, fpb=fpb, bps=bps)
! return channels, encoding, blocksize, fpb, bps
!
! def GetAudioFrameRate(self):
! if not self.audiodescr:
! return None
! return int(self.audiodescr['sampleRate'])
!
! def GetVideoFormat(self):
! width = self.videodescr['width']
! height = self.videodescr['height']
! return VideoFormat('dummy_format', 'Dummy Video Format', width, height, macrgb)
!
! def GetVideoFrameRate(self):
! tv = self.videocurtime
! if tv == None:
! tv = 0
! flags = QuickTime.nextTimeStep|QuickTime.nextTimeEdgeOK
! tv, dur = self.videomedia.GetMediaNextInterestingTime(flags, tv, 1.0)
! dur = self._videotime_to_ms(dur)
! return int((1000.0/dur)+0.5)
!
! def ReadAudio(self, nframes, time=None):
! if not time is None:
! self.audiocurtime = time
! flags = QuickTime.nextTimeStep|QuickTime.nextTimeEdgeOK
! if self.audiocurtime == None:
! self.audiocurtime = 0
! tv = self.audiomedia.GetMediaNextInterestingTimeOnly(flags, self.audiocurtime, 1.0)
! if tv < 0 or (self.audiocurtime and tv < self.audiocurtime):
! return self._audiotime_to_ms(self.audiocurtime), None
! h = Res.Handle('')
! desc_h = Res.Handle('')
! size, actualtime, sampleduration, desc_index, actualcount, flags = \
! self.audiomedia.GetMediaSample(h, 0, tv, desc_h, nframes)
! self.audiocurtime = actualtime + actualcount*sampleduration
! return self._audiotime_to_ms(actualtime), h.data
!
! def ReadVideo(self, time=None):
! if not time is None:
! self.videocurtime = time
! flags = QuickTime.nextTimeStep
! if self.videocurtime == None:
! flags = flags | QuickTime.nextTimeEdgeOK
! self.videocurtime = 0
! tv = self.videomedia.GetMediaNextInterestingTimeOnly(flags, self.videocurtime, 1.0)
! if tv < 0 or (self.videocurtime and tv <= self.videocurtime):
! return self._videotime_to_ms(self.videocurtime), None
! self.videocurtime = tv
! moviecurtime = self._videotime_to_movietime(self.videocurtime)
! self.movie.SetMovieTimeValue(moviecurtime)
! self.movie.MoviesTask(0)
! return self._videotime_to_ms(self.videocurtime), self._getpixmapcontent()
!
! def _getpixmapcontent(self):
! """Shuffle the offscreen PixMap data, because it may have funny stride values"""
! rowbytes = Qdoffs.GetPixRowBytes(self.pixmap)
! width = self.videodescr['width']
! height = self.videodescr['height']
! start = 0
! rv = ''
! for i in range(height):
! nextline = Qdoffs.GetPixMapBytes(self.pixmap, start, width*4)
! start = start + rowbytes
! rv = rv + nextline
! return rv
def reader(url):
! try:
! rdr = _Reader(url)
! except IOError:
! return None
! return rdr
def _test():
! import EasyDialogs
! try:
! import img
! except ImportError:
! img = None
! import MacOS
! Qt.EnterMovies()
! path = EasyDialogs.AskFileForOpen(message='Video to convert')
! if not path: sys.exit(0)
! rdr = reader(path)
! if not rdr:
! sys.exit(1)
! dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
! if not dstdir: sys.exit(0)
! num = 0
! os.mkdir(dstdir)
! videofmt = rdr.GetVideoFormat()
! imgfmt = videofmt.getformat()
! imgw, imgh = videofmt.getsize()
! timestamp, data = rdr.ReadVideo()
! while data:
! fname = 'frame%04.4d.jpg'%num
! num = num+1
! pname = os.path.join(dstdir, fname)
! if not img: print 'Not',
! print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
! if img:
! wrt = img.writer(imgfmt, pname)
! wrt.width = imgw
! wrt.height = imgh
! wrt.write(data)
! timestamp, data = rdr.ReadVideo()
! MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
! if num > 20:
! print 'stopping at 20 frames so your disk does not fill up:-)'
! break
! print 'Total frames:', num
!
if __name__ == '__main__':
! _test()
! sys.exit(1)
!
--- 14,292 ----
from Carbon import Res
try:
! import MediaDescr
except ImportError:
! def _audiodescr(data):
! return None
else:
! def _audiodescr(data):
! return MediaDescr.SoundDescription.decode(data)
try:
! from imgformat import macrgb
except ImportError:
! macrgb = "Macintosh RGB format"
import os
# import audio.format
class VideoFormat:
! def __init__(self, name, descr, width, height, format):
! self.__name = name
! self.__descr = descr
! self.__width = width
! self.__height = height
! self.__format = format
!
! def getname(self):
! return self.__name
!
! def getdescr(self):
! return self.__descr
!
! def getsize(self):
! return self.__width, self.__height
!
! def getformat(self):
! return self.__format
!
class _Reader:
! def __init__(self, path):
! fd = Qt.OpenMovieFile(path, 0)
! self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0)
! self.movietimescale = self.movie.GetMovieTimeScale()
! try:
! self.audiotrack = self.movie.GetMovieIndTrackType(1,
! QuickTime.AudioMediaCharacteristic, QuickTime.movieTrackCharacteristic)
! self.audiomedia = self.audiotrack.GetTrackMedia()
! except Qt.Error:
! self.audiotrack = self.audiomedia = None
! self.audiodescr = {}
! else:
! handle = Res.Handle('')
! n = self.audiomedia.GetMediaSampleDescriptionCount()
! self.audiomedia.GetMediaSampleDescription(1, handle)
! self.audiodescr = _audiodescr(handle.data)
! self.audiotimescale = self.audiomedia.GetMediaTimeScale()
! del handle
!
! try:
! self.videotrack = self.movie.GetMovieIndTrackType(1,
! QuickTime.VisualMediaCharacteristic, QuickTime.movieTrackCharacteristic)
! self.videomedia = self.videotrack.GetTrackMedia()
! except Qt.Error:
! self.videotrack = self.videomedia = self.videotimescale = None
! if self.videotrack:
! self.videotimescale = self.videomedia.GetMediaTimeScale()
! x0, y0, x1, y1 = self.movie.GetMovieBox()
! self.videodescr = {'width':(x1-x0), 'height':(y1-y0)}
! self._initgworld()
! self.videocurtime = None
! self.audiocurtime = None
!
! def __del__(self):
! self.audiomedia = None
! self.audiotrack = None
! self.videomedia = None
! self.videotrack = None
! self.movie = None
!
! def _initgworld(self):
! old_port, old_dev = Qdoffs.GetGWorld()
! try:
! movie_w = self.videodescr['width']
! movie_h = self.videodescr['height']
! movie_rect = (0, 0, movie_w, movie_h)
! self.gworld = Qdoffs.NewGWorld(32, movie_rect, None, None, QDOffscreen.keepLocal)
! self.pixmap = self.gworld.GetGWorldPixMap()
! Qdoffs.LockPixels(self.pixmap)
! Qdoffs.SetGWorld(self.gworld.as_GrafPtr(), None)
! Qd.EraseRect(movie_rect)
! self.movie.SetMovieGWorld(self.gworld.as_GrafPtr(), None)
! self.movie.SetMovieBox(movie_rect)
! self.movie.SetMovieActive(1)
! self.movie.MoviesTask(0)
! self.movie.SetMoviePlayHints(QuickTime.hintsHighQuality, QuickTime.hintsHighQuality)
! # XXXX framerate
! finally:
! Qdoffs.SetGWorld(old_port, old_dev)
!
! def _gettrackduration_ms(self, track):
! tracktime = track.GetTrackDuration()
! return self._movietime_to_ms(tracktime)
!
! def _movietime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.movietimescale, None), 1000)
! return value
!
! def _videotime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.videotimescale, None), 1000)
! return value
!
! def _audiotime_to_ms(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.audiotimescale, None), 1000)
! return value
!
! def _videotime_to_movietime(self, time):
! value, d1, d2 = Qt.ConvertTimeScale((time, self.videotimescale, None),
! self.movietimescale)
! return value
!
! def HasAudio(self):
! return not self.audiotrack is None
!
! def HasVideo(self):
! return not self.videotrack is None
!
! def GetAudioDuration(self):
! if not self.audiotrack:
! return 0
! return self._gettrackduration_ms(self.audiotrack)
! def GetVideoDuration(self):
! if not self.videotrack:
! return 0
! return self._gettrackduration_ms(self.videotrack)
!
! def GetAudioFormat(self):
! if not self.audiodescr:
! return None, None, None, None, None
! bps = self.audiodescr['sampleSize']
! nch = self.audiodescr['numChannels']
! if nch == 1:
! channels = ['mono']
! elif nch == 2:
! channels = ['left', 'right']
! else:
! channels = map(lambda x: str(x+1), range(nch))
! if bps % 8:
! # Funny bits-per sample. We pretend not to understand
! blocksize = 0
! fpb = 0
! else:
! # QuickTime is easy (for as far as we support it): samples are always a whole
! # number of bytes, so frames are nchannels*samplesize, and there's one frame per block.
! blocksize = (bps/8)*nch
! fpb = 1
! if self.audiodescr['dataFormat'] == 'raw ':
! encoding = 'linear-excess'
! elif self.audiodescr['dataFormat'] == 'twos':
! encoding = 'linear-signed'
! else:
! encoding = 'quicktime-coding-%s'%self.audiodescr['dataFormat']
! ## return audio.format.AudioFormatLinear('quicktime_audio', 'QuickTime Audio Format',
! ## channels, encoding, blocksize=blocksize, fpb=fpb, bps=bps)
! return channels, encoding, blocksize, fpb, bps
!
! def GetAudioFrameRate(self):
! if not self.audiodescr:
! return None
! return int(self.audiodescr['sampleRate'])
!
! def GetVideoFormat(self):
! width = self.videodescr['width']
! height = self.videodescr['height']
! return VideoFormat('dummy_format', 'Dummy Video Format', width, height, macrgb)
!
! def GetVideoFrameRate(self):
! tv = self.videocurtime
! if tv == None:
! tv = 0
! flags = QuickTime.nextTimeStep|QuickTime.nextTimeEdgeOK
! tv, dur = self.videomedia.GetMediaNextInterestingTime(flags, tv, 1.0)
! dur = self._videotime_to_ms(dur)
! return int((1000.0/dur)+0.5)
!
! def ReadAudio(self, nframes, time=None):
! if not time is None:
! self.audiocurtime = time
! flags = QuickTime.nextTimeStep|QuickTime.nextTimeEdgeOK
! if self.audiocurtime == None:
! self.audiocurtime = 0
! tv = self.audiomedia.GetMediaNextInterestingTimeOnly(flags, self.audiocurtime, 1.0)
! if tv < 0 or (self.audiocurtime and tv < self.audiocurtime):
! return self._audiotime_to_ms(self.audiocurtime), None
! h = Res.Handle('')
! desc_h = Res.Handle('')
! size, actualtime, sampleduration, desc_index, actualcount, flags = \
! self.audiomedia.GetMediaSample(h, 0, tv, desc_h, nframes)
! self.audiocurtime = actualtime + actualcount*sampleduration
! return self._audiotime_to_ms(actualtime), h.data
!
! def ReadVideo(self, time=None):
! if not time is None:
! self.videocurtime = time
! flags = QuickTime.nextTimeStep
! if self.videocurtime == None:
! flags = flags | QuickTime.nextTimeEdgeOK
! self.videocurtime = 0
! tv = self.videomedia.GetMediaNextInterestingTimeOnly(flags, self.videocurtime, 1.0)
! if tv < 0 or (self.videocurtime and tv <= self.videocurtime):
! return self._videotime_to_ms(self.videocurtime), None
! self.videocurtime = tv
! moviecurtime = self._videotime_to_movietime(self.videocurtime)
! self.movie.SetMovieTimeValue(moviecurtime)
! self.movie.MoviesTask(0)
! return self._videotime_to_ms(self.videocurtime), self._getpixmapcontent()
!
! def _getpixmapcontent(self):
! """Shuffle the offscreen PixMap data, because it may have funny stride values"""
! rowbytes = Qdoffs.GetPixRowBytes(self.pixmap)
! width = self.videodescr['width']
! height = self.videodescr['height']
! start = 0
! rv = ''
! for i in range(height):
! nextline = Qdoffs.GetPixMapBytes(self.pixmap, start, width*4)
! start = start + rowbytes
! rv = rv + nextline
! return rv
def reader(url):
! try:
! rdr = _Reader(url)
! except IOError:
! return None
! return rdr
def _test():
! import EasyDialogs
! try:
! import img
! except ImportError:
! img = None
! import MacOS
! Qt.EnterMovies()
! path = EasyDialogs.AskFileForOpen(message='Video to convert')
! if not path: sys.exit(0)
! rdr = reader(path)
! if not rdr:
! sys.exit(1)
! dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
! if not dstdir: sys.exit(0)
! num = 0
! os.mkdir(dstdir)
! videofmt = rdr.GetVideoFormat()
! imgfmt = videofmt.getformat()
! imgw, imgh = videofmt.getsize()
! timestamp, data = rdr.ReadVideo()
! while data:
! fname = 'frame%04.4d.jpg'%num
! num = num+1
! pname = os.path.join(dstdir, fname)
! if not img: print 'Not',
! print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
! if img:
! wrt = img.writer(imgfmt, pname)
! wrt.width = imgw
! wrt.height = imgh
! wrt.write(data)
! timestamp, data = rdr.ReadVideo()
! MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
! if num > 20:
! print 'stopping at 20 frames so your disk does not fill up:-)'
! break
! print 'Total frames:', num
!
if __name__ == '__main__':
! _test()
! sys.exit(1)
!