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