/usr/share/pyshared/zope/container/sample.py is in python-zope.container 3.12.0-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Sample container implementation.
This is primarily for testing purposes.
It might be useful as a mix-in for some classes, but many classes will
need a very different implementation.
"""
__docformat__ = 'restructuredtext'
from zope.container.interfaces import IContainer
from zope.interface import implements
from zope.container.contained import Contained, setitem, uncontained
class SampleContainer(Contained):
"""Sample container implementation suitable for testing.
It is not suitable, directly as a base class unless the subclass
overrides `_newContainerData` to return a persistent mapping object.
"""
implements(IContainer)
def __init__(self):
self.__data = self._newContainerData()
def _newContainerData(self):
"""Construct an item-data container
Subclasses should override this if they want different data.
The value returned is a mapping object that also has `get`,
`has_key`, `keys`, `items`, and `values` methods.
"""
return {}
def keys(self):
'''See interface `IReadContainer`'''
return self.__data.keys()
def __iter__(self):
return iter(self.__data)
def __getitem__(self, key):
'''See interface `IReadContainer`'''
return self.__data[key]
def get(self, key, default=None):
'''See interface `IReadContainer`'''
return self.__data.get(key, default)
def values(self):
'''See interface `IReadContainer`'''
return self.__data.values()
def __len__(self):
'''See interface `IReadContainer`'''
return len(self.__data)
def items(self):
'''See interface `IReadContainer`'''
return self.__data.items()
def __contains__(self, key):
'''See interface `IReadContainer`'''
return self.__data.has_key(key)
has_key = __contains__
def __setitem__(self, key, object):
'''See interface `IWriteContainer`'''
setitem(self, self.__data.__setitem__, key, object)
def __delitem__(self, key):
'''See interface `IWriteContainer`'''
uncontained(self.__data[key], self, key)
del self.__data[key]
|