[Twisted-Python] perspective introspection

Sean Riley sean at twistedmatrix.com
Mon Feb 11 22:40:55 EST 2002


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 at ninjaneering.com





More information about the Twisted-Python mailing list