--- commands.py.orig	2005-05-29 03:27:28.000000000 +0200
+++ commands.py	2005-07-04 04:29:37.000000000 +0200
@@ -35,7 +35,7 @@
 from xmpp.client import PlugIn
 
 class Commands(PlugIn):
-    """Commands is an ancestor of Plugin and can be attached to any session.
+    """Commands is an ancestor of PlugIn and can be attached to any session.
     
     The commands class provides a lookup and browse mechnism. It follows the same priciple of the Browser class, for Service Discovery to provide the list of commands, it adds the 'list' disco type to your existing disco handler function. 
     
@@ -43,21 +43,21 @@
         The commands are added into the existing Browser on the correct nodes. When the command list is built the supplied discovery handler function needs to have a 'list' option in type. This then gets enumerated, all results returned as None are ignored.
         The command executed is then called using it's Execute method. All session management is handled by the command itself.
     """
-    def __init__(self):
+    def __init__(self, browser):
         """Initialises class and sets up local variables"""
         PlugIn.__init__(self)
         DBG_LINE='commands'
         self._exported_methods=[]
         self._handlers={'':{}}
+        self._browser = browser
     
-    def plugin(self, owner, browser):
+    def plugin(self, owner):
         """Makes handlers within the session"""
         # Plug into the session and the disco manager
         # We only need get and set, results are not needed by a service provider, only a service user.
         owner.RegisterHandler('iq',self._CommandHandler,typ='set',ns=NS_COMMANDS)
         owner.RegisterHandler('iq',self._CommandHandler,typ='get',ns=NS_COMMANDS)
-        browser.setDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid='')
-        self._browser = browser
+        self._browser.setDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid='')
         
     def plugout(self):
         """Removes handlers from the session"""
@@ -195,6 +195,10 @@
     def plugin(self,owner,jid=''):
         """Plug command into the commands class"""
         # The owner in this instance is the Command Processor
+        # this really messes up things, because the PlugIn class expects the owner to be a Component class,
+        #  and the Commands class doesn't implement everything that is expected
+        # so let's just hack this to work manually
+        self._owner = owner
         owner.addCommand(self.name,self._DiscoHandler,self.Execute,jid=jid)
     
     def plugout(self,jid):
@@ -227,13 +231,16 @@
                     self.sessions[session]['actions'][action](conn,request)
                 else:
                     # Stage not presented as an option
-                    self._owner.send(Error(request,BAD_REQUEST))
+                    self._owner._owner.send(Error(request,ERR_BAD_REQUEST))
+                    raise NodeProcessed
             else:
                 # Jid and session don't match. Go away imposter
-                self._owner.send(Error(request,BAD_REQUEST))
+                self._owner._owner.send(Error(request,ERR_BAD_REQUEST))
+                raise NodeProcessed
         elif session != None:
             # Not on this sessionid you won't.
-            self._owner.send(Error(request,BAD_REQUEST))
+            self._owner._owner.send(Error(request,ERR_BAD_REQUEST))
+            raise NodeProcessed
         else:
             # New session
             self.initial[action](conn,request)
@@ -274,11 +281,11 @@
         form = DataForm(title='Select type of operation',data=['Use the combobox to select the type of calculation you would like to do, then click Next',DataField(name='calctype',label='Calculation Type',value=sessions[session]['data']['type'],options=[['circlediameter','Calculate the Diameter of a circle'],['circlearea','Calculate the area of a circle']],typ='list-single',required=1)])
         replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
         reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
-        self._owner.send(reply)
+        self._owner._owner.send(reply)
         raise NodeProcessed
 
     def cmdSecondStage(self,conn,request):
-        form = DataForm(node = result.getTag(name='command').getTag(namespace=NS_DATA))
+        form = DataForm(node = result.getTag(name='command').getTag(name='x',namespace=NS_DATA))
         sessions[request.getTagAttr('command','sessionid')]['data']['type']=form.getField('calctype')
         sessions[request.getTagAttr('command','sessionid')]['actions']={'cancel':self.cmdCancel,None:self.cmdThirdStage,'previous':cmdFirstStage}
         # The form generation is split out to another method as it may be called by cmdThirdStage
@@ -289,11 +296,11 @@
         form = DataForm(title = 'Enter the radius', data=['Enter the radius of the circle (numbers only)',DataField(label='Radius',name='radius',typ='text-single')])
         replypayload = [Node('actions',attrs={'execute':'complete'},payload=[Node('complete'),Node('prev')]),form]
         reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'executing'},payload=replypayload)
-        self._owner.send(reply)
+        self._owner._owner.send(reply)
         raise NodeProcessed
         
     def cmdThirdStage(self,conn,request):
-        form = DataForm(node = result.getTag(name='command').getTag(namespace=NS_DATA))
+        form = DataForm(node = result.getTag(name='command').getTag(name='x',namespace=NS_DATA))
         try:
             num = float(form.getField('radius'))
         except:
@@ -305,13 +312,13 @@
         reply = result.buildReply(request)
         form = DataForm(typ='result',data=[DataField(label='result',name='result',value=result)])
         reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'completed'},payload=form)
-        self._owner.send(reply)
+        self._owner._owner.send(reply)
         raise NodeProcessed
         
     def cmdCancel(self,conn,request):
         reply = request.buildReply('result')
         reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'cancelled'})
-        self._owner.send(reply)
+        self._owner._owner.send(reply)
         del sessions[request.getTagAttr('command','sessionid')]
             
     
