zope security proxy doesn't handle __unicode__
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zope.security |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
There is no implementation of the __unicode__ method to handle objects that are wrapped in the zope.security.
For example, this class implementation:
class ICustomClass(
def __unicode__():
pass
def __str__():
pass
@implementer(
class CustomClass(
def __unicode__(self):
print "In __unicode__"
return u'Español con caracteres especiales'
def __str__(self):
print "In __str__"
return unicode(
With the associated zcml:
<class class="
<allow
</class>
And a simple test:
>>> from zope.security.
>>> obj = CustomClass()
>>> str(obj)
In __str__
In __unicode__
'Espa\xc3\xb1ol con caracteres especiales'
>>> unicode(obj)
In __unicode__
u'Espa\xf1ol con caracteres especiales'
>>> prox = ProxyFactory(obj)
>>> str(prox)
In __str__
In __unicode__
'Espa\xc3\xb1ol con caracteres especiales'
>>> unicode(prox)
In __str__
In __unicode__
*** UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
The object, that should return a unicode string with special characters works fine on the original object, but causes an error on the proxied object because it actually calls the __str__ method which returns a 'utf-8' encoded byte string and when trying to make it into a unicode string, fails since it is trying to decode it with the system default of 'ascii.' Essentially, it is the equivalent of calling:
>>> unicode(
In __str__
In __unicode__
*** UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
Now tracked on Github:
https:/ /github. com/zopefoundat ion/zope. security/ issues/ 10