Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="mac.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="mac.html" title='Macintosh Library Modules' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-aetypes.html" /> | |
13 | <link rel="prev" href="module-aetools.html" /> | |
14 | <link rel="parent" href="scripting.html" /> | |
15 | <link rel="next" href="module-aetypes.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>3.3 aepack -- Conversion between Python variables and AppleEvent data containers</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="3.2 aetools " | |
25 | href="module-aetools.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="3. MacPython OSA Modules" | |
28 | href="scripting.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="3.4 aetypes " | |
31 | href="module-aetypes.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Macintosh Library Modules</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-aetools.html">3.2 aetools </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="scripting.html">3. MacPython OSA Modules</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-aetypes.html">3.4 aetypes </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION005300000000000000000"> | |
56 | 3.3 <tt class="module">aepack</tt> -- | |
57 | Conversion between Python variables and AppleEvent data containers</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-aepack"></A> | |
62 | <p class="availability">Availability: <span | |
63 | class="platform">Macintosh</span>.</p> | |
64 | ||
65 | <P> | |
66 | The <tt class="module">aepack</tt> module defines functions for converting (packing) | |
67 | Python variables to AppleEvent descriptors and back (unpacking). | |
68 | Within Python the AppleEvent descriptor is handled by Python objects | |
69 | of built-in type <tt class="class">AEDesc</tt>, defined in module <tt class="module"><a href="module-Carbon.AE.html">Carbon.AE</a></tt>. | |
70 | ||
71 | <P> | |
72 | The <tt class="module">aepack</tt> module defines the following functions: | |
73 | ||
74 | <P> | |
75 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
76 | <td><nobr><b><tt id='l2h-150' xml:id='l2h-150' class="function">pack</tt></b>(</nobr></td> | |
77 | <td><var>x</var><big>[</big><var>, forcetype</var><big>]</big><var></var>)</td></tr></table></dt> | |
78 | <dd> | |
79 | Returns an <tt class="class">AEDesc</tt> object containing a conversion of Python | |
80 | value x. If <var>forcetype</var> is provided it specifies the descriptor | |
81 | type of the result. Otherwise, a default mapping of Python types to | |
82 | Apple Event descriptor types is used, as follows: | |
83 | ||
84 | <P> | |
85 | <div class="center"><table class="realtable"> | |
86 | <thead> | |
87 | <tr> | |
88 | <th class="left" >Python type</th> | |
89 | <th class="left" >descriptor type</th> | |
90 | </tr> | |
91 | </thead> | |
92 | <tbody> | |
93 | <tr><td class="left" valign="baseline"><tt class="class">FSSpec</tt></td> | |
94 | <td class="left" >typeFSS</td></tr> | |
95 | <tr><td class="left" valign="baseline"><tt class="class">FSRef</tt></td> | |
96 | <td class="left" >typeFSRef</td></tr> | |
97 | <tr><td class="left" valign="baseline"><tt class="class">Alias</tt></td> | |
98 | <td class="left" >typeAlias</td></tr> | |
99 | <tr><td class="left" valign="baseline">integer</td> | |
100 | <td class="left" >typeLong (32 bit integer)</td></tr> | |
101 | <tr><td class="left" valign="baseline">float</td> | |
102 | <td class="left" >typeFloat (64 bit floating point)</td></tr> | |
103 | <tr><td class="left" valign="baseline">string</td> | |
104 | <td class="left" >typeText</td></tr> | |
105 | <tr><td class="left" valign="baseline">unicode</td> | |
106 | <td class="left" >typeUnicodeText</td></tr> | |
107 | <tr><td class="left" valign="baseline">list</td> | |
108 | <td class="left" >typeAEList</td></tr> | |
109 | <tr><td class="left" valign="baseline">dictionary</td> | |
110 | <td class="left" >typeAERecord</td></tr> | |
111 | <tr><td class="left" valign="baseline">instance</td> | |
112 | <td class="left" ><em>see below</em></td></tr></tbody> | |
113 | </table></div> | |
114 | ||
115 | <P> | |
116 | If <var>x</var> is a Python instance then this function attempts to call an | |
117 | <tt class="method">__aepack__()</tt> method. This method should return an | |
118 | <tt class="class">AEDesc</tt> object. | |
119 | ||
120 | <P> | |
121 | If the conversion <var>x</var> is not defined above, this function returns | |
122 | the Python string representation of a value (the repr() function) | |
123 | encoded as a text descriptor. | |
124 | </dl> | |
125 | ||
126 | <P> | |
127 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
128 | <td><nobr><b><tt id='l2h-151' xml:id='l2h-151' class="function">unpack</tt></b>(</nobr></td> | |
129 | <td><var>x</var><big>[</big><var>, formodulename</var><big>]</big><var></var>)</td></tr></table></dt> | |
130 | <dd> | |
131 | <var>x</var> must be an object of type <tt class="class">AEDesc</tt>. This function | |
132 | returns a Python object representation of the data in the Apple | |
133 | Event descriptor <var>x</var>. Simple AppleEvent data types (integer, | |
134 | text, float) are returned as their obvious Python counterparts. | |
135 | Apple Event lists are returned as Python lists, and the list | |
136 | elements are recursively unpacked. Object references | |
137 | (ex. <code>line 3 of document 1</code>) are returned as instances of | |
138 | <tt class="class">aetypes.ObjectSpecifier</tt>, unless <code>formodulename</code> | |
139 | is specified. AppleEvent descriptors with | |
140 | descriptor type typeFSS are returned as <tt class="class">FSSpec</tt> | |
141 | objects. AppleEvent record descriptors are returned as Python | |
142 | dictionaries, with 4-character string keys and elements recursively | |
143 | unpacked. | |
144 | ||
145 | <P> | |
146 | The optional <code>formodulename</code> argument is used by the stub packages | |
147 | generated by <tt class="module">gensuitemodule</tt>, and ensures that the OSA classes | |
148 | for object specifiers are looked up in the correct module. This ensures | |
149 | that if, say, the Finder returns an object specifier for a window | |
150 | you get an instance of <code>Finder.Window</code> and not a generic | |
151 | <code>aetypes.Window</code>. The former knows about all the properties | |
152 | and elements a window has in the Finder, while the latter knows | |
153 | no such things. | |
154 | </dl> | |
155 | ||
156 | <P> | |
157 | <div class="seealso"> | |
158 | <p class="heading">See Also:</p> | |
159 | ||
160 | <dl compact="compact" class="seemodule"> | |
161 | <dt>Module <b><tt class="module"><a href="module-Carbon.AE.html">Carbon.AE</a></tt>:</b> | |
162 | <dd>Built-in access to Apple Event Manager routines. | |
163 | </dl> | |
164 | <dl compact="compact" class="seemodule"> | |
165 | <dt>Module <b><tt class="module"><a href="module-aetypes.html">aetypes</a></tt>:</b> | |
166 | <dd>Python definitions of codes for Apple Event | |
167 | descriptor types. | |
168 | </dl> | |
169 | <dl compact="compact" class="seetitle"> | |
170 | <dt><em class="citetitle"><a href="http://developer.apple.com/techpubs/mac/IAC/IAC-2.html" | |
171 | > | |
172 | Inside Macintosh: Interapplication | |
173 | Communication</a></em></dt> | |
174 | <dd>Information about inter-process | |
175 | communications on the Macintosh.</dd> | |
176 | </dl> | |
177 | </div> | |
178 | ||
179 | <DIV CLASS="navigation"> | |
180 | <div class='online-navigation'> | |
181 | <p></p><hr /> | |
182 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
183 | <tr> | |
184 | <td class='online-navigation'><a rel="prev" title="3.2 aetools " | |
185 | href="module-aetools.html"><img src='../icons/previous.png' | |
186 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
187 | <td class='online-navigation'><a rel="parent" title="3. MacPython OSA Modules" | |
188 | href="scripting.html"><img src='../icons/up.png' | |
189 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
190 | <td class='online-navigation'><a rel="next" title="3.4 aetypes " | |
191 | href="module-aetypes.html"><img src='../icons/next.png' | |
192 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
193 | <td align="center" width="100%">Macintosh Library Modules</td> | |
194 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
195 | href="contents.html"><img src='../icons/contents.png' | |
196 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
197 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
198 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
199 | <td class='online-navigation'><a rel="index" title="Index" | |
200 | href="genindex.html"><img src='../icons/index.png' | |
201 | border='0' height='32' alt='Index' width='32' /></A></td> | |
202 | </tr></table> | |
203 | <div class='online-navigation'> | |
204 | <b class="navlabel">Previous:</b> | |
205 | <a class="sectref" rel="prev" href="module-aetools.html">3.2 aetools </A> | |
206 | <b class="navlabel">Up:</b> | |
207 | <a class="sectref" rel="parent" href="scripting.html">3. MacPython OSA Modules</A> | |
208 | <b class="navlabel">Next:</b> | |
209 | <a class="sectref" rel="next" href="module-aetypes.html">3.4 aetypes </A> | |
210 | </div> | |
211 | </div> | |
212 | <hr /> | |
213 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
214 | </DIV> | |
215 | <!--End of Navigation Panel--> | |
216 | <ADDRESS> | |
217 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
218 | </ADDRESS> | |
219 | </BODY> | |
220 | </HTML> |