/[papo]/gnue/common/src/commdrivers/_directory/DirectoryServer.py
ViewVC logotype

Diff of /gnue/common/src/commdrivers/_directory/DirectoryServer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by charlie, Tue Aug 27 18:15:52 2002 UTC revision 1.4 by styxman, Fri Nov 15 15:32:55 2002 UTC
# Line 58  class DirectoryServer(GCommBase.Server): Line 58  class DirectoryServer(GCommBase.Server):
58      GDebug.printMesg(5,'XML-RPC Service Directory:\n%s' % \      GDebug.printMesg(5,'XML-RPC Service Directory:\n%s' % \
59              self.directory.keys())              self.directory.keys())
60            
61        self._dispatchers=[self.methodDispatcher]
62            
63    # add some standard methods to the service directory    # add some standard methods to the service directory
64    
# Line 253  class DirectoryServer(GCommBase.Server): Line 253  class DirectoryServer(GCommBase.Server):
253            
254      return self.directory[method]      return self.directory[method]
255    
256    
257    
258      ##########################################################
259      #
260      #  method / call dispatching
261      #
262      ##########################################################
263    
264    
265      #
266      # Call the requested method
267      #
268      def call(self, method, params):
269        if self._loglevel>0:
270          print _("Dispatching: "), method, params
271    
272        for i in self._dispatchers:
273          (result,rtype,method,params) = i(method,params)
274    
275          if rtype:
276            # check for empty results (not allowed for XMLRPC)
277            if result==None:
278              GDebug.printMesg(3,'Transform result None into 1')
279              result=1
280              return result
281        
282            return result
283    
284      #
285      # dispatch methods
286      #
287      def methodDispatcher(self, method, params):
288    
289        # call to a service method or a helper call (get/set) for
290        # a service attribut
291        try:
292          direntry = self.getMethodDirEntry(method)
293          server_method = direntry['binding']
294          server_attribute = None
295          
296          # check if it is an real method (binding -> method)      
297          # or an get/set method for an attribut (binding-> attribut)
298          if (type(server_method)!=type(self.call)):
299            server_attribute = server_method
300            server_method=None
301              
302          signature=direntry['signature']
303    
304          if (server_method==None) and (server_attribute==None):
305            raise AttributeError, \
306                  _("Server XML-RPC method '%s' is not ") % method +\
307                  _("bound to real method")
308          
309        except KeyError:
310          raise AttributeError, \
311                  _("Server does not have XML-RPC ") +\
312                  _("procedure %s") % method
313        
314        self.checkParamsAgainstSignature(signature,params)
315        
316        # check if it is an real method (binding -> method)
317        # or an get/set method for an attribut (binding-> attribut)
318    
319        if (server_method!=None):
320                
321          # call method with params
322          result=server_method(*params)
323          
324        else:
325          # simulate a get_X / set_X method
326          result=self.emulate_get_set_method(self, server_attribute,
327                                             method, params)
328        return (result,signature[0],method,params)
329    
330    
331      #
332      # Call the requested method
333      #
334      def emulate_get_set_method(self, real_attribute, methodname, params):
335          
336        ## check wether its the set or the get method for the attribut
337        mparts=string.splitfields(methodname,'.')
338        mparts.reverse()
339        calltype=mparts[0]
340        calltype=calltype[:4]
341        GDebug.printMesg(7,'method %s has calling type %s' %\
342                         (method,calltype))
343        
344        if calltype=='set_':
345          # setAttribut method
346          server_attribute=params[0]
347          return None
348        elif calltype=='get_':
349          # getAttribut method
350          return server_attribute
351        else:
352          raise AttributeError, \
353                _("Internal Server XML-RPC error: method type") +\
354                _("(get/set attribute) couldn't be detected (method %s)") \
355                % method      
356    
357    
358      #
359      # check if the requested method has correct parameters and
360      #   correct parameter types
361      #
362      def checkParamsAgainstSignature(self, method, params):
363        try:
364          # TODO:  Compare submitted attributs with signature
365          pass
366        except KeyError:
367            raise AttributeError, \
368                  _("Server XML-RPC ") +\
369                  _("procedure %s accepts just %s as attributs") % (method,attr)
370        
371    
372    
373    
374  ####### Introspection support  ####### Introspection support
375    
376    def system__listMethods(self):    def system__listMethods(self):

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26