/Doc/library/aepack.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 92 lines · 71 code · 21 blank · 0 comment · 0 complexity · 61280b1f9f4ffb0cd6f9a4a03f980825 MD5 · raw file

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