
    ig                        d Z dZdZddlZddlZddlZej                  dk\  reZe	Z
ddlZej                  j                  dd      aej                  j                  dd      at         ej                          dk(  rd	an"d
anej"                  j%                  t              at         ej                          dk(  rdan"danej"                  j%                  t              at        ej                  d<   t        ej                  d<   ej"                  j'                  t               ddlmZ  G d de      Zd ZdddZd Zd Z G d de      Z G d de      Z G d de      Z G d de      Zda  G d de      Z!y)z
VirtualBox Python API Glue.
a  
Copyright (C) 2009-2023 Oracle and/or its affiliates.

This file is part of VirtualBox base platform packages, as
available from https://www.virtualbox.org.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, in version 3 of the
License.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses>.

The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
in the VirtualBox distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.

You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.

SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
z$Revision: 155244 $    N)   r   VBOX_PROGRAM_PATHVBOX_SDK_PATHDarwinz+/Applications/VirtualBox.app/Contents/MacOSz/usr/lib/virtualboxz//Applications/VirtualBox.app/Contents/MacOS/sdkz/usr/lib/virtualbox/sdk   )VirtualBoxReflectionInfoc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)PerfCollectoraz   This class provides a wrapper over IPerformanceCollector in order to
    get more 'pythonic' interface.

    To begin collection of metrics use setup() method.

    To get collected data use query() method.

    It is possible to disable metric collection without changing collection
    parameters with disable() method. The enable() method resumes metric
    collection.
    c                 \    || _         |j                  dk(  | _        |j                  | _        y)z$ Initializes the instance.

        MSCOMN)mgrtypeisMscomperformanceCollector	collector)selfr   vboxs      2/usr/lib/python3/dist-packages/vboxapi/__init__.py__init__zPerfCollector.__init__e   s(     G+22    c                 @    | j                   j                  ||||       y)z Discards all previously collected values for the specified
        metrics, sets the period of collection and the number of retained
        samples, enables collection.
        N)r   setupMetrics)r   namesobjectsperiodnsampless        r   setupzPerfCollector.setupm   s    
 	##E7FHEr   c                 <    | j                   j                  ||       y)z> Resumes metric collection for the specified metrics.
        N)r   enableMetricsr   r   r   s      r   enablezPerfCollector.enablet   s     	$$UG4r   c                 <    | j                   j                  ||       y)z? Suspends metric collection for the specified metrics.
        N)r   disableMetricsr    s      r   disablezPerfCollector.disabley   s     	%%eW5r   c                    | j                   r(| j                  j                  ||      \
  }}}}}}}}}	}
n%| j                  j                  ||      \  }}}}}}}	}
g }t        dt	        |            D ]  }t        ||         }|dk7  rd}nd}|j                  t        ||         t        ||         t        ||         |t        t        |	|         t        |	|         t        |
|         z         D cg c]  }t        ||          c}ddj                  t        t        |	|         t        |	|         t        |
|         z         D cg c]  }|t        ||         |z  ||   fz   c}      z   dz   d        |S c c}w c c}w )	a   Retrieves collected metric values as well as some auxiliary
        information. Returns an array of dictionaries, one dictionary per
        metric. Each dictionary contains the following entries:
        'name': metric name
        'object': managed object this metric associated with
        'unit': unit of measurement
        'scale': divide 'values' by this number to get float numbers
        'values': collected data
        'values_as_string': pre-processed values ready for 'print' statement
        r   r   z%.2f%sz%d %s[z, ])nameobjectunitscalevaluesvalues_as_string)	r   r   queryMetricsDataxrangelenintappendstrjoin)r   r   r   r,   	names_outobjects_outunitsscalessequence_numbersindiceslengthsoutir+   fmtjs                   r   queryzPerfCollector.query~   s    <<!%!@!@!PVUGYUFL\g "&!@!@!PVYUF<Lg3y>* 	Aq	NEzJJIaL)k!n-E!H39#gaj/3wWXz?]`ahijak]lKl3mna3vay>n$'$))5;C
OSQXYZQ[__bcjklcm_nMn5o5qbcSCq	NU<RTYZ[T\;]5] 5q +r %rtw%x 	 
	 o5qs   5F F	N)	__name__
__module____qualname____doc__r   r   r!   r$   r@    r   r   r
   r
   X   s!    
3F5
6
#r   r
   c                 4    | d   j                         | dd  z   S )Nr   r   )
