[PEAK] Adapting based on property
parente at cs.unc.edu
Wed Jun 29 07:12:00 EDT 2005
I'd like to use pyprotocols to adapt objects returned by a third party
library to a set
of interfaces specified in my system. The external library returns
instances of type
Accessible via a number of methods. The Accessible object is a client side
some server side object.
The Accessible object is a generic interface to a slew of different server
The Role attribute of the accessible object says exactly what kind of
object it is
representing on the server side and, thus, what its various values mean.
the Value property of an Accessible object with a Role of 'list' is the
length of the
list while the Value property of an Accessible object with a Role of
'tree' is the
number of levels in the tree.
What's I'd like to do is adapt instances of the generic Accessible objects
specific interfaces based on the Role attribute. For example, I'd like to
protocol with a method of getLength. Then I'd like to have an adapters like
AccessibleListViewAsList and AccessibleComboboxAsList that implement the
for various list-like objects.
Here's my problem.
In the pyprotocols documentation, I only see a way to declare a class as
an adapter for
a type of object. But in this case, everything is an Accessible and so
adapters causes an "ambiguous adapter choice" error:
Notice the implementations need to be different so a single adapter will
I'm guessing what I really need is an adapter factory that does something
like the following pseudocode:
# get object role
role = obj.Role
# look for adapters for given role and type
return protocol.registry.findAdapterFor(role=role, type=type(obj))
Is such a thing possible with pyprotocols? Is there another solution?
More information about the PEAK