[Zope3-dev] Re: Make message ids into "rocks", was Re: Re: SVN: Zope3/trunk/src/zope/ Internationalized apidoc modules description.

Philipp von Weitershausen philipp at weitershausen.de
Fri Sep 3 10:43:59 EDT 2004


Jim Fulton wrote:
>> I don't see the need for these dictproxies. Otherwise I agree. 
>> Specifically, I have something like this in mind:
>>
>> def keys_and_values_to_unicode(mapping):
>>     items = [(unicode(key), unicode(value) for key, value
>>              in mapping.items()]
>>     return dict(items)
>>
>> class MessageID(unicode):
>>
>>     def __new__(cls, ustr, domain=None, default=None, mapping={}):
>>         self = super(MessageID, cls).__new__(cls, ustr)
>>         self._domain = domain
>>         self._default = default
>>         self._mapping = keys_and_values_to_unicode(mapping)
>>
>>     def domain(self):
>>         return self._domain
>>     domain = property(domain)
>>
>>     def default(self):
>>         return self._default
>>     default = property(default)
>>
>>     def mapping(self):
>>         return self._mapping.copy()
>>     mapping = property(mapping)
>>
>>     def __mod__(self, mapping):
>>         new_mapping = self.mapping
>>         new_mapping.update(keys_and_values_to_unicode(mapping))
>>         return self.__class__(
>>             self,
>>             domain=self._domain,
>>             default=self._default,
>>             mapping=new_mapping
>>         )
>>
>> This class's instances would be immutable since their attributes can't 
>> be changed. Changing the mapping causes a new isntance to be created.
> 
> 
> Unless I say:
> 
>   foo._domain = 'myfakedomain'
> 
> or
> 
>   foo._default = 'hee hee hee'
> 
> or maybe:
> 
>   foo._mapping = {'this is': 'what you deserve ;)'}
> 
> I don't think that it is possible to implement
> truly read-only attributes in Python.

*grrmmm* Yeah, ok. At least you admit that this is cheating :). But I 
see your point. We need true immutability. I'll read up on dictproxies.

Philipp



More information about the Zope3-dev mailing list