def slice(self, streamable, protocol): broker = self.requireBroker(protocol) puid = ipb.IReferenceable(self.obj).processUniqueID() tracker = broker.getTrackerForMyReference(puid, self.obj) if broker.remote_broker: # emit a my-reference sequence yield b'my-reference' yield tracker.clid firstTime = tracker.send() if firstTime: # this is the first time the Referenceable has crossed this # wire. In addition to the clid, send the interface name (if # any), and any URL this reference might be known by iname = ipb.IRemotelyCallable(self.obj).getInterfaceName() yield iname or '' url = tracker.getURL() if url: yield url else: # when we're serializing to data, rather than to a live # connection, all of my Referenceables are turned into # their-reference sequences, to prompt the eventual recipient to # create a new connection for this object. # a big note on object lifetimes: obviously, the data cannot keep # the Referenceable alive. Use tub.registerReference() on any # Referenceable that you want to include in the serialized data, # and take steps to make sure that later incarnations of this Tub # will do the same. yield b'their-reference' yield 0 # giftID==0 tells the recipient to not try to ack it yield tracker.getURL()
def getSchema(self): return None # TODO: not quite ready yet # callables which are actually bound methods of a pb.Referenceable # can use the schema from that s = ipb.IReferenceable(self.obj.im_self, None) if s: return s.getSchemaForMethodNamed(self.obj.im_func.__name__) # both bound methods and raw callables can also use a .schema # attribute return getattr(self.obj, "schema", None)