commit-gnue
[Top][All Lists]
Advanced

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

gnue/common/src GComm.py commdrivers/GCommBase....


From: Jason Cater
Subject: gnue/common/src GComm.py commdrivers/GCommBase....
Date: Tue, 11 Dec 2001 00:31:12 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/12/11 00:31:11

Modified files:
        common/src     : GComm.py 
        common/src/commdrivers: GCommBase.py 
        common/src/commdrivers/_test: server.py test.py 
        common/src/commdrivers/proxy: CommDriver.py 
        common/src/commdrivers/xmlrpc: CommDriver.py 

Log message:
        synching machines

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GComm.py.diff?cvsroot=OldCVS&tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/GCommBase.py.diff?cvsroot=OldCVS&tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/_test/server.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/_test/test.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/proxy/CommDriver.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/xmlrpc/CommDriver.py.diff?cvsroot=OldCVS&tr1=1.11&tr2=1.12&r1=text&r2=text

Patches:
Index: gnue/common/src/GComm.py
diff -c gnue/common/src/GComm.py:1.12 gnue/common/src/GComm.py:1.13
*** gnue/common/src/GComm.py:1.12       Sun Dec  9 23:41:02 2001
--- gnue/common/src/GComm.py    Tue Dec 11 00:31:11 2001
***************
*** 28,34 ****
  #
  
  import GDebug
! from gnue.common import dyn_import
  
  
  ##############################################################################
--- 28,34 ----
  #
  
  import GDebug
! from gnue.common import dyn_import, openResource
  
  
  ##############################################################################
***************
*** 103,124 ****
    for interface in drivers.keys():
      params = drivers[interface]
  
!     for service in bindings.keys():
!       binding = bindings[service]
  
!       try:
!         driver = dyn_import('gnue.common.commdrivers.%s' % interface)
!       except ImportError, mesg:
!         GDebug.printMesg(1, \
!            "Unable to import GComm Adapter '%s': \n%s" % (interface,mesg))
!         raise InvalidAdapter, mesg
! 
!       if not (hasattr(driver,'SERVER') and driver.SERVER):
!         raise NoServerAdapter, \
!                "GComm adapter '%s' does not support servers" % interface
! 
!       adapter = driver.ServerAdapter(params)
!       servers[interface] = adapter
  
    return servers
  
--- 103,121 ----
    for interface in drivers.keys():
      params = drivers[interface]
  
!     try:
!       driver = dyn_import('gnue.common.commdrivers.%s' % interface)
!     except ImportError, mesg:
!       GDebug.printMesg(1, \
!          "Unable to import GComm Adapter '%s': \n%s" % (interface,mesg))
!       raise InvalidAdapter, mesg
! 
!     if not (hasattr(driver,'SERVER') and driver.SERVER):
!       raise NoServerAdapter, \
!              "GComm adapter '%s' does not support servers" % interface
  
!     adapter = driver.ServerAdapter(mapping, bindings, params)
!     servers[interface] = adapter
  
    return servers
  
Index: gnue/common/src/commdrivers/GCommBase.py
diff -c gnue/common/src/commdrivers/GCommBase.py:1.10 
gnue/common/src/commdrivers/GCommBase.py:1.11
*** gnue/common/src/commdrivers/GCommBase.py:1.10       Thu Dec  6 18:19:41 2001
--- gnue/common/src/commdrivers/GCommBase.py    Tue Dec 11 00:31:11 2001
***************
*** 27,36 ****
  # NOTES:
  #
  
  from gnue.common import GComm
  
  class Client:
!   def requestService(self, service, params={}):
      pass
  
    def close():
--- 27,45 ----
  # NOTES:
  #
  
+ 
  from gnue.common import GComm
+ from gnue.common import GDebug
+ import string, sys
+ 
+ 
  
+ ##############################################################################
+ #
+ # ClientAdapter
+ #
  class Client:
!   def request(self, service, params={}):
      pass
  
    def close():
***************
*** 53,59 ****
--- 62,77 ----
        pass
  
  
+       
+ ##############################################################################
+ #
+ # ServerAdapter
+ #
  class Server:
+   def __init__(self, rpcdef, bindings, params):
+     self._bindings = bindings
+     self._rpcdef = rpcdef
+ 
    def runService(self, method, data):
      pass
  
***************
*** 61,72 ****
      raise exception, message
  
  
  class ProxyObject:
    def __init__(self, adapter, attr, parent=None, **params):
      for param in params.keys():
        self.__dict__["_%s" % param] = params[param]
!     self.__adapter = adapter
!     self.__parent = parent
      self._attr = attr
  
      try:
--- 79,95 ----
      raise exception, message
  
  
+ 
+ ##############################################################################
+ #
+ # ProxyObject
+ #
  class ProxyObject:
    def __init__(self, adapter, attr, parent=None, **params):
      for param in params.keys():
        self.__dict__["_%s" % param] = params[param]
!     self._adapter = adapter
!     self._parent = parent
      self._attr = attr
  
      try:
***************
*** 76,96 ****
  
      self._attrPath.append(attr)
  
      try:
        self._subobject = params['subobject']
      except KeyError:
        self._subobject = 0
  
  
