Index: trunk/src/VBox/Main/glue/vboxapi.py
===================================================================
--- trunk/src/VBox/Main/glue/vboxapi.py	(revision 20031)
+++ trunk/src/VBox/Main/glue/vboxapi.py	(revision 20036)
@@ -106,5 +106,5 @@
             #win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
 
-    def getSessionObject(self):
+    def getSessionObject(self, vbox):
         import win32com
         from win32com.client import Dispatch
@@ -145,5 +145,5 @@
         import xpcom.components
 
-    def getSessionObject(self):
+    def getSessionObject(self, vbox):
         import xpcom.components
         return xpcom.components.classes["@virtualbox.org/Session;1"].createInstance()
@@ -177,15 +177,17 @@
         import VirtualBox_services
         import VirtualBox_wrappers
-        from VirtualBox_wrappers import IWebsessionManager
-        from VirtualBox_wrappers import g_port
-        from VirtualBox_wrappers import g_reflectionInfo
-        self.wsmgr = IWebsessionManager()
-        self.port = g_port
-        self.constants = g_reflectionInfo
-        self.user = ""
-        self.password = ""
-
-    def getSessionObject(self):
-        return self.wsmgr.getSessionObject()
+        from VirtualBox_wrappers import IWebsessionManager2
+        if params is not None:
+            self.user = params.get("user", "")
+            self.password = params.get("password", "")
+            self.url = params.get("url", "")
+        else:
+            self.user = ""
+            self.password = ""
+            self.url = None
+        self.wsmgr = IWebsessionManager2(self.url)
+
+    def getSessionObject(self, vbox):
+        return self.wsmgr.getSessionObject(vbox)
 
     def getVirtualBox(self):
@@ -193,6 +195,5 @@
 
     def getConstants(self):
-        from VirtualBox_wrappers import g_reflectionInfo
-        return g_reflectionInfo
+        return None
     
     def getType(self):
@@ -216,5 +217,5 @@
 
     def getSessionObject(self, vbox):
-        return self.mgr.platform.getSessionObject()
+        return self.mgr.platform.getSessionObject(vbox)
 
 class VirtualBoxManager:
Index: trunk/src/VBox/Main/webservice/Makefile.kmk
===================================================================
--- trunk/src/VBox/Main/webservice/Makefile.kmk	(revision 20031)
+++ trunk/src/VBox/Main/webservice/Makefile.kmk	(revision 20036)
@@ -326,5 +326,5 @@
  #
  VBOXWEB_GLUE_PYTHON           = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_wrappers.py
- VBOXWEB_WS_PYTHON             = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_service.py
+ VBOXWEB_WS_PYTHON             = $(VBOX_PATH_SDK)/bindings/webservice/python/lib/VirtualBox_services.py
  VBOXWEB_WS_PERL               = $(VBOX_PATH_SDK)/bindings/webservice/perl/lib/vboxService.pm
  VBOXWEB_SAMPLES_AXIS_DIR      = $(VBOX_PATH_SDK)/bindings/webservice/java/axis/samples
Index: trunk/src/VBox/Main/webservice/websrv-python.xsl
===================================================================
--- trunk/src/VBox/Main/webservice/websrv-python.xsl	(revision 20031)
+++ trunk/src/VBox/Main/webservice/websrv-python.xsl	(revision 20036)
@@ -72,4 +72,5 @@
   </xsl:call-template>
   <xsl:text>(</xsl:text>
+   <xsl:text>self.mgr,</xsl:text>
   <xsl:value-of select="$value"/>
   <xsl:if test="$safearray='yes'">
@@ -89,5 +90,5 @@
        req=<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>RequestMsg()
        req._this=self.handle
-       val=g_port.<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
+       val=self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)
        <xsl:text>return  </xsl:text>
        <xsl:call-template name="emitOutParam">
@@ -113,5 +114,5 @@
        else:
             req._<xsl:value-of select="$attrname"/> = value.handle
-       g_port.<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)      
+       self.mgr.getPort().<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>(req)      
 </xsl:template>
 
@@ -120,6 +121,7 @@
    <xsl:variable name="ename"><xsl:value-of select="@type" /></xsl:variable>
 class <xsl:value-of select="$cname"/>:
-   def __init__(self, array):
+   def __init__(self, mgr, array):
        self.array = array
+       self.mgr = mgr
 
    def __next(self):
@@ -133,5 +135,5 @@
 
    def __getitem__(self, index):
-       return <xsl:value-of select="$ename"/>(self.array._array[index])
+       return <xsl:value-of select="$ename"/>(self.mgr, self.array._array[index])
        
 </xsl:template>
@@ -140,13 +142,16 @@
    <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
 class <xsl:value-of select="$ifname"/>:
-   def __init__(self, handle = None,isarray = False):
+   def __init__(self, mgr, handle, isarray = False):
+       self.mgr = mgr
+       if handle is None or handle == "":
+           raise Exception("bad handle: "+str(handle))
        self.handle = handle
        self.isarray = isarray
 <!--
     This doesn't work now
-       g_manMgr.register(handle)
+       mgr.register(handle)
 
    def __del__(self):
-       g_manMgr.unregister(self.handle) 
+       mgr.unregister(self.handle) 
 -->
    def releaseRemote(self):
