VirtualBox

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

Last change on this file since 101359 was 98108, checked in by vboxsync, 2 years ago

Manual (C) year updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 29.5 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-2023 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>
136class <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
180class <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>,&#10;</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>
325class <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>&#10;&#10;</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>):&#10; </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">
448class <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>&#xa;</xsl:text>
488</xsl:for-each>
489</xsl:template>
490
491<xsl:template match="/">
492<xsl:text># Copyright (C) 2008-2023 Oracle and/or its affiliates.
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# SPDX-License-Identifier: LGPL-2.1-only
511#
512
513#
514# This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
515#
516
517# Works only with ZSI 2.0 generated stubs (part of the VirtualBox SDK).
518from VirtualBox_client import *
519
520class ObjectRefManager:
521 def __init__(self, sessionmgr):
522 self.map = {}
523 self.sessionmgr = sessionmgr
524
525 def register(self, handle):
526 if handle == None:
527 return
528 c = self.map.get(handle,0)
529 c = c + 1
530 self.map[handle]=c
531
532 def unregister(self, handle):
533 if handle == None:
534 return
535 c = self.map.get(handle,-1)
536 if c == -1:
537 raise Error('wrong refcount')
538 c = c - 1
539 if c == 0:
540 try:
541 req=IManagedObjectRef_releaseRequestMsg()
542 req._this=handle
543 self.sessionmgr.getPort().IManagedObjectRef_release(req)
544 except:
545 pass
546 del self.map[handle]
547 else:
548 self.map[handle] = c
549
550class String:
551 def __init__(self, mgr, handle, isarray = False):
552 self.handle = handle
553 self.mgr = mgr
554 self.isarray = isarray
555
556 def __next(self):
557 if self.isarray:
558 return self.handle.__next()
559 raise TypeError("iteration over non-sequence")
560
561 def __size(self):
562 if self.isarray:
563 return self.handle.__size()
564 raise TypeError("iteration over non-sequence")
565
566 def __len__(self):
567 if self.isarray:
568 return self.handle.__len__()
569 raise TypeError("iteration over non-sequence")
570
571 def __getitem__(self, index):
572 if self.isarray:
573 return String(self.mgr, self.handle[index])
574 raise TypeError("iteration over non-sequence")
575
576 def __str__(self):
577 return str(self.handle)
578
579 def __eq__(self,other):
580 if self.isarray:
581 return isinstance(other,String) and self.handle == other.handle
582 if isinstance(other,String):
583 return self.handle == other.handle
584 if isinstance(other,basestring):
585 return self.handle == other
586 return False
587
588 def __ne__(self,other):
589 if self.isarray:
590 return not isinstance(other,String) or self.handle != other.handle
591 if isinstance(other,String):
592 return self.handle != other.handle
593 if isinstance(other,basestring):
594 return self.handle != other
595 return True
596
597 def __add__(self,other):
598 return str(self.handle)+str(other)
599
600
601class Boolean:
602 def __init__(self, mgr, handle, isarray = False):
603 self.handle = handle
604 if self.handle == "false":
605 self.handle = None
606 self.mgr = mgr
607 self.isarray = isarray
608
609 def __str__(self):
610 if self.handle:
611 return "true"
612 else:
613 return "false"
614
615 def __eq__(self,other):
616 if isinstance(other,Bool):
617 return self.handle == other.value
618 if isinstance(other,bool):
619 return self.handle == other
620 return False
621
622 def __ne__(self,other):
623 if isinstance(other,Bool):
624 return self.handle != other.handle
625 if isinstance(other,bool):
626 return self.handle != other
627 return True
628
629 def __int__(self):
630 if self.handle:
631 return 1
632 else:
633 return 0
634
635 def __long__(self):
636 if self.handle:
637 return 1
638 else:
639 return 0
640
641 def __nonzero__(self):
642 if self.handle:
643 return True
644 else:
645 return False
646
647 def __next(self):
648 if self.isarray:
649 return self.handle.__next()
650 raise TypeError("iteration over non-sequence")
651
652 def __size(self):
653 if self.isarray:
654 return self.handle.__size()
655 raise TypeError("iteration over non-sequence")
656
657 def __len__(self):
658 if self.isarray:
659 return self.handle.__len__()
660 raise TypeError("iteration over non-sequence")
661
662 def __getitem__(self, index):
663 if self.isarray:
664 return Boolean(self.mgr, self.handle[index])
665 raise TypeError("iteration over non-sequence")
666
667class Number:
668 def __init__(self, mgr, handle, isarray = False):
669 self.handle = handle
670 self.mgr = mgr
671 self.isarray = isarray
672
673 def __next(self):
674 if self.isarray:
675 return self.handle.__next()
676 raise TypeError("iteration over non-sequence")
677
678 def __size(self):
679 if self.isarray:
680 return self.handle.__size()
681 raise TypeError("iteration over non-sequence")
682
683 def __len__(self):
684 if self.isarray:
685 return self.handle.__len__()
686 raise TypeError("iteration over non-sequence")
687
688 def __str__(self):
689 return str(self.handle)
690
691 def __int__(self):
692 return int(self.handle)
693
694 def __long__(self):
695 return long(self.handle)
696
697 def __float__(self):
698 return float(self.handle)
699
700 def __lt__(self, other):
701 if self.isarray:
702 return NotImplemented
703 else:
704 return self.handle &lt; other
705
706 def __le__(self, other):
707 if self.isarray:
708 return NotImplemented
709 else:
710 return self.handle &lt;= other
711
712 def __eq__(self, other):
713 return self.handle == other
714
715 def __ne__(self, other):
716 return self.handle != other
717
718 def __gt__(self, other):
719 if self.isarray:
720 return NotImplemented
721 else:
722 return self.handle &gt; other
723
724 def __ge__(self, other):
725 if self.isarray:
726 return NotImplemented
727 else:
728 return self.handle &gt;= other
729
730class Octet:
731 def __init__(self, mgr, handle, isarray = False):
732 self.mgr = mgr
733 self.isarray = isarray
734 if isarray:
735 self.handle = mgr.decodebase64(handle)
736 else:
737 raise TypeError("only octet arrays")
738
739 def __getitem__(self, index):
740 return self.handle[index]
741
742 def __str__(self):
743 return str(self.handle)
744
745 def __len__(self):
746 return self.handle.__len__()
747
748class UnsignedInt(Number):
749 def __init__(self, mgr, handle, isarray = False):
750 self.handle = handle
751 self.mgr = mgr
752 self.isarray = isarray
753
754 def __getitem__(self, index):
755 if self.isarray:
756 return UnsignedInt(self.mgr, self.handle[index])
757 raise TypeError("iteration over non-sequence")
758
759
760class Int(Number):
761 def __init__(self, mgr, handle, isarray = False):
762 self.handle = handle
763 self.mgr = mgr
764 self.isarray = isarray
765
766 def __getitem__(self, index):
767 if self.isarray:
768 return Int(self.mgr, self.handle[index])
769 raise TypeError("iteration over non-sequence")
770
771class UnsignedShort(Number):
772 def __init__(self, mgr, handle, isarray = False):
773 self.handle = handle
774 self.mgr = mgr
775 self.isarray = isarray
776
777 def __getitem__(self, index):
778 if self.isarray:
779 return UnsignedShort(self.mgr, self.handle[index])
780 raise TypeError("iteration over non-sequence")
781
782class Short(Number):
783 def __init__(self, mgr, handle, isarray = False):
784 self.handle = handle
785 self.mgr = mgr
786 self.isarray = isarray
787
788 def __getitem__(self, index):
789 if self.isarray:
790 return Short(self.mgr, self.handle[index])
791 raise TypeError("iteration over non-sequence")
792
793class UnsignedLong(Number):
794 def __init__(self, mgr, handle, isarray = False):
795 self.handle = handle
796 self.mgr = mgr
797 self.isarray = isarray
798
799 def __getitem__(self, index):
800 if self.isarray:
801 return UnsignedLong(self.mgr, self.handle[index])
802 raise TypeError("iteration over non-sequence")
803
804class Long(Number):
805 def __init__(self, mgr, handle, isarray = False):
806 self.handle = handle
807 self.mgr = mgr
808 self.isarray = isarray
809
810 def __getitem__(self, index):
811 if self.isarray:
812 return Long(self.mgr, self.handle[index])
813 raise TypeError("iteration over non-sequence")
814
815class Double(Number):
816 def __init__(self, mgr, handle, isarray = False):
817 self.handle = handle
818 self.mgr = mgr
819 self.isarray = isarray
820
821 def __getitem__(self, index):
822 if self.isarray:
823 return Double(self.mgr, self.handle[index])
824 raise TypeError("iteration over non-sequence")
825
826class Float(Number):
827 def __init__(self, mgr, handle, isarray = False):
828 self.handle = handle
829 self.mgr = mgr
830 self.isarray = isarray
831
832 def __getitem__(self, index):
833 if self.isarray:
834 return Float(self.mgr, self.handle[index])
835 raise TypeError("iteration over non-sequence")
836
837class IUnknown:
838 def __init__(self, mgr, handle, isarray = False):
839 self.handle = handle
840 self.mgr = mgr
841 self.isarray = isarray
842
843 def __nonzero__(self):
844 if self.handle != "":
845 return True
846 else:
847 return False
848
849 def __next(self):
850 if self.isarray:
851 return self.handle.__next()
852 raise TypeError("iteration over non-sequence")
853
854 def __size(self):
855 if self.isarray:
856 return self.handle.__size()
857 raise TypeError("iteration over non-sequence")
858
859 def __len__(self):
860 if self.isarray:
861 return self.handle.__len__()
862 raise TypeError("iteration over non-sequence")
863
864 def __getitem__(self, index):
865 if self.isarray:
866 return IUnknown(self.mgr, self.handle[index])
867 raise TypeError("iteration over non-sequence")
868
869 def __str__(self):
870 return str(self.handle)
871
872 def __eq__(self, other):
873 return self.handle == other
874
875 def __ne__(self, other):
876 return self.handle != other
877
878 def __getattr__(self,attr):
879 if self.__class__.__dict__.get(attr) != None:
880 return self.__class__.__dict__.get(attr)
881 if self.__dict__.get(attr) != None:
882 return self.__dict__.get(attr)
883 raise AttributeError
884
885</xsl:text>
886 <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
887 <xsl:call-template name="interface"/>
888 </xsl:for-each>
889 <xsl:for-each select="//interface[@wsmap='struct']">
890 <xsl:call-template name="interfacestruct"/>
891 </xsl:for-each>
892 <xsl:for-each select="//enum">
893 <xsl:call-template name="enum"/>
894 </xsl:for-each>
895 <xsl:text>
896
897import base64
898
899class IWebsessionManager2(IWebsessionManager, ObjectRefManager):
900 def __init__(self, url):
901 self.url = url
902 self.port = None
903 self.handle = None
904 self.mgr = self
905 ObjectRefManager.__init__(self, self.mgr)
906
907 def getPort(self):
908 if self.port is None:
909 try:
910 self.port = vboxServiceLocator().getvboxPortType(self.url)
911 except:
912 self.port = vboxServiceLocator().getvboxServicePort(self.url)
913 return self.port
914
915 def decodebase64(self, str):
916 return base64.decodestring(str)
917
918 def encodebase64(self, str):
919 return base64.encodestring(str)
920</xsl:text>
921</xsl:template>
922
923</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