commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src GComm.py commdrivers/_parser/Pa...


From: Jason Cater
Subject: gnue/common/src GComm.py commdrivers/_parser/Pa...
Date: Wed, 27 Feb 2002 15:45:53 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/02/27 15:45:53

Modified files:
        common/src     : GComm.py 
        common/src/commdrivers/_parser: Parser.py 
        common/src/commdrivers/_test: donuts.grpc server.py 
        common/src/commdrivers/xmlrpc: DebugSocketServer.py 
                                       ServerAdapter.py 

Log message:
        grpc patches by Jan Ischebeck

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GComm.py.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/_parser/Parser.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/_test/donuts.grpc.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/_test/server.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: gnue/common/src/GComm.py
diff -c gnue/common/src/GComm.py:1.13 gnue/common/src/GComm.py:1.14
*** gnue/common/src/GComm.py:1.13       Tue Dec 11 00:31:11 2001
--- gnue/common/src/GComm.py    Wed Feb 27 15:45:52 2002
***************
*** 76,82 ****
  # bindings   A dictionary containing binding definitions. The dictionary
  #            is of the form: {server:handler} where:
  #              1) service: Name of the service being bound/exposed
! #              2) handler: Method that when called returns a class instance
  #
  def bind(rpcdef, drivers, bindings):
  
--- 76,83 ----
  # bindings   A dictionary containing binding definitions. The dictionary
  #            is of the form: {server:handler} where:
  #              1) service: Name of the service being bound/exposed
! #              2) handler: Method that when called returns a class 
! #                 instance i.e. {'DonutPlace',getDonutPlaceObj}
  #
  def bind(rpcdef, drivers, bindings):
  
