VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/websrv-python.xsl@ 106378

Last change on this file since 106378 was 106065, checked in by vboxsync, 2 months ago

Manual copyright year updates.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette