commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7047 - trunk/gnue-common/src/rpc/drivers/pyro


From: jan
Subject: [gnue] r7047 - trunk/gnue-common/src/rpc/drivers/pyro
Date: Sun, 20 Feb 2005 08:52:32 -0600 (CST)

Author: jan
Date: 2005-02-20 08:52:31 -0600 (Sun, 20 Feb 2005)
New Revision: 7047

Modified:
   trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py
   trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py
   trunk/gnue-common/src/rpc/drivers/pyro/__init__.py
Log:
first step to fix pyro. adapter is working again, but without proper error 
handling


Modified: trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py     2005-02-20 
14:43:17 UTC (rev 7046)
+++ trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py     2005-02-20 
14:52:31 UTC (rev 7047)
@@ -37,9 +37,9 @@
 #    port        The port that the service is located on
 #
 
-from gnue.common.rpc import GCommBase
-from gnue.common.rpc import GComm
-from gnue.common.apps import GConfig
+from gnue.common.rpc import client
+from gnue.common.rpc.drivers import Base
+from gnue.common.apps import GConfig, GDebug, errors
 from gnue import paths
 
 import string, sys
@@ -59,7 +59,7 @@
 #
 # ClientAdapter
 #
-class ClientAdapter(GCommBase.Client):
+class ClientAdapter(Base.Client):
 
   def __init__(self, params):
 
@@ -149,22 +149,23 @@
       locator = Pyro.naming.NameServerLocator()
       print 'Searching Naming Service...',
       self.ns = locator.getNS()
-      print 'Naming Service found 
at',self.ns.URI.address,'('+(Pyro.protocol.getHostname(self.ns.URI.address) \
-                                                               or '??')+') 
port',self.ns.URI.port
+      print ''
+      print 'Naming Service found at',self.ns.URI.address,'('+\
+            (Pyro.protocol.getHostname(self.ns.URI.address) \
+             or '??')+') port',self.ns.URI.port
+      
     except KeyError:
