[Twisted-Python] perspective introspection
other remote object APIs such as COM and CORBA have ways of asking a remote object for it's published interface. SOAP also has this with WSDL (http://www.w3.org/TR/wsdl). implementing a way for pb perspectives to tell consumers about their interface seemed like it would be a trivial undertaking - and it was: (for twisted.spread.pb): from twisted.python import reflect def perspective_getInterface(self): """Retrieve the set of perspective methods for this perspective. This allows client to retrieve the "published" external interface for this perspective/service. the result is returned in a dictionary with the keys being the names of the methods for the client to call, and the values a tuple of the names of the arguments to each method. """ dict = {} reflect.addMethodNamesToDict(self.__class__, dict, "perspective_") del dict["getInterface"] # remove the perspective_interface method (THIS method) # populate args for k in dict.keys(): func = self.__class__.__dict__["perspective_%s"%k] l = func.func_code.co_varnames[1:] dict[k] = l return dict it would probably even be possible to wrap this up into WSDL if we wanted to, for further "enterprise" compatibility... it isn't possible for clients to do this introspection on their own as they only have a RemoteReference to the perspective object. does this create any security holes? is a bad idea for any other reason? ---- "If it's not running programs or fusing atoms, it's just bending space.", Ken Macleod "That's it, I'm outta here.", Homer Simpson's Brain Sean Riley sean@ninjaneering.com
Sean Riley wrote:
it isn't possible for clients to do this introspection on their own as they only have a RemoteReference to the perspective object. does this create any security holes? is a bad idea for any other reason?
Well, I want a general idea of interfaces with defined types for published objects ("interface Foo := I have a method foo that returns an integer and accepts two args, an integer and an object implementing interface Bar"). Basically IDL, when you get down to it :) Introspection would be part of this, as would auto-generation of docs.
Itamar Shtull-Trauring wrote:
Well, I want a general idea of interfaces with defined types for published objects ("interface Foo := I have a method foo that returns an integer and accepts two args, an integer and an object implementing interface Bar"). Basically IDL, when you get down to it :)
Or PEP 245 interfaces with Grouch style docstrings.
Well, I asked glyph about this earlier, and he said that it's just as good to have versioned objects instead of publishing interfaces. I'm not sure what cases versioned objects wouldn't be sufficient enough, so I'm not sure which is the best route to go. On Mon, 2002-02-11 at 22:40, Sean Riley wrote:
other remote object APIs such as COM and CORBA have ways of asking a remote object for it's published interface. SOAP also has this with WSDL (http://www.w3.org/TR/wsdl).
implementing a way for pb perspectives to tell consumers about their interface seemed like it would be a trivial undertaking - and it was:
(for twisted.spread.pb):
from twisted.python import reflect
def perspective_getInterface(self): """Retrieve the set of perspective methods for this perspective. This allows client to retrieve the "published" external interface for this perspective/service.
the result is returned in a dictionary with the keys being the names of the methods for the client to call, and the values a tuple of the names of the arguments to each method. """ dict = {} reflect.addMethodNamesToDict(self.__class__, dict, "perspective_") del dict["getInterface"] # remove the perspective_interface method (THIS method)
# populate args for k in dict.keys(): func = self.__class__.__dict__["perspective_%s"%k] l = func.func_code.co_varnames[1:] dict[k] = l return dict
it would probably even be possible to wrap this up into WSDL if we wanted to, for further "enterprise" compatibility...
it isn't possible for clients to do this introspection on their own as they only have a RemoteReference to the perspective object. does this create any security holes? is a bad idea for any other reason?
---- "If it's not running programs or fusing atoms, it's just bending space.", Ken Macleod "That's it, I'm outta here.", Homer Simpson's Brain Sean Riley sean@ninjaneering.com
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -- Chris Armstrong << radix@twistedmatrix.com >> http://twistedmatrix.com/users/carmstro.twistd/
On Mon, 2002-02-11 at 19:40, Sean Riley wrote:
implementing a way for pb perspectives to tell consumers about their interface seemed like it would be a trivial undertaking - and it was:
And this is essentially what python.explorer does, although for a different purpose. It exports an object's native interface so it can be explored/manipulated through manhole. If you haven't seen this yet, fire up manhole and try something like /browse sys.modules['__main__'].application
participants (4)
-
Christopher Armstrong -
Itamar Shtull-Trauring -
Kevin Turner -
Sean Riley