summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-03-31 13:32:59 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-03-31 13:32:59 (GMT)
commitfc71026c8ad67e26cfef26e61b10471647a9f261 (patch)
tree1e8a18fcab3ab54e62c1d162e1b7226d1043744c
parent397e9142096d5ccd2b4a63bc04d3b05b3c86cc48 (diff)
downloadcpython-fc71026c8ad67e26cfef26e61b10471647a9f261.zip
cpython-fc71026c8ad67e26cfef26e61b10471647a9f261.tar.gz
cpython-fc71026c8ad67e26cfef26e61b10471647a9f261.tar.bz2
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.
-rw-r--r--Lib/plat-mac/aepack.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/plat-mac/aepack.py b/Lib/plat-mac/aepack.py
index 17a7e70..5dd95b8 100644
--- a/Lib/plat-mac/aepack.py
+++ b/Lib/plat-mac/aepack.py
@@ -23,7 +23,7 @@ import MacOS
import Carbon.File
import StringIO
import aetypes
-from aetypes import mkenum, mktype
+from aetypes import mkenum, ObjectSpecifier
import os
# These ones seem to be missing from AppleEvents
@@ -99,7 +99,7 @@ def pack(x, forcetype = None):
if isinstance(x, StringType):
return AE.AECreateDesc('TEXT', x)
if isinstance(x, UnicodeType):
- data = t.encode('utf16')
+ data = x.encode('utf16')
if data[:2] == '\xfe\xff':
data = data[2:]
return AE.AECreateDesc('utxt', data)
@@ -114,6 +114,9 @@ def pack(x, forcetype = None):
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'):
@@ -231,7 +234,7 @@ def unpack(desc, formodulename=""):
if t == typeTrue:
return 1
if t == typeType:
- return mktype(desc.data)
+ return mktype(desc.data, formodulename)
#
# The following are special
#
@@ -339,11 +342,25 @@ def mkobject(dict):
# to __class__ is safe. Moreover, shouldn't there be a better
# 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)