[Grok-dev] grok_overview.html: issue with adapters
Sebastian Ware
sebastian at urbantalk.se
Tue Nov 4 09:40:18 EST 2008
Actually, you will find that the example code is correct. The code
above what you quoted says:
def sized(context):
if isinstance(context, Document):
return DocumentedSized(context)
elif isinstance(context, Image):
return ImageSized(context)
elif isinstance(context, Container):
return ContainerSized(context)
so calling:
s = sized(my_content_object)
will return an adapter* (DocumentSized, etc...) that provides the
method size().
*adapter being a special "coder view" of an object allowing access to
object specific methods that are only available when you are accessing
the object through the adapter. In this case the adapter provides the
method size().
Mvh Sebastian
4 nov 2008 kl. 15.08 skrev Roger Erens:
> In the code example following
> 'We can now call sized for a content object and get an object back
> that
> implements the “sized API”:'
>
> we have currently:
>
> s = sized(my_content_object)
> print s.size()
>
> but size() is not defined in the code above. It seems to me that
> either
> the second line should read:
>
> print s.sized()
>
> But it looks silly to me to use 'sized' twice. So, in the code
> fragment
> above, the method definitions in the three classes would better be
> refactored from sized(self) to size(self)?
>
> Cheers,
>
> Roger
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
More information about the Grok-dev
mailing list