blob: d8aef6b3c3da7fc1d86c38ce8f6f7421343dc888 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`aepack` --- Conversion between Python variables and AppleEvent data containers
3====================================================================================
4
5.. module:: aepack
6 :platform: Mac
7 :synopsis: Conversion between Python variables and AppleEvent data containers.
8.. sectionauthor:: Vincent Marchetti <vincem@en.com>
Georg Brandlb19be572007-12-29 10:57:00 +00009.. moduleauthor:: Jack Jansen
Georg Brandl8ec7f652007-08-15 14:28:01 +000010
11The :mod:`aepack` module defines functions for converting (packing) Python
12variables to AppleEvent descriptors and back (unpacking). Within Python the
13AppleEvent descriptor is handled by Python objects of built-in type
14:class:`AEDesc`, defined in module :mod:`Carbon.AE`.
15
16The :mod:`aepack` module defines the following functions:
17
18
19.. function:: pack(x[, forcetype])
20
21 Returns an :class:`AEDesc` object containing a conversion of Python value x. If
22 *forcetype* is provided it specifies the descriptor type of the result.
23 Otherwise, a default mapping of Python types to Apple Event descriptor types is
24 used, as follows:
25
26 +-----------------+-----------------------------------+
27 | Python type | descriptor type |
28 +=================+===================================+
29 | :class:`FSSpec` | typeFSS |
30 +-----------------+-----------------------------------+
31 | :class:`FSRef` | typeFSRef |
32 +-----------------+-----------------------------------+
33 | :class:`Alias` | typeAlias |
34 +-----------------+-----------------------------------+
35 | integer | typeLong (32 bit integer) |
36 +-----------------+-----------------------------------+
37 | float | typeFloat (64 bit floating point) |
38 +-----------------+-----------------------------------+
39 | string | typeText |
40 +-----------------+-----------------------------------+
41 | unicode | typeUnicodeText |
42 +-----------------+-----------------------------------+
43 | list | typeAEList |
44 +-----------------+-----------------------------------+
45 | dictionary | typeAERecord |
46 +-----------------+-----------------------------------+
47 | instance | *see below* |
48 +-----------------+-----------------------------------+
49
50 If *x* is a Python instance then this function attempts to call an
51 :meth:`__aepack__` method. This method should return an :class:`AEDesc` object.
52
53 If the conversion *x* is not defined above, this function returns the Python
54 string representation of a value (the repr() function) encoded as a text
55 descriptor.
56
57
58.. function:: unpack(x[, formodulename])
59
60 *x* must be an object of type :class:`AEDesc`. This function returns a Python
61 object representation of the data in the Apple Event descriptor *x*. Simple
62 AppleEvent data types (integer, text, float) are returned as their obvious
63 Python counterparts. Apple Event lists are returned as Python lists, and the
64 list elements are recursively unpacked. Object references (ex. ``line 3 of
65 document 1``) are returned as instances of :class:`aetypes.ObjectSpecifier`,
66 unless ``formodulename`` is specified. AppleEvent descriptors with descriptor
67 type typeFSS are returned as :class:`FSSpec` objects. AppleEvent record
68 descriptors are returned as Python dictionaries, with 4-character string keys
69 and elements recursively unpacked.
70
71 The optional ``formodulename`` argument is used by the stub packages generated
72 by :mod:`gensuitemodule`, and ensures that the OSA classes for object specifiers
73 are looked up in the correct module. This ensures that if, say, the Finder
74 returns an object specifier for a window you get an instance of
75 ``Finder.Window`` and not a generic ``aetypes.Window``. The former knows about
76 all the properties and elements a window has in the Finder, while the latter
77 knows no such things.
78
79
80.. seealso::
81
82 Module :mod:`Carbon.AE`
83 Built-in access to Apple Event Manager routines.
84
85 Module :mod:`aetypes`
86 Python definitions of codes for Apple Event descriptor types.