Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Make sure init is called only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
alga committed Jun 5, 2012
1 parent 35f877a commit 30f54de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cipher/configstore/configstore.py
Expand Up @@ -242,9 +242,13 @@ def _add(self, name, item):
def _applyPostAddConfig(self, item, config, section):
pass

def clearContext(self):
ctx = removeSecurityProxy(self.context)
for key in list(ctx):
del ctx[key]

def load(self, config):
# Remove all existing items
removeSecurityProxy(self.context).__init__()
self.clearContext()
# Load one item at a time.
for section in config.sections():
if not section.startswith(self.section_prefix):
Expand Down
4 changes: 4 additions & 0 deletions src/cipher/configstore/configstore.txt
Expand Up @@ -200,10 +200,14 @@ Let's say a person has a collection of phone numbers:

>>> class PhoneNumbers(dict):
... zope.interface.implements(IPhoneNumbers)
... def __init__(self):
... print "Initializing PhoneNumbers"
... super(PhoneNumbers, self).__init__()
... def __repr__(self):
... return '<%s %i>' %(self.__class__.__name__, len(self))

>>> numbers = PhoneNumbers()
Initializing PhoneNumbers
>>> numbers['home'] = PhoneNumber(u'home', u'555-111-2222')
>>> numbers['work'] = PhoneNumber(u'work', u'555-333-4444')

Expand Down

0 comments on commit 30f54de

Please sign in to comment.