[Python-checkins] python/dist/src/Lib/plat-mac aepack.py,1.4,1.5

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Mon, 31 Mar 2003 05:33:03 -0800


Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1:/tmp/cvs-serv32372

Modified Files:
	aepack.py 
Log Message:
Subclasses of ObjectSpecifier can now be packed and unpacked. This allows
you to say something like "talker.count(want=Address_Book.people)" in
stead of having to manually create the aetypes.Type(Address_Book.people.want)
OSA type.


Index: aepack.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/aepack.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** aepack.py	12 Feb 2003 15:37:25 -0000	1.4
--- aepack.py	31 Mar 2003 13:32:59 -0000	1.5
***************
*** 24,28 ****
  import StringIO
  import aetypes
! from aetypes import mkenum, mktype
  import os
  
--- 24,28 ----
  import StringIO
  import aetypes
! from aetypes import mkenum, ObjectSpecifier
  import os
  
***************
*** 100,104 ****
  		return AE.AECreateDesc('TEXT', x)
  	if isinstance(x, UnicodeType):
! 		data = t.encode('utf16')
  		if data[:2] == '\xfe\xff':
  			data = data[2:]
--- 100,104 ----
  		return AE.AECreateDesc('TEXT', x)
  	if isinstance(x, UnicodeType):
! 		data = x.encode('utf16')
  		if data[:2] == '\xfe\xff':
  			data = data[2:]
***************
*** 115,118 ****
--- 115,121 ----
  			#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__()
***************
*** 232,236 ****
  		return 1
  	if t == typeType:
! 		return mktype(desc.data)
  	#
  	# The following are special
--- 235,239 ----
  		return 1
  	if t == typeType:
! 		return mktype(desc.data, formodulename)
  	#
  	# The following are special
***************
*** 340,343 ****
--- 343,350 ----
  # 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)
***************
*** 346,349 ****
--- 353,366 ----
  	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)