[PEAK] adapt and 'str'

Phillip J. Eby pje at telecommunity.com
Tue Aug 24 07:12:41 EDT 2004


At 09:06 AM 8/24/04 +0200, Gabriel Jägenstedt wrote:

>adapt(pub.lang, ILang).initiate()
>Which should do all the work to make the object library and such
>english.

Create a class that accepts a string in its __init__, and has an 'initiate' 
method that knows how to interpret the string, and declare it as an adapter 
for type 'str':

class Lang:
     protocols.advise(
         instancesProvide=[ILang], asAdapterForTypes=[str]
     )
     def __init__(self,langstr):
         # XXX

     def initiate(self):
         # XXX


If the object needs more data than this, you'll have to add arguments to 
the 'initiate()' signature.




More information about the PEAK mailing list