Re: Acquisition wrapped objects do not behave well on unicode call

Hanno Schlichting <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
On Tue, Feb 15, 2011 at 2:35 PM, Michael Howitz <[email protected]> wrote:
> When I have an acquisition wrapped object, e. g. my_object and call:
>
>>>> unicode(my_object)
>
> The method __str__ of my_object is called even when it has an __unicode__ method.

Acquisition wrappers only fill the tp_repr and tp_str slot and as far
as I can tell there's no tp_unicode slot in PyObject_HEAD_INIT.

So I'm not sure how to add the C equivalent of a __unicode__ to the
Wrappertype and XaqWrappertype PyExtensionClasses. It would probably
have to do a lookup for a __unicode__ method on the wrapped instance,
call it if it exists and otherwise call its own __str__ - essentially
duplicating the logic of the string type.

My C-fu is too weak to attempt this. The workaround is to call
unicode(aq_base(my_object)).

Hanno
_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.