cpython/Doc/library/aepack.rst
Christian Heimes 5b5e81c637 Merged revisions 59605-59624 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59606 | georg.brandl | 2007-12-29 11:57:00 +0100 (Sat, 29 Dec 2007) | 2 lines

  Some cleanup in the docs.
........
  r59611 | martin.v.loewis | 2007-12-29 19:49:21 +0100 (Sat, 29 Dec 2007) | 2 lines

  Bug #1699: Define _BSD_SOURCE only on OpenBSD.
........
  r59612 | raymond.hettinger | 2007-12-29 23:09:34 +0100 (Sat, 29 Dec 2007) | 1 line

  Simpler documentation for itertools.tee().  Should be backported.
........
  r59613 | raymond.hettinger | 2007-12-29 23:16:24 +0100 (Sat, 29 Dec 2007) | 1 line

  Improve docs for itertools.groupby().  The use of xrange(0) to create a unique object is less obvious than object().
........
  r59620 | christian.heimes | 2007-12-31 15:47:07 +0100 (Mon, 31 Dec 2007) | 3 lines

  Added wininst-9.0.exe executable for VS 2008
  Integrated bdist_wininst into PCBuild9 directory
........
  r59621 | christian.heimes | 2007-12-31 15:51:18 +0100 (Mon, 31 Dec 2007) | 1 line

  Moved PCbuild directory to PC/VS7.1
........
  r59622 | christian.heimes | 2007-12-31 15:59:26 +0100 (Mon, 31 Dec 2007) | 1 line

  Fix paths for build bot
........
  r59623 | christian.heimes | 2007-12-31 16:02:41 +0100 (Mon, 31 Dec 2007) | 1 line

  Fix paths for build bot, part 2
........
  r59624 | christian.heimes | 2007-12-31 16:18:55 +0100 (Mon, 31 Dec 2007) | 1 line

  Renamed PCBuild9 directory to PCBuild
........
2007-12-31 16:14:33 +00:00

90 lines
4.3 KiB
ReStructuredText

:mod:`aepack` --- Conversion between Python variables and AppleEvent data containers
====================================================================================
.. module:: aepack
:platform: Mac
:synopsis: Conversion between Python variables and AppleEvent data containers.
.. sectionauthor:: Vincent Marchetti <vincem@en.com>
.. moduleauthor:: Jack Jansen
The :mod:`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
:class:`AEDesc`, defined in module :mod:`Carbon.AE`.
The :mod:`aepack` module defines the following functions:
.. function:: pack(x[, forcetype])
Returns an :class:`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 |
+=================+===================================+
| :class:`FSSpec` | typeFSS |
+-----------------+-----------------------------------+
| :class:`FSRef` | typeFSRef |
+-----------------+-----------------------------------+
| :class:`Alias` | typeAlias |
+-----------------+-----------------------------------+
| integer | typeLong (32 bit integer) |
+-----------------+-----------------------------------+
| float | typeFloat (64 bit floating point) |
+-----------------+-----------------------------------+
| string | typeText |
+-----------------+-----------------------------------+
| unicode | typeUnicodeText |
+-----------------+-----------------------------------+
| list | typeAEList |
+-----------------+-----------------------------------+
| dictionary | typeAERecord |
+-----------------+-----------------------------------+
| instance | *see below* |
+-----------------+-----------------------------------+
If *x* is a Python instance then this function attempts to call an
:meth:`__aepack__` method. This method should return an :class:`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.
.. function:: unpack(x[, formodulename])
*x* must be an object of type :class:`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 :class:`aetypes.ObjectSpecifier`,
unless ``formodulename`` is specified. AppleEvent descriptors with descriptor
type typeFSS are returned as :class:`FSSpec` objects. AppleEvent record
descriptors are returned as Python dictionaries, with 4-character string keys
and elements recursively unpacked.
The optional ``formodulename`` argument is used by the stub packages generated
by :mod:`gensuitemodule`, and ensures that the OSA classes for object specifiers
are looked up in the correct module. This ensures that if, say, the Finder
returns an object specifier for a window you get an instance of
``Finder.Window`` and not a generic ``aetypes.Window``. The former knows about
all the properties and elements a window has in the Finder, while the latter
knows no such things.
.. seealso::
Module :mod:`Carbon.AE`
Built-in access to Apple Event Manager routines.
Module :mod:`aetypes`
Python definitions of codes for Apple Event descriptor types.
`Inside Macintosh: Interapplication Communication <http://developer.apple.com/techpubs/mac/IAC/IAC-2.html>`_
Information about inter-process communications on the Macintosh.