Index: gnue/common/src/commdrivers/_parser/Parser.py
diff -c gnue/common/src/commdrivers/_parser/Parser.py:1.4 
gnue/common/src/commdrivers/_parser/Parser.py:1.5
*** gnue/common/src/commdrivers/_parser/Parser.py:1.4   Wed Dec 19 02:50:27 2001
--- gnue/common/src/commdrivers/_parser/Parser.py       Wed Feb 27 15:45:52 2002
***************
*** 85,91 ****
           'Attributes': {
              'name': {
                 'Typecast': GTypecast.name,
!                'Required': 1 } },
           'ParentTags': ('gnurpc','service') },
  
        'method': {
--- 85,93 ----
           'Attributes': {
              'name': {
                 'Typecast': GTypecast.name,
!                'Required': 1 },
!             'binding': {
!                'Typecast': GTypecast.name } },
           'ParentTags': ('gnurpc','service') },
  
        'method': {
Index: gnue/common/src/commdrivers/_test/donuts.grpc
diff -c gnue/common/src/commdrivers/_test/donuts.grpc:1.3 
gnue/common/src/commdrivers/_test/donuts.grpc:1.4
*** gnue/common/src/commdrivers/_test/donuts.grpc:1.3   Thu Dec  6 18:19:42 2001
--- gnue/common/src/commdrivers/_test/donuts.grpc       Wed Feb 27 15:45:53 2002
***************
*** 1,7 ****
  <?xml version="1.0"?>
  <gnurpc>
  
!   <service name="DonutPlace" >
  
      <service name="Management">
  
--- 1,7 ----
  <?xml version="1.0"?>
  <gnurpc>
  
!   <service name="DonutPlace" binding="DonutPlace">
  
      <service name="Management">
  
***************
*** 21,26 ****
--- 21,29 ----
          <attribute name="flavor" type="string" readonly=""/>
          <attribute name="unitLocation" type="string" readonly=""/>
          <method name="requestDelivery" return="string">
+ 
+         </method>
+         <method name="get_flavor" return="string">
  
          </method>
        </object>
Index: gnue/common/src/commdrivers/_test/server.py
diff -c gnue/common/src/commdrivers/_test/server.py:1.6 
gnue/common/src/commdrivers/_test/server.py:1.7
*** gnue/common/src/commdrivers/_test/server.py:1.6     Tue Dec 11 00:31:11 2001
--- gnue/common/src/commdrivers/_test/server.py Wed Feb 27 15:45:53 2002
***************
*** 41,47 ****
      self.unitLocation = unitLocation
  
    def get_flavor(self):
!     return flavor
  
    def set_flavor(self, flavor):
      self.flavor = flavor
--- 41,47 ----
      self.unitLocation = unitLocation
  
    def get_flavor(self):
!     return self.flavor
  
    def set_flavor(self, flavor):
      self.flavor = flavor
***************
*** 75,91 ****
    def run(self):
  
      # Create the various servers
!     bind(self.requestDonutPlace)
  
      # Daemonize (if appropriate)
      GServerApp.run(self)
  
  
    def requestDonutPlace(self):
      # In real applications, this would probably either
      #  1) Maintain a single DonutPlace that was always used, or
      #  2) Maintain a pool of DonutPlaces that got recycled.
      # We are just testing transports, so we can cheat :)
      return DonutPlace()
  
  
--- 75,94 ----
    def run(self):
  
      # Create the various servers
!     servers=bind(self.requestDonutPlace)
  
      # Daemonize (if appropriate)
      GServerApp.run(self)
  
+     servers["xmlrpc"].serve()
+     
  
    def requestDonutPlace(self):
      # In real applications, this would probably either
      #  1) Maintain a single DonutPlace that was always used, or
      #  2) Maintain a pool of DonutPlaces that got recycled.
      # We are just testing transports, so we can cheat :)
+     print "New Donutplace created"
      return DonutPlace()
  
  
***************
*** 112,117 ****
--- 115,121 ----
    # Expose our services to the world
    return GComm.bind ( "donuts.grpc",
                        transports,
+                      # {'xmlrpc': handler }) 
                        {'DonutPlace': handler })
  
  
Index: gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py
diff -c gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py:1.3 
gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py:1.4
*** gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py:1.3 Thu Dec 20 
00:14:53 2001
--- gnue/common/src/commdrivers/xmlrpc/DebugSocketServer.py     Wed Feb 27 
15:45:53 2002
***************
*** 34,39 ****
--- 34,40 ----
  
  
  import SocketServer
+ import socket
  import xmlrpclib
  
  from gnue.common.commdrivers import GCommBase
***************
*** 46,54 ****
        self._port = params['port']
      except KeyError:
        raise GComm.AdapterConfigurationError,'Required parameter "port" not 
supplied'
! 
!     self._tcpserver = SocketServer.TCPServer(('',self._port),
!           DebugRequestHandler)
  
  
  
--- 47,54 ----
        self._port = params['port']
      except KeyError:
        raise GComm.AdapterConfigurationError,'Required parameter "port" not 
supplied'
!     # self._tcpserver = SocketServer.TCPServer(('',self._port),
!     #      self._requestHandler)
  
  
  
***************
*** 56,66 ****
      pass
  
  
- 
  class HTTPServer(DebugSocketServer):
  
    def __init__(self, params):
      DebugSocketServer.__init__(self, params)
  
  
  
--- 56,74 ----
      pass
  
  
  class HTTPServer(DebugSocketServer):
  
    def __init__(self, params):
      DebugSocketServer.__init__(self, params)
+ 
+ 
+ class MyHTTPServer(SocketServer.ThreadingTCPServer):
+   def setParent(self,parent):
+     self._parent=parent
+     
+   def server_bind(self):
+     self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+     self.socket.bind(self.server_address)
  
  
  
Index: gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py
diff -c gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.7 
gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.8
*** gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.7     Tue Jan  1 
13:31:35 2002
--- gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py Wed Feb 27 15:45:53 2002
***************
*** 44,52 ****
  
  #from gnue.common.commdrivers._helpers.AsyncSocketServer import 
AsyncHTTPServer
  
! from DebugSocketServer import HTTPServer
  import BaseHTTPServer
! 
  from gnue.common import GComm, GDebug
  from gnue.common.commdrivers._helpers import ObjectLibrarian
  from gnue.common.commdrivers import GCommBase
--- 44,52 ----
  
  #from gnue.common.commdrivers._helpers.AsyncSocketServer import 
AsyncHTTPServer
  
! from DebugSocketServer import HTTPServer,MyHTTPServer
  import BaseHTTPServer
! import SocketServer
  from gnue.common import GComm, GDebug
  from gnue.common.commdrivers._helpers import ObjectLibrarian
  from gnue.common.commdrivers import GCommBase
***************
*** 111,120 ****
                          + 'the specified function' }
         }
  
- 
      # Add all the grpc defined methods
      # to our internal "service directory"
!     self._xmlrpc_mapObjects(rpcdef)
  
      GDebug.printMesg(3,'XML-RPC Service Directory:\n * %s' % \
              string.join(self.directory.keys(),'\n * '))
--- 111,119 ----
                          + 'the specified function' }
         }
  
      # Add all the grpc defined methods
      # to our internal "service directory"
!     self._xmlrpc_mapObjects(rpcdef,bindings)
  
      GDebug.printMesg(3,'XML-RPC Service Directory:\n * %s' % \
              string.join(self.directory.keys(),'\n * '))
***************
*** 125,131 ****
    #
    # Create an internal "service directory"
    #
!   def _xmlrpc_mapObjects(self, object, parent=None):
  
      # For servicable objects, maintain a complete "path" for reference
      if object._type in ('RpService','RpMethod','RpObject'):