!   def __getattr__(self, attr, value):
      try:
        if attr[0] == '_':
!         return AttributeError, attr
        else:
          try:
            return self.__dict__[attr]
          except KeyError:
!           po = self.__class__(self._adapter, self, attr=attr,
                                subobject=1)
            self.__dict__[attr] = po
            return po
--- 99,121 ----
  
      self._attrPath.append(attr)
  
+     print "Creating ProxyObject %s" % string.join(self._attrPath,'.')
+ 
      try:
        self._subobject = params['subobject']
      except KeyError:
        self._subobject = 0
  
  
!   def __getattr__(self, attr):
      try:
        if attr[0] == '_':
!         raise AttributeError, attr
        else:
          try:
            return self.__dict__[attr]
          except KeyError:
!           po = self.__class__(self._adapter, attr, self,
                                subobject=1)
            self.__dict__[attr] = po
            return po
***************
*** 101,111 ****
  
    def __setattr__(self, attr, value):
      if attr[0] == '_':
!       self.__dict__[attr] == value
      else:
        raise GComm.ProgrammingError
  
  
    def __call__(self, *args, **params):
!     self._server.runMethod(self, *args, **params)
  
--- 126,136 ----
  
    def __setattr__(self, attr, value):
      if attr[0] == '_':
!       self.__dict__[attr] = value
      else:
        raise GComm.ProgrammingError
  
  
    def __call__(self, *args, **params):
!     self._adapter.runMethod(self, *args, **params)
  
Index: gnue/common/src/commdrivers/_test/server.py
diff -c gnue/common/src/commdrivers/_test/server.py:1.5 
gnue/common/src/commdrivers/_test/server.py:1.6
*** gnue/common/src/commdrivers/_test/server.py:1.5     Sun Dec  9 23:41:02 2001
--- gnue/common/src/commdrivers/_test/server.py Tue Dec 11 00:31:11 2001
***************
*** 75,81 ****
    def run(self):
  
      # Create the various servers
!     bind()
  
      # Daemonize (if appropriate)
      GServerApp.run(self)
--- 75,81 ----
    def run(self):
  
      # Create the various servers
!     bind(self.requestDonutPlace)
  
      # Daemonize (if appropriate)
      GServerApp.run(self)
***************
*** 106,118 ****
  # taken out of the DonutServery class so
  # it can be used by the proxy tests.
  #
! def bind()
  
  
    # Expose our services to the world
    return GComm.bind ( "donuts.grpc",
                        transports,
!                       {'DonutPlace': self.requestDonutPlace })
  
  
  
--- 106,118 ----
  # taken out of the DonutServery class so
  # it can be used by the proxy tests.
  #
! def bind(handler):
  
  
    # Expose our services to the world
    return GComm.bind ( "donuts.grpc",
                        transports,
!                       {'DonutPlace': handler })
  
  
  
***************
*** 155,161 ****
  #
  def create_proxy():
    print "Exporting our services via proxy..."
!   return bind()
  
  
  #
--- 155,165 ----
  #
  def create_proxy():
    print "Exporting our services via proxy..."
!   transports['proxy'] = {}
!   return bind(__request)['proxy']
! 
! def __request():
!   return DonutPlace()
  
  
  #
Index: gnue/common/src/commdrivers/_test/test.py
diff -c gnue/common/src/commdrivers/_test/test.py:1.2 
gnue/common/src/commdrivers/_test/test.py:1.3
*** gnue/common/src/commdrivers/_test/test.py:1.2       Sun Dec  9 23:41:02 2001
--- gnue/common/src/commdrivers/_test/test.py   Tue Dec 11 00:31:11 2001
***************
*** 1,5 ****
--- 1,7 ----
  
  
+ from gnue.common import GComm
+ 
  #
  # Primary testing routine
  #
***************
*** 11,23 ****
    print "Testing %s interface..." % interface
  
    server = GComm.attach(interface, params)
  
    print "  Donut Plant Operational Status:"
!   print server.DonutProvider.Management.Status()
  
  
!   address = 'Jason Cater\n123 Main St\nMemphis, TN 38001"
!   glazedBakery = server.DonutProvider.Bakery.getBakeryUnit('glazed yeast')
  
    print "  Sending %s donuts to Jason Cater" % glazedBakery.get_flavor()
    print "  Kitchen in use:", glazedBakery.get_unitLocation()
--- 13,26 ----
    print "Testing %s interface..." % interface
  
    server = GComm.attach(interface, params)
+   donutProvider = server.request("DonutPlace")
  
    print "  Donut Plant Operational Status:"
!   print donutProvider.Management.Status()
  
  
!   address = 'Jason Cater\n123 Main St\nMemphis, TN 38001'
!   glazedBakery = donutProvider.Bakery.getBakeryUnit('glazed yeast')
  
    print "  Sending %s donuts to Jason Cater" % glazedBakery.get_flavor()
    print "  Kitchen in use:", glazedBakery.get_unitLocation()
***************
*** 42,47 ****
--- 45,51 ----
    test('proxy',params)
  
  
