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:

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)

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

\malthe
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to