capitalize)r(   s    r   
ComifyNamerH      s     7$qr(**r   )getattrsetattrc                    | j                   j                  j                  |      }||S |j                         }t	        | j                   j                  j                               D ]Q  }|j                         |k(  st        | j                   || j                   j                  |          t        | |      c S  	 t        d   | t        |            S # t        $ r t        d   | |      cY S w xY w)z0 Our getattr replacement for DispatchBaseClass. rI   )	__class____dict__getlowerlistkeysrJ   rI   _g_dCOMForwardrH   AttributeError)r   sAttroRet
sAttrLowerks        r   _CustomGetAttrrX      s     >>""&&u-D J$..))..01 $779
"DNNE4>>+B+B1+EF4##$6i(z%/@AA 6i(u556s   <C C/.C/c                 t    	 t        d   | t        |      |      S # t        $ r t        d   | ||      cY S w xY w)z0 Our setattr replacement for DispatchBaseClass. rJ   )rR   rH   rS   )r   rT   oValues      r   _CustomSetAttrr[      sC    >i(z%/@&II >i(uf==>s    77c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed        Zy)PlatformBasez4
    Base class for the platform specific code.
    c                     |}y NrE   )r   aoParams_s      r   r   zPlatformBase.__init__   s    r   c                      y)z3
        Gets a the IVirtualBox singleton.
        NrE   r   s    r   getVirtualBoxzPlatformBase.getVirtualBox        r   c                      y)z
        Get a session object that can be used for opening machine sessions.

        The oIVBox parameter is an getVirtualBox() return value, i.e. an
        IVirtualBox reference.

        See also openMachineSession.
        NrE   rc   s    r   getSessionObjectzPlatformBase.getSessionObject   s     r   c                      y)z9 Returns the platform type (class name sans 'Platform'). NrE   rc   s    r   getTypezPlatformBase.getType       r   c                      y)zW
        Returns True if remote (web services) and False if local (COM/XPCOM).
        FrE   rc   s    r   isRemotezPlatformBase.isRemote        r   c                     |}|}y)z
        Retrives the value of the array attribute 'sAttrib' from
        interface 'oInterface'.

        This is for hiding platform specific differences in attributes
        returning arrays.
        NrE   )r   
oInterfacesAttribra   s       r   getArrayzPlatformBase.getArray   s     r   c                     |}|}|}y)z
        Sets the value (aoArray) of the array attribute 'sAttrib' in
        interface 'oInterface'.

        This is for hiding platform specific differences in attributes
        setting arrays.
        NrE   )r   ro   rp   aoArrayra   s        r   setArrayzPlatformBase.setArray   s     r   c                      y)zN
        Does backend specific initialization for the calling thread.
        TrE   rc   s    r   initPerThreadzPlatformBase.initPerThread  re   r   c                      y)zP
        Does backend specific uninitialization for the calling thread.
        TrE   rc   s    r   deinitPerThreadzPlatformBase.deinitPerThread  re   r   c                      |}|}t        d      )ac  
        Instantiates and wraps an active event listener class so it can be
        passed to an event source for registration.

        oImplClass is a class (type, not instance) which implements
        IEventListener.

        dArgs is a dictionary with string indexed variables.  This may be
        modified by the method to pass platform specific parameters. Can
        be None.

        This currently only works on XPCOM.  COM support is not possible due to
        shortcuts taken in the COM bridge code, which is not under our control.
        Use passive listeners for COM and web services.
        z%No active listeners for this platform)	Exception)r   
oImplClassdArgsra   s       r   createListenerzPlatformBase.createListener  s      ?@@r   c                     |}y)a>  
        Wait for events to arrive and process them.

        The timeout (cMsTimeout) is in milliseconds for how long to wait for
        events to arrive.  A negative value means waiting for ever, while 0
        does not wait at all.

        Returns 0 if events was processed.
        Returns 1 if timed out or interrupted in some way.
        Returns 2 on error (like not supported for web services).

        Raises an exception if the calling thread is not the main thread (the one
        that initialized VirtualBoxManager) or if the time isn't an integer.
           rE   )r   
cMsTimeoutra   s      r   waitForEventszPlatformBase.waitForEvents,  s     r   c                      y)z
        Interrupt a waitForEvents call.
        This is normally called from a worker thread to wake up the main thread.

        Returns True on success, False on failure.
        FrE   rc   s    r   interruptWaitEventsz PlatformBase.interruptWaitEvents>  s     r   c                      y)z<
        Unitializes the platform specific backend.
        NrE   rc   s    r   deinitzPlatformBase.deinitG  re   r   c                      y)z
        IUnknown::QueryInterface wrapper.

        oIUnknown is who to ask.
        sClassName is the name of the interface we're asking for.
        NrE   r   	oIUnknown