+ 
  #
  # Test the xmlrpc interface
  #
***************
*** 79,82 ****
    test_proxy()
    #test_xmlrpc()
    #test_sockets()
! `
\ No newline at end of file
--- 83,86 ----
    test_proxy()
    #test_xmlrpc()
    #test_sockets()
! 
Index: gnue/common/src/commdrivers/proxy/CommDriver.py
diff -c gnue/common/src/commdrivers/proxy/CommDriver.py:1.2 
gnue/common/src/commdrivers/proxy/CommDriver.py:1.3
*** gnue/common/src/commdrivers/proxy/CommDriver.py:1.2 Sun Dec  9 23:41:02 2001
--- gnue/common/src/commdrivers/proxy/CommDriver.py     Tue Dec 11 00:31:11 2001
***************
*** 40,50 ****
  CLIENT = 1      # ClientAdapter
  SERVER = 1      # ServerAdapter
  
  from gnue.common.commdrivers import GCommBase
  
! class ClientAdapter(GBaseApp.Client):
!   pass
  
- class ServerAdapter(GBaseApp.Server):
-   pass
  
--- 40,116 ----
  CLIENT = 1      # ClientAdapter
  SERVER = 1      # ServerAdapter
  
+ 
  from gnue.common.commdrivers import GCommBase
+ from gnue.common import GComm
+ 
+ import string, sys
+ 
+ ##############################################################################
+ #
+ # ClientAdapter
+ #
+ class ClientAdapter(GCommBase.Client):
+ 
+   def __init__(self, params):
+     print "Proxy Client Adapter created"
+     try:
+       self._serverproxy = params['_proxy']
+     except KeyError:
+       raise GComm.AdapterInitializationError, \
+          'Proxy client adapter should be called with the server object'
+ 
+   def request(self, service, params={}):
+     proxy = _ProxyObject(self, service, \
+         servicer=self._serverproxy._bindings[service],
+         proxyinstance=self._serverproxy._bindings[service]())
+     return proxy
+ 
+ 
+ 
+ 
+ ##############################################################################
+ #
+ # ServerAdapter
+ #
+ class ServerAdapter(GCommBase.Server):
+ 
+   def __init__(self, rpcdef, bindings, params):
+     print "Proxy Server Adapter created"
+     GCommBase.Server.__init__(self, rpcdef, bindings, params)
+ 
+   def raiseException(self, exception, message, event=None):
+     raise exception, message
+ 
+ 
+ 
+ 
+ ##############################################################################
+ #
+ # ProxyObject
+ #
+ class _ProxyObject(GCommBase.ProxyObject):
+   def __init__(self, adapter, attr, parent=None, **params):
+     GCommBase.ProxyObject.__init__(self, adapter, attr, parent=None, **params)
+ 
+ 
+   # Server raised an exception...
+   # Translate the exception into a local python
+   # exception and raise it...
+   def _exceptionRaised(self, data):
+     if data.isGNUeGenerated():
+       name, text = string.split(data.message,': ',1)
+       # TODO: _lookup???
+       exception = _lookup[name]
+       raise exception, text
+     else:
+       # TODO:
+       raise StandardError, data.message
+ 
  
!   def __call__(self, *args, **params):
!     print "Calling %s" % self._adapter
!     return self._adapter.runMethod(self, string.join(self._attrPath,'.'),
!                                   *args, **params)
  
  
Index: gnue/common/src/commdrivers/xmlrpc/CommDriver.py
diff -c gnue/common/src/commdrivers/xmlrpc/CommDriver.py:1.11 
gnue/common/src/commdrivers/xmlrpc/CommDriver.py:1.12
*** gnue/common/src/commdrivers/xmlrpc/CommDriver.py:1.11       Sun Dec  9 
23:41:02 2001
--- gnue/common/src/commdrivers/xmlrpc/CommDriver.py    Tue Dec 11 00:31:11 2001
***************
*** 105,112 ****
           "Unable to initialize the XML-RPC interface at %s" % url
  
  
!   def requestService(self, service, params={}):
      proxy = _ProxyObject(self, None, 
servicer=self._server.__getattr__(service))
  
  
    def close():
--- 105,113 ----
           "Unable to initialize the XML-RPC interface at %s" % url
  
  
!   def request(self, service, params={}):
      proxy = _ProxyObject(self, None, 
servicer=self._server.__getattr__(service))
+     return proxy
  
  
    def close():
***************
*** 125,134 ****
  #
  class ServerAdapter(HTTPServer):
  
!   def __init__(self, params):
!     HTTPServer.__init__(self, params)
  
-     
    def raiseException(self, exception, message, event=None):
      xmlrpclib.dumps(xmlrpclib.Fault(34543, '%s: %s' % (exception, message)))
  
--- 126,135 ----
  #
  class ServerAdapter(HTTPServer):
  
!   def __init__(self, rpcdef, bindings, params):
!     HTTPServer.__init__(self, rpcdef, bindings, params)
! 
  
    def raiseException(self, exception, message, event=None):
      xmlrpclib.dumps(xmlrpclib.Fault(34543, '%s: %s' % (exception, message)))
  



reply via email to

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