[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src/commdrivers xmlrpc/ServerAdapte...
From: |
Jan Ischebeck |
Subject: |
gnue/common/src/commdrivers xmlrpc/ServerAdapte... |
Date: |
Tue, 11 Jun 2002 19:44:15 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jan Ischebeck <address@hidden> 02/06/11 19:44:15
Modified files:
common/src/commdrivers/xmlrpc: ServerAdapter.py
common/src/commdrivers/_directory: DirectoryServer.py
common/src/commdrivers: GCommBase.py
Added files:
common/src/commdrivers/_helpers: ObjectEnabler.py
Removed files:
common/src/commdrivers/xmlrpc: DebugSocketServer.py
Log message:
split up call dispatching, move directory based dispatching into
directoryServer, added new ObjectEnabler object for object-method
dispatching
new dispatchers can be added on the fly.
Just update xmlrpc for now
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/_directory/DirectoryServer.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/GCommBase.py.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/commdrivers/_helpers/ObjectEnabler.py?rev=1.1
Patches:
Index: gnue/common/src/commdrivers/GCommBase.py
diff -c gnue/common/src/commdrivers/GCommBase.py:1.18
gnue/common/src/commdrivers/GCommBase.py:1.19
*** gnue/common/src/commdrivers/GCommBase.py:1.18 Thu Jun 6 19:56:23 2002
--- gnue/common/src/commdrivers/GCommBase.py Tue Jun 11 19:44:15 2002
***************
*** 68,73 ****
--- 68,74 ----
def __init__(self, rpcdef, bindings, params):
self._bindings = bindings
self._rpcdef = rpcdef
+ self._dispatchers = []
def allowObjectIntrospection(self,allow):
# allow the remote client to get the type of an object by its handle
***************
*** 80,91 ****
def serveAsNewThread(self):
thread.start_new_thread(self.serve,())
! ## ObjectMethodChecking means, to check if the method of an object is
! ## included in the grpc
! ## in the service directory
! def setObjectMethodChecking(self,checking_on):
! self._objectMethodChecking=checking_on
! pass
def runService(self, method, data):
pass
--- 81,91 ----
def serveAsNewThread(self):
thread.start_new_thread(self.serve,())
! # add an function which accepts the parameter (method, params)
! # which is called to dispatch incoming method requests
! # and returns a tuple (result,rtype,method,params)
! def addDispatcher(self,func):
! self._dispatchers=[func]+self._dispatchers
def runService(self, method, data):
pass
Index: gnue/common/src/commdrivers/_directory/DirectoryServer.py
diff -c gnue/common/src/commdrivers/_directory/DirectoryServer.py:1.4
gnue/common/src/commdrivers/_directory/DirectoryServer.py:1.5
*** gnue/common/src/commdrivers/_directory/DirectoryServer.py:1.4 Thu Jun
6 19:56:23 2002
--- gnue/common/src/commdrivers/_directory/DirectoryServer.py Tue Jun 11
19:44:15 2002
***************
*** 58,64 ****
GDebug.printMesg(5,'XML-RPC Service Directory:\n%s' % \
self.directory.keys())
!
# add some standard methods to the service directory
--- 58,64 ----
GDebug.printMesg(5,'XML-RPC Service Directory:\n%s' % \
self.directory.keys())
! self._dispatchers=[self.methodDispatcher]
# add some standard methods to the service directory
***************
*** 252,257 ****
--- 252,375 ----
self.directory[method]['binding']))
return self.directory[method]
+
+
+
+ ##########################################################
+ #
+ # method / call dispatching
+ #
+ ##########################################################
+
+
+ #
+ # Call the requested method
+ #
+ def call(self, method, params):
+ if self._loglevel>0:
+ print _("Dispatching: "), method, params
+
+ for i in self._dispatchers:
+ (result,rtype,method,params) = i(method,params)
+
+ if rtype:
+ # check for empty results (not allowed for XMLRPC)
+ if result==None:
+ GDebug.printMesg(3,'Transform result None into 1')
+ result=1
+ return result
+
+ return result
+
+ #
+ # dispatch methods
+ #
+ def methodDispatcher(self, method, params):
+
+ # call to a service method or a helper call (get/set) for
+ # a service attribut
+ try:
+ direntry = self.getMethodDirEntry(method)
+ server_method = direntry['binding']
+ server_attribute = None
+
+ # check if it is an real method (binding -> method)
+ # or an get/set method for an attribut (binding-> attribut)
+ if (type(server_method)!=type(self.call)):
+ server_attribute = server_method
+ server_method=None
+
+ signature=direntry['signature']
+
+ if (server_method==None) and (server_attribute==None):
+ raise AttributeError, \
+ _("Server XML-RPC method '%s' is not ") % method +\
+ _("bound to real method")
+
+ except KeyError:
+ raise AttributeError, \
+ _("Server does not have XML-RPC ") +\
+ _("procedure %s") % method
+
+ self.checkParamsAgainstSignature(signature,params)
+
+ # check if it is an real method (binding -> method)
+ # or an get/set method for an attribut (binding-> attribut)
+
+ if (server_method!=None):
+
+ # call method with params
+ result=server_method(*params)
+
+ else:
+ # simulate a get_X / set_X method
+ result=self.emulate_get_set_method(self, server_attribute,
+ method, params)
+ return (result,signature[0],method,params)
+
+
+ #
+ # Call the requested method
+ #
+ def emulate_get_set_method(self, real_attribute, methodname, params):
+
+ ## check wether its the set or the get method for the attribut
+ mparts=string.splitfields(methodname,'.')
+ mparts.reverse()
+ calltype=mparts[0]
+ calltype=calltype[:4]
+ GDebug.printMesg(7,'method %s has calling type %s' %\
+ (method,calltype))
+
+ if calltype=='set_':
+ # setAttribut method
+ server_attribute=params[0]
+ return None
+ elif calltype=='get_':
+ # getAttribut method
+ return server_attribute
+ else:
+ raise AttributeError, \
+ _("Internal Server XML-RPC error: method type") +\
+ _("(get/set attribute) couldn't be detected (method %s)") \
+ % method
+
+
+ #
+ # check if the requested method has correct parameters and
+ # correct parameter types
+ #
+ def checkParamsAgainstSignature(self, method, params):
+ try:
+ # TODO: Compare submitted attributs with signature
+ pass
+ except KeyError:
+ raise AttributeError, \
+ _("Server XML-RPC ") +\
+ _("procedure %s accepts just %s as attributs") % (method,attr)
+
+
+
####### Introspection support
Index: gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py
diff -c gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.15
gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.16
*** gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.15 Mon May 27
14:06:45 2002
--- gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py Tue Jun 11 19:44:15 2002
***************
*** 31,36 ****
--- 31,37 ----
# Server Parameters:
#
# port The port that the service is located on
+ # loglevel Loglevel of the internal server
#
***************
*** 46,52 ****
from gnue.common import GComm, GDebug
! from gnue.common.commdrivers._helpers import ObjectLibrarian
from gnue.common.commdrivers._directory import DirectoryServer
from gnue.common.commdrivers import GCommBase
--- 47,53 ----
from gnue.common import GComm, GDebug
! from gnue.common.commdrivers._helpers import ObjectLibrarian,ObjectEnabler
from gnue.common.commdrivers._directory import DirectoryServer
from gnue.common.commdrivers import GCommBase
***************
*** 79,85 ****
#
# ServerAdapter
#
! class ServerAdapter(DirectoryServer.DirectoryServer):
def __init__(self, rpcdef, bindings, params):
--- 80,86 ----
#
# ServerAdapter
#
! class ServerAdapter(ObjectEnabler.ObjectEnabler):
def __init__(self, rpcdef, bindings, params):
***************
*** 94,102 ****
self.server=XMLRPC_Server()
! ## Build up Service Directory
! DirectoryServer.DirectoryServer.__init__(self, rpcdef, \
! bindings, params)
if hasattr(params,'loglevel'):
self._loglevel = params['loglevel']
--- 95,103 ----
self.server=XMLRPC_Server()
! ## Build up Service Directory and enable object dispatching
! ObjectEnabler.ObjectEnabler.__init__(self, rpcdef, \
! bindings, params)
if hasattr(params,'loglevel'):
self._loglevel = params['loglevel']
***************
*** 110,124 ****
self.server.setOnErr(self.OnErr)
def serve(self):
! while 1:
try:
self.server.work()
# you could set a timeout if desired
except:
e = sys.exc_info()
if e[0] in (KeyboardInterrupt, SystemExit):
! raise e[0], e[1], e[2]
! traceback.print_exc()
def addRpMethod(self,object,parent,binding):
--- 111,134 ----
self.server.setOnErr(self.OnErr)
def serve(self):
! quit=0
! while quit==0:
try:
self.server.work()
# you could set a timeout if desired
except:
e = sys.exc_info()
if e[0] in (KeyboardInterrupt, SystemExit):
! # shut down server without showing error message
! quit=1
! # raise e[0], e[1], e[2]
! else:
! print "*" * 60
! print "Error occured on server:"
! print "*" * 60
! traceback.print_exc()
! print "*" * 60
! print "\n\n"
def addRpMethod(self,object,parent,binding):
***************
*** 149,316 ****
print _("Internal server error occured:\n"+
" server %s \n on source %s.") % (server,source)
return xmlrpc.ONERR_KEEP_WORK
-
-
- #
- # Call the requested method
- #
- def call(self, method, params):
- if self._loglevel>0:
- 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)
- try:
- server_method=getattr(o,method)
- server_attribute=None
- except AttributeError:
- server_method=None
- try:
- server_attribute=getattr(o,method[4:])
- except AttributeError:
-
- if method!="_close":
- msg=_("Internal XMLRPC server error: method %s can be ")% \
- method +\
- _("found in the directory (build out of a .grpc file),")+\
- _(" but the object doesn't contain this method/attribut.")+\
- _(" Please check you .grpc file for wrong return types.")
-
- raise AttributeError, msg
-
- if method!="_close":
- direntry = self.getMethodDirEntry(o._type+"."+method)
- signature=direntry['signature']
- else:
- signature= ('string',)
-
- else:
-
- # call to a service method or a helper call (get/set) for
- # a service attribut
- try:
- direntry = self.getMethodDirEntry(method)
- server_method = direntry['binding']
- server_attribute = None
-
- # check if it is an real method (binding -> method)
- # or an get/set method for an attribut (binding-> attribut)
- if (type(server_method)!=type(self.call)):
- server_attribute = server_method
- server_method=None
-
- signature=direntry['signature']
-
- if (server_method==None) and (server_attribute==None):
- raise AttributeError, \
- _("Server XML-RPC method %s is not ")% method +\
- _("bound to real method")
- except KeyError:
- raise AttributeError, \
- _("Server does not have XML-RPC ") +\
- _("procedure %s") % method
- try:
- #
- pass
- # TODO: Compare submitted attributs with signature
- except KeyError:
- 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;
-
- # check if it is an real method (binding -> method)
- # or an get/set method for an attribut (binding-> attribut)
-
- if (server_method!=None):
-
- # call method with params
- result=server_method(*params)
-
- # check if it's the close object method
- elif (method=="_close"):
-
- result=self.releaseDynamicObject(o)
-
- else:
-
- ## check wether its the set or the get method for the attribut
- mparts=string.splitfields(method,'.')
- mparts.reverse()
- calltype=mparts[0]
- calltype=calltype[:4]
- GDebug.printMesg(7,'method %s has calling type %s' %\
- (method,calltype))
- if calltype=='set_':
- # setAttribut method
- server_attribute=params[0]
- elif calltype=='get_':
- # getAttribut method
- result=server_attribute
- else:
- raise AttributeError, \
- _("Internal Server XML-RPC error: method type") +\
- _("(get/set attribute) couldn't be detected (method %s)") \
- % method
-
-
- # replace real object in param with an object handle
- if type(result)==type(self): ## both should be instances
- ObjectLibrarian.archiveObject(result)
-
- # get the type of the result
- rtype=signature[0]
- # delete the surrounding brackets < >
- rtype=rtype[1:len(rtype)-1]
- # store typeinfo in new object
- result._type=rtype
-
- result=ObjectLibrarian.getObjectReference(result)
- self.registerDynamicObject(result,rtype)
-
- # check for empty results (not allowed for XMLRPC)
- if result==None:
- GDebug.printMesg(3,'Transform result None into 1')
- result=1
-
- return result
-
def registerDynamicObject(self,objhandle,type):
#
# add new methods to the xmlrpc server
--- 159,166 ----
***************
*** 344,355 ****
# remove the method to close this object
self.server.removeMethods({"["+objhandle+"]._close":None})
-
- def releaseDynamicObject(self,object):
- # delete bindings for this object in the xmlrpc method directory
- self.deregisterDynamicObject(object)
- # release object for Object Librarian
- ObjectLibrarian.deferenceObject(object)
class XMLRPC_Server(xmlrpc.server):
--- 194,199 ----
***************
*** 367,413 ****
# del self._o.comtab[name]
# or
# self._o.removeMethods(d)
-
- ##############################################################################
- #
- # Used internally by the XML-RPC server to proxy
- # between Object-by-Ref and actual objects.
- #
- class _ObjectByReferenceHandler:
-
- def __init__(self, oclass):
- self._class = oclass
-
- # If this makes absolutely no sense, move on and trust the code :)
- def requestHandler(self, method, *params, **args):
-
- if len(params):
-
- # If parameters were passed, the first one is always the handle
- refid = params[0]
-
- # The object's real method doesn't expect to receive the object handle
- params = params[1:]
-
- else:
-
- try:
-
- # If only named parameters are present, then
- # obj_handle should be the object handle...
- refid = args['obj_handle']
-
- # The object's real method doesn't expect to receive the object handle
- del args['obj_handle']
-
- except KeyError:
- raise StandardError, _('Object handle not returned') # TODO
-
- try:
- return ObjectLibrarian. \
- retrieveObject(refid).__dict__[method](*params, **args)
- except KeyError:
-
- # Attempt to use an invalid objecthandle
- raise StandardError, _('Invalid object handle') # TODO
-
--- 211,213 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/common/src/commdrivers xmlrpc/ServerAdapte...,
Jan Ischebeck <=