sClassNames      r   queryInterfacezPlatformBase.queryInterfaceM  s     r   c                      y)zP
        Returns the COM status code from the VBox API given exception.
        NrE   r   oXcpts     r   xcptGetStatuszPlatformBase.xcptGetStatusZ  re   r   c                      y)zc
        Returns True if the exception indicates that the interface is dead, False if not.
        FrE   r   s     r   xcptIsDeadInterfacez PlatformBase.xcptIsDeadInterface`  rm   r   c                     	 | j                  |      }||k(  ryd|cxk  rdk  rn y|dk  r	|dz
  |k(  ryy# t        $ r Y yw xY w)a?  
        Checks if the exception oXcpt is equal to the COM/XPCOM status code
        hrStatus.

        The oXcpt parameter can be any kind of object, we'll just return True
        if it doesn't behave like a our exception class.

        Will not raise any exception as long as hrStatus and self are not bad.
        FTi    r   l        )r   rS   )r   r   hrStatushrXcpts       r   xcptIsEqualzPlatformBase.xcptIsEqualf  sh    	''.F X .J.  4:A:;&61  		s   6 	AAc                      y)z
        Returns the best error message found in the COM-like exception.
        Returns None to fall back on xcptToString.
        Raises exception if oXcpt isn't our kind of exception object.
        NrE   r   s     r   xcptGetMessagezPlatformBase.xcptGetMessage}  s     r   c                      y)z3
        Returns the base exception class.
        NrE   rc   s    r   xcptGetBaseXcptzPlatformBase.xcptGetBaseXcpt  re   r   c                     |S )z>
        Copy/whatever all error constants onto oDst.
        rE   )r   oDsts     r   xcptSetupConstantszPlatformBase.xcptSetupConstants  s	     r   c                     t        |      D ]]  }|d   j                         s|d   j                         s	|d   dk(  s3t        ||      }t        |      t        u sQt        | ||       _ | S )zT
        Copy everything that looks like error constants from oDst to oSrc.
        r   r   ra   )dirisupperrI   r   r1   rJ   )r   oSrcrT   oAttrs       r   xcptCopyErrorConstantsz#PlatformBase.xcptCopyErrorConstants  sk    
 Y 	0EQx!uQx'7'7'9U1X_e,;#%D%/		0
 r   N)rA   rB   rC   rD   r   rd   rg   ri   rl   rq   rt   rv   rx   r}   r   r   r   r   r   r   r   r   r   r   staticmethodr   rE   r   r   r]   r]      s    	
A($. 	 	r   r]   c                       e Zd ZdZdZdZdZdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)PlatformMSCOMz,
    Platform specific code for MS COM.
    z&{D7569351-1750-46F0-936E-BD127D5BC264}r   r   r   c           
      ^   t         j                  | |       ddlm} ddlm}m} ddlm}m} dd l}dd l	}dd l
}	dd l}
ddlm} ddl
m}m}m}m} dd l}|
| _        	 |j'                  d d d |j(                  |j*                  d |j,                  d         |       | _         |       } || |       |dd|      g| _        t>        d
   N|j@                  d   t>        d<   |j@                  d   t>        d
<   tC        |dtD               tC        |dtF               | jI                  |jJ                  j
                         |jJ                  j
                  jM                  d       |jJ                  j
                  jM                  d       |jJ                  j
                  jM                  d       d | _'        |jQ                         | _)        d| _*        |}y #  t/        j0                         \  }}}t3        ||j4                        r | j7                  |      dk(  rt9        d       nt9        d	|       Y xY w)Nr   )	universal)gencacheDispatchBaseClass)	constants	getevents)DUPLICATE_SAME_ACCESS)GetCurrentThreadGetCurrentThreadIdDuplicateHandleGetCurrentProcessiz0Warning: CoInitializeSecurity was already calledz&Warning: CoInitializeSecurity failed: rJ   __getattr__rI   __setattr__VirtualBox.SessionzVirtualBox.VirtualBoxVirtualBox.VirtualBoxClientF)+r]   r   win32comr   win32com.clientr   r   r   r   	pythoncomwin32apiwinerrorwin32conr   r   r   r   r   	threadingCoInitializeSecurityRPC_C_AUTHN_LEVEL_DEFAULTRPC_C_IMP_LEVEL_IMPERSONATE	EOAC_NONEsysexc_info
isinstance	com_errorr   printtid	aoHandlesrR   rM   rJ   rX   r[   flushGenPyCacheclientEnsureDispatchoClient	ConditionoIntCvfInterrupted)r   dParamsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ra   r   pids                       r   r   zPlatformMSCOM.__init__  s   dG, 	'?82ee 	H**4+/+/+4+N+N+4+P+P+/+4+>+>+/1  &'!)#/?/A31Ncdf )$,(9(B(B=(QN9%(9(B(B=(QN9%%}nE%}nE 	X__556  //0DE  //0GH  //0MN))+!K	H,,.KAua%!4!45$:L:LU:SWb:bHI>Fs   6G AH,c                    |j                  | j                  | j                  | j                  | j                        }|j                         }t        |      dkD  rdt        |      dkD  rVt        j                  j                  ||      }t        j                  j                  |      rddl}|j                  |d       |j                  | j                  | j                  | j                  | j                        S )z
        Flushes VBox related files in the win32com gen_py cache.

        This is necessary since we don't follow the typelib versioning rules
        that everyeone else seems to subscribe to.
        $      r   NT)ignore_errors)GetGeneratedFileNameVBOX_TLB_GUIDVBOX_TLB_LCIDVBOX_TLB_MAJORVBOX_TLB_MINORGetGeneratePathr0   ospathr4   isdirshutilrmtreeEnsureModule)r   	oGenCachesNamesGenPathsTypelibPathr   s         r   r   zPlatformMSCOM.flushGenPyCache  s     ..t/A/A4CUCU/3/B/BDDWDWY,,.u:?s8}q077<<%8Lww}}\*l$?
 %%d&8&8$:L:LdNaNacgcvcvwwr   c                 L    dd l }ddlm} |j                  j                  d      S )Nr   Dispatchr   )r   r   r   r   r   r   r   s      r   rg   zPlatformMSCOM.getSessionObject  s    ,''(<==r   c                     | j                   *dd l}ddlm} |j                  j                  d      | _         | j                   j
                  S )Nr   r   r   )r   r   r   r   r   
virtualBoxr   s      r   rd   zPlatformMSCOM.getVirtualBox  s;     <<0#??334QRDL||&&&r   c                      y)Nr   rE   rc   s    r   ri   zPlatformMSCOM.getType      r   c                 $    |j                  |      S r_   r   r   ro   rp   s      r   rq   zPlatformMSCOM.getArray       %%g..r   c                 2   t        |d      }t        |d      }t        |d      }||v r|n
t        |      }	 ||   \  }}	||   }
dd l}|j                  |d   |d   |d   |j                  df|
d   f|       y # t        $ r |j                  ||      cY S w xY w)N_oleobj__prop_map_get__prop_map_put_r   r   r   )rI   rH   KeyErrorr   r   InvokeTypes
VT_HRESULT)r   ro   rp   rs   oOleObjaPropMapGetaPropMapPut
sComAttribaArgsaDefaultArgsaGetArgsr   s               r   rt   zPlatformMSCOM.setArray#  s     j*5j*:;j*:;!(K!7gZ=P
	<"-j"9E<"-j"9H 	E!H!!H!!H&1115%a[N#	&	  	<))'7;;	<s   A8 8BBc                 .    dd l }|j                  d       y Nr   )r   CoInitializeExr   r   s     r   rv   zPlatformMSCOM.initPerThread?  s      #r   c                 ,    dd l }|j                          y r   )r   CoUninitializer  s     r   rx   zPlatformMSCOM.deinitPerThreadC  s      "r   c                     	 t        d      )Nzno active listeners on Windows as PyGatewayBase::QueryInterface() returns new gateway objects all the time, thus breaking EventQueue assumptions about the listener interface pointer being constants between calls )rz   r   r   r   r   exec)r   r{   r|   dstr_s        r   r}   zPlatformMSCOM.createListenerG  s     n o or   c                 *   ddl m} ddlm} ddlm}m}m}m} ddlm	} dd l
}	t        |t              st        d      | j                   |       k7  rt        d      |dk  r|}
n|}
 || j                   d|
|      }||cxk  r|t#        | j                         z   k  rn nd}n'||t#        | j                         z   k(  r
 |        d}nd	}| j$                  j'                          | j(                  r	d
| _        d	}| j$                  j+                          |S )Nr   )r   )INFINITE)MsgWaitForMultipleObjectsQS_ALLINPUTWAIT_TIMEOUTWAIT_OBJECT_0)PumpWaitingMessagesz&The timeout argument is not an integerz0wait for events from the same thread you inited!r   r   F)r   r   
win32eventr	  r
  r  r  r  r   r  typesr   r1   	TypeErrorr   rz   r   r0   r   acquirer   release)r   timeoutr   r	  r
  r  r  r  r  r  r   rcs               r   r   zPlatformMSCOM.waitForEventsf  s    /'bb1'3'DEE88)++NOOQ;!J J&t~~q*kRBDT^^1D!DDB=3t~~#666!B B 	 %DB	r   c                     ddl m} ddlm} | j                  j                          d| _        | j                  j                          	  || j                  |dd       y#  Y yxY w)aJ  
        Basically a python implementation of NativeEventQueue::postEvent().

        The magic value must be in sync with the C++ implementation or this
        won't work.

        Note that because of this method we cannot easily make use of a
        non-visible Window to handle the message like we would like to do.
        r   )PostThreadMessage)WM_USERTNl   8d F)	r   r  r   r  r   r  r   r  r   )r   r  r  s      r   r   z!PlatformMSCOM.interruptWaitEvents  sX     	/$ 	dhhzB 	s   	A A#c                 l    | j                   D ]  }||j                           d | _        | `d | _        y r_   )r   CloseoHandler   )r   r  s     r   r   zPlatformMSCOM.deinit  s9    ~~ 	!G"	! Lr   c                      ddl m}  |||      S )Nr   )CastTo)r   r  )r   r   r   r  s       r   r   zPlatformMSCOM.queryInterface  s    *i,,r   c                     |j                   }|| j                  j                  k(  r	 |j                  d   }|S |S #  Y |S xY w)Nr   )hresultr   DISP_E_EXCEPTION	excepinfo)r   r   r   s      r   r   zPlatformMSCOM.xcptGetStatus  sL     T]]333+ vs   : ?c                 (    | j                  |      dv S )N)
