[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/utilities - session.py:1.2

Stuart Bishop stuart at stuartbishop.net
Tue Feb 10 06:50:21 EST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 09/02/2004, at 10:10 PM, Stephan Richter wrote:

>> +# XXX: These mapping interfaces should probably live somewhere like
>> +# zope.interface.common.mapping, but there are already similar but 
>> less
>> +# useful ones defined there.
>
> Right, we should definitely think about moving them there and merge 
> these with
> the other version. Why are the others less usefull?

The interfaces I implemented are better for expressing security
restrictions. ISessionDataContainer grants get and set to
zope.Public, but allowing methods that expose what the keys are
is a security hole since they are secret. (ISessionDataContainer
may end up extending IFullMapping to allow a management view to
be written).

>> +_missing = []
>> +class IReadMapping(Interface):
>> +    ''' Mapping methods for retrieving data '''
>> +    def __getitem__(key): 'Return a value'
>> +    def __contains__(key): 'True if there is a value for key'
>> +    def get(key, default=_missing):
>> +        'Return a value, or default if key not found'
>
> I think having missing be a list is a bad idea. If someone appends a 
> value to
> this list, then the default will always have this value. You should 
> use a
> non-mutable type for the default. If not 'None', you can always use
> 'object()', which would be the best.

I don't think it matters - the default argument to 'default' will
never be used for anything except an identity check. The
implementation would be:

def get(self, key, default=_missing):
	try:
		return self[key]
	except KeyError:
		if default is _missing:
			raise
		return default

- --  
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFAKMWFAfqZj7rGN0oRAjmLAJ4zFt16DAuCAa5zjl4LrVaRrXTQdACfVx0v
o4rahJOacP9ADJPBcrlhosk=
=asr1
-----END PGP SIGNATURE-----




More information about the Zope3-Checkins mailing list