[Zope-dev] Acquisition wrapped objects do not behave well on unicode call

Christian Zagrodnick cz at gocept.com
Tue Feb 15 15:26:50 EST 2011


On 2011-02-15 15:26:28 +0100, Hanno Schlichting said:

> On Tue, Feb 15, 2011 at 2:35 PM, Michael Howitz <mh at gocept.com> 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 · cz at gocept.com
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




More information about the Zope-Dev mailing list