[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7973 - in trunk/gnue-common/src/rpc/drivers: . pyro
From: |
johannes |
Subject: |
[gnue] r7973 - in trunk/gnue-common/src/rpc/drivers: . pyro |
Date: |
Wed, 28 Sep 2005 12:35:36 -0500 (CDT) |
Author: johannes
Date: 2005-09-22 10:13:13 -0500 (Thu, 22 Sep 2005)
New Revision: 7973
Removed:
trunk/gnue-common/src/rpc/drivers/_helpers/
trunk/gnue-common/src/rpc/drivers/pyro/Driver.py
Modified:
trunk/gnue-common/src/rpc/drivers/Base.py
trunk/gnue-common/src/rpc/drivers/TODO
trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py
trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py
Log:
Rebuilt pyro driver
Modified: trunk/gnue-common/src/rpc/drivers/Base.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/Base.py 2005-09-22 09:42:11 UTC (rev
7972)
+++ trunk/gnue-common/src/rpc/drivers/Base.py 2005-09-22 15:13:13 UTC (rev
7973)
@@ -386,6 +386,19 @@
# ---------------------------------------------------------------------------
+ # Shut down the server
+ # ---------------------------------------------------------------------------
+
+ def shutdown (self):
+ """
+ """
+
+ assert gEnter (8)
+ self._shutdown_ ()
+ assert gLeave (8)
+
+
+ # ---------------------------------------------------------------------------
# Virtual methods to be implemented by descendants
# ---------------------------------------------------------------------------
@@ -395,3 +408,10 @@
"""
pass
+
+
+ # ---------------------------------------------------------------------------
+
+ def _shutdown_ (self):
+
+ pass
Modified: trunk/gnue-common/src/rpc/drivers/TODO
===================================================================
--- trunk/gnue-common/src/rpc/drivers/TODO 2005-09-22 09:42:11 UTC (rev
7972)
+++ trunk/gnue-common/src/rpc/drivers/TODO 2005-09-22 15:13:13 UTC (rev
7973)
@@ -5,10 +5,7 @@
XMLRPC:
------
-* improve error handling: a) server side: send traceback over the net to
- the client
- b) internal xmlrpc errors
- (includes connection timeout etc.)
+* connection timeout
base stuff and helper applications:
@@ -22,33 +19,7 @@
* Add an garbage collector to the simple object store ( possibly based on a
mixture of timeout values and maximum cache size)
-* Make the "Object Store" an optional argument which can be send to the
- GNURPC Server object at initialisation. i.e. two use cases:
- a) GNURPC standalone: automaticly use the "simple object store"
- provided by GNURPC, or use other means of helper functions to
- enable access and transport of objects over a network (f.e.
- the things in the SOAP implementation for Python)
- b) GEAS: replace the "simple object store" of GNURPC XMLRPC
- implementation by the object store of GEAS. even build in
- "transport or access object over the net" mechanism (like in
- the python SOAP implementation) will be replaced by the GEAS
- implementation of such mechanism.
-* Add an GRPC 2 IDL and IDL 2 GRPC converter
-
-* Add an lokal socket implementation, which creates an GRPC file just
- by protocoling all communications between a server and a client.
- With this tool it is possible to change your application, or write a
- new application, then use this special protokol one time and voila you
- get a GRPC file you can use for normal protocols (like XMLRPC etc.)
-
-* Possibility to switch between different modes of XMLRPC object
- submission like
- a) just send OID (object identifier)
- b) just send data (doesn't need object handling
- c) send OID and data
-
-
Other possible drivers / interesting applications:
--------------------------------------------------
@@ -60,7 +31,3 @@
It includes a web server, a telnet server, a multiplayer RPG engine, a
generic client and server for remote object access, and APIs for creating
new protocols.
-
-
-
-
Modified: trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py 2005-09-22
09:42:11 UTC (rev 7972)
+++ trunk/gnue-common/src/rpc/drivers/pyro/ClientAdapter.py 2005-09-22
15:13:13 UTC (rev 7973)
@@ -1,6 +1,9 @@
+# GNU Enterprise Common Library - RPC Interface - Pyro ClientAdapter
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
@@ -16,288 +19,58 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2003-2005 Free Software Foundation
-#
-# FILE:
-# pyro/ClientAdapter.py
-#
-# DESCRIPTION:
-# Set of classes that implement the pyro client adapter for GNUe Comm.
-#
-# NOTES:
-# Requires pyro from http://sourceforge.net/Projects/pyro
-#
-# Client Parameters:
-#
-# url The complete URI address of the XML-RPC service.
-# e.g, url="https://www.domain.com:9876/service.php"
-# ..or..
-# transport The service transport (either "http" or "https")
-# host The hostname or IP address of the service
-# port The port that the service is located on
-#
+# $Id$
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
+from gnue.common.apps import errors
-import string, sys
+import Pyro.core
+# =============================================================================
+# Plugin initialization
+# =============================================================================
+
def __initplugin__ ():
try:
- import Pyro.naming, Pyro.core, Pyro.protocol
+ import Pyro.core
except ImportError:
- tmsg = _("\nUnable to load pyro. To use the Pyro interface, \n"
- "please install xmlrpc from:\n"
- " http://sourceforge.net/projects/pyro "
- "the appropriate DEBIAN package is python-pyro.deb")
- raise client.AdapterInitializationError, tmsg
+ raise client.AdapterInitializationError, \
+ u_("Unable to load Pyro. To use the Pyro interface, please install " \
+ "pyro from http://pyro.sf.net")
-##############################################################################
-#
+# =============================================================================
# ClientAdapter
-#
-class ClientAdapter(Base.Client):
+# =============================================================================
- def __init__(self, params):
+class ClientAdapter (Base.Client):
- self._timeout = 1.0
-
- #
- # check for the correct parameters
- #
-
- try:
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
- #
- # test for an url parameter
- #
- try:
- url = params['url']
- if not len(url):
- raise KeyError
+ def __init__ (self, params):
+ """
+ @param params: parameter dictionary for adapter initialization
+ """
- # split url into server + host + path parts
- import urlparse
-
- transport, netloc, path, params, query, fragment = \
- urlparse.urlparse(url)
- host, port=split(netloc,':',1)
-
- except KeyError:
- #
- # transport parameter
- #
- try:
- transport = params['transport']
- except KeyError:
- transport = 'http'
+ Base.Client.__init__ (self, params)
- if (transport!='http'):
- tmsg = _("py-xmlrpc just support http as a transport. "
- "If you need https please have a look at the "
- "'pw_xmlrpc' adapter.")
- raise client.AdapterConfigurationError, tmsg
- #
- # path parameter
- #
- try:
- path = params['path']
- except KeyError:
- path = '/'
+ # initialize the client and set the default namespace group
+ self._pyroGroup = ':GNUeRPC'
- #
- # port parameter
- #
- try:
- port = params['port']
- except KeyError:
- port = 8765
-
-
- #
- # host parameter
- #
- try:
- host = params['host']
- except KeyError:
- host = 'localhost'
+ Pyro.core.initClient ()
+ Pyro.config.PYRO_NS_DEFAULTGROUP = self._pyroGroup
-
- try:
- self._url = "%s://%s:%s%s" % \
- ( transport, params['host'], port,path )
- except:
- pass
-
- # setLoglevel
- if hasattr(params,'loglevel'):
- pass
-
- # care for non-integer port settings
- if type(port)!=type(12):
- port=string.atoi(port)
- self.pyro_group=':GComm'
-
- # initialize the client and set the default namespace group
- Pyro.core.initClient()
- Pyro.config.PYRO_NS_DEFAULTGROUP=self.pyro_group
-
- locator = Pyro.naming.NameServerLocator()
- print 'Searching Naming Service...',
- self.ns = locator.getNS()
- 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 Pyro, you must either specify a 'url' or\n"
- "a 'host' and 'port' setting.")
- raise client.AdapterConfigurationError, tmsg
- except:
- tmsg = u_("Unable to initialize the Pyro interface at %s") % url
- raise client.AdapterInitializationError, tmsg
-
-
- def request(self, service, params={}):
- # resolve the Pyro object
- print "Service: %s " % service
- print 'binding to object',service
- try:
- URI=self.ns.resolve(service+'.self')
- print 'URI:',URI
- except Pyro.core.PyroError,x:
- print 'Couldn\'t bind object (%s), nameserver says: %s' % (service,x)
- raise SystemExit
-
- return Pyro.core.getProxyForURI(URI)
- #return Pyro.core.getAttrProxyForURI(URI)
-
- def close(self):
- # do a cleanup of the proxy objects and the object stubs
- # on the XMLRPC server side
-
- # 1. close the proxy objects for services (static, client only)
- self._baseproxy=None
-
- # 2. close the proxy objects for objects (dynamic, client+server)
- for i in self._objectProxys:
- i._close()
- self._objectProxys=[]
-
- # close the client it self
- self.ns=None
-
- # just in case the user forgot to delete some objects
- def __del__(self):
- if self.ns!=None:
- self.close()
- Base.Client.__del__()
-
-
- def runMethod(self, method, *args, **params):
- __args = [typeconv.python_to_rpc (arg, client.InvalidParameter)
- for arg in args]
-
- # 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)
- print 'URI:',URI
- except Pyro.core.PyroError,x:
- print 'Couldn\'t bind object for method %s, nameserver says: %s' %
(method,x)
- raise SystemExit
-
- obj = Pyro.core.getAttrProxyForURI(URI)
- print obj
- result=obj(args)
-
- if 0: #except:
- msg="Error: %s" % (sys.exc_value,)
-
- print
- print "********************************************\n"
- print msg,"\n\n"
- print "********************************************"
- sys.exit(0)
-
- # 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(Base.ProxyObject):
-
- def __call__(self, *args, **params):
- assert 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(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)
-
- return getattr(self.__parent.__pyrobind, self.__service)(*args, **params)
-
- # TODO: Create new getattr/setattr commands
# ---------------------------------------------------------------------------
- # Get a (proxy) method
+ #
# ---------------------------------------------------------------------------
- def __getattr__ (self, attr):
+ def _getServerProxy_ (self):
+ """
+ """
- 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.__service + '._close')
+ return Pyro.core.getProxyForURI ("PYRONAME://GNUeRPCService")
Deleted: trunk/gnue-common/src/rpc/drivers/pyro/Driver.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/Driver.py 2005-09-22 09:42:11 UTC
(rev 7972)
+++ trunk/gnue-common/src/rpc/drivers/pyro/Driver.py 2005-09-22 15:13:13 UTC
(rev 7973)
@@ -1,32 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2005 Free Software Foundation
-#
-# FILE:
-# __init__.py
-#
-# DESCRIPTION:
-# __init__ class for commdrivers.
-#
-# NOTES:
-#
-
-from ClientAdapter import *
-from ServerAdapter import *
-
Modified: trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py 2005-09-22
09:42:11 UTC (rev 7972)
+++ trunk/gnue-common/src/rpc/drivers/pyro/ServerAdapter.py 2005-09-22
15:13:13 UTC (rev 7973)
@@ -1,6 +1,9 @@
+# GNU Enterprise Common Library - RPC Interface - Pyro ServerAdapter
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2005 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
@@ -16,454 +19,110 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2001-2005 Free Software Foundation
-#
-# FILE:
-# pyro/ServerAdapter.py
-#
-# DESCRIPTION:
-# Set of classes that implement the Pyro server driver for GNUe Comm.
-#
-# NOTES:
-# Requires pyro from pyro.sf.net
-#
-# Server Parameters:
-#
-# port The port that the service is located on
-#
+# $Id$
-
-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
+from gnue.common.apps import errors
-import string, sys, os, posixpath, urllib, socket
+# =============================================================================
+# Initialization of the plugin
+# =============================================================================
+
def __initplugin__ ():
+
try:
import Pyro.naming
import Pyro.core
- from Pyro.protocol import getHostname
- from Pyro.errors import PyroError,NamingError
+ import Pyro.protocol
except ImportError:
- tmsg = _("\nUnable to load Pyro. To use the Pyro interface, \n"
- "please install pyro from:\n http://pyro.sf.net/")
- raise server.AdapterInitializationError, tmsg
+ raise server.AdapterInitializationError, \
+ u_("Unable to load Pyro. To use the Pyro interface, please install " \
+ "pyro from http://pyro.sf.net")
-# Mapping from GRPC's datatype to XML-RPC datatypes
-_datatypeMap = {
- 'integer': 'int',
- 'string': 'string',
- 'boolean': 'boolean',
- 'date': 'dateTime.iso8601',
- 'number': 'double',
- 'base64': 'base64',
- 'binary': 'base64'
-}
-
-##############################################################################
-#
+# =============================================================================
# ServerAdapter
-#
-class ServerAdapter(Base.Server):
+# =============================================================================
- def __init__(self, rpcdef, bindings, params):
- try:
- self._port = params['port']
- except KeyError:
- pass
+class ServerAdapter (Base.Server):
- if params.has_key('bindto'):
- self._bindto = params['bindto']
- else:
- self._bindto = '' # bind to all interfaces
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
- if params.has_key('allowed_hosts'):
- # TODO: Remove spaces, etc.
- self._allowed_hosts = string.split(params['allowed_hosts'],',')
- else:
- self._allowed_hosts = [''] # allow access from all hosts
+ def __init__ (self, service, parameters):
+ """
+ @param service: python object to be served
+ @param parameters: dictionary of server specific paramters
+ """
- if params.has_key('loglevel'):
- self._loglevel = params['loglevel']
- else:
- self._loglevel = 0
+ import Pyro.core
+ import Pyro.protocol
+ import Pyro.naming
- self.pyro_group = ':GComm'
- # TODO: set pyro_group to other name, depending on grpc
+ Base.Server.__init__ (self, service, parameters)
+ self._pyroGroup = ':GNUeRPC'
+
# initialize pyro server
- Pyro.core.initServer()
- Pyro.config.PYRO_NS_DEFAULTGROUP=self.pyro_group
- self.daemon = Pyro.core.Daemon()
+ Pyro.core.initServer ()
+ Pyro.config.PYRO_NS_DEFAULTGROUP = self._pyroGroup
+ self._daemon = Pyro.core.Daemon()
# locate the name server
- if not hasattr(self,'ns'):
- 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))
+ locator = Pyro.naming.NameServerLocator ()
+ self._ns = locator.getNS ()
+ gDebug (9, "PYRO NameServer 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:
- self.ns.createGroup(self.pyro_group)
- except NamingError:
+ self._ns.createGroup (self._pyroGroup)
+
+ except Pyro.core.NamingError:
pass
- self.daemon.useNameServer(self.ns)
+ self._daemon.useNameServer (self._ns)
- self.mapObjects(rpcdef,bindings)
-
+ self._pyroService = Pyro.core.ObjBase ()
+ self._pyroService.delegateTo (self.instance)
- #
- # Return an exception
- #
- def raiseException(self, exception, message, event=None):
- pass
+ uri = self._daemon.connect (self._pyroService, 'GNUeRPCService')
-
- # #
- # #
- ##########################################################################
- def serve(self):
-
- # enter the service loop.
- GDebug.printMesg(9,'Starting pyro daemon loop.')
- try:
- # daemon.setTimeout(5)
- self.daemon.requestLoop()
- except KeyboardInterrupt:
- print 'shutting down gracefully.'
- # todo: disconnect all obj.
- #daemon.disconnect(obj)
- self.daemon.shutdown()
- print 'Exiting.'
+ # ---------------------------------------------------------------------------
+ # Start the server
+ # ---------------------------------------------------------------------------
- #
- # Create an internal "service directory"
- #
- def mapObjects(self, object, bindings, parent=None):
+ def _serve_ (self):
- # For servicable objects, maintain a complete "path" for reference
- if object._type in ('RpService','RpMethod','RpObject'):
- if parent and hasattr(parent,'_path'):
- object._path = "%s.%s" % (parent._path, object.name)
- else:
- object._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(9,'GNURPC Binding Information:');
- GDebug.printMesg(9,' * %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]()
- # TODO: Clearup this "static" object
-
- else:
-
- # in all other cases just save the binding information
- object._realbinding=bindings[object.binding]
-
- else:
- # RpObject normaly don't need binding information, because
- # they are bound dynamicly
- if object._type != 'RpObject':
-
- print u_("Missing Binding information. Please add binding "
- "information for %s") % 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)
-
- GDebug.printMesg(9,'* %s is bound to \n * %s' % \
- (object._path,object._realbinding))
- except:
- tmsg = u_("GNURPC cannot bind service '%(name)s' to service "
- "'%(destination)s'") \
- % {'name' : object.name,
- 'destination': parent.name}
- raise AttributeError, tmsg
- elif parent._type == 'RpGnuRpc':
- pass
- else:
- tmsg = u_("GNURPC cannot bind service '%(name)s' to service "
- "'%(destination)s'") \
- % {'name' : object.name,
- 'destination': parent._type}
- raise AttributeError, tmsg
-
- # create binding for service
- try:
- self.ns.deleteGroup(object._path)
- except:
- pass
-
- self.ns.createGroup(object._path)
-
- self._bindDelegateto(object._path+'.self',object._realbinding)
-
-
-
- # Compute binding for methods and for attributs
- # both are direct lins to the specific object
- #
- # the dispatcher has to distinguish methods and
- # objects by testing if they are callable
- if (object._type == 'RpMethod') or \
- (object._type == 'RpAttribute'):
-
- # check for the binding
- if hasattr(object,'_realbinding'):
- bindto=object._realbinding
- else:
- if parent._type == 'RpService':
- try:
- bindto=getattr(parent._realbinding,object.name)
- GDebug.printMesg(9,'* %s is bound to \n * %s' % \
- (object._path,bindto))
- except:
- tmsg = u_("GNURPC cannot bind method/attribut '%(name)s' to "
- "service '%(service)s'") \
- % {'name' : object.name,
- 'service': parent.name}
- raise AttributeError, tmsg
- pass
- else:
- bindto=None
-
- if object._type == 'RpMethod':
- self.addRpMethod(object,parent,bindto)
-
- #
- # Add all attribute methods to our directory..
- # XML-RPC doesn't support "Attributes", so an
- # attribute is exposed as a pair of get_<name>
- # and set_<name> methods.
- #
- if object._type == 'RpAttribute':
- self.addRpAttribut(object,parent,bindto)
-
-
- # Now, map our children
- for child in object._children:
- self.mapObjects(child, bindings, object)
-
- def addRpMethod(self,object,parent,binding):
- if binding!=None:
- self._bindDelegateto(object._path,binding)
-
- def _bindDelegateto(self,name,binding):
- # unregister method
try:
- self.ns.unregister(name)
- except NamingError:
- pass
- except:
- pass
+ self._daemon.requestLoop ()
- # register using delegation
- proxy=Pyro.core.ObjBase()
- proxy.delegateTo(binding)
- #print 'bindto: %s (%s,%s)' % (name,binding, type(binding))
- self.daemon.connect(proxy,name)
+ finally:
+ self._daemon.shutdown ()
- def addRpAttribut(self,object,parent,binding):
- return
- if not object.readonly:
- # Add the set_* directory entry
- self.daemon.connect({'%s.set_%s' % \
- (parent._path, object.name):\
- binding})
- if not object.writeonly:
- # Add the get_* directory entry
- self.server.addMethods({'%s.get_%s' % \
- (parent._path, object.name):\
- binding})
-
+ # ---------------------------------------------------------------------------
#
- # 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"
+ def _shutdown_ (self):
- 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:
- tmsg = u_("Wrong format of object handle in method call %s") % method
- raise AttributeError, tmsg
- # 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 = u_("Internal XMLRPC server error: method %s can be "
- "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.") \
- % method
-
- raise AttributeError, msg
-
- if method!="_close":
- direntry = self.getMethodDirEntry(o._type+"."+method)
- signature=direntry['signature']
- else:
- signature= ('string',)
+ print "Shutting down pyro daemon"
+ self._daemon.shutdown ()
- 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']
+ # ---------------------------------------------------------------------------
+ # Nice string representation
+ # ---------------------------------------------------------------------------
- if (server_method==None) and (server_attribute==None):
- tmsg = u_("Server XML-RPC method '%s' is not bound to real method") \
- % method
- raise AttributeError, tmsg
- except KeyError:
- tmsg = u_("Server does not have XML-RPC procedure %s") % method
- raise AttributeError, tmsg
- try:
- #
- pass
- # TODO: Compare submitted attributs with signature
- except KeyError:
- tmsg = u_("Server XML-RPC procedure %(method)s accepts just %(attr)s "
- "as attributs") \
- % {'method': method,
- 'attr' : attr}
- raise AttributeError, tmsg
-
-
- # 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(9,'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:
- tmsg = u_("Internal Server XML-RPC error: method type (get/set "
- "attribute) couldn't be detected (method %s)") % method
- raise AttributeError, tmsg
-
-
- # 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) or (result==[None]):
- GDebug.printMesg(9,'Transform result None into 1')
- result=1
-
- return result
+ def __repr__ (self):
+ return "<Pyro RPC server serving '%s' at %d>" % (self.instance, id (self))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7973 - in trunk/gnue-common/src/rpc/drivers: . pyro,
johannes <=