l     i     l     il     il     ir   r   s     r   r   z!PlatformMSCOM.xcptIsDeadInterface  s    !!%( -
 
 	
r   c                    t        |d      r;	 t        |j                        dk\  r"|j                  d   }t        |      dkD  r|dd  S t        |d      r	 |j                  }t        |      dkD  r|S 	 y y #  Y 0xY w#  Y y xY w)Nr!  r   r   r   strerror)hasattrr0   r!  r'  r   r   sRets      r   r   zPlatformMSCOM.xcptGetMessage  s    5+&u'1, ??1-D4y1}#ABx 5*%~~t9q=K ! s   9A4 A; 4A8;A?c                 "    dd l }|j                  S r   )r   r   r  s     r   r   zPlatformMSCOM.xcptGetBaseXcpt  s    """r   c                 d   dd l }| j                  ||      }|j                  |_        |j                  |_        |j                  |_        |j                  |_	        |j                  |_        |j                  |_        |j                  |_        |j                   |_        |j$                  |_        |S r   )r   r   S_OKNS_OKE_FAILNS_ERROR_FAILUREE_ABORTNS_ERROR_ABORT	E_POINTERNS_ERROR_NULL_POINTERE_NOINTERFACENS_ERROR_NO_INTERFACEE_INVALIDARGNS_ERROR_INVALID_ARGE_OUTOFMEMORYNS_ERROR_OUT_OF_MEMORY	E_NOTIMPLNS_ERROR_NOT_IMPLEMENTEDE_UNEXPECTEDNS_ERROR_UNEXPECTED)r   r   r   s      r   r   z PlatformMSCOM.xcptSetupConstants  s    **4: YY
 $"ll%)^^"%)%7%7"$($5$5!&*&8&8#(,%#'#4#4 r   N)rA   rB   rC   rD   r   r   r   r   r   r   rg   rd   ri   rq   rt   rv   rx   r}   r   r   r   r   r   r   r   r   r   rE   r   r   r   r     s     =MMNNCJx8>
'/&8$#>#J,-	
$#
r   r   c                   |    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)PlatformXPCOMz+
    Platform specific code for XPCOM.
    c                     t         j                  | |       t        j                  j	                  t
        dz          dd l}dd l}dd l}|}y )Nz/bindings/xpcom/python/r   )	r]   r   r   r   r2   
VBoxSdkDirxpcom.vboxxpcomxpcomxpcom.components)r   r   rD  ra   s       r   r   zPlatformXPCOM.__init__  s6    dG,
%>>?r   c                 X    dd l }|j                  j                  d   j                         S )Nr   z@virtualbox.org/Session;1)rE  
componentsclassescreateInstancer   rD  s     r   rg   zPlatformXPCOM.getSessionObject  s&    ''(CDSSUUr   c                 p    dd l }|j                  j                  d   j                         }|j                  S )Nr   z"@virtualbox.org/VirtualBoxClient;1)rE  rG  rH  rI  r   )r   rD  r   s      r   rd   zPlatformXPCOM.getVirtualBox  s1    !!))*NO^^`   r   c                      y)NXPCOMrE   rc   s    r   ri   zPlatformXPCOM.getType  r   r   c                 F     |j                  dt        |      z                S )NrN   r   rH   r   s      r   rq   zPlatformXPCOM.getArray	  s"    Bz%%ej.A&ABDDr   c                 H     |j                  dt        |      z         |      S )NsetrO  r   ro   rp   rs   s       r   rt   zPlatformXPCOM.setArray  s$    Bz%%ej.A&AB7KKr   c                 @    dd l }|j                  j                          y r   )rD  _xpcomAttachThreadrJ  s     r   rv   zPlatformXPCOM.initPerThread      !!#r   c                 @    dd l }|j                  j                          y r   )rD  rT  DetachThreadrJ  s     r   rx   zPlatformXPCOM.deinitPerThread  rV  r   c                 t    i }||d<   ||d<   d}|dz  }|dz  }|dz  }|dz  }|dz  }t        |||       |d	   S )
N	BaseClassr|    zimport xpcom.components
zclass ListenerImpl(BaseClass):
zA   _com_interfaces_ = xpcom.components.interfaces.IEventListener
z7   def __init__(self): BaseClass.__init__(self, dArgs)
zresult = ListenerImpl()
resultr  )r   r{   r|   r  r3   s        r   r}   zPlatformXPCOM.createListener  sj    #+'
**11SSII**S!Q{r   c                 @    dd l }|j                  j                  |      S r   )rD  rT  WaitForEvents)r   r  rD  s      r   r   zPlatformXPCOM.waitForEvents$  s    ||))'22r   c                 >    dd l }|j                  j                         S r   )rD  rT  InterruptWaitrJ  s     r   r   z!PlatformXPCOM.interruptWaitEvents(  s    ||))++r   c                 @    dd l }|j                  j                          y r   )rD  rT  	DeinitCOMrJ  s     r   r   zPlatformXPCOM.deinit,  s     r   c                 h    dd l }|j                  t        |j                  j                  |            S r   )rE  r   rI   rG  
interfaces)r   r   r   rD  s       r   r   zPlatformXPCOM.queryInterface0  s)    ''0@0@0K0KZ(XYYr   c                     |j                   S r_   )errnor   s     r   r   zPlatformXPCOM.xcptGetStatus4  s    {{r   c                 (    | j                  |      dv S )N)l   @   i@ r#  r$  r%  r   s     r   r   z!PlatformXPCOM.xcptIsDeadInterface7  s    !!%( -
 
 	
r   c                 h    t        |d      r	 |j                  }t        |      dkD  r|S 	 y y #  Y y xY w)Nmsgr   )r(  rj  r0   r)  s      r   r   zPlatformXPCOM.xcptGetMessage=  sA    5% yyt9q=K ! s   - 1c                 "    dd l }|j                  S r   )rD  rz   rJ  s     r   r   zPlatformXPCOM.xcptGetBaseXcptG  s    r   c                    dd l }| j                  ||j                        }d|_        |j                  |_        |j                  |_        |j                  |_	        |j                  |_        |j                  |_        |j                  |_        |j                   |_        |j$                  |_        |j(                  |_        d|_        |S )Nr   i i	 )rD  r   nsErrorE_ACCESSDENIEDr.  r-  r0  r/  r2  r1  r4  r3  r6  r5  r8  r7  r:  r9  r<  r;  r>  r=  r   )r   r   rD  s      r   r   z PlatformXPCOM.xcptSetupConstantsK  s    **4? *JJ	++**33!77 55!8866 44 +r   N)rA   rB   rC   rD   r   rg   rd   ri   rq   rt   rv   rx   r}   r   r   r   r   r   r   r   r   r   rE   r   r   r@  r@    se    V!
EL$$3,!Z
r   r@  c                   ^    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zy)PlatformWEBSERVICEz4
    VirtualBox Web Services API specific code.
    c                    t         j                  | |       t        j                  j	                  t
        dddd      }|t        j                  vrt        j                  j                  |       dd l}ddlm	} |F|j                  dd      | _        |j                  d	d      | _        |j                  d
d      | _        nd| _        d| _        d | _        d | _        d | _        y )Nbindings
webservicepythonlibr   IWebsessionManager2userr[  passwordurl)r]   r   r   r   r4   rB  r   r2   VirtualBox_wrappersrw  rN   rx  ry  rz  r   wsmgr)r   r   sWebServLibr{  rw  s        r   r   zPlatformWEBSERVICE.__init__c  s    dG,ggll:z<SXYchh&HHOOK("; FB/DI#KK
B7DM{{5"-DHDIDMDH	
r   c                 L    | j                   j                  | j                        S r_   )r|  rg   r   rc   s    r   rg   z#PlatformWEBSERVICE.getSessionObject|  s    zz**49955r   c                 d    | j                  | j                  | j                  | j                        S r_   )connectrz  rx  ry  rc   s    r   rd   z PlatformWEBSERVICE.getVirtualBox  s!    ||DHHdii??r   c                      y)N
WEBSERVICErE   rc   s    r   ri   zPlatformWEBSERVICE.getType  s    r   c                      y)z3 Returns True if remote VBox host, False if local. TrE   rc   s    r   rl   zPlatformWEBSERVICE.isRemote  rj   r   c                 $    |j                  |      S r_   r   r   s      r   rq   zPlatformWEBSERVICE.getArray  r   r   c                 &    |j                  ||      S r_   )r   rR  s       r   rt   zPlatformWEBSERVICE.setArray  s    %%gw77r   c                      y)Nr   rE   r   r  s     r   r   z PlatformWEBSERVICE.waitForEvents  s    r   c                      y)NFrE   r  s     r   r   z&PlatformWEBSERVICE.interruptWaitEvents  s    r   c                 4    	 | j                          y #  Y y xY wr_   )
disconnectrc   s    r   r   zPlatformWEBSERVICE.deinit  s    	OO	s    c                 d    i }||d<   d}|d|z   dz   z  }|d|z   dz   z  }t        |||       |d   S )Nr   r[  z from VirtualBox_wrappers import 
z	result = z"(oIUnknown.mgr, oIUnknown.handle)
r\  r]  )r   r   r   r  r3   s        r   r   z!PlatformWEBSERVICE.queryInterface  sT    "+1J>EE{Z'*OOOS!Q{r   c                    | j                   | j                          ddlm} |d}|| _        |d}|| _        |d}|| _         || j                        | _        | j                  j                  | j
                  | j                        | _         | j                   j                  s+t        d| j                  z   dz   | j
                  z   dz         | j                   S )Nr   rv  r[  zcannot connect to 'z' as '')r   r  r{  rw  rz  rx  ry  r|  logonhandlerz   )r   rz  rx  passwdrw  s        r   r  zPlatformWEBSERVICE.connect  s    99 OO;;C<D	>F(2
JJ$$TYY>	yy1DHH<xG$))SVYYZZyyr   c                     | j                   A| j                  4| j                  j                  | j                          d | _         d | _        y y y r_   )r   r|  logoffrc   s    r   r  zPlatformWEBSERVICE.disconnect  sA    99 TZZ%;JJdii(DIDJ &< r   N)rA   rB   rC   rD   r   rg   rd   ri   rl   rq   rt   r   r   r   r   r  r  rE   r   r   rp  rp  ^  sI    26@/8(r   rp  c                       e Zd ZdZ G d de      Zd!dZd Zd Ze	d        Z
d	 Zd"d
Zd Zd Zd"dZd Zd Zd Zd Zd Zd Zd#dZd Zd Zd Zd Zd$dZd"dZd"dZd"dZd Zd Z d"dZ!d"d Z"y)%VirtualBoxManagera  
    VirtualBox API manager class.

    The API users will have to instantiate this.  If no parameters are given,
    it will default to interface with the VirtualBox running on the local
    machine.  sStyle can be None (default), MSCOM, XPCOM or WEBSERVICES.  Most
    users will either be specifying None or WEBSERVICES.

    The dPlatformParams is an optional dictionary for passing parameters to the
    WEBSERVICE backend.
    c                       e Zd Zd Zy)VirtualBoxManager.Statusesc                      y r_   rE   rc   s    r   r   z#VirtualBoxManager.Statuses.__init__  s    r   N)rA   rB   rC   r   rE   r   r   Statusesr    s    	r   r  Nc                 r   |t         j                  dk(  rd}nd}|dk(  rt        |      | _        n:|dk(  rt        |      | _        n$|dk(  rt	        |      | _        nt        d|      || _        | j                  j                         | _        | j                  j                         | _
        t        |dk(        | _        | j                  j                  t        j                               | _        d | _        i | _        | j                  j'                         | _        | j(                  a	 | j                  j-                         }y # t.        $ r! t1        d       t3        j4                           t
        $ r; t        j6                         \  }}}t1        d|       t3        j4                          Y y w xY w)Nwin32r   rM  r  zUnknown sStyle=z:Installation problem: check that appropriate libs in placezinit exception: )r   platformr@  r   rp  rz   styleri   r   rl   remoter   r   r   r  r  statuses_dErrorValToName_ddEnumValueToNamer   
oXcptClassCurXcptClassrd   	NameErrorr   	traceback	print_excr   )r   sStyledPlatformParamsr   ra   es         r   r   zVirtualBoxManager.__init__  sj   >||w&  W)/:DMw)/:DM|#.?DM6;<<
MM))+	mm,,.1&L2HI 889J9S9S9UV !% #% --779		"==..0D 	NO! 	"llnGAq!$a(!	"s   /E
 
A)F65F6c                 $    | j                          y r_   )r   rc   s    r   __del__zVirtualBoxManager.__del__  s    r   c                      y)z~
        Returns a Python API revision number.
        This will be incremented when features are added to this file.
        r   rE   rc   s    r   getPythonApiRevisionz&VirtualBoxManager.getPythonApiRevision  s    
 r   c                     | S )z
        This used to be an attribute referring to a session manager class with
        only one method called getSessionObject. It moved into this class.
        rE   rc   s    r   r   zVirtualBoxManager.mgr  s	     r   c                 6    | j                   j                         S )z$ See PlatformBase::getVirtualBox(). )r  rd   rc   s    r   rd   zVirtualBoxManager.getVirtualBox$  s    }}**,,r   c                 :    |}| j                   j                         S )z' See PlatformBase::getSessionObject(). )r  rg   )r   oIVBoxra   s      r   rg   z"VirtualBoxManager.getSessionObject(  s     }}--//r   c                 :    | j                   j                  ||      S )z See PlatformBase::getArray(). )r  rq   r   s      r   rq   zVirtualBoxManager.getArray.  s    }}%%j'::r   c                 <    | j                   j                  |||      S )z See PlatformBase::setArray(). )r  rt   rR  s       r   rt   zVirtualBoxManager.setArray2  s    }}%%j'7CCr   c                 :    | j                   j                  ||      S )z% See PlatformBase::createListener(). )r  r}   )r   r{   r|   s      r   r}   z VirtualBoxManager.createListener6  s    }}++J>>r   c                 8    | j                   j                  |      S )z$ See PlatformBase::waitForEvents(). )r  r   )r   r   s     r   r   zVirtualBoxManager.waitForEvents:  s    }}**:66r   c                 6    | j                   j                         S )z* See PlatformBase::interruptWaitEvents(). )r  r   rc   s    r   r   z%VirtualBoxManager.interruptWaitEvents>  s    }}0022r   c                 :    | j                   j                  ||      S )z% See PlatformBase::queryInterface(). )r  r   r   s      r   r   z VirtualBoxManager.queryInterfaceB  s    }}++IzBBr   c                 8    | j                   j                          y)& See PlatformBase::deinitPerThread(). N)r  rv   rc   s    r   rv   zVirtualBoxManager.initPerThreadI  s    ##%r   c                 6    | j                   j                         S )r  )r  rx   rc   s    r   rx   z!VirtualBoxManager.deinitPerThreadM  s    }},,..r   c                 v    t        | d      r-| j                  !| j                  j                          d| _        y)zc
        For unitializing the manager.
        Do not access it after calling this method.
        r  NT)r(  r  r   rc   s    r   r   zVirtualBoxManager.deinitQ  s1    
 4$)BMM  " DMr   c                     | j                         }|r| j                  j                  }n| j                  j                  }|j	                  ||       |S )z
        Attempts to open the a session to the machine.
        Returns a session object on success.
        Raises exception on failure.
        )rg   r   LockType_SharedLockType_WritelockMachine)r   	oIMachinefPermitSharingoSessioneTypes        r   openMachineSessionz$VirtualBoxManager.openMachineSession^  sH     ((*NN22ENN11Eh.r   c                 (    ||j                          y)za
        Closes a session opened by openMachineSession.
        Ignores None parameters.
        T)unlockMachine)r   r  s     r   closeMachineSessionz%VirtualBoxManager.closeMachineSessionl  s    
 ""$r   c                     t        | |      S )z
        Returns a helper class (PerfCollector) for accessing performance
        collector goodies.  See PerfCollector for details.
        )r
   )r   r  s     r   getPerfCollectorz"VirtualBoxManager.getPerfCollectoru  s    
 T6**r   c                     t         S )z:
        Returns the VirtualBox binary directory.
        )
VBoxBinDirrc   s    r   	getBinDirzVirtualBoxManager.getBinDir|  
    
 r   c                     t         S )z7
        Returns the VirtualBox SDK directory.
        )rB  rc   s    r   	getSdkDirzVirtualBoxManager.getSdkDir  r  r   c                 d   | j                   j                  |      }||j                  |      }|rz|s|S |d|S | j                  j                  |      }t	        |      dkD  rFt               }|D ]
  }||||   <    || j                   |<   |j                  |      }|r|s|S |d|S |d|S )zM
        Returns the name (string) for the corresponding enum value.
        ra   r   	_Unknown_)r  rN   r   
all_valuesr0   dict)r   sEnumTypeNm
oEnumValuefTypePrefixdValueNames
sValueNamedNamedValuesr   s           r   getEnumValueNamez"VirtualBoxManager.getEnumValueName  s    
 --11+>"$4J)4z][R\:]]  >>44[AL< 1$"f) >E7<KU 34>7B''4 )__Z8
-8:aV`>aa #.z::r   c                 j    |t        j                         d   }| j                  j                  |      S )z
        Gets the status code from an exception.  If the exception parameter
        isn't specified, the current exception is examined.
        r   )r   r   r  r   r   s     r   r   zVirtualBoxManager.xcptGetStatus  s.    
 =LLN1%E}}**511r   c                 j    |t        j                         d   }| j                  j                  |      S )z
        Returns True if the exception indicates that the interface is dead,
        False if not.  If the exception parameter isn't specified, the current
        exception is examined.
        r   )r   r   r  r   r   s     r   r   z%VirtualBoxManager.xcptIsDeadInterface  s.     =LLN1%E}}0077r   c                 z    | j                   y|t        j                         d   }t        || j                         S )z
        Checks if the exception is one that could come from the VBox API. If
        the exception parameter isn't specified, the current exception is
        examined.
        Fr   )r  r   r   r   r   s     r   xcptIsOurXcptKindz#VirtualBoxManager.xcptIsOurXcptKind  s7     ??"=LLN1%E%11r   c                 l    |t        j                         d   }| j                  j                  ||      S )a  
        Checks if the exception oXcpt is equal to the COM/XPCOM status code
        hrStatus.

        The oXcpt parameter can be any kind of object, we'll just return True
        if it doesn't behave like a our exception class.  If it's None, we'll
        query the current exception and examine that.

        Will not raise any exception as long as hrStatus and self are not bad.
        r   )r   r   r  r   r   r   r   s      r   r   zVirtualBoxManager.xcptIsEqual  s0     =LLN1%E}}((99r   c                 (    | j                  ||       S )z&
        Negated xcptIsEqual.
        )r   r  s      r   xcptIsNotEqualz VirtualBoxManager.xcptIsNotEqual  s     ##E8444r   c                 (   || j                  |      r| j                  |      }n|}| j                  t               }t	        | j
                        D ]Q  }|d   j                         st        | j
                  |      }t        |t        t        f      sD||t        |      <   S dD ]!  }t        | j
                  |d      }||||<   # || _        	 | j                  t        |         }|S # t        $ r t        |      }d|dz  |fz  }Y |S w xY w)z
        Converts the specified COM status code, or the status code of the
        specified exception, to a C constant string.  If the parameter isn't
        specified (is None), the current exception is examined.
        Nr   )	r-  r/  r1  r3  r5  r7  r9  r;  r=  z%#x (%d)r   )r  r   r  r  r   r  r   rI   r   r1   longr   )r   hrStatusOrXcptr   dErrorValToNamesKeyrZ   sStrhrLongs           r   xcptToStringzVirtualBoxManager.xcptToString  s$    !T%;%;N%K)).9H%H   ("fODMM* <7??$$T]]D9F!&3+67;F4	<H 3 d;%.2OF+	3
 %4D!	>((X7D   	>(^F*!4f ==D	>s   C/ /DDc                     |t        j                         d   }| j                  j                  |      }|| j	                  |      }|S )z
        Returns the best error message found in the COM-like exception. If the
        exception parameter isn't specified, the current exception is examined.
        r   )r   r   r  r   r  r)  s      r   r   z VirtualBoxManager.xcptGetMessage  sG    
 =LLN1%E}}++E2<$$U+Dr   )NNr_   )T)F)#rA   rB   rC   rD   r)   r  r   r  r  propertyr   rd   rg   rq   rt   r}   r   r   r   rv   rx   r   r  r  r  r  r  r  r   r   r  r   r  r  r   rE   r   r   r  r    s    
6 -"^  -0;D?73C&/+<@28
2:5#J
r   r  )"rD   __copyright____version__r   r   r  version_inforanger/   r1   r  r  environrN   r  rB  systemr   abspathr2   VirtualBox_constantsr   r)   r
   rH   rR   rX   r[   r]   r   r@  rp  r  r  rE   r   r   <module>r     s  
 > $ 
 
  vFD
 ZZ^^/6
ZZ^^OT2
xH$B
*
,JxH$F
.
,J",

 (

?  
  ;IF I^+ 6*>K6 K\OL Od
kL k\e e\ ~ ~r   