[Zope-dev] C-extension in zope.i18nmessageid

Marius Gedminas marius at gedmin.as
Fri Dec 12 11:07:18 EST 2008


On Fri, Dec 12, 2008 at 12:45:27PM +0000, Malthe Borch wrote:
> Martijn Pieters wrote:
> > The C extension is required to make messageids immutable. Because they
> > are immutable, the security machinery can treat them as rocks, e.g.
> > safe to pass around. Removing the C-extension undoes this, as you
> > cannot make truely immutable.
> 
> I believe it is possible to do this in pure Python:

I have doubts about that, but I don't think I'm smart enough to consider
all the security implications.

> We'll set up a security-proxied global dictionary ``messages`` that maps
> 
>    object_id of message -> weakref(message)
> 
> Then, the ``Message`` class would roughly look like this:
> 
> class Message(unicode):
> 
>    def __new__(...):
>       self = unicode.__new__(...)
> 
>       messages = removeSecurityProxy(messages)
> 
>       messages[id(self)] = (default, domain, mapping)

Careful: id(some_object) will likely be reused when the old object is
garbage collected.

>    @property
>    def default(self):
>       return messages[id(self)][0]
> 
> The message data is effectively immutable, since the ``messages`` 
> dictionary is security-proxied.
> 
> To make sure the message properties are persisted along with the 
> message, we must override the __reduce__-method to maintain the 
> ``messages`` dict upon load.

-- 
http://pov.lt/ -- Zope 3 consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20081212/8d1befda/attachment.bin 


More information about the Zope-Dev mailing list