--- 124,130 ----
    #
    # Create an internal "service directory"
    #
!   def _xmlrpc_mapObjects(self, object, bindings, parent=None):
  
      # For servicable objects, maintain a complete "path" for reference
      if object._type in ('RpService','RpMethod','RpObject'):
***************
*** 135,140 ****
--- 134,188 ----
          object._xmlrpc__path = object.name
  
  
+     ##    
+     ## Add binding informations to the objects
+     ##
+     ## services are static objects and
+     ## objects  are dynamic ones
+     ##
+     if hasattr(object,'binding'):      
+ 
+       # the direct mapping
+       if bindings.has_key(object.binding):
+         GDebug.printMesg(3,'XML-RPC Binding Information:');
+         GDebug.printMesg(3,' * %s is bound to \n * %s' % \
+                          (object.binding,bindings[object.binding]))
+ 
+         # for services create an "static" object
+         if object._type == 'RpService':
+           object._realbinding=bindings[object.binding]()
+ 
+         else:
+           
+           # in all other cases just save the binding information
+           object._realbinding=bindings[object.binding]          
+         
+         
+       else:
+         print "Missing Binding information. Please add binding ",\
+               "information for ", \
+               object.binding      
+         
+     # care for bindings in all Services
+     if object._type == 'RpService':
+       if hasattr(object,'_realbinding'):
+         pass  # nothing to do
+       else:
+         if parent._type == 'RpService':
+           try:
+             object._realbinding=getattr(parent._realbinding,\
+                                          object.name)
+           except:
+             raise AttributeError, \
+                   "XML-RPC can't bind service '%s' to service '%s'" %\
+                   (object.name,parent.name)
+         elif parent._type == 'RpGnuRpc':
+           pass
+         else:
+           raise AttributeError, \
+                 "XML-RPC: cannot bind service '%s' to %s" %\
+                 (object.name,parent._type) 
+           
  
      # Add all methods to our directory
      if object._type == 'RpMethod':
***************
*** 159,169 ****
          signature.append(_datatypeMap[arg.type])
  
  
        # Add the directory entry
        self.directory[object._xmlrpc__path] = \
          { 'signature': tuple(signature),
            'help': '',         # TODO
!           'binding': None   } # TODO
  
  
      #
--- 207,232 ----
          signature.append(_datatypeMap[arg.type])
  
  
+       # check for the binding
+       if hasattr(object,'_realbinding'):
+         bindto=object._realbinding
+       else:
+         if parent._type == 'RpService':
+           try:
+             bindto=getattr(parent._realbinding,object.name)
+           except:
+             raise AttributeError, \
+                       "XML-RPC can't bind method '%s' to service '%s'" %\
+                       (object.name,parent.name)
+             pass
+         else:
+           bindto=None
+         
        # Add the directory entry
        self.directory[object._xmlrpc__path] = \
          { 'signature': tuple(signature),
            'help': '',         # TODO
!           'binding': bindto  }
  
  
      #
***************
*** 201,210 ****
  
      # Now, map our children
      for child in object._children:
!       self._xmlrpc_mapObjects(child, object)
  
      # Sigh... what kind of drugs was I on to volunteer for RPC abstraction?
  
  
    #
    # Return an exception
--- 264,282 ----
  
      # Now, map our children
      for child in object._children:
!       self._xmlrpc_mapObjects(child, bindings, object)
  
      # Sigh... what kind of drugs was I on to volunteer for RPC abstraction?
+   def getObject(self,name):
+     return obj
  
+   def getMethodDirEntry(self,method):
+     GDebug.printMesg(6,'XML-RPC Directory entry:\n (%s,%s,%s)' % \
+                      (self.directory[method]['signature'],\
+                       self.directory[method]['help'],\
+                       self.directory[method]['binding']))
+     
+     return self.directory[method]
  
    #
    # Return an exception
***************
*** 223,229 ****
    #
  
    def system__listMethods(self):
!     return self.supportedMethods.keys()
  
  
    def system__methodHelp(self, method):
--- 295,301 ----
    #
  
    def system__listMethods(self):
!     return self.directory.keys()
  
  
    def system__methodHelp(self, method):
***************
*** 252,258 ****
    #                                                                        #
    #                                                                        #
    ##########################################################################
! 
  
  ##############################################################################
  ##############################################################################
--- 324,339 ----
    #                                                                        #
    #                                                                        #
    ##########################################################################
!   def serve(self):
!     self._requestHandler = RequestHandler
!     self._tcpserver = MyHTTPServer(('',self._port),
!                                              self._requestHandler)
!     self._tcpserver.setParent(self)
!     try: 
!       self._tcpserver.serve_forever()
!     except KeyboardInterrupt:
!       pass
!       
  
  ##############################################################################
  ##############################################################################
