def _handleInvocation2(self, daemon, req, pflags, conn, obj, mustInitTLS=False): if mustInitTLS: daemon.initTLS(daemon.getLocalStorage()) try: flags=req[2] importer=None if not Pyro.config.PYRO_MOBILE_CODE: res = obj.Pyro_dyncall(req[1],flags,req[3]) # (method,flags,args) else: try: # install a custom importer to intercept any extra needed modules # when executing the remote method. (using the data passed in by # the client may trigger additional imports) imp.acquire_lock() importer=agent_import(__builtin__.__import__) __builtin__.__import__=importer res = obj.Pyro_dyncall(req[1],flags,req[3]) # (method,flags,args) finally: __builtin__.__import__=importer.orig_import imp.release_lock() if flags&Pyro.constants.RIF_Oneway: return # no result, return immediately # reply the result to the caller if pflags&PFLG_XMLPICKLE_GNOSIS: replyflags=PFLG_XMLPICKLE_GNOSIS if Pyro.config.PYRO_XML_PICKLE=='gnosis': body=pickle.dumps(res,Pyro.config.PYRO_PICKLE_FORMAT) else: body=Pyro.util.getXMLPickle('gnosis').dumps(res,Pyro.config.PYRO_PICKLE_FORMAT) else: replyflags=0 body=pickle.dumps(res,Pyro.config.PYRO_PICKLE_FORMAT) sock_sendmsg(conn.sock, self.createMsg(body,replyflags),self.timeout) except ImportError,ix: if Pyro.config.PYRO_MOBILE_CODE: # Return a special exception that will be processed by client; # it will call the internal 'remote_supply_code' member. # We have to use this seemingly complex way to signal the client # to supply us some code, but it is only a proxy! We can't *call* it! if importer: # grab the import info from our importer name=importer.name fromlist=importer.fromlist else: # XXX the importerror sometimes doesn't contain the package :-( name=ix.args[0][16:] fromlist=None Log.msg('PYROAdapter','failed to import',name) self.returnException(conn, _InternalNoModuleError(name,fromlist),0) # don't shutdown! else: Log.error('PYROAdapter','code problem with incoming object: '+str(ix)) self.returnException(conn, NoModuleError(* ix.args))
def handleInvocation(self,daemon,conn): ver,body,pflags = self.receiveMsg(conn) if not body: # something went wrong even before receiving the full message body return if ver!=self.version: Log.error('PYROAdapter','incompatible protocol version') self.returnException(conn, ProtocolError('incompatible protocol version')) return # Unpickle the request, which is a tuple: # (object ID, method name, flags, (arg1,arg2,...)) importer=fromlist=None try: if Pyro.config.PYRO_MOBILE_CODE: # install a custom importer to intercept any extra needed modules # when unpickling the request just obtained from the client try: imp.acquire_lock() importer=agent_import(__builtin__.__import__) __builtin__.__import__=importer req=self._unpickleRequest(pflags, body) finally: __builtin__.__import__=importer.orig_import imp.release_lock() else: # no mobile code; just unpickle the stuff without a custom importer. req=self._unpickleRequest(pflags, body) if type(req)!=tuple or len(req)!=4 or type(req[3])!=tuple: # sanity check failed raise ProtocolError("invalid request data format") except ImportError,x: if Pyro.config.PYRO_MOBILE_CODE: # return a special exception that will be processed by client; # it will call the internal 'remote_supply_code' member if importer: modname=importer.name fromlist=importer.fromlist else: modname = x.args[0][16:] fromlist=None self.returnException(conn, _InternalNoModuleError(modname,fromlist),0) # don't shutdown! else: Log.error('PYROAdapter','code problem with incoming object: '+str(x)) self.returnException(conn, NoModuleError(* x.args)) return