예제 #1
0
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)
    return aetypes.Property(
        seld.type, fr) if want == 'prop' and form == 'prop' and aetypes.IsType(
            seld) else aetypes.ObjectSpecifier(want, form, seld, fr)
예제 #2
0
class TestAepack(unittest.TestCase):
    OBJECTS = [
        aetypes.Enum('enum'),
        aetypes.Type('type'),
        aetypes.Keyword('kwrd'),
        aetypes.Range(1, 10),
        aetypes.Comparison(1, '<   ', 10),
        aetypes.Logical('not ', 1),
        aetypes.IntlText(0, 0, 'international text'),
        aetypes.IntlWritingCode(0,0),
        aetypes.QDPoint(50,100),
        aetypes.QDRectangle(50,100,150,200),
        aetypes.RGBColor(0x7000, 0x6000, 0x5000),
        aetypes.Unknown('xxxx', 'unknown type data'),
        aetypes.Character(1),
        aetypes.Character(2, aetypes.Line(2)),
    ]

    def test_roundtrip_string(self):
        o = 'a string'
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_int(self):
        o = 12
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_float(self):
        o = 12.1
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_None(self):
        o = None
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_aeobjects(self):
        for o in self.OBJECTS:
            packed = aepack.pack(o)
            unpacked = aepack.unpack(packed)
            self.assertEqual(repr(o), repr(unpacked))

    def test_roundtrip_FSSpec(self):
        try:
            import Carbon.File
        except:
            return
        o = Carbon.File.FSSpec(os.curdir)
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o.as_pathname(), unpacked.as_pathname())

    def test_roundtrip_Alias(self):
        try:
            import Carbon.File
        except:
            return
        o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
            unpacked.FSResolveAlias(None)[0].as_pathname())
예제 #3
0
"""Tools for use in AppleEvent clients and servers: