2.13 aepack -- Conversion between Python variables and AppleEvent data containers
Keywords: mac

# 2.13 `aepack` -- Conversion between Python variables and AppleEvent data containers

Availability: Macintosh.

The `aepack` module defines functions for converting (packing) Python variables to AppleEvent descriptors and back (unpacking). Within Python the AppleEvent descriptor is handled by Python objects of built-in type AEDesc, defined in module `AE`.

The `aepack` module defines the following functions:

`pack`(x[, forcetype])
  Returns an `AEDesc` object containing a conversion of Python value x. If forcetype is provided it specifies the descriptor type of the result. Otherwise, a default mapping of Python types to Apple Event descriptor types is used, as follows:

  Python type | descriptor type
  --- | ---
  `FSSpec` | typeFSS
  `Alias` | typeAlias
  integer | typeLong (32 bit integer)
  float | typeFloat (64 bit floating point)
  string | typeText
  list | typeAEList
  dictionary | typeAERecord
  instance | see below

  FSSpec and Alias are built-in object types defined in the module `macfs`.

  If x is a Python instance then this function attempts to call an `__aepack__()` method. This method should return an AE.AEDesc object.

  If the conversion x is not defined above, this function returns the Python string representation of a value (the repr() function) encoded as a text descriptor.

`unpack`(x)
  x must be an object of type `AEDesc`. This function returns a Python object representation of the data in the Apple Event descriptor x. Simple AppleEvent data types (integer, text, float) are returned as their obvious Python counterparts. Apple Event lists are returned as Python lists, and the list elements are recursively unpacked. Object references (ex. `line 3 of document 1`) are returned as instances of `aetypes.ObjectSpecifier`. AppleEvent descriptors with descriptor type typeFSS are returned as `FSSpec` objects. AppleEvent record descriptors are returned as Python dictionaries, with keys of type `?` and elements recursively unpacked.

See Also:

Module `AE`:
  Built-in access to Apple Event Manager routines.

Module `aetypes`:
  Python definitions of codes for Apple Event descriptor types.

Inside Macintosh: Interapplication Communication
  Information about inter-process communications on the Macintosh.