[Grok-dev] grok_overview.html: issue with adapters

Sebastian Ware sebastian at urbantalk.se
Tue Nov 4 10:26:39 EST 2008


you are absolutely right, that's a bit of magic that only happens in a  
hurry :)

Anyway, to anybody who can fix it, the typo is on

   http://grok.zope.org/doc/current/grok_overview.html

and as Roger points out, the method sized() on:

   DocumentSized,
   ImageSized,
   ContainerSized

should probably be renamed size()

Mvh Sebastian

4 nov 2008 kl. 16.07 skrev Roger Erens:

> on 4-11-2008 15:40 sebastian at urbantalk.se wrote:
>> 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().
>
> Hi Sebastian,
>
> there is even more code above this part:
>
> class DocumentSized(object):
>    def __init__(self, context):
>        self.context = context
>
>    def sized(self):
>        return len(self.context.text.encode('UTF-8'))
>
> class ImageSized(object):
>    def __init__(self, context):
>        self.context = context
>
>    def sized(self):
>        return len(self.context.data)
>
> class ContainerSized(object):
>    def __init__(self, context):
>        self.context = context
>
>    def sized(self):
>        total = 0
>        for obj in self.context.values():
>            total += sized(obj).size()
>        return total
>
> in which I cannot detect a method size() being defined. I don't  
> believe it is magically derived from the sized(self) methods by  
> stripping the terminating d :-)
>
> Thanks for taking the time to answer,
>
> Roger



More information about the Grok-dev mailing list