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

Christian Zagrodnick <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
On 2011-02-15 15:26:28 +0100, Hanno Schlichting said:

> 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.

Jup.

> 
> My C-fu is too weak to attempt this.

Heh. My C-fu is also rather weak but I might try it if there are no 
objections.  (or there is somebody hacking it in 5 minutes …)

> The workaround is to call
> unicode(aq_base(my_object)).

Yes, but that's not really an option.

Regards,
-- 
Christian Zagrodnick · [email protected]
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 4 · fax +49 345 1229889 1
Zope and Plone consulting and development


_______________________________________________
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.