1 | <xsl:stylesheet version = '1.0'
|
---|
2 | xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
---|
3 | xmlns:vbox="http://www.virtualbox.org/">
|
---|
4 |
|
---|
5 | <!--
|
---|
6 | websrv-python.xsl:
|
---|
7 | XSLT stylesheet that generates VirtualBox_services.py from
|
---|
8 | VirtualBox.xidl. This Python file represents our
|
---|
9 | web service API. Depends on WSDL file for actual SOAP bindings.
|
---|
10 | -->
|
---|
11 | <!--
|
---|
12 | Copyright (C) 2008-2022 Oracle and/or its affiliates.
|
---|
13 |
|
---|
14 | This file is part of VirtualBox base platform packages, as
|
---|
15 | available from https://www.virtualbox.org.
|
---|
16 |
|
---|
17 | This program is free software; you can redistribute it and/or
|
---|
18 | modify it under the terms of the GNU General Public License
|
---|
19 | as published by the Free Software Foundation, in version 3 of the
|
---|
20 | License.
|
---|
21 |
|
---|
22 | This program is distributed in the hope that it will be useful, but
|
---|
23 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
25 | General Public License for more details.
|
---|
26 |
|
---|
27 | You should have received a copy of the GNU General Public License
|
---|
28 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
29 |
|
---|
30 | SPDX-License-Identifier: GPL-3.0-only
|
---|
31 | -->
|
---|
32 |
|
---|
33 |
|
---|
34 | <xsl:output
|
---|
35 | method="text"
|
---|
36 | version="1.0"
|
---|
37 | encoding="utf-8"
|
---|
38 | indent="no"/>
|
---|
39 |
|
---|
40 | <xsl:include href="../idl/typemap-shared.inc.xsl" />
|
---|
41 |
|
---|
42 | <xsl:variable name="G_setSuppressedInterfaces"
|
---|
43 | select="//interface[@wsmap='suppress']" />
|
---|
44 |
|
---|
45 | <xsl:template name="emitConvertedType">
|
---|
46 | <xsl:param name="ifname" />
|
---|
47 | <xsl:param name="methodname" />
|
---|
48 | <xsl:param name="type" />
|
---|
49 | <xsl:choose>
|
---|
50 | <xsl:when test="$type='wstring'">String</xsl:when>
|
---|
51 | <xsl:when test="$type='uuid'">String</xsl:when>
|
---|
52 | <xsl:when test="$type='boolean'">Boolean</xsl:when>
|
---|
53 | <xsl:when test="$type='unsigned long'">UnsignedInt</xsl:when>
|
---|
54 | <xsl:when test="$type='double'">Double</xsl:when>
|
---|
55 | <xsl:when test="$type='float'">Float</xsl:when>
|
---|
56 | <xsl:when test="$type='long'">Int</xsl:when>
|
---|
57 | <xsl:when test="$type='long long'">Long</xsl:when>
|
---|
58 | <xsl:when test="$type='short'">Short</xsl:when>
|
---|
59 | <xsl:when test="$type='unsigned short'">UnsignedShort</xsl:when>
|
---|
60 | <xsl:when test="$type='unsigned long long'">UnsignedLong</xsl:when>
|
---|
61 | <xsl:when test="$type='result'">UnsignedInt</xsl:when>
|
---|
62 | <xsl:when test="$type='octet'">Octet</xsl:when>
|
---|
63 | <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
|
---|
64 | <xsl:otherwise><xsl:value-of select="$type" /></xsl:otherwise>
|
---|
65 | </xsl:choose>
|
---|
66 | </xsl:template>
|
---|
67 |
|
---|
68 | <xsl:template name="emitOutParam">
|
---|
69 | <xsl:param name="ifname" />
|
---|
70 | <xsl:param name="methodname" />
|
---|
71 | <xsl:param name="type" />
|
---|
72 | <xsl:param name="value" />
|
---|
73 | <xsl:param name="safearray" />
|
---|
74 |
|
---|
75 | <xsl:choose>
|
---|
76 | <xsl:when test="$type='octet' and $safearray">
|
---|
77 | <xsl:value-of select="concat('self.mgr.decodebase64(',$value,')')" />
|
---|
78 | </xsl:when>
|
---|
79 | <xsl:otherwise>
|
---|
80 | <xsl:call-template name="emitConvertedType">
|
---|
81 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
82 | <xsl:with-param name="methodname" select="$methodname" />
|
---|
83 | <xsl:with-param name="type" select="$type" />
|
---|
84 | </xsl:call-template>
|
---|
85 | <xsl:text>(</xsl:text>
|
---|
86 | <xsl:text>self.mgr,</xsl:text>
|
---|
87 | <xsl:value-of select="$value"/>
|
---|
88 | <xsl:if test="$safearray='yes'">
|
---|
89 | <xsl:value-of select="', True'"/>
|
---|
90 | </xsl:if>
|
---|
91 | <xsl:text>)</xsl:text>
|
---|
92 | </xsl:otherwise>
|
---|
93 | </xsl:choose>
|
---|
94 | </xsl:template>
|
---|
95 |
|
---|
96 |
|
---|
97 | <xsl:template name="emitGetAttribute">
|
---|
98 | <xsl:param name="ifname" />
|
---|
99 | <xsl:param name="attrname" />
|
---|
100 | <xsl:param name="attrtype" />
|
---|
101 | <xsl:param name="attrsafearray" />
|
---|
102 | <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
|
---|
103 | def <xsl:value-of select="$fname"/>(self):
|
---|
104 | req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
|
---|
105 | req._this=self.handle
|
---|
106 | val=self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
|
---|
107 | <xsl:text>return </xsl:text>
|
---|
108 | <xsl:call-template name="emitOutParam">
|
---|
109 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
110 | <xsl:with-param name="methodname" select="@name" />
|
---|
111 | <xsl:with-param name="type" select="$attrtype" />
|
---|
112 | <xsl:with-param name="value" select="concat('val.','_returnval')" />
|
---|
113 | <xsl:with-param name="safearray" select="$attrsafearray"/>
|
---|
114 | </xsl:call-template>
|
---|
115 | </xsl:template>
|
---|
116 |
|
---|
117 | <xsl:template name="emitSetAttribute">
|
---|
118 | <xsl:param name="ifname" />
|
---|
119 | <xsl:param name="attrname" />
|
---|
120 | <xsl:param name="attrtype" />
|
---|
121 | <xsl:param name="attrsafearray" />
|
---|
122 | <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
|
---|
123 | def <xsl:value-of select="$fname"/>(self, value):
|
---|
124 | req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
|
---|
125 | req._this=self.handle
|
---|
126 | if type(value) in [int, bool, basestring, str<xsl:if test="$attrsafearray='yes'">, tuple, list</xsl:if>]:
|
---|
127 | req._<xsl:value-of select="$attrname"/> = value
|
---|
128 | else:
|
---|
129 | req._<xsl:value-of select="$attrname"/> = value.handle
|
---|
130 | self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
|
---|
131 | </xsl:template>
|
---|
132 |
|
---|
133 | <xsl:template name="collection">
|
---|
134 | <xsl:variable name="cname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
135 | <xsl:variable name="ename"><xsl:value-of select="@type" /></xsl:variable>
|
---|
136 | class <xsl:value-of select="$cname"/>:
|
---|
137 | def __init__(self, mgr, array):
|
---|
138 | self.array = array
|
---|
139 | self.mgr = mgr
|
---|
140 |
|
---|
141 | def __next(self):
|
---|
142 | return self.array.__next()
|
---|
143 |
|
---|
144 | def __size(self):
|
---|
145 | return self.array._array.__size()
|
---|
146 |
|
---|
147 | def __len__(self):
|
---|
148 | return self.array._array.__len__()
|
---|
149 |
|
---|
150 | def __getitem__(self, index):
|
---|
151 | return <xsl:value-of select="$ename"/>(self.mgr, self.array._array[index])
|
---|
152 |
|
---|
153 | </xsl:template>
|
---|
154 |
|
---|
155 |
|
---|
156 | <xsl:template name="computeExtends">
|
---|
157 | <xsl:param name="base" />
|
---|
158 |
|
---|
159 | <xsl:choose>
|
---|
160 | <xsl:when test="($base = '$unknown')">
|
---|
161 | <xsl:value-of select="'IUnknown'"/>
|
---|
162 | </xsl:when>
|
---|
163 | <xsl:when test="($base = '$errorinfo') ">
|
---|
164 | <xsl:value-of select="'IUnknown'"/>
|
---|
165 | </xsl:when>
|
---|
166 | <xsl:otherwise>
|
---|
167 | <xsl:value-of select="$base"/>
|
---|
168 | </xsl:otherwise>
|
---|
169 | </xsl:choose>
|
---|
170 | </xsl:template>
|
---|
171 |
|
---|
172 | <xsl:template name="interface">
|
---|
173 | <xsl:variable name="base">
|
---|
174 | <xsl:call-template name="computeExtends">
|
---|
175 | <xsl:with-param name="base" select="@extends" />
|
---|
176 | </xsl:call-template>
|
---|
177 | </xsl:variable>
|
---|
178 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
179 |
|
---|
180 | class <xsl:value-of select="$ifname"/>(<xsl:value-of select="$base" />):
|
---|
181 | def __init__(self, mgr, handle, isarray = False):
|
---|
182 | self.mgr = mgr
|
---|
183 | if handle is None:
|
---|
184 | raise Exception("bad handle: "+str(handle))
|
---|
185 | self.handle = handle
|
---|
186 | self.isarray = isarray
|
---|
187 | if self.isarray:
|
---|
188 | for strHnd in handle:
|
---|
189 | mgr.register(strHnd)
|
---|
190 | else:
|
---|
191 | mgr.register(self.handle)
|
---|
192 |
|
---|
193 | def __del__(self):
|
---|
194 | self.releaseRemote()
|
---|
195 |
|
---|
196 | def releaseRemote(self):
|
---|
197 | try:
|
---|
198 | if self.handle is not None:
|
---|
199 | if self.isarray:
|
---|
200 | for strHnd in self.handle:
|
---|
201 | self.mgr.unregister(strHnd)
|
---|
202 | else:
|
---|
203 | self.mgr.unregister(self.handle)
|
---|
204 | self.handle = None;
|
---|
205 | except:
|
---|
206 | pass
|
---|
207 |
|
---|
208 | def __next(self):
|
---|
209 | if self.isarray:
|
---|
210 | return self.handle.__next()
|
---|
211 | raise TypeError("iteration over non-sequence")
|
---|
212 |
|
---|
213 | def __size(self):
|
---|
214 | if self.isarray:
|
---|
215 | return self.handle.__size()
|
---|
216 | raise TypeError("iteration over non-sequence")
|
---|
217 |
|
---|
218 | def __len__(self):
|
---|
219 | if self.isarray:
|
---|
220 | return self.handle.__len__()
|
---|
221 | raise TypeError("iteration over non-sequence")
|
---|
222 |
|
---|
223 | def __getitem__(self, index):
|
---|
224 | if self.isarray:
|
---|
225 | return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
|
---|
226 | raise TypeError("iteration over non-sequence")
|
---|
227 |
|
---|
228 | def __str__(self):
|
---|
229 | if self.isarray:
|
---|
230 | return str(self.handle)
|
---|
231 | else:
|
---|
232 | return self.handle
|
---|
233 |
|
---|
234 | def isValid(self):
|
---|
235 | return self.handle != None and self.handle != ''
|
---|
236 |
|
---|
237 | def __getattr__(self,name):
|
---|
238 | hndl = <xsl:value-of select="$ifname" />._Attrs_.get(name, None)
|
---|
239 | if hndl != None:
|
---|
240 | if hndl[0] != None:
|
---|
241 | return hndl[0](self)
|
---|
242 | else:
|
---|
243 | raise AttributeError
|
---|
244 | else:
|
---|
245 | return <xsl:value-of select="$base" />.__getattr__(self, name)
|
---|
246 |
|
---|
247 | def __setattr__(self, name, val):
|
---|
248 | hndl = <xsl:value-of select="$ifname" />._Attrs_.get(name, None)
|
---|
249 | if (hndl != None and hndl[1] != None):
|
---|
250 | hndl[1](self,val)
|
---|
251 | else:
|
---|
252 | self.__dict__[name] = val
|
---|
253 |
|
---|
254 | <xsl:for-each select="method">
|
---|
255 | <xsl:call-template name="method"/>
|
---|
256 | </xsl:for-each>
|
---|
257 |
|
---|
258 | <xsl:for-each select="attribute">
|
---|
259 | <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
260 | <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
|
---|
261 | <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
|
---|
262 | <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
|
---|
263 | <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
|
---|
264 | <xsl:choose>
|
---|
265 | <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
|
---|
266 | <xsl:comment><xsl:value-of select="concat('skipping attribute ', $attrtype, ' for it is of a suppressed type')" /></xsl:comment>
|
---|
267 | </xsl:when>
|
---|
268 | <xsl:otherwise>
|
---|
269 | <xsl:choose>
|
---|
270 | <xsl:when test="@readonly='yes'">
|
---|
271 | <xsl:comment> readonly attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
272 | </xsl:when>
|
---|
273 | <xsl:otherwise>
|
---|
274 | <xsl:comment> read/write attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
275 | </xsl:otherwise>
|
---|
276 | </xsl:choose>
|
---|
277 | <!-- aa) get method: emit request and result -->
|
---|
278 | <xsl:call-template name="emitGetAttribute">
|
---|
279 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
280 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
281 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
282 | <xsl:with-param name="attrsafearray" select="$attrsafearray" />
|
---|
283 | </xsl:call-template>
|
---|
284 | <!-- bb) emit a set method if the attribute is read/write -->
|
---|
285 | <xsl:if test="not($attrreadonly='yes')">
|
---|
286 | <xsl:call-template name="emitSetAttribute">
|
---|
287 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
288 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
289 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
290 | <xsl:with-param name="attrsafearray" select="$attrsafearray" />
|
---|
291 | </xsl:call-template>
|
---|
292 | </xsl:if>
|
---|
293 | </xsl:otherwise>
|
---|
294 | </xsl:choose>
|
---|
295 | </xsl:for-each>
|
---|
296 |
|
---|
297 |
|
---|
298 | _Attrs_=<xsl:text>{</xsl:text>
|
---|
299 | <xsl:for-each select="attribute">
|
---|
300 | <xsl:if test="not( @type=($G_setSuppressedInterfaces/@name) )">
|
---|
301 | <xsl:text> </xsl:text>'<xsl:value-of select="@name"/>'<xsl:text>:[</xsl:text>
|
---|
302 | <xsl:call-template name="makeGetterName">
|
---|
303 | <xsl:with-param name="attrname" select="@name"/>
|
---|
304 | </xsl:call-template>
|
---|
305 | <xsl:text>,</xsl:text>
|
---|
306 | <xsl:choose>
|
---|
307 | <xsl:when test="@readonly='yes'">
|
---|
308 | <xsl:text>None</xsl:text>
|
---|
309 | </xsl:when>
|
---|
310 | <xsl:otherwise>
|
---|
311 | <xsl:call-template name="makeSetterName">
|
---|
312 | <xsl:with-param name="attrname" select="@name"/>
|
---|
313 | </xsl:call-template>,
|
---|
314 | </xsl:otherwise>
|
---|
315 | </xsl:choose>
|
---|
316 | <xsl:text>]</xsl:text>
|
---|
317 | <xsl:if test="not(position()=last())"><xsl:text>, </xsl:text></xsl:if>
|
---|
318 | </xsl:if>
|
---|
319 | </xsl:for-each>
|
---|
320 | <xsl:text>}</xsl:text>
|
---|
321 | </xsl:template>
|
---|
322 |
|
---|
323 | <xsl:template name="interfacestruct">
|
---|
324 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
325 | class <xsl:value-of select="$ifname"/>:
|
---|
326 | def __init__(self, mgr, handle, isarray = False):
|
---|
327 | self.mgr = mgr
|
---|
328 | self.isarray = isarray
|
---|
329 | if isarray:
|
---|
330 | self.handle = handle
|
---|
331 | else:
|
---|
332 | <xsl:for-each select="attribute">
|
---|
333 | self.<xsl:value-of select="@name"/> = <xsl:call-template name="emitConvertedType">
|
---|
334 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
335 | <xsl:with-param name="methodname" select="''" />
|
---|
336 | <xsl:with-param name="type" select="@type" />
|
---|
337 | </xsl:call-template>(self.mgr, handle._<xsl:value-of select="@name"/>)
|
---|
338 | </xsl:for-each>
|
---|
339 | pass
|
---|
340 |
|
---|
341 | <!-- also do getters/setters -->
|
---|
342 | <xsl:for-each select="attribute">
|
---|
343 | def <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>(self):
|
---|
344 | return self.<xsl:value-of select="@name"/>
|
---|
345 |
|
---|
346 | def <xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>(self):
|
---|
347 | raise Error('setters not supported')
|
---|
348 | </xsl:for-each>
|
---|
349 |
|
---|
350 | def __next(self):
|
---|
351 | if self.isarray:
|
---|
352 | return self.handle.__next()
|
---|
353 | raise TypeError("iteration over non-sequence")
|
---|
354 |
|
---|
355 | def __size(self):
|
---|
356 | if self.isarray:
|
---|
357 | return self.handle.__size()
|
---|
358 | raise TypeError("iteration over non-sequence")
|
---|
359 |
|
---|
360 | def __len__(self):
|
---|
361 | if self.isarray:
|
---|
362 | return self.handle.__len__()
|
---|
363 | raise TypeError("iteration over non-sequence")
|
---|
364 |
|
---|
365 | def __getitem__(self, index):
|
---|
366 | if self.isarray:
|
---|
367 | return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
|
---|
368 | raise TypeError("iteration over non-sequence")
|
---|
369 | <xsl:call-template name="xsltprocNewlineOutputHack"/>
|
---|
370 | </xsl:template>
|
---|
371 |
|
---|
372 | <xsl:template name="convertInParam">
|
---|
373 | <xsl:param name="type" />
|
---|
374 | <xsl:param name="safearray" />
|
---|
375 | <xsl:param name="arg" />
|
---|
376 |
|
---|
377 | <xsl:choose>
|
---|
378 | <xsl:when test="$type='octet' and $safearray">
|
---|
379 | <xsl:value-of select="concat('self.mgr.encodebase64(',$arg,')')" />
|
---|
380 | </xsl:when>
|
---|
381 | <xsl:otherwise>
|
---|
382 | <xsl:value-of select="$arg" />
|
---|
383 | </xsl:otherwise>
|
---|
384 | </xsl:choose>
|
---|
385 | </xsl:template>
|
---|
386 |
|
---|
387 | <xsl:template name="genreq">
|
---|
388 | <xsl:text>req=</xsl:text><xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>RequestMsg()
|
---|
389 | req._this=self.handle
|
---|
390 | <xsl:for-each select="param[@dir='in']">
|
---|
391 | req._<xsl:value-of select="@name" />=<xsl:call-template name="convertInParam">
|
---|
392 | <xsl:with-param name="type" select="@type" />
|
---|
393 | <xsl:with-param name="safearray" select="@safearray" />
|
---|
394 | <xsl:with-param name="arg" select="concat('_arg_', @name)" />
|
---|
395 | </xsl:call-template>
|
---|
396 | </xsl:for-each>
|
---|
397 | val=self.mgr.getPort().<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
|
---|
398 | <!-- return needs to be the first one -->
|
---|
399 | return <xsl:for-each select="param[@dir='return']">
|
---|
400 | <xsl:call-template name="emitOutParam">
|
---|
401 | <xsl:with-param name="ifname" select="../@name" />
|
---|
402 | <xsl:with-param name="methodname" select="@name" />
|
---|
403 | <xsl:with-param name="type" select="@type" />
|
---|
404 | <xsl:with-param name="value" select="concat('val.','_returnval')" />
|
---|
405 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
406 | </xsl:call-template>
|
---|
407 | <xsl:if test="../param[@dir='out']">
|
---|
408 | <xsl:text>, </xsl:text>
|
---|
409 | </xsl:if>
|
---|
410 | </xsl:for-each>
|
---|
411 | <xsl:for-each select="param[@dir='out']">
|
---|
412 | <xsl:if test="not(position()=1)">
|
---|
413 | <xsl:text>, </xsl:text>
|
---|
414 | </xsl:if>
|
---|
415 | <xsl:call-template name="emitOutParam">
|
---|
416 | <xsl:with-param name="ifname" select="../@name" />
|
---|
417 | <xsl:with-param name="methodname" select="@name" />
|
---|
418 | <xsl:with-param name="type" select="@type" />
|
---|
419 | <xsl:with-param name="value" select="concat('val._',@name)" />
|
---|
420 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
421 | </xsl:call-template>
|
---|
422 | </xsl:for-each>
|
---|
423 | <xsl:text> </xsl:text>
|
---|
424 | </xsl:template>
|
---|
425 |
|
---|
426 | <xsl:template name="method" >
|
---|
427 | def <xsl:value-of select="@name"/><xsl:text>(self</xsl:text>
|
---|
428 | <xsl:for-each select="param[@dir='in']">
|
---|
429 | <xsl:text>, </xsl:text>
|
---|
430 | <xsl:value-of select="concat('_arg_',@name)"/>
|
---|
431 | </xsl:for-each><xsl:text>): </xsl:text>
|
---|
432 | <xsl:call-template name="genreq"/>
|
---|
433 | </xsl:template>
|
---|
434 |
|
---|
435 | <xsl:template name="makeConstantName" >
|
---|
436 | <xsl:choose>
|
---|
437 | <!-- special case for reserved word, maybe will need more in the future -->
|
---|
438 | <xsl:when test="@name='None'">
|
---|
439 | <xsl:text>_None</xsl:text>
|
---|
440 | </xsl:when>
|
---|
441 | <xsl:otherwise>
|
---|
442 | <xsl:value-of select="@name"/>
|
---|
443 | </xsl:otherwise>
|
---|
444 | </xsl:choose>
|
---|
445 | </xsl:template>
|
---|
446 |
|
---|
447 | <xsl:template name="enum">
|
---|
448 | class <xsl:value-of select="@name"/>:
|
---|
449 | def __init__(self,mgr,handle):
|
---|
450 | self.mgr=mgr
|
---|
451 | if isinstance(handle,basestring):
|
---|
452 | self.handle=<xsl:value-of select="@name"/>._ValueMap[handle]
|
---|
453 | else:
|
---|
454 | self.handle=handle
|
---|
455 |
|
---|
456 | def __eq__(self,other):
|
---|
457 | if isinstance(other,<xsl:value-of select="@name"/>):
|
---|
458 | return self.handle == other.handle
|
---|
459 | if isinstance(other,int):
|
---|
460 | return self.handle == other
|
---|
461 | if isinstance(other,basestring):
|
---|
462 | return str(self) == other
|
---|
463 | return False
|
---|
464 |
|
---|
465 | def __ne__(self,other):
|
---|
466 | if isinstance(other,<xsl:value-of select="@name"/>):
|
---|
467 | return self.handle != other.handle
|
---|
468 | if isinstance(other,int):
|
---|
469 | return self.handle != other
|
---|
470 | if isinstance(other,basestring):
|
---|
471 | return str(self) != other
|
---|
472 | return True
|
---|
473 |
|
---|
474 | def __str__(self):
|
---|
475 | return <xsl:value-of select="@name"/>._NameMap[self.handle]
|
---|
476 |
|
---|
477 | def __int__(self):
|
---|
478 | return self.handle
|
---|
479 |
|
---|
480 | _NameMap={<xsl:for-each select="const">
|
---|
481 | <xsl:value-of select="@value"/>:'<xsl:value-of select="@name"/>'<xsl:if test="not(position()=last())">,</xsl:if>
|
---|
482 | </xsl:for-each>}
|
---|
483 | _ValueMap={<xsl:for-each select="const">
|
---|
484 | '<xsl:value-of select="@name"/>':<xsl:value-of select="@value"/><xsl:if test="not(position()=last())">,</xsl:if>
|
---|
485 | </xsl:for-each>}
|
---|
486 |
|
---|
487 | <xsl:for-each select="const"><xsl:text> </xsl:text><xsl:call-template name="makeConstantName"><xsl:with-param name="name" select="@name"/></xsl:call-template>=<xsl:value-of select="@value"/><xsl:text>
</xsl:text>
|
---|
488 | </xsl:for-each>
|
---|
489 | </xsl:template>
|
---|
490 |
|
---|
491 | <xsl:template match="/">
|
---|
492 | <xsl:text># Copyright (C) 2008-2022 Oracle Corporation
|
---|
493 | #
|
---|
494 | # This file is part of a free software library; you can redistribute
|
---|
495 | # it and/or modify it under the terms of the GNU Lesser General
|
---|
496 | # Public License version 2.1 as published by the Free Software
|
---|
497 | # Foundation and shipped in the "COPYING.LIB" file with this library.
|
---|
498 | # The library is distributed in the hope that it will be useful,
|
---|
499 | # but WITHOUT ANY WARRANTY of any kind.
|
---|
500 | #
|
---|
501 | # Oracle LGPL Disclaimer: For the avoidance of doubt, except that if
|
---|
502 | # any license choice other than GPL or LGPL is available it will
|
---|
503 | # apply instead, Oracle elects to use only the Lesser General Public
|
---|
504 | # License version 2.1 (LGPLv2) at this time for any software where
|
---|
505 | # a choice of LGPL license versions is made available with the
|
---|
506 | # language indicating that LGPLv2 or any later version may be used,
|
---|
507 | # or where a choice of which version of the LGPL is applied is
|
---|
508 | # otherwise unspecified.
|
---|
509 | #
|
---|
510 | # This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
|
---|
511 | #
|
---|
512 |
|
---|
513 | # Works only with ZSI 2.0 generated stubs (part of the VirtualBox SDK).
|
---|
514 | from VirtualBox_client import *
|
---|
515 |
|
---|
516 | class ObjectRefManager:
|
---|
517 | def __init__(self, sessionmgr):
|
---|
518 | self.map = {}
|
---|
519 | self.sessionmgr = sessionmgr
|
---|
520 |
|
---|
521 | def register(self, handle):
|
---|
522 | if handle == None:
|
---|
523 | return
|
---|
524 | c = self.map.get(handle,0)
|
---|
525 | c = c + 1
|
---|
526 | self.map[handle]=c
|
---|
527 |
|
---|
528 | def unregister(self, handle):
|
---|
529 | if handle == None:
|
---|
530 | return
|
---|
531 | c = self.map.get(handle,-1)
|
---|
532 | if c == -1:
|
---|
533 | raise Error('wrong refcount')
|
---|
534 | c = c - 1
|
---|
535 | if c == 0:
|
---|
536 | try:
|
---|
537 | req=IManagedObjectRef_releaseRequestMsg()
|
---|
538 | req._this=handle
|
---|
539 | self.sessionmgr.getPort().IManagedObjectRef_release(req)
|
---|
540 | except:
|
---|
541 | pass
|
---|
542 | del self.map[handle]
|
---|
543 | else:
|
---|
544 | self.map[handle] = c
|
---|
545 |
|
---|
546 | class String:
|
---|
547 | def __init__(self, mgr, handle, isarray = False):
|
---|
548 | self.handle = handle
|
---|
549 | self.mgr = mgr
|
---|
550 | self.isarray = isarray
|
---|
551 |
|
---|
552 | def __next(self):
|
---|
553 | if self.isarray:
|
---|
554 | return self.handle.__next()
|
---|
555 | raise TypeError("iteration over non-sequence")
|
---|
556 |
|
---|
557 | def __size(self):
|
---|
558 | if self.isarray:
|
---|
559 | return self.handle.__size()
|
---|
560 | raise TypeError("iteration over non-sequence")
|
---|
561 |
|
---|
562 | def __len__(self):
|
---|
563 | if self.isarray:
|
---|
564 | return self.handle.__len__()
|
---|
565 | raise TypeError("iteration over non-sequence")
|
---|
566 |
|
---|
567 | def __getitem__(self, index):
|
---|
568 | if self.isarray:
|
---|
569 | return String(self.mgr, self.handle[index])
|
---|
570 | raise TypeError("iteration over non-sequence")
|
---|
571 |
|
---|
572 | def __str__(self):
|
---|
573 | return str(self.handle)
|
---|
574 |
|
---|
575 | def __eq__(self,other):
|
---|
576 | if self.isarray:
|
---|
577 | return isinstance(other,String) and self.handle == other.handle
|
---|
578 | if isinstance(other,String):
|
---|
579 | return self.handle == other.handle
|
---|
580 | if isinstance(other,basestring):
|
---|
581 | return self.handle == other
|
---|
582 | return False
|
---|
583 |
|
---|
584 | def __ne__(self,other):
|
---|
585 | if self.isarray:
|
---|
586 | return not isinstance(other,String) or self.handle != other.handle
|
---|
587 | if isinstance(other,String):
|
---|
588 | return self.handle != other.handle
|
---|
589 | if isinstance(other,basestring):
|
---|
590 | return self.handle != other
|
---|
591 | return True
|
---|
592 |
|
---|
593 | def __add__(self,other):
|
---|
594 | return str(self.handle)+str(other)
|
---|
595 |
|
---|
596 |
|
---|
597 | class Boolean:
|
---|
598 | def __init__(self, mgr, handle, isarray = False):
|
---|
599 | self.handle = handle
|
---|
600 | if self.handle == "false":
|
---|
601 | self.handle = None
|
---|
602 | self.mgr = mgr
|
---|
603 | self.isarray = isarray
|
---|
604 |
|
---|
605 | def __str__(self):
|
---|
606 | if self.handle:
|
---|
607 | return "true"
|
---|
608 | else:
|
---|
609 | return "false"
|
---|
610 |
|
---|
611 | def __eq__(self,other):
|
---|
612 | if isinstance(other,Bool):
|
---|
613 | return self.handle == other.value
|
---|
614 | if isinstance(other,bool):
|
---|
615 | return self.handle == other
|
---|
616 | return False
|
---|
617 |
|
---|
618 | def __ne__(self,other):
|
---|
619 | if isinstance(other,Bool):
|
---|
620 | return self.handle != other.handle
|
---|
621 | if isinstance(other,bool):
|
---|
622 | return self.handle != other
|
---|
623 | return True
|
---|
624 |
|
---|
625 | def __int__(self):
|
---|
626 | if self.handle:
|
---|
627 | return 1
|
---|
628 | else:
|
---|
629 | return 0
|
---|
630 |
|
---|
631 | def __long__(self):
|
---|
632 | if self.handle:
|
---|
633 | return 1
|
---|
634 | else:
|
---|
635 | return 0
|
---|
636 |
|
---|
637 | def __nonzero__(self):
|
---|
638 | if self.handle:
|
---|
639 | return True
|
---|
640 | else:
|
---|
641 | return False
|
---|
642 |
|
---|
643 | def __next(self):
|
---|
644 | if self.isarray:
|
---|
645 | return self.handle.__next()
|
---|
646 | raise TypeError("iteration over non-sequence")
|
---|
647 |
|
---|
648 | def __size(self):
|
---|
649 | if self.isarray:
|
---|
650 | return self.handle.__size()
|
---|
651 | raise TypeError("iteration over non-sequence")
|
---|
652 |
|
---|
653 | def __len__(self):
|
---|
654 | if self.isarray:
|
---|
655 | return self.handle.__len__()
|
---|
656 | raise TypeError("iteration over non-sequence")
|
---|
657 |
|
---|
658 | def __getitem__(self, index):
|
---|
659 | if self.isarray:
|
---|
660 | return Boolean(self.mgr, self.handle[index])
|
---|
661 | raise TypeError("iteration over non-sequence")
|
---|
662 |
|
---|
663 | class Number:
|
---|
664 | def __init__(self, mgr, handle, isarray = False):
|
---|
665 | self.handle = handle
|
---|
666 | self.mgr = mgr
|
---|
667 | self.isarray = isarray
|
---|
668 |
|
---|
669 | def __next(self):
|
---|
670 | if self.isarray:
|
---|
671 | return self.handle.__next()
|
---|
672 | raise TypeError("iteration over non-sequence")
|
---|
673 |
|
---|
674 | def __size(self):
|
---|
675 | if self.isarray:
|
---|
676 | return self.handle.__size()
|
---|
677 | raise TypeError("iteration over non-sequence")
|
---|
678 |
|
---|
679 | def __len__(self):
|
---|
680 | if self.isarray:
|
---|
681 | return self.handle.__len__()
|
---|
682 | raise TypeError("iteration over non-sequence")
|
---|
683 |
|
---|
684 | def __str__(self):
|
---|
685 | return str(self.handle)
|
---|
686 |
|
---|
687 | def __int__(self):
|
---|
688 | return int(self.handle)
|
---|
689 |
|
---|
690 | def __long__(self):
|
---|
691 | return long(self.handle)
|
---|
692 |
|
---|
693 | def __float__(self):
|
---|
694 | return float(self.handle)
|
---|
695 |
|
---|
696 | def __lt__(self, other):
|
---|
697 | if self.isarray:
|
---|
698 | return NotImplemented
|
---|
699 | else:
|
---|
700 | return self.handle < other
|
---|
701 |
|
---|
702 | def __le__(self, other):
|
---|
703 | if self.isarray:
|
---|
704 | return NotImplemented
|
---|
705 | else:
|
---|
706 | return self.handle <= other
|
---|
707 |
|
---|
708 | def __eq__(self, other):
|
---|
709 | return self.handle == other
|
---|
710 |
|
---|
711 | def __ne__(self, other):
|
---|
712 | return self.handle != other
|
---|
713 |
|
---|
714 | def __gt__(self, other):
|
---|
715 | if self.isarray:
|
---|
716 | return NotImplemented
|
---|
717 | else:
|
---|
718 | return self.handle > other
|
---|
719 |
|
---|
720 | def __ge__(self, other):
|
---|
721 | if self.isarray:
|
---|
722 | return NotImplemented
|
---|
723 | else:
|
---|
724 | return self.handle >= other
|
---|
725 |
|
---|
726 | class Octet:
|
---|
727 | def __init__(self, mgr, handle, isarray = False):
|
---|
728 | self.mgr = mgr
|
---|
729 | self.isarray = isarray
|
---|
730 | if isarray:
|
---|
731 | self.handle = mgr.decodebase64(handle)
|
---|
732 | else:
|
---|
733 | raise TypeError("only octet arrays")
|
---|
734 |
|
---|
735 | def __getitem__(self, index):
|
---|
736 | return self.handle[index]
|
---|
737 |
|
---|
738 | def __str__(self):
|
---|
739 | return str(self.handle)
|
---|
740 |
|
---|
741 | def __len__(self):
|
---|
742 | return self.handle.__len__()
|
---|
743 |
|
---|
744 | class UnsignedInt(Number):
|
---|
745 | def __init__(self, mgr, handle, isarray = False):
|
---|
746 | self.handle = handle
|
---|
747 | self.mgr = mgr
|
---|
748 | self.isarray = isarray
|
---|
749 |
|
---|
750 | def __getitem__(self, index):
|
---|
751 | if self.isarray:
|
---|
752 | return UnsignedInt(self.mgr, self.handle[index])
|
---|
753 | raise TypeError("iteration over non-sequence")
|
---|
754 |
|
---|
755 |
|
---|
756 | class Int(Number):
|
---|
757 | def __init__(self, mgr, handle, isarray = False):
|
---|
758 | self.handle = handle
|
---|
759 | self.mgr = mgr
|
---|
760 | self.isarray = isarray
|
---|
761 |
|
---|
762 | def __getitem__(self, index):
|
---|
763 | if self.isarray:
|
---|
764 | return Int(self.mgr, self.handle[index])
|
---|
765 | raise TypeError("iteration over non-sequence")
|
---|
766 |
|
---|
767 | class UnsignedShort(Number):
|
---|
768 | def __init__(self, mgr, handle, isarray = False):
|
---|
769 | self.handle = handle
|
---|
770 | self.mgr = mgr
|
---|
771 | self.isarray = isarray
|
---|
772 |
|
---|
773 | def __getitem__(self, index):
|
---|
774 | if self.isarray:
|
---|
775 | return UnsignedShort(self.mgr, self.handle[index])
|
---|
776 | raise TypeError("iteration over non-sequence")
|
---|
777 |
|
---|
778 | class Short(Number):
|
---|
779 | def __init__(self, mgr, handle, isarray = False):
|
---|
780 | self.handle = handle
|
---|
781 | self.mgr = mgr
|
---|
782 | self.isarray = isarray
|
---|
783 |
|
---|
784 | def __getitem__(self, index):
|
---|
785 | if self.isarray:
|
---|
786 | return Short(self.mgr, self.handle[index])
|
---|
787 | raise TypeError("iteration over non-sequence")
|
---|
788 |
|
---|
789 | class UnsignedLong(Number):
|
---|
790 | def __init__(self, mgr, handle, isarray = False):
|
---|
791 | self.handle = handle
|
---|
792 | self.mgr = mgr
|
---|
793 | self.isarray = isarray
|
---|
794 |
|
---|
795 | def __getitem__(self, index):
|
---|
796 | if self.isarray:
|
---|
797 | return UnsignedLong(self.mgr, self.handle[index])
|
---|
798 | raise TypeError("iteration over non-sequence")
|
---|
799 |
|
---|
800 | class Long(Number):
|
---|
801 | def __init__(self, mgr, handle, isarray = False):
|
---|
802 | self.handle = handle
|
---|
803 | self.mgr = mgr
|
---|
804 | self.isarray = isarray
|
---|
805 |
|
---|
806 | def __getitem__(self, index):
|
---|
807 | if self.isarray:
|
---|
808 | return Long(self.mgr, self.handle[index])
|
---|
809 | raise TypeError("iteration over non-sequence")
|
---|
810 |
|
---|
811 | class Double(Number):
|
---|
812 | def __init__(self, mgr, handle, isarray = False):
|
---|
813 | self.handle = handle
|
---|
814 | self.mgr = mgr
|
---|
815 | self.isarray = isarray
|
---|
816 |
|
---|
817 | def __getitem__(self, index):
|
---|
818 | if self.isarray:
|
---|
819 | return Double(self.mgr, self.handle[index])
|
---|
820 | raise TypeError("iteration over non-sequence")
|
---|
821 |
|
---|
822 | class Float(Number):
|
---|
823 | def __init__(self, mgr, handle, isarray = False):
|
---|
824 | self.handle = handle
|
---|
825 | self.mgr = mgr
|
---|
826 | self.isarray = isarray
|
---|
827 |
|
---|
828 | def __getitem__(self, index):
|
---|
829 | if self.isarray:
|
---|
830 | return Float(self.mgr, self.handle[index])
|
---|
831 | raise TypeError("iteration over non-sequence")
|
---|
832 |
|
---|
833 | class IUnknown:
|
---|
834 | def __init__(self, mgr, handle, isarray = False):
|
---|
835 | self.handle = handle
|
---|
836 | self.mgr = mgr
|
---|
837 | self.isarray = isarray
|
---|
838 |
|
---|
839 | def __nonzero__(self):
|
---|
840 | if self.handle != "":
|
---|
841 | return True
|
---|
842 | else:
|
---|
843 | return False
|
---|
844 |
|
---|
845 | def __next(self):
|
---|
846 | if self.isarray:
|
---|
847 | return self.handle.__next()
|
---|
848 | raise TypeError("iteration over non-sequence")
|
---|
849 |
|
---|
850 | def __size(self):
|
---|
851 | if self.isarray:
|
---|
852 | return self.handle.__size()
|
---|
853 | raise TypeError("iteration over non-sequence")
|
---|
854 |
|
---|
855 | def __len__(self):
|
---|
856 | if self.isarray:
|
---|
857 | return self.handle.__len__()
|
---|
858 | raise TypeError("iteration over non-sequence")
|
---|
859 |
|
---|
860 | def __getitem__(self, index):
|
---|
861 | if self.isarray:
|
---|
862 | return IUnknown(self.mgr, self.handle[index])
|
---|
863 | raise TypeError("iteration over non-sequence")
|
---|
864 |
|
---|
865 | def __str__(self):
|
---|
866 | return str(self.handle)
|
---|
867 |
|
---|
868 | def __eq__(self, other):
|
---|
869 | return self.handle == other
|
---|
870 |
|
---|
871 | def __ne__(self, other):
|
---|
872 | return self.handle != other
|
---|
873 |
|
---|
874 | def __getattr__(self,attr):
|
---|
875 | if self.__class__.__dict__.get(attr) != None:
|
---|
876 | return self.__class__.__dict__.get(attr)
|
---|
877 | if self.__dict__.get(attr) != None:
|
---|
878 | return self.__dict__.get(attr)
|
---|
879 | raise AttributeError
|
---|
880 |
|
---|
881 | </xsl:text>
|
---|
882 | <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
|
---|
883 | <xsl:call-template name="interface"/>
|
---|
884 | </xsl:for-each>
|
---|
885 | <xsl:for-each select="//interface[@wsmap='struct']">
|
---|
886 | <xsl:call-template name="interfacestruct"/>
|
---|
887 | </xsl:for-each>
|
---|
888 | <xsl:for-each select="//enum">
|
---|
889 | <xsl:call-template name="enum"/>
|
---|
890 | </xsl:for-each>
|
---|
891 | <xsl:text>
|
---|
892 |
|
---|
893 | import base64
|
---|
894 |
|
---|
895 | class IWebsessionManager2(IWebsessionManager, ObjectRefManager):
|
---|
896 | def __init__(self, url):
|
---|
897 | self.url = url
|
---|
898 | self.port = None
|
---|
899 | self.handle = None
|
---|
900 | self.mgr = self
|
---|
901 | ObjectRefManager.__init__(self, self.mgr)
|
---|
902 |
|
---|
903 | def getPort(self):
|
---|
904 | if self.port is None:
|
---|
905 | try:
|
---|
906 | self.port = vboxServiceLocator().getvboxPortType(self.url)
|
---|
907 | except:
|
---|
908 | self.port = vboxServiceLocator().getvboxServicePort(self.url)
|
---|
909 | return self.port
|
---|
910 |
|
---|
911 | def decodebase64(self, str):
|
---|
912 | return base64.decodestring(str)
|
---|
913 |
|
---|
914 | def encodebase64(self, str):
|
---|
915 | return base64.encodestring(str)
|
---|
916 | </xsl:text>
|
---|
917 | </xsl:template>
|
---|
918 |
|
---|
919 | </xsl:stylesheet>
|
---|