@@ -154,5 +159,5 @@
             req=IManagedObjectRef_releaseRequestMsg() 
             req._this=handle
-            g_port.IManagedObjectRef_release(req)
+            self.mgr.getPort().IManagedObjectRef_release(req)
         except:
             pass
@@ -175,5 +180,5 @@
    def __getitem__(self, index):
       if self.isarray:
-          return <xsl:value-of select="$ifname" />(self.handle[index])
+          return <xsl:value-of select="$ifname" />(self.mgr, self.handle[index])
       raise TypeError, "iteration over non-sequence"       
 
@@ -267,5 +272,6 @@
    <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
 class <xsl:value-of select="$ifname"/>:
-    def __init__(self, handle):<xsl:for-each select="attribute">
+    def __init__(self, mgr, handle):<xsl:for-each select="attribute">
+       self.mgr = mgr
        self.<xsl:value-of select="@name"/> = handle._<xsl:value-of select="@name"/>
        </xsl:for-each>
@@ -287,5 +293,5 @@
        req._<xsl:value-of select="@name" />=_arg_<xsl:value-of select="@name" />
        </xsl:for-each>
-       val=g_port.<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
+       val=self.mgr.getPort().<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>(req)
        <!-- return needs to be the first one -->      
        return <xsl:for-each select="param[@dir='return']">
@@ -339,5 +345,6 @@
 <xsl:template name="enum">
 class <xsl:value-of select="@name"/>:
-   def __init__(self,handle):
+   def __init__(self,mgr,handle):
+       self.mgr=mgr
        if isinstance(handle,basestring):
            self.handle=<xsl:value-of select="@name"/>._ValueMap[handle]
@@ -395,6 +402,4 @@
 from VirtualBox_services import *
 
-g_port = vboxServiceLocator().getvboxPortType()
-
 class ManagedManager:
   def __init__(self):
@@ -419,5 +424,5 @@
             req=IManagedObjectRef_releaseRequestMsg() 
             req._this=handle
-            g_port.IManagedObjectRef_release(req)
+            self.mgr.getPort().IManagedObjectRef_release(req)
         except:
             pass
@@ -426,9 +431,7 @@
      else:
         self.map[handle] = c
-
-g_manMgr = ManagedManager()
-
+  
 class String:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
       self.handle = handle
       self.isarray = isarray
@@ -477,5 +480,5 @@
 
 class UUID:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
       self.handle = handle
       self.isarray = isarray
@@ -523,5 +526,5 @@
 
 class Boolean:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
        self.isarray = isarray
@@ -545,5 +548,5 @@
 
 class UnsignedInt:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
        self.isarray = isarray
@@ -577,5 +580,5 @@
     
 class Int:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
        self.isarray = isarray
@@ -608,5 +611,5 @@
 
 class UnsignedShort:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
        self.isarray = isarray
@@ -619,5 +622,5 @@
 
 class Short:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
  
@@ -629,5 +632,5 @@
 
 class UnsignedLong:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
  
@@ -639,5 +642,5 @@
 
 class Long:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
  
@@ -649,5 +652,5 @@
 
 class Double:
-  def __init__(self, handle = None, isarray = False):
+  def __init__(self, mgr, handle, isarray = False):
        self.handle = handle
  
@@ -659,7 +662,7 @@
 
 class Float:
-  def __init__(self, handle = None, isarray = False):
-       self.handle = handle
- 
+  def __init__(self, mgr, handle, isarray = False):
+       self.handle = handle
+       
   def __str__(self):
        return str(self.handle)
@@ -670,6 +673,7 @@
 
 class IUnknown:
-  def __init__(self, handle = None, isarray = False):
-       self.handle = handle
+  def __init__(self,  mgr, handle, isarray = False):
+       self.handle = handle
+       self.mgr = mgr
        self.isarray = isarray
 
@@ -691,5 +695,5 @@
   def __getitem__(self, index):
       if self.isarray:
-          return IUnknown(self.handle[index])
+          return IUnknown(self.mgr, self.handle[index])
       raise TypeError, "iteration over non-sequence"       
   
@@ -711,24 +715,15 @@
   </xsl:for-each>
 
-class VirtualBoxReflectionInfo:
-   def __init__(self):
-      self.map = {}
-  
-   def add(self,name,ref):
-      self.map[name] = ref
-
-   def __getattr__(self,name):
-      ref = self.map.get(name,None)
-      if ref == None:
-          return self.__dict__[name]
-      return ref
-
-g_reflectionInfo = VirtualBoxReflectionInfo()
-<xsl:for-each select="//enum">
-  <xsl:variable name="ename">
-    <xsl:value-of select="@name"/>
-  </xsl:variable>
-  <xsl:value-of select="concat('g_reflectionInfo.add(&#34;',$ename,'&#34;,',$ename,')&#10;')"/>
-</xsl:for-each>
+class IWebsessionManager2(IWebsessionManager):
+  def __init__(self, url):
+       self.url = url
+       self.port = None
+       self.handle = None
+       self.mgr = self
+
+  def getPort(self):
+      if self.port is None:
+          self.port = vboxServiceLocator().getvboxPortType(self.url)
+      return self.port
 
 </xsl:template>