***************
*** 282,288 ****
        # generate response
        try:
          response = self.call(method, params)
!         if type(response) != type(()):
            response = (response,)
        except:
          # report exception back to server
--- 363,371 ----
        # generate response
        try:
          response = self.call(method, params)
!         if response==None:
!           response=()
!         elif type(response) != type(()):
            response = (response,)
        except:
          # report exception back to server
***************
*** 315,333 ****
    #
    def call(self, method, params):
      print "Dispatching: ", method, params
!     try:
!       server_method = getattr(self, method)
!     except:
!       raise AttributeError, \
!              "Server does not have XML-RPC " \
               "procedure %s" % method
-     return server_method(method, params)
  
  
  
  ##############################################################################
  #
! # Used internally be the XML-RPC server to proxy
  # between Object-by-Ref and actual objects.
  #
  class _ObjectByReferenceHandler:
--- 398,502 ----
    #
    def call(self, method, params):
      print "Dispatching: ", method, params
!     
!     ## Check if the Method is part of a service or a pointer to a
!     ## single object
!     ##
!     ## Call to an object:  method="_Management:235423456_.getAttr"
!     ##                     params=""
!     ## Call to an method: (of a service=one object)
!     ##                     method="DonutPlace.Management.Restart"
! 
!     if method[0]=='[':
!       # call to an object
!       # 1. get the object from the objectlibrarian
!       # 2. check, if the object is supported by the gfd
!       try:
!         i=string.index(method,']',1)
!         objhandle=method[1:i]
!         method=method[i+2:]        
!       except ValueError:
!         raise AttributeError, \
!               "Wrong format of object handler " \
!               "in method call %s" % method
!       # TODO check in service dir, if obj is supported or not
!       o=ObjectLibrarian.retrieveObject(objhandle)
!       server_method=getattr(o,method)
!     else:
! 
!       # call to a service method            
!       try:      
!         direntry = self.server._parent.getMethodDirEntry(method)      
!         server_method = direntry['binding']
!         
!         if server_method==None:
!           raise AttributeError, \
!               "Server XML-RPC method %s has is not " \
!               "bound to real method" % method
!       except:
!         raise AttributeError, \
!               "Server does not have XML-RPC " \
!               "procedure %s" % method
!       try:
!         attr=direntry['signature']
!         # TODO:  Compare submitted attributs with signature
!       except:
!         raise AttributeError, \
!               "Server XML-RPC " \
!               "procedure %s accepts just %s as attributs" % (method,attr)
! 
!     # replace object handles in param with the real object
!     counter=0
!     while counter<len(params):
!       p=params[counter]
!       if type(p)==type(""):
!         if (len(p)==42) and (p[0]=="[") and (p[41]=="]"):
!           try:            
!             p=p[1:41]
!             obj=ObjectLibrarian.retrieveObject(p)
!             newp=params[0:counter-1]+(obj,)+params[counter+1:] 
!             params=newp
!           except:
!             pass        
!       counter=counter+1;
!             
!     
!     # call method with params
!     if len(params)==0:
!       result=server_method()
!     elif len(params)==1:
!       result=server_method(params[0])
!     elif len(params)==2:
!       result=server_method(params[0],params[1])
!     elif len(params)==3:
!       result=server_method(params[0],params[1],params[2])
!     elif len(params)==4:
!       result=server_method(params[0],params[1],params[2],params[3])
!     elif len(params)==5:
!       result=server_method(params[0],params[1],params[2],params[3],\
!                            params[4])
!     elif len(params)==6:
!       result=server_method(params[0],params[1],params[2],params[3],\
!                            params[4],params[5])
!     elif len(params)==7:
!       result=server_method(params[0],params[1],params[2],params[3],\
!                            params[4],params[5],params[6])
!     else:
!       raise AttributeError,\
!              "Too many param for XML-RPC " \
               "procedure %s" % method
  
+     # replace real object in param with an object handle
+     if type(result)==type(self):  ## both should be instances
+        ObjectLibrarian.archiveObject(result)
+        result=ObjectLibrarian.getObjectReference(result)
+     
+     return result
  
  
  ##############################################################################
  #
! # Used internally by the XML-RPC server to proxy
  # between Object-by-Ref and actual objects.
  #
  class _ObjectByReferenceHandler:
***************
*** 358,364 ****
          del args['obj_handle']
  
        except KeyError:
!         raise StandardError, 'Object handle not returned'   # TDOO
  
      try:
        return ObjectLibrarian. \
--- 527,533 ----
          del args['obj_handle']
  
        except KeyError:
!         raise StandardError, 'Object handle not returned'   # TODO
  
      try:
        return ObjectLibrarian. \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]