-      tmsg = _("To use XML-RPC, you must either specify a 'url' or\n"
+      tmsg = _("To use Pyro, you must either specify a 'url' or\n"
                "a 'host' and 'port' setting.")
       raise GComm.AdapterConfigurationError,  tmsg
     except:
-      tmsg = u_("Unable to initialize the XML-RPC interface at %s") % url
+      tmsg = u_("Unable to initialize the Pyro interface at %s") % url
       raise GComm.AdapterInitializationError, tmsg
 
 
   def request(self, service, params={}):
-    # TODO: add support for more than one baseproxy
     # resolve the Pyro object
-    self._baseproxy = _ProxyObject(self, service)
-    return self._baseproxy
+    print "Service: %s " % service
     print 'binding to object',service
     try:
       URI=self.ns.resolve(service+'.self')
@@ -173,29 +174,8 @@
       print 'Couldn\'t bind object (%s), nameserver says: %s' % (service,x)
       raise SystemExit
     
-    obj = Pyro.core.getProxyForURI(URI)
-    return obj
-    #obj = Pyro.core.getAttrProxyForURI(URI)
-    self._baseproxy = _ProxyObject(self, service)
-    return self._baseproxy
-
-
-  def errorHandler(self,src, exc):
-    # doesn't work correct, so is being disabled
-    if exc[1]==(111, 'Connection refused'):
-      # cannot raise a new error, so I try to change it
-      exc = (GComm.AdapterInitializationError,
-             u_("Unable to initialize the XML-RPC interface at %s: "
-                "Connection refused") % src.getDesc(), None)
-
-    print "Connection to ",src.getDesc()," failed."
-    print exc
-    # sys.exit(0)
-    #import traceback
-    #sys.stderr.write()
-    #traceback.print_exception(exc[0], exc[1], exc[2])
-    #return xmlrpc.ONERR_KEEP_WORK
-    return xmlrpc.ONERR_KEEP_DEF
+    return Pyro.core.getProxyForURI(URI)
+    #return Pyro.core.getAttrProxyForURI(URI)
   
   def close(self):
     # do a cleanup of the proxy objects and the object stubs
@@ -210,46 +190,24 @@
     self._objectProxys=[] 
     
     # close the client it self
-    self._client=None    
+    self.ns=None    
 
   # just in case the user forgot to delete some objects
   def __del__(self):
-    if self._client!=None:
+    if self.ns!=None:
       self.close()
-    GCommBase.Client.__del__()
+    Base.Client.__del__()
 
-  def setTimeout(self,timeout):
-    self._timeout=timeout
-    
-  def setAuthentification(self,name,passw):
-    self._auth_name=name
-    self._auth_passw=passw
 
-
   def runMethod(self, method, *args, **params):
-    # print "Calling method: %s with attr %s " % method,string.join(args,",")
-    
-    # check for special parameters
-    i=0
-    while i<len(args):
-      # care for special types
-      if hasattr(args[i],'_type'):
-        if args[i]._type=='base64':
-          args[i]=xmlrpc.base64(args[i]._value)
-        elif args[i]._type=='binary':
-          args[i]=xmlrpc.base64(args[i]._value)
-        elif args[i]._type=='boolean':
-          args[i]=xmlrpc.boolean(args[i]._value)
-        elif args[i]._type=='datetime':
-          args[i]=xmlrpc.datetime(args[i]._value)
-        else:
-          if hasattr(args[i],'_value'):
-            args[i]=args[i]._value
-      i=i+1
+    __args = [typeconv.python_to_rpc (arg, client.InvalidParameter)
+              for arg in args]
 
-            
-    # call the method
-    if 1: #try:
+    # TODO: Add type conversion for **params 
+
+    # to_call = getattr (self.__proxy, method);
+        
+    if 1==1: # try:
           print 'binding to object',method
           try:
             URI=self.ns.resolve(method)
@@ -271,33 +229,74 @@
       print "********************************************"
       sys.exit(0)
            
-    return result
+    #  result = to_call (*__args, **params)
+    #except xmlrpclib.Fault, e:
+    #  (exType, exName, exMessage, exDetail) = string.split (e.faultString,
+    #                                                        u'\x91')
+    #  raise errors.RemoteError, (exType, exName, exMessage, exDetail)
 
+    # check, if an object handle is sent
+    # TODO: make a better check
+    if type(result)==type("String") and len(result)==40 :
 
+      # create an proxy for this handle
+      return self._createproxy ("[%s]" % result)
 
+    else:
+      return typeconv.rpc_to_python (result, client.InvalidParameter)
 
+
+
+
 ##############################################################################
 #
 # ProxyObject
 #
-class _ProxyObject(GCommBase.ProxyObject):
+class _ProxyObject(Base.ProxyObject):
 
   def __call__(self, *args, **params):
-    if not hasattr(self,'_parent'):
-      return
-    if not hasattr(self._parent,'_pyrobind'):
+    gDebug (3, "%s (%s)" \
+            % (self.__service,
+               string.join ([repr (x) for x in args] + \
+                          ["%s = %s" % (x [0], repr (x [1])) \
+                           for x in params.items ()], ', ')))
+    print self.__parent
+    #if not hasattr(self,'__parent'):
+    #  print "The object '%s' can't be called" % self.__service
+    #  return
+    if not hasattr(self.__parent,'__pyrobind'):
       try:
-        
URI=self._adapter.ns.resolve(string.join(self._parent._attrPath,'.')+'.self')
+        URI=self.__adapter.ns.resolve(self.__parent.__service+'.self')
       except Pyro.core.PyroError,x:
         print 'Couldn\'t bind object %s, nameserver says: %s' % 
(string.join(self._parent._attrPath,'.')+'.self',x)
         raise SystemExit      
-      self._parent._pyrobind = Pyro.core.getProxyForURI(URI)
+      self.__parent.__pyrobind = Pyro.core.getProxyForURI(URI)
     
-    return getattr(self._parent._pyrobind, self._attr)(*args, **params)
+    return getattr(self.__parent.__pyrobind, self.__service)(*args, **params)
 
   # TODO: Create new getattr/setattr commands
+  # ---------------------------------------------------------------------------
+  # Get a (proxy) method
+  # ---------------------------------------------------------------------------
 
-  def _close(self):
+  def __getattr__ (self, attr):
+
+    if attr[0] == '_':
+      raise AttributeError, attr
+
+    print "\n service '%s' get '%s' " % (self.__service,attr)
+
+    method = _ProxyObject (self.__adapter, self.__service + '.' + attr, False)
+    
+    method.__parent = self
+    print method.__parent
+    self.__dict__ [attr] = method
+    return method
+
+
+  def __del__(self):
+    
+    if self.__dynamic:
     # if it is a dynamic object then close it
-    if self._attrPath==[self._attr]:
-      self._adapter.runMethod(self._attr+'._close')
+    #if self._attrPath==[self._attr]:
+      self.__adapter.runMethod(self.__service + '._close')

Modified: trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py     2005-02-20 
14:43:17 UTC (rev 7046)
+++ trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py     2005-02-20 
14:52:31 UTC (rev 7047)
@@ -33,10 +33,10 @@
 #
 
 
-from gnue.common.rpc import GComm
-from gnue.common.apps import GDebug
-from gnue.common.rpc.drivers._helpers import ObjectLibrarian, DirectoryServer
-from gnue.common.rpc import GCommBase
+from gnue.common.apps import errors, GDebug
+from gnue.common.rpc import server
+from gnue.common.rpc.drivers import Base
+from gnue.common.rpc.drivers._helpers import ObjectLibrarian, ObjectEnabler
 
 import string, sys, os, posixpath, urllib, socket
 
@@ -67,7 +67,7 @@
 #
 # ServerAdapter
 #
-class ServerAdapter(GCommBase.Server):
+class ServerAdapter(Base.Server):
 
   def __init__(self, rpcdef, bindings, params):
     try:
@@ -104,9 +104,10 @@
       locator = Pyro.naming.NameServerLocator()
       GDebug.printMesg(9,'PYRO: searching for Naming Service...')
       self.ns = locator.getNS()
-      GDebug.printMesg(9,'Naming Service found at %s (%s) %s.' % 
(self.ns.URI.address,
-                                                                
(Pyro.protocol.getHostname(self.ns.URI.address) or '??'),
-                                                                
self.ns.URI.port))
+      GDebug.printMesg(9,'Naming Service found at %s (%s) %s.' % \
+                       (self.ns.URI.address,
+                        (Pyro.protocol.getHostname(self.ns.URI.address) or 
'??'),
+                        self.ns.URI.port))
 
     # make sure our namespace group exists
     try:
@@ -223,6 +224,7 @@
         self.ns.deleteGroup(object._path)
       except:
         pass
+      
       self.ns.createGroup(object._path)
       
       self._bindDelegateto(object._path+'.self',object._realbinding)

Modified: trunk/gnue-common/src/rpc/drivers/pyro/__init__.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/__init__.py  2005-02-20 14:43:17 UTC 
(rev 7046)
+++ trunk/gnue-common/src/rpc/drivers/pyro/__init__.py  2005-02-20 14:52:31 UTC 
(rev 7047)
@@ -1,2 +1,2 @@
 # Not functional at the moment
-__noplugin__ = True
+#__noplugin__ = True





